Select the correct option to test your answer:
Computer
Dynamic Programming In Data Structures
Difficulty: Medium
What is the time complexity of the following recursive implementation? #include<stdio.h> #include<limits.h> int max_of_two(int a, int b) { if(a > b) return a; return b; } int rod_cut(int *prices, int len) { int max_price = INT_MIN; // INT_MIN is the min value an integer can take int i; if(len <= 0 ) return 0; for(i = 0; i < len; i++) // subtract 1 because index starts from 0 max_price = max_of_two(max_price, prices[i] + rod_cut(prices,len - i - 1)); return max_price; } int main() { int prices[]={2, 5, 6, 9, 9, 17, 17, 18, 20, 22},len_of_rod = 10; int ans = rod_cut(prices, len_of_rod); printf("%d",ans); return 0; }
More Computer Questions
Which attribute uniquely identification element?
What will be the output of the following C++ code? #include <iostream> using namespace std; int operate (int a, int b) { return (a * b); } float operate (float a, float b) { return (a / b); } int main() { int x = 5, y = 2; float n = 5.0, m = 2.0; cout << operate(x, y) <<"\t"; cout << operate (n, m); return 0; }
What is the result of the expression 8 % 4 in C?
What is the purpose of an event in GUI programming?
Which data structure is used for maintaining a time-stamped log of events for rollback operations?