GATE CS Searching, Sorting, Hashing questions
Practise Searching, Sorting, Hashing questions for GATE CS. Explore official PYQs and original topic-wise quizzes, check answers and view available solutions. Free, no sign-in.
Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.
20 on this page
An array of distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to decimal places) is ________
Let be an array of numbers consisting of a sequence of 's followed by a sequence of 's. The problem is to find the smallest index such that is by probing the minimum number of locations in . The worst case number of probes performed by an optimal algorithm is ____________.
The worst case running times of Insertion sort , Merge sort and Quick sort, respectively are:
Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in the ascending order, which of the following are TRUE? Quicksort runs in time Bubblesort runs in time Mergesort runs in time Insertion sort runs in time
Which one of the following is the recurrence equation for the worst case time complexity of the quick sort algorithm for sorting numbers? In the recurrence equations given in the options below, is a constant.
Suppose you are provided with the following function declaration in the C programming language. int partition(int a[], int n); The function treats the first element of as a pivot and rearranges the array so that all elements less than or equal to the pivot is in the left part of the array, and all elements greater than the pivot is in the right …
Assume that a mergesort algorithm in the worst case takes seconds for an input of size . Which of the following most closely approximates the maximum input size of a problem that can be solved in minutes?
The minimum number of comparisons required to find the minimum and the maximum of numbers is ________
Let be quicksort program to sort numbers in ascending order using the first element as the pivot. Let and be the number of comparisons made by P for the inputs and respectively. Which one of the following holds?
Suppose are sorted sequences having lengths respectively. They are to be merged into a single sequence by merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is ____.
You have an array of 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
The number of elements that can be sorted in time using heap sort is
Which one of the following is the tightest upper bound that represents the number of swaps required to sort numbers using selection sort?
A list of strings, each of length , is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is
In quick-sort, for sorting elements, the smallest element is selected as pivot using an time algorithm. What is the worst case time complexity of the quick sort?
What is the number of swaps required to sort elements using selection sort, in the worst case?
Consider the following C program that attempts to locate an element in an array using binary search. The program is erroneous. f (int Y[10] , int x) { int i, j, k; i= 0; j = 9; do { k = (i + j) / 2; if( Y[k] < x) i = k;else j = k; } while (Y[k] != x) && (i < j)) ; if(Y[k] == x) printf(" x is in the array ") ; else printf(" x is …
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 be the number of comparisons required to sort elements. Then
Consider the following C program that attempts to locate an element in an array using binary search. The program is erroneous. f (int Y[10] , int x) { int i, j, k; i= 0; j = 9; do { k = (i+ j) / 2; if( Y[k] < x) i = k;else j = k; } while (Y[k] != x) && (i < j)) ; if(Y[k] == x) printf(" x is in the array ") ; else printf(" x is …
Which of the following sorting algorithms has the lowest worse-case complexity?
