Design & Analysis of Algorithms
105402Module 1: Introduction and Complexity Analysis
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
View this question on its own page →In the following C++ function, let .
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 ?
- (i)
- (ii)
- (iii)
- (iv)
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
View this question on its own page →Any decision trees that sorts elements has height:
- (i)
- (ii)
- (iii)
- (iv)
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
View this question on its own page →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
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
View this question on its own page →Any decision tree that sorts elements has height:
- (i)
- (ii)
- (iii)
- (iv)
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
View this question on its own page →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
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
View this question on its own page →What is the minimum number of stacks of size required to implement a queue of size
- (i) one
- (ii) two
- (iii) three
- (iv) four
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
View this question on its own page →Given an unsorted array. The array has this property that every element in array is at most distance from its position in sorted array where 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
- (ii) Heap sort with time complexity
- (iii) Quick sort with time complexity
- (iv) Merge sort with time complexity
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
View this question on its own page →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
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
View this question on its own page →An algorithm is made up of two independent time complexities and . Then the complexity of the algorithm is in order of:
- (i)
- (ii)
- (iii)
- (iv)
Q2a. Define Asymptotic Notation. Show that n^2 + 3\log n = O(n^2)20247m
Module 1: Introduction and Complexity Analysis
View this question on its own page →Define Asymptotic Notation. Show that
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q2a. Discuss the average, worst, and best time complexity of the algorithm. Give suitable examples.20237m
Module 1: Introduction and Complexity Analysis
View this question on its own page →Discuss the average, worst, and best time complexity of the algorithm. Give suitable examples.
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
View this question on its own page →Calculate the time complexity of the following problem using divide and conquer strategies:
(i)
(ii)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
View this question on its own page →Discuss the steps in mathematical analysis for recursive algorithm. Do the same for finding the factorial of a number?
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
View this question on its own page →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"); } }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
View this question on its own page →What are the rules of manipulate Big-Oh expression? Write about the typical growth rates of algorithms.
Q2b. Solve the recurrence relation T(n) = 2T(n/2) + O(n)20247m
Module 1: Introduction and Complexity Analysis
View this question on its own page →Solve the recurrence relation
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
View this question on its own page →What are the rules of manipulate Big-Oh expression and about the typical growth rates of algorithms.
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
View this question on its own page →Prove that if and , then .
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
View this question on its own page →State Master's theorem and find the time complexity for the following recurrence:
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
View this question on its own page →Explain how radix sort works, to what inputs it can be applied and what is its asymptotic complexity?
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q9a. Write short notes on: Asymptotic notations20237m
Module 1: Introduction and Complexity Analysis
View this question on its own page →Write short notes on: Asymptotic notations
Q9c. Write short notes on: Amortized analysis.20197m
Module 1: Introduction and Complexity Analysis
View this question on its own page →Write short notes on: Amortized analysis.
Q9d. Write short notes on: Masters theorem20247m
Module 1: Introduction and Complexity Analysis
View this question on its own page →Write short notes on: Masters theorem