Question
#include<stdio.h>
int longest_inc_sub(int *arr, int len)
{
int i, j, tmp_max;
int LIS[len]; // array to store the lengths of the longest increasing subsequence
LIS[0]=1;
for(i = 1; i < len; i++)
{
tmp_max = 0;
for(j = 0; j < i; j++)
{
if(arr[j] < arr[i])
{
if(LIS[j] > tmp_max)
tmp_max = LIS[j];
}
}
LIS[i] = tmp_max + 1;
}
int max = LIS[0];
for(i = 0; i < len; i++)
if(LIS[i] > max)
max = LIS[i];
return max;
}
int main()
{
int arr[] = {10,22,9,33,21,50,41,60,80}, len = 9;
int ans = longest_inc_sub(arr, len);
printf("%d",ans);
return 0;
}
a.
2
b.
3
c.
4
d.
5
Posted under Data Structures and Algorithms
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the value stored in LIS[5] after the following program is executed?
Similar Questions
Discover Related MCQs
Q. Given a rod of length n and the selling prices of all pieces smaller than equal to n, find the most beneficial way of cutting the rod into smaller pieces. This problem is called the rod cutting problem. Which of these methods can be used to solve the rod cutting problem?
View solution
Q. You are given a rod of length 5 and the prices of each length are as follows:
length price
1 2
2 5
3 6
4 9
5 9
What is the maximum value that you can get after cutting the rod and selling the pieces?
View solution
Q. Consider the brute force implementation of the rod cutting problem in which all the possible cuts are found and the maximum value is calculated. What is the time complexity of this brute force implementation?
View solution
Q. You are given a rod of length 10 and the following prices.
length price
1 2
2 5
3 6
4 9
5 9
6 17
7 17
8 18
9 20
10 22
Which of these pieces give the maximum price?
View solution
Q. For every rod cutting problem there will be a unique set of pieces that give the maximum price.
View solution
Q. You are given an array of elements where each array element represents the MAXIMUM number of jumps that can be made in the forward direction from that element. You have to find the minimum number of jumps that are required to reach the end of the array. Which of these methods can be used to solve the problem?
View solution
Q. Consider the following array:
{1, 3, 5, 8, 9, 2, 6, 7, 6}
What is the minimum number of jumps required to reach the end of the array?
View solution
Q. For a given array, there can be multiple ways to reach the end of the array using minimum number of jumps.
View solution
Q. For any array, given that at most one element is non-zero, it is ALWAYS possible to reach the end of the array using minimum jumps.
View solution
Q. The Knapsack problem is an example of ____________
View solution
Q. Which of the following methods can be used to solve the Knapsack problem?
View solution
Q. You are given a knapsack that can carry a maximum weight of 60. There are 4 items with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the items you can carry using the knapsack?
View solution
Q. Which of the following problems is equivalent to the 0-1 Knapsack problem?
View solution
Q. What is the time complexity of the brute force algorithm used to solve the Knapsack problem?
View solution
Q. The 0-1 Knapsack problem can be solved using Greedy algorithm.
View solution
Q. Which of the following methods can be used to solve the matrix chain multiplication problem?
View solution
Q. Which of the following is the recurrence relation for the matrix chain multiplication problem where mat[i-1] * mat[i] gives the dimension of the ith matrix?
View solution
Q. Consider the two matrices P and Q which are 10 x 20 and 20 x 30 matrices respectively. What is the number of multiplications required to multiply the two matrices?
View solution
Q. Consider the matrices P, Q and R which are 10 x 20, 20 x 30 and 30 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the three matrices?
View solution
Q. Consider the matrices P, Q, R and S which are 20 x 15, 15 x 30, 30 x 5 and 5 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the four matrices?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!