Searching and Sorting · Algorithms · GATE CSE

Start Practice

Marks 1

1

Let $A$ be an array containing integer values. The distance of $A$ is defined as the minimum number of elements in $A$ that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array [2, 5, 3, 1, 4, 2, 6] is __________

GATE CSE 2024 Set 2
2

Consider the following array.

23

32

45

69

72

73

89

97


Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort above array in ascending order?
GATE CSE 2021 Set 1
3
An array of 25 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 2 decimal places) is ______.
GATE CSE 2019
4
The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
GATE CSE 2016 Set 1
5
Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the following are TRUE?

$$\,\,\,\,\,\,\,{\rm I}.\,\,\,\,\,\,\,$$ Quicksort runs in $$\Theta \left( {{n^2}} \right)$$ time
$$\,\,\,\,\,{\rm I}{\rm I}.\,\,\,\,\,\,\,$$ Bubblesort runs in $$\Theta \left( {{n^2}} \right)$$ time
$$\,\,\,{\rm I}{\rm I}{\rm I}.\,\,\,\,\,\,\,$$ Mergesort runs in $$\Theta \left( n \right)$$ time
$$\,\,\,{\rm I}V.\,\,\,\,\,\,\,$$ Insertion sort runs in $$\Theta \left( n \right)$$ time

GATE CSE 2016 Set 2
6
Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting n ( $$ \ge 2$$ ) numbers? In the recurrence equations given in the options below, c is a constant.
GATE CSE 2015 Set 1
7
Consider the following array of elements.

$$\,\,\,\,\,\,\,\,$$$$〈89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100〉$$

The minimum number of interchanges needed to convert it into a max-heap is
GATE CSE 2015 Set 3
8
An unordered list contains $$n$$ distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum is
GATE CSE 2015 Set 2
9
A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is: 10, 8, 5, 3, 2. Two new elements 1 and 7 are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
GATE CSE 2014 Set 2
10
A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?
GATE CSE 2011
11
What is the number of swaps required to sort n elements using selection sort, in the worst case?
GATE CSE 2009
12
The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is GATE CSE 2008 Algorithms - Searching and Sorting Question 35 English
GATE CSE 2008
13
The most efficient algorithm for finding the number of connected components in an undirected graph on n vertices and m edges has time complexity
GATE CSE 2008
14
Which of the following sorting algorithms has the lowest worst-case complexity?
GATE CSE 2007
15
Consider the DAG with $$V = \{1,2,3,4,5,6\}$$, shown below. GATE CSE 2007 Algorithms - Searching and Sorting Question 38 English Which of the following is NOT a topological ordering?
GATE CSE 2007
16
An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array
GATE CSE 2006
17
In a binary max heap containing n numbers, the smallest element can be found in time
GATE CSE 2006
18
Which one of the following in place sorting algorithms needs the minimum number of swaps?
GATE CSE 2006
19
The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is of the order of
GATE CSE 2004
20
In a heap with n elements with the smallest element at the root, the 7th smallest element can be found in time
GATE CSE 2003
21
Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array $$\left( {i \le n} \right)$$, the index of the parent is
GATE CSE 2001
22
Suppose we want to arrange the n numbers stored in any array such that all negative values occur before all positive ones. Minimum number of exchanges required in the worst case is
GATE CSE 1999
23
The number of articulation points of the following graph is GATE CSE 1999 Algorithms - Searching and Sorting Question 45 English
GATE CSE 1999
24

Give the correct matching for the following pairs:

Group - 1

(A) $${\rm O}(\log n)$$
(B) $${\rm O}(n)$$
(C) $${\rm O}(n\log n)$$
(D) $${\rm O}({n^2})$$

Group - 2

(P) Selection
(Q) Insertion sort
(R) Binary search
(S) Merge sort
GATE CSE 1998
25
The correct matching for the following pairs is
A. All pairs shortest path 1. Greedy
B. Quick Sort 2. Depth-First Search
C. Minimum weight spanning tree 3. Dynamic Programming
D. Connected Components 4. Divide and Conquer
GATE CSE 1997

Marks 2

1
An operator $$delete(i)$$ for a binary heap data structure is to be designed to delete the item in the $$i$$-th node. Assume that the heap is implemented in an array and i refers to the $$i$$-th index of the array. If the heap tree has depth $$d$$ (number of edges on the path from the root to the farthest leaf), then what is the time complexity to re-fix the heap efficiently after the removal of the element?
GATE CSE 2016 Set 1
2
A complete binary min-heap is made by including each integer in $$[1,1023]$$ exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is at depth $$0.$$ The maximum depth at which integer $$9$$ can appear is ___________.
GATE CSE 2016 Set 2
3
Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4.
Array Index 1 2 3 4 5 6 7 8 9
Value 40 30 20 10 15 16 17 8 4

