Design & Analysis of Algorithms

105402
Back to Design & Analysis of Algorithms

Module 1: Introduction and Complexity Analysis

  1. Q1a. In the following C++ function, let n >= m. ``cpp int gcd(int n, int m) { if (n % m == 0) return m; if (n < m) swap(n, m); while (m > 0) { n = n % m; swap(n, m); } return n; } `` What is the time complexity of the above function assuming n > m? - (i) \Theta(\log n) - (ii) \Omega(n) - (iii) \Theta(\log \log n) - (iv) \Theta(\sqrt{n})20192m

    Module 1: Introduction and Complexity Analysis

    In the following C++ function, let n>=mn >= m.

    int gcd(int n, int m) {
      if (n % m == 0) return m;
      if (n < m) swap(n, m);
      while (m > 0) {
        n = n % m;
        swap(n, m);
      }
      return n;
    }
    

    What is the time complexity of the above function assuming n>mn > m?

    • (i) Θ(logn)\Theta(\log n)
    • (ii) Ω(n)\Omega(n)
    • (iii) Θ(loglogn)\Theta(\log \log n)
    • (iv) Θ(n)\Theta(\sqrt{n})
    View this question on its own page →
  2. Q1a. Any decision trees that sorts n elements has height: - (i) \Omega(\lg n) - (ii) \Omega(n) - (iii) \Omega(n \lg n) - (iv) \Omega(n^2)20222m

    Module 1: Introduction and Complexity Analysis

    Any decision trees that sorts nn elements has height:

    • (i) Ω(lgn)\Omega(\lg n)
    • (ii) Ω(n)\Omega(n)
    • (iii) Ω(nlgn)\Omega(n \lg n)
    • (iv) Ω(n2)\Omega(n^2)
    View this question on its own page →
  3. Q1b. Which of the following is an application of Queue Data Structure? - (i) When a resource is shared among multiple consumers - (ii) When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes - (iii) Load balancing - (iv) All of the above20222m

    Module 1: Introduction and Complexity Analysis

    Which of the following is an application of Queue Data Structure?

    • (i) When a resource is shared among multiple consumers
    • (ii) When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes
    • (iii) Load balancing
    • (iv) All of the above
    View this question on its own page →
  4. Q1d. In linear search algorithm the worst case occurs when: - (i) the item is somewhere in the middle of the array - (ii) the item is not in the array at all - (iii) the item is the last element in the array - (iv) the item is the last element in the array or is not there at all20222m

    Module 1: Introduction and Complexity Analysis

    In linear search algorithm the worst case occurs when:

    • (i) the item is somewhere in the middle of the array
    • (ii) the item is not in the array at all
    • (iii) the item is the last element in the array
    • (iv) the item is the last element in the array or is not there at all
    View this question on its own page →
  5. Q1d. Any decision tree that sorts n elements has height: - (i) \Omega(\lg n) - (ii) \Omega(n) - (iii) \Omega(n \lg n) - (iv) \Omega(n^2)20192m

    Module 1: Introduction and Complexity Analysis

    Any decision tree that sorts nn elements has height:

    • (i) Ω(lgn)\Omega(\lg n)
    • (ii) Ω(n)\Omega(n)
    • (iii) Ω(nlgn)\Omega(n \lg n)
    • (iv) Ω(n2)\Omega(n^2)
    View this question on its own page →
  6. Q1e. What is the minimum number of stacks of size n required to implement a queue of size n - (i) one - (ii) two - (iii) three - (iv) four20242m

    Module 1: Introduction and Complexity Analysis

    What is the minimum number of stacks of size nn required to implement a queue of size nn

    • (i) one
    • (ii) two
    • (iii) three
    • (iv) four
    View this question on its own page →
  7. Q1e. Given an unsorted array. The array has this property that every element in array is at most k distance from its position in sorted array where k is a positive integer smaller than size of array. Which sorting algorithm can be easily modified for sorting this array and what is the obtainable time complexity? - (i) Insertion sort with time complexity O(kn) - (ii) Heap sort with time complexity O(n \log k) - (iii) Quick sort with time complexity O(k \log k) - (iv) Merge sort with time complexity O(k \log k)20222m

    Module 1: Introduction and Complexity Analysis

    Given an unsorted array. The array has this property that every element in array is at most kk distance from its position in sorted array where kk is a positive integer smaller than size of array. Which sorting algorithm can be easily modified for sorting this array and what is the obtainable time complexity?

    • (i) Insertion sort with time complexity O(kn)O(kn)
    • (ii) Heap sort with time complexity O(nlogk)O(n \log k)
    • (iii) Quick sort with time complexity O(klogk)O(k \log k)
    • (iv) Merge sort with time complexity O(klogk)O(k \log k)
    View this question on its own page →
  8. Q1h. An algorithm is made up of two independent time complexities f(n) and g(n). Then the complexity of the algorithm is in order of: - (i) f(n) \times g(n) - (ii) \max(f(n), g(n)) - (iii) \min(f(n), g(n)) - (iv) f(n) + g(n)20232m

    Module 1: Introduction and Complexity Analysis

    An algorithm is made up of two independent time complexities f(n)f(n) and g(n)g(n). Then the complexity of the algorithm is in order of:

    • (i) f(n)×g(n)f(n) \times g(n)
    • (ii) max(f(n),g(n))\max(f(n), g(n))
    • (iii) min(f(n),g(n))\min(f(n), g(n))
    • (iv) f(n)+g(n)f(n) + g(n)
    View this question on its own page →
  9. Q1h. Which one of the following is an application of Queue Data Structure? - (i) When a resource is shared among multiple consumers - (ii) When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes - (iii) Load balancing - (iv) All of the above20192m

    Module 1: Introduction and Complexity Analysis

    Which one of the following is an application of Queue Data Structure?

    • (i) When a resource is shared among multiple consumers
    • (ii) When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes
    • (iii) Load balancing
    • (iv) All of the above
    View this question on its own page →
  10. Q2a. Calculate the time complexity of the following problem using divide and conquer strategies: (i) T(n) = \sqrt{n} \cdot T(\sqrt{n}) + n, \quad n > 2 (ii) T(n) = T(n-1) + 1/n, \quad n > 120227m

    Module 1: Introduction and Complexity Analysis

    Calculate the time complexity of the following problem using divide and conquer strategies:
    (i) T(n)=nT(n)+n,n>2T(n) = \sqrt{n} \cdot T(\sqrt{n}) + n, \quad n > 2
    (ii) T(n)=T(n1)+1/n,n>1T(n) = T(n-1) + 1/n, \quad n > 1

    View this question on its own page →
  11. Q2a. Discuss the steps in mathematical analysis for recursive algorithm. Do the same for finding the factorial of a number?20197m

    Module 1: Introduction and Complexity Analysis

    Discuss the steps in mathematical analysis for recursive algorithm. Do the same for finding the factorial of a number?

    View this question on its own page →
  12. Q2a. Define Asymptotic Notation. Show that n^2 + 3\log n = O(n^2)20247m

    Module 1: Introduction and Complexity Analysis

    Define Asymptotic Notation. Show that n2+3logn=O(n2)n^2 + 3\log n = O(n^2)

    View this question on its own page →
  13. Q2a. Discuss the average, worst, and best time complexity of the algorithm. Give suitable examples.20237m

    Module 1: Introduction and Complexity Analysis

    Discuss the average, worst, and best time complexity of the algorithm. Give suitable examples.

    View this question on its own page →
  14. Q2b. Solve the recurrence relation T(n) = 2T(n/2) + O(n)20247m

    Module 1: Introduction and Complexity Analysis

    Solve the recurrence relation T(n)=2T(n/2)+O(n)T(n) = 2T(n/2) + O(n)

    View this question on its own page →
  15. Q2b. Write time function and calculate the time complexity, space complexity and number of function calls of the following pseudocode using substitution method: ``c rec(n) { if (n <= 1) return(1); else { rec(n / 2); for (i = 1; i <= n; i++) printf("algorithm"); } } ``20227m

    Module 1: Introduction and Complexity Analysis

    Write time function and calculate the time complexity, space complexity and number of function calls of the following pseudocode using substitution method:

    rec(n) {
        if (n <= 1) return(1);
        else {
            rec(n / 2);
            for (i = 1; i <= n; i++)
                printf("algorithm");
        }
    }
    
    View this question on its own page →
  16. Q2b. What are the rules of manipulate Big-Oh expression? Write about the typical growth rates of algorithms.20197m

    Module 1: Introduction and Complexity Analysis

    What are the rules of manipulate Big-Oh expression? Write about the typical growth rates of algorithms.

    View this question on its own page →
  17. Q3b. What are the rules of manipulate Big-Oh expression and about the typical growth rates of algorithms.20227m

    Module 1: Introduction and Complexity Analysis

    What are the rules of manipulate Big-Oh expression and about the typical growth rates of algorithms.

    View this question on its own page →
  18. Q4. Prove that if f_1(n) = O(g_1(n)) and f_2(n) = O(g_2(n)), then f_1(n) + f_2(n) = O(g_1(n) + g_2(n)).201914m

    Module 1: Introduction and Complexity Analysis

    Prove that if f1(n)=O(g1(n))f_1(n) = O(g_1(n)) and f2(n)=O(g2(n))f_2(n) = O(g_2(n)), then f1(n)+f2(n)=O(g1(n)+g2(n))f_1(n) + f_2(n) = O(g_1(n) + g_2(n)).

    View this question on its own page →
  19. Q4a. State Master's theorem and find the time complexity for the following recurrence: T(n) = 2T(n^{1/2}) + \log n20237m

    Module 1: Introduction and Complexity Analysis

    State Master's theorem and find the time complexity for the following recurrence: T(n)=2T(n1/2)+lognT(n) = 2T(n^{1/2}) + \log n

    View this question on its own page →
  20. Q4b. Explain how radix sort works, to what inputs it can be applied and what is its asymptotic complexity?20227m

    Module 1: Introduction and Complexity Analysis

    Explain how radix sort works, to what inputs it can be applied and what is its asymptotic complexity?

    View this question on its own page →
  21. Q9a. Write short notes on: Asymptotic notations20237m

    Module 1: Introduction and Complexity Analysis

    Write short notes on: Asymptotic notations

    View this question on its own page →
  22. Q9c. Write short notes on: Amortized analysis.20197m

    Module 1: Introduction and Complexity Analysis

    Write short notes on: Amortized analysis.

    View this question on its own page →
  23. Q9d. Write short notes on: Masters theorem20247m

    Module 1: Introduction and Complexity Analysis

    Write short notes on: Masters theorem

    View this question on its own page →