Write a function lis_rec(arr) that outputs the length of the longest increasing sequence and the actual longest increasing sequence. This function should use divide and conquer strategy to the solve the problem, by using an auxiliary function that is recursive. For example, one possibility is to define a recursive function, lis_rec(arr, i, prev), that takes the array arr, an index i, and the previous element index prev of LIS (which is part of the array arr before index i), and returns the length of the LIS that can be obtained by considering the subarray arr[i:]. Write a dynamic programming version ofthe function, lis_dp(arr), that outputs the length of the longest increasing sequence and the actual longest increasing sequence by using a table to store the results of subproblems in a bottom-up manner. Test the performance of the two functions on arrays of length n = 100, 500, 1000, 5000, 10000. Compare the running times and memory usage of the two functions.
Write a function lis_rec(arr) that outputs the length of the longest increasing sequence and the actual longest increasing sequence. This function should use divide and conquer strategy to the solve the problem, by using an auxiliary function that is recursive. For example, one possibility is to define a recursive function, lis_rec(arr, i, prev), that takes the array arr, an index i, and the previous element index prev of LIS (which is part of the array arr before index i), and returns the length of the LIS that can be obtained by considering the subarray arr[i:]. Write a dynamic
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images