


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
PRACTICE QUESTIONS ON Data structures and algorithm
Typology: Exercises
1 / 4
This page cannot be seen from the preview
Don't miss anything!
1. Assume that a merge sort algorithm in the worst case takes 30 seconds for an input of size 64. Which of the following most closely approximates the maximum input size of a problem that can be solved in 6 minutes?
A. 256 B. 512 C. 1024 D. 2048
2. Which one of the following is the recurrence equation for the worst case time complexity of the Quick sort algorithm for sorting n(≥ 2) numbers? In the recurrence equations given in the options below, c is a constant.
A. T(n) = 2T (n/2) + cn B. T(n) = T(n – 1) + T(0) + cn C. T(n) = 2T (n – 2) + cn D. T(n) = T(n/2) + cn
3. Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quicksort?
A. O(n) B. O(n Log n)
C. O(n^2 ) D. O(n!)
4. In a permutation a1…..an of n distinct integers, an inversion is a pair (ai, aj) such that i < j and ai > aj. What would be the worst case time complexity of the Insertion Sort algorithm, if the inputs are restricted to permutations of 1…..n with at most n inversions?
A. Θ (n2) B. Θ (n log n) C. Θ (n^1 .5) D. Θ (n)
5. You have an array of n elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is—
A. O(n^2 ) B. O(n Log n) C. Theta(n Log n) D. O(n^3 )
6. Let P be a Quicksort Program to sort numbers in ascending order using the first element as pivot. Let t 1 and t 2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds?
A. t 1 = 5 B. t 1 < t 2 C. t 1 > t 2 D. t 1 = t 2
7. Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then—
A. T(n) <= 2T(n/5) + n B. T(n) <= T(n/5) + T(4n/5) + n C. T(n) <= 2T(4n/5) + n D. T(n) <= 2T(n/2) + n
8. In quick sort, for sorting n elements, the (n/4)th^ smallest element is selected as pivot using an O(n) time algorithm. What is the worst case time complexity of the quick sort?
(A) theta(n) (B) theta(nLog n) (C) theta(n^2) (D) theta(n^2 log n)
A. (A) B. (B) C. (C) D. (D)
9. Given an array where numbers are in range from 1 to n^6 , which sorting algorithm can be used to sort these number in linear time?
A. Not possible to sort in linear time B. Radix Sort C. Counting Sort D. Quick Sort
10. Which of the following is true about merge sort?
A. Merge sort works better than quick sort if data is accessed from slow sequential memory B. Merge Sort is stable sort by nature C. Merge sort outperforms heap sort in most of the practical situations
16. Partition and exchange sort is ........
A. quick sort B. tree sort C. heap sort D. bubble sort
17. Which of the following is an external sorting?
A. Insertion sort B. Bubble sort C. Merge sort D. Tree sort
18. Very slow way of sorting is—
A. Insertion sort B. Heap sort C. Bubble sort D. Quick sort