Now consider that a value 35 is inserted into this heap. After insertion, the new heap is

GATE CSE 2015 Set 1
4
Assume that a mergesort 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?
GATE CSE 2015 Set 3
5
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 a[ ] 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 part. In addition, it moves the pivot so that the pivot is the last element of the left part. The return value is the number of elements in the left part. The following partially given function in the C programming language is used to find the kth smallest element in an array a[ ] of size n using the partition function. We assume k≤n.
int kth_smallest (int a[], int n, int k)
{
    int left_end = partition (a, n);
    if (left_end+1==k) {
        return a[left_end];
    }
    if (left_end+1 > k) {
        return kth_smallest (___________);
    } else {
        return kth_smallest (___________);   
    }
}
The missing arguments lists are respectively
GATE CSE 2015 Set 2
6
Consider a binary max-heap implemented using an array. Which one of the following array represents a binary max-heap?
GATE CSE 2009
7
Consider a binary max-heap implemented using an array. What is the content of the array {25, 14, 16, 13, 10, 8, 12} after two delete operations?
GATE CSE 2009
8
We have a binary heap on n elements and wish to insert n more elements (not necessarily one after another) into this heap. The total time required for this is
GATE CSE 2008
9
Consider the process of inserting an element into a Max Heap, where the Max Heap is represented by an array. Suppose we perform a binary search on the path from the new leaf to the root to find the position for the newly inserted element, the number of comparisons performed is:
GATE CSE 2007
10

A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], nodes in the next level, from left to right, is stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property.

Suppose the elements 7, 2, 10 and 4 are inserted, in that order, into the valid 3- ary max heap found in the previous question. Which one of the following is the sequence of items in the array representing the resultant heap?

GATE CSE 2006
11

A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], nodes in the next level, from left to right, is stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property.

Which one of the following is a valid sequence of elements in an array representing 3-ary max heap?

GATE CSE 2006
12
Given two arrays of numbers a1,......,an and b1,......, bn where each number is 0 or 1, the fastest algorithm to find the largest span (i, j) such that ai+ai+1......aj = bi+bi+1......bj or report that there is not such span,
GATE CSE 2006
13
Let G(V, E) an undirected graph with positive edge weights. Dijkstra's single-source shortest path algorithm can be implemented using the binary heap data structure with time complexity:
GATE CSE 2005
14
Suppose there are $$\lceil \log n \rceil$$ sorted lists of $$\left\lfloor {{n \over {\log n}}} \right\rfloor $$ elements each. The time complexity of producing a sorted list of all these elements is :
(Hint : Use a heap data structure)
GATE CSE 2005
15
The elements 32, 15, 20, 30, 12, 25, 16, are inserted one by one in the given order into a max Heap. The resultant max Heap is
GATE CSE 2004
16
If T1 = O(1), give the correct matching for the following pairs:

List - I

(M) Tn = Tn - 1 + n
(N) Tn = Tn/2 + n
(O) Tn = Tn/2 + nlog n
(P) Tn = Tn - 1 + log n

List - II

(U) Tn= O(n)
(V) Tn = O(nlogn)
(W) Tn = O(n2)
(X) Tn = O(log2n)
GATE CSE 1999
17
The average number of key comparisons done on a successful sequential search in list of length n is
GATE CSE 1996
18
The minimum number of interchanges needed to convert the array

89, 19, 40, 17, 12, 10, 2, 5, 7, 11, 6, 9, 70

into a heap with the maximum element at the root is
GATE CSE 1996
19
Which one of the following statements is false?
GATE CSE 1994
20
Following algorithm(s) can be used to sort n integers in the range [1....... n3] in O(n) time
GATE CSE 1992
21
Minimum number of comparisons required to sort 5 elements
GATE CSE 1991
22
Match the pairs in the following:

List - I

(a) Heap construction
(b) Constructing hash table witn linear probing
(c) AVL Tree construction
(d) Digital tree construction

List - II

(p) $$\Omega \left( {n\log _{10}^n} \right)$$
(q) O(n)
(r) O(n2)
(s) $$\Omega \left( {n\log _2^n} \right)$$
GATE CSE 1990
23
Match the pairs in the following:

List - I

(a) Straseen's matrix multiplication algorithm
(b) Kruskal's minimum spanning tree algorithm
(c) Bioconnected components algorithm
(d) Floyd's shortest path algorithm

List - II

(p) Greedy method
(q) Dynamic programming
(r) Divide and Conquer
(s) Depth first search
GATE CSE 1990
EXAM MAP
Medical
NEETAIIMS
Graduate Aptitude Test in Engineering
GATE CSEGATE ECEGATE EEGATE MEGATE CEGATE PIGATE IN
Civil Services
UPSC Civil Service
Defence
NDA
Staff Selection Commission
SSC CGL Tier I
CBSE
Class 12