Question

In: Computer Science

What is the auxiliary space and space complexity for a dynamic programming algorithm with time complexity...

What is the auxiliary space and space complexity for a dynamic programming algorithm with time complexity of O(n^2)? Justify.

Solutions

Expert Solution

Auxiliary Space complexity of dynamic pragraming :-

  • Auxilary space complexity of algoritham is the extra space or temporary space used by algoritham during its execution .
  • Think temporary arrays , pointer etc.
  • The temporary space is allocated in order to solve problem .
  • For example :- merge sort uses new array to solve to solve problem so it has auxilary space complexity is O(n), where has Quick sort does not uses extra space so auxilary space is O(1).
  • With respect to time complexity O( n^2 ) then Auxilary time complexity is O(n) .
  • int count = 0;
    for (int i = N; i > 0; i /= 2) 
        for (int j = 0; j < i; j++) 
            count++;

    Because auxilary space require extra space .

Space Complexity of dynamic programing :-

  • Space complexity is total space taken by algoritham with respect to input size .
  • space complexity = Auxilary space complexity + space used by input value .
  • with respect to time complexity O(n^2) the space complexity is O(n).
  •  for(i = 0; i < n; i++)
      {
        for (j=i+1; j<=n;j++)
        {
        sum = arr[j] + arr[i];
         }
      }

Related Solutions

what is the time complexity of the edit distance ("ALASKA" vs "ALABAMA" example) dynamic programming algorithm?...
what is the time complexity of the edit distance ("ALASKA" vs "ALABAMA" example) dynamic programming algorithm? what is the space complexity of the edit distance ("ALASKA" vs "ALABAMA" example) dynamic programming algorithm?
What is the Average time complexity of sequential search algorithm in a linked list?
What is the Average time complexity of sequential search algorithm in a linked list?
What is the time complexity of my algorithm? It uses an vector E that contains and...
What is the time complexity of my algorithm? It uses an vector E that contains and object made of a string and an integer. It takes an empty vector as parameter and returns the vector with the top three integers from the objects in E . void Trendtracker::top_three_trends(vector<string> &T) {    T.clear();    if (E.size() == 0) {        return;    }    if (E.size() == 1) {        T.push_back(E[0].hashtag);    }    else if (E.size() == 2)...
Please explain what we mean by Time Complexity and Space Complexity. Please provide a short survey...
Please explain what we mean by Time Complexity and Space Complexity. Please provide a short survey of Complexity classes.
Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the...
Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the 0-1 Knapsack problem is in Ω(2n). Do this by considering the instance in which W = 2n −2 and wi = 2i−1 for 1 ≤ i ≤ n. Please answer with clear explanations!!! Excerpt From: Richard Neapolitan. “Foundations of Algorithms.”
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, ....
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, . . . , n] of positive integers, an integer K. Decide: Are there integers in A such that their sum is K. (Return T RUE or F ALSE) Example: The answer is TRUE for the array A = [1, 2, 3] and 5, since 2 + 3 = 5. The answer is FALSE for A = [2, 3, 4] and 8. Note that you...
Problem 2. Purpose: practice algorithm design using dynamic programming. A subsequence is palindromic if it is...
Problem 2. Purpose: practice algorithm design using dynamic programming. A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence A,C,G,T,G,T,C,A,A,A,A,T,C,G has many palindromic subsequences, including A,C,G,C,A and A,A,A,A (on the other hand, the subsequence A,C,T is not palindromic). Assume you are given a sequence x[1...n] of characters. Denote L(i,j) the length of the longest palindrome in the substring x[i,...,j]. The goal of the Maximum Palindromic Subsequence Problem (MPSP)...
Build a Dynamic Programming algorithm in Python for the following problem. Given two sequences of vowels,...
Build a Dynamic Programming algorithm in Python for the following problem. Given two sequences of vowels, find the length of longest subsequence present in both of them. NOTE: A subsequence is a sequence that appears in the same order, but not necessarily contiguous. For example, “aei”, “aeo”, “eio”, “aiu”, ... are subsequences of “aeiou”. Sample Input 1: aeiou aiu Sample Output 1: 3 Sample Input 2: aeaiueoiuaeeoeooaauoi aeuioauuuoaeieeaueuiouaiieuiuuuaoueueauaeiauuo Sample Output 2: 16 Sample Input 3: iioioieiaiauaoeoiioiiue iuuueauiaieooaoaaouaaaae Sample Output 3:...
Recall the dynamic programming algorithm we saw in class for solving the 0/1 knapsack problem for...
Recall the dynamic programming algorithm we saw in class for solving the 0/1 knapsack problem for n objects with a knapsack capacity of K. In particular, we characterized our recurrence OPT(j, W) to be following quantity: OPT(j, W) := The maximum profit that can be obtained when selecting from objects 1, 2, . . . , j with a knapsack capacity of W , where (after filling in our dynamic programming table), we return the value stored at OPT(n, K)...
Using the dynamic programming-based algorithm for chain matrix multiplcation, show the best way to multiply a...
Using the dynamic programming-based algorithm for chain matrix multiplcation, show the best way to multiply a chain of matrices with dimensions that are: 10x5, 5x2, 2x20, 20x12, 12x4 and 4x60. Finally, use the resulting tables to provide the complete optimal parenthesization of the matrix chain product A0 · A1 · A2 · A3 · A4 · A5.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT