64
DEPARTMENT OF INFORMATION TECHNOLOGY 2020 2021 EVEN SEMESTER GATE BOOKLET DATA STRUCTURES & ALGORITHMS (Questions From 2000 To 2020) COMPILED BY Dr. P. Subathra, Prof./IT

DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

  • Upload
    others

  • View
    21

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

DEPARTMENT OF INFORMATION TECHNOLOGY

2020 – 2021 EVEN SEMESTER

GATE BOOKLET

DATA STRUCTURES

&

ALGORITHMS

(Questions From 2000 To 2020)

COMPILED BY

Dr. P. Subathra, Prof./IT

Page 2: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE SYLLABUS

CS Computer Science and Information Technology

Section1: Engineering Mathematics

Discrete Mathematics: Propositional and first order logic. Sets, relations, functions, partial orders and

lattices. Groups. Graphs: connectivity, matching, coloring. Combinatorics: counting, recurrence relations,

generating functions. Linear Algebra: Matrices, determinants, system of linear equations, eigenvalues and

eigenvectors, LU decomposition. Calculus: Limits, continuity and differentiability. Maxima and minima.

Mean value theorem. Integration. Probability: Random variables. Uniform, normal, exponential, poisson

and binomial distributions. Mean, median, mode and standard deviation. Conditional probability and

Bayes theorem.

Computer Science and Information Technology

Section 2: Digital Logic

Boolean algebra. Combinational and sequential circuits. Minimization. Number representations and

computer arithmetic (fixed and floating point).

Section 3: Computer Organization and Architecture

Machine instructions and addressing modes. ALU, data‐path and control unit. Instruction pipelining.

Memory hierarchy: cache, main memory and secondary storage; I/O interface (interrupt and DMA mode).

Section 4: Programming and Data Structures

Programming in C. Recursion. Arrays, Stacks, Queues, Linked Lists, Trees, Binary Search Trees,

Binary Heaps, Graphs.

Section 5: Algorithms

Searching, Sorting, Hashing. Asymptotic Worst Case Time and Space Complexity. Algorithm Design

Techniques: Greedy, Dynamic programming and Divide‐and‐Conquer. Graph Search, Minimum

Spanning Trees, Shortest Paths.

Section 6: Theory of Computation

Regular expressions and finite automata. Context-free grammars and push-down automata. Regular and

contex-free languages, pumping lemma. Turing machines and undecidability.

Section 7: Compiler Design

Lexical analysis, parsing, syntax-directed translation. Runtime environments. Intermediate code

generation.

Section 8: Operating System

Page 3: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

Processes, threads, inter‐process communication, concurrency and synchronization. Deadlock. CPU

scheduling. Memory management and virtual memory. File systems.

CS8391 DATA STRUCTURES

OBJECTIVES:

To understand the concepts of ADTs

To learn linear data structures – lists, stacks, and queues

To understand sorting, searching and hashing algorithms

To apply Tree and Graph structures

UNIT I LINEAR DATA STRUCTURES – LIST

Abstract Data Types (ADTs) – List ADT – array-based implementation – linked list implementation ––

singly linked lists- circularly linked lists- doubly-linked lists – applications of lists –Polynomial

Manipulation – All operations (Insertion, Deletion, Merge, Traversal).

UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES

Stack ADT – Operations - Applications - Evaluating arithmetic expressions- Conversion of Infix to

postfix expression - Queue ADT – Operations - Circular Queue – Priority Queue - deQueue –

applications of queues.

UNIT III NON LINEAR DATA STRUCTURES – TREES

Tree ADT – tree traversals - Binary Tree ADT – expression trees – applications of trees – binary search

tree ADT –Threaded Binary Trees- AVL Trees – B-Tree - B+ Tree - Heap – Applications of heap.

UNIT IV NON LINEAR DATA STRUCTURES - GRAPHS Definition –

Representation of Graph – Types of graph - Breadth-first traversal - Depth-first traversal – Topological

Sort – Bi-connectivity – Cut vertex – Euler circuits – Applications of graphs.

UNIT V SEARCHING, SORTING AND HASHING TECHNIQUES

Searching- Linear Search - Binary Search. Sorting - Bubble sort - Selection sort - Insertion sort - Shell

sort – Radix sort. Hashing- Hash Functions – Separate Chaining – Open Addressing – Rehashing –

Extendible Hashing.

OUTCOMES:

At the end of the course, the student should be able to:

Implement abstract data types for linear data structures

Apply the different linear and non-linear data structures to problem solutions

Critically analyze the various sorting algorithms

Page 4: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

CS8451 DESIGN AND ANALYSIS OF ALGORITHMS

OBJECTIVES:

To understand and apply the algorithm analysis techniques

To critically analyze the efficiency of alternative algorithmic solutions for the same problem

To understand different algorithm design techniques

To understand the limitations of Algorithmic power

UNIT I INTRODUCTION

Notion of an Algorithm – Fundamentals of Algorithmic Problem Solving – Important Problem Types –

Fundamentals of the Analysis of Algorithmic Efficiency –Asymptotic Notations and their properties.

Analysis Framework – Empirical analysis - Mathematical analysis for Recursive and Non-recursive

algorithms - Visualization

UNIT II BRUTE FORCE AND DIVIDE-AND-CONQUER

Brute Force – Computing an – String Matching - Closest-Pair and Convex-Hull Problems - Exhaustive

Search - Travelling Salesman Problem - Knapsack Problem - Assignment problem. Divide and Conquer

Methodology – Binary Search – Merge sort – Quick sort – Heap Sort - Multiplication of Large Integers –

Closest-Pair and Convex - Hull Problems.

UNIT III DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE

Dynamic programming – Principle of optimality - Coin changing problem, Computing a Binomial

Coefficient – Floyd‘s algorithm – Multi stage graph - Optimal Binary Search Trees – Knapsack Problem

and Memory functions. Greedy Technique – Container loading problem - Prim‘s algorithm and Kruskal's

Algorithm – 0/1 Knapsack problem, Optimal Merge pattern - Huffman Trees.

UNIT IV ITERATIVE IMPROVEMENT The Simplex

Method - The Maximum-Flow Problem – Maximum Matching in Bipartite Graphs, Stable marriage

Problem.

UNIT V COPING WITH THE LIMITATIONS OF ALGORITHM POWER Lower - Bound

Arguments - P, NP NP- Complete and NP Hard Problems. Backtracking – n-Queen problem -

Hamiltonian Circuit Problem – Subset Sum Problem. Branch and Bound – LIFO Search and FIFO search

- Assignment problem – Knapsack Problem – Travelling Salesman Problem - Approximation Algorithms

for NP-Hard Problems – Travelling Salesman problem – Knapsack problem.

OUTCOMES:

At the end of the course, the students should be able to:

Design algorithms for various computing problems

Analyze the time and space complexity of algorithms

Page 5: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

Critically analyze the different algorithm design techniques for a given problem

Modify existing algorithms to improve efficiency

GATE QUESTIONS - DATA STRUCTURES AND ALGORITHMS

INDEX

S. No. Name of the Topic Number of

Questions Page Number

1 Stacks 4 1

2 Queues 4 3

3 Linked Lists 5 5

4

Trees

4.1 Trees

4.2 Binary Trees

4.3 Binary Search Trees

4.4 n- ary Trees

4.5 B Trees

4.6 B+ Trees

4.7 Expression Trees

4.8 AVL Trees

28 7

5 Heaps

14 19

6

Graphs

6.1 Graph Traversal

6.2 Minimum Spanning Tree

6.3 Shortest Path

34 26

7 Searching 2 42

8 Sorting 12 43

9 Hashing 7 47

10 Asymptotic Worst Case Time

and Space Complexity 11 50

11

Algorithm Design Techniques:

11.1 Greedy Algorithms

11.2 Dynamic Programming

11.3 Divide‐and‐Conquer

Technique

8 54

TOTAL NUMBER OF QUESTIONS: 109

Page 6: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

Faculty In - Charge GATE Coordinator HoD/IT

Page 7: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 1

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

STACK

1. The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is GATE-CS-2015 (Set 3)

(A) 284

(B) 213

(C) 142

(D) 71

2. The following postfix expression with single digit operands is evaluated using a stack:

8 2 3 ^ / 2 3 * + 5 1 * -

Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is

evaluated are: GATE CS 2007

(A) 6, 1

(B) 5, 7

(C) 3, 2

(D) 1, 5

Page 8: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 2

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

STACK

3. A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from

opposite ends of the array. Variables top1 and top2 (topl< top 2) point to the location of the

topmost element in each of the stacks. If the space is to be used efficiently, the condition for

“stack full” is (GATE CS 2004)

a) (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)

b) top1 + top2 = MAXSIZE

c) (top1= MAXSIZE/2) or (top2 = MAXSIZE)

d) top1= top2 -1

4. The best data structure to check whether an arithmetic expression has balanced

parentheses is a (GATE CS 2004)

a) queue

b) stack

c) tree

d) list

Page 9: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 3

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

QUEUE

5. Suppose implementation supports an instruction REVERSE, which reverses the order of

elements on the stack, in addition to the PUSH and POP instructions. Which one of the

following statements is TRUE with respect to this modified stack?

A. A queue cannot be implemented using this stack.

B. A queue can be implemented where ENQUEUE takes a single instruction and

DEQUEUE takes a sequence of two instructions.

C. A queue can be implemented where ENQUEUE takes a sequence of three

instructions and DEQUEUE takes a single instruction.

D. A queue can be implemented where both ENQUEUE and DEQUEUE take a single

instruction each.

6. A queue is implemented using a non-circular singly linked list. The queue has a head pointer

and a tail pointer, as shown in the figure. Let n denote the number of nodes in the queue. Let

‘enqueue’ be implemented by inserting a new node at the head, and ‘dequeue’ be

implemented by deletion of a node from the tail.

Which one of the following is the time complexity of the most time-efficient implementation

of ‘enqueue’ and ‘dequeue, respectively, for this data structure? GATE CS 2018

(A) Θ(1), Θ(1)

(B) Θ(1), Θ(n)

(C) Θ(n), Θ(1)

(D) Θ(n), Θ(n)

Page 10: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 4

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

CIRCULAR QUEUE

7. A Circular queue has been implemented using singly linked list where each node consists of a

value and a pointer to next node. We maintain exactly two

pointers FRONT and REAR pointing to the front node and rear node of queue. Which of the

following statements is/are correct for circular queue so that insertion and deletion operations

can be performed in O(1) i.e. constant time. GATE-CS-2017 (Set 2)

I. Next pointer of front node points to the rear node.

II. Next pointer of rear node points to the front node.

A. I only

B. II only

C. Both I and II

D. Neither I nor II

8. Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n

elements. Assume that the insertion and deletion operation are carried out using REAR and

FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions

to detect queue full and queue empty are (GATE CS 2012)

(A) Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT

(B) Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

(C) Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT

(D) Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT

Page 11: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 5

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

LINKED LIST

9. 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-CS-2015 (Set 2)

(A) Θ(nlogn)

(B) Θ(n)

(C) Θ(logn)

(D) Θ(1)

10. In the worst case, the number of comparisons needed to search a singly linked list of

length n for a given element is (GATE CS 2002)

a) log 2 n

b) n/2

c) log 2 n – 1

d) n

11. Suppose each set is represented as a linked list with elements in arbitrary order. Which of the

operations among union, intersection, membership, cardinality will be the slowest? (GATE

CS 2004)

a) union only

b) intersection, membership

c) membership, cardinality

d) union, intersection

Page 12: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 6

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

LINKED LIST

12. The following C function takes a simply-linked list as input argument. It modifies the list by

moving the last element to the front of the list and returns the modified list. Some part of the

code is left blank.

typedef struct node

{

int value;

struct node *next;

}Node;

Node *move_to_front(Node *head)

{

Node *p, *q;

if ((head == NULL: || (head->next == NULL))

return head;

q = NULL; p = head;

while (p-> next !=NULL)

{

q = p;

p = p->next;

}

_______________________________

return head;

}

Choose the correct alternative to replace the blank line. GATE CS 2010

(A) q = NULL; p->next = head; head = p;

(B) q->next = NULL; head = p; p->next = head;

(C) head = p; p->next = q; q->next = NULL;

(D) q->next = NULL; p->next = head; head = p;

Page 13: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 7

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

TREES - STRUCTURE

13. Let T be a tree with 10 vertices. The sum of the degrees of all the vertices in T is _____.

GATE-CS-2017 (Set 1)

Note: This questions appeared as Numerical Answer Type.

(A) 18

(B) 19

(C) 20

(D) 21

14. The height of a tree is the length of the longest root-to-leaf path in it. The maximum and

minimum number of nodes in a binary tree of height 5 are GATE-CS-2015 (Set 1)

(A) 63 and 6, respectively

(B) 64 and 5, respectively

(C) 32 and 6, respectively

(D) 31 and 5, respectively

Page 14: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 8

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

BINARY TREES - STRUCTURE

15. A binary tree T has 20 leaves. The number of nodes in T having two children is GATE-CS-

2015 (Set 2)

(A) 18

(B) 19

(C) 17

(D) Any number between 10 and 20

16. Consider a binary tree T that has 200 leaf nodes. Then, the number of nodes in T that have

exactly two children are _________. GATE-CS-2015 (Set 3)

(A) 199

(B) 200

(C) Any number between 0 and 199

(D) Any number between 100 and 200

17. In a binary tree with n nodes, every node has an odd number of descendants. Every node is

considered to be its own descendant. What is the number of nodes in the tree that have exactly

one child? GATE CS 2010

(A) 0

(B) 1

(C) (n-1)/2

(D) n-1

Page 15: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 9

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

BINARY TREES - STRUCTURE

18. The maximum number of binary trees that can be formed with three unlabeled nodes is:

GATE CS 2007

(A) 1

(B) 5

(C) 4

(D) 3

19. The height of a binary tree is the maximum number of edges in any root to leaf path. The

maximum number of nodes in a binary tree of height h is: GATE CS 2007

(A) 2^h -1

(B) 2^(h-1) – 1

(C) 2^(h+1) -1

(D) 2*(h+1)

Page 16: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 10

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

BINARY TREES - TRAVERSAL

20. The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g,

respectively. The postorder traversal of the binary tree is: GATE CS 2007

(A) d e b f g c a

(B) e d b g f c a

(C) e d b f g c a

(D) d e f g b c a

21. Let LASPOST, LASTIN and LASTPRE denote the last vertex visited in a postorder, inorder

and preorder traversal. Respectively, of a complete binary tree. Which of the following is

always true? (GATE CS 2000)

(a) LASTIN = LASTPOST

(b) LASTIN = LASTPRE

(c) LASTPRE = LASTPOST

(d) None of the above

22. Consider the following nested representation of binary trees: (X Y Z) indicates Y and Z are

the left and right sub stress, respectively, of node X. Note that Y and Z may be NULL, or

further nested. Which of the following represents a valid binary tree? (GATE CS 2000)

(a) (1 2 (4 5 6 7))

(b) (1 (2 3 4) 5 6) 7)

(c) (1 (2 3 4)(5 6 7))

(d) (1 (2 3 NULL) (4 5))

Page 17: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 11

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

BINARY SEARCH TREES - CREATION

23. While inserting the elements 71, 65, 84, 69, 67, 83 in an empty binary search tree (BST) in

the sequence shown, the element in the lowest level is GATE-CS-2015 (Set 3)

A. 65

B. 67

C. 69

D. 83

Page 18: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 12

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

BINARY SEARCH TREES - STRUCTURE

24. Let T be a full binary tree with 8 leaves. (A full binary tree has every level full.) Suppose two

leaves aa and b of T are chosen uniformly and independently at random. The expected value

of the distance between aa and b in T (i.e., the number of edges in the unique path

between aa and b) is (rounded off to 2 decimal places) . (GATE 2019)

25. Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of

T are: GATE-CS-2017 (Set 1)

Note: The height of a tree with a single node is 0.

(A) 4 and 15 respectively

(B) 3 and 14 respectively

(C) 4 and 14 respectively

(D) 3 and 15 respectively

26. Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is

a vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the

maximum possible value of n is ________ GATE-CS-2016 (Set 2)

[This Question was originally a Fill-in-the-blanks Question]

(A) 15

(B) 16

(C) 31

(D) 32

Page 19: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 13

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

BINARY SEARCH TREES - TRAVERSAL

27. The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19.Which one of

the following is the postorder traversal of the tree? (GATE 2019)

(A) 10, 11, 12, 15, 16, 18, 19, 20

(B) 11, 12, 10, 16, 19, 18, 20, 15

(C) 20, 19, 18, 16, 15, 12, 11, 10

(D) 19, 16, 18, 20, 11, 12, 10, 15

28. The preorder traversal of a binary search tree is 15, 10. 12, 11, 20, 18, 16, 19. Which one of

the following is the postorder traversal of the tree? (GATE 2020)

(a) 20, 19, 18, 16, 15, 12, 11, 10

(b) 10, 11, 12, 15, 16, 18, 19, 20

(c) 19, 16, 18, 20, 11, 12, 10, 15

(d) 11, 12, 10, 16, 19, 18, 20, 15

29. Postorder traversal of a given binary search tree, T produces the following sequence of keys

10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29

Which one of the following sequences of keys can be the result of an in-order traversal of the

tree T? (GATE CS 2005)

a) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95

b) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29

c) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95

d) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

30. The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42.

Which one of the following is the postorder traversal sequence of the same tree? (GATE CS

2013)

(A) 10, 20, 15, 23, 25, 35, 42, 39, 30

(B) 15, 10, 25, 23, 20, 42, 35, 39, 30

(C) 15, 20, 10, 23, 25, 42, 35, 39, 30

(D) 15, 10, 23, 25, 20, 35, 42, 39, 30

Page 20: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 14

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

N-ARY TREES - STRUCTURE

31. In a complete k-ary tree, every internal node has exactly k children. The number of leaves in

such a tree with n internal nodes is: GATE CS 2005

(a) nk

(b) (n – 1) k+ 1

(c) n( k – 1) + 1

(d) n(k – 1)

32. A complete n-ary tree is a tree in which each node has n children or no children. Let I be the

number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41,

and I = 10, what is the value of n?

(A) 3

(B) 4

(C) 5

(D) 6

Page 21: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 15

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

B TREES AND B+ TREES

33. Which one of the following is a key factor for preferring B-trees to binary search trees for

indexing database relations? GATE CS 2005

(a) Database relations have a large number of records

(b) Database relations are sorted on the primary key

(c) B-trees require less memory than binary search trees

(d) Data transfer form disks is in blocks.

34. B+ Trees are considered BALANCED because GATE-CS-2016 (Set 2)

A. the lengths of the paths from the root to all leaf nodes are all equal.

B. the lengths of the paths from the root to all leaf nodes differ from each other by at

most 1.

C. the number of children of any two non-leaf sibling nodes differ by at most 1.

D. the number of records in any two leaf nodes differ by at most 1.

Page 22: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 16

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

B+ TREES

35. With reference to the B+ tree index of order 1 shown below, the minimum number of nodes

(including the root node) that must be fetched in order to satisfy the following query: “Get all

records with a search key greater than or equal to 7 and less than 15” is ________ GATE-CS-

2015 (Set 2)

(A) 4

(B) 5

(C) 6

(D) 7

36. Consider a B+-tree in which the maximum number of keys in a node is 5. What is the

minimum number of keys in any non-root node? (GATE CS 2010)

(A) 1

(B) 2

(C) 3

(D) 4

Page 23: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 17

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

EXPRESSION TREES & AVL TREES

37. Consider the expression tree shown. Each leaf represents a numerical value, which can either

be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of

the expression represented by the tree is ___. GATE-CS-2014-(Set-2)

(A) 4

(B) 6

(C) 8

(D) 10

38. What is the worst case time complexity of inserting n2 elements into an AVL-tree

with n elements intially ?(GATE 2019 & GATE 2020)

Page 24: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 18

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

EXPRESSION TREES & AVL TREES

39. In a balanced binary search tree with n elements, what is the worst case time complexity of

reporting all elements in range [a, b]? Assume that the number of reported elements is k

(GATE 2020)

40. What is the maximum height of any AVL-tree with 7 nodes? Assume that the height of a tree

with a single node is 0. GATE-CS-2009

(A) 2

(B) 3

(C) 4

(D) 5

Page 25: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 19

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HEAP - TRAVERSAL

41. 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-

CS-2014-(Set-2)

A. 10, 8, 7, 3, 2, 1, 5

B. 10, 8, 7, 2, 3, 1, 5

C. 10, 8, 7, 1, 2, 3, 5

D. 10, 8, 7, 5, 3, 2, 1

42. A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order

traversal of the heap is given below: 10, 8, 5, 3, 2. Two new elements ”1‘ and ”7‘ are inserted

in the heap in that order. The level-order traversal of the heap after the insertion of the

elements is: GATE CS 2005

(a) 10, 8, 7, 5, 3, 2, 1

(b) 10, 8, 7, 2, 3, 1, 5

(c) 10, 8, 7, 1, 2, 3, 5

(d) 10, 8, 7, 3, 2, 1, 5

Page 26: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 20

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HEAP - CREATION

43. Consider a max heap, represented by the array: 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-CS-2015

(Set 1)

(A) 40, 30, 20, 10, 15, 16, 17, 8, 4, 35

(B) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15

(C) 40, 30, 20, 10, 35, 16, 17, 8, 4, 15

(D) 40, 35, 20, 10, 15, 16, 17, 8, 4, 30

Page 27: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 21

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HEAP - IDENTIFICATION

44. The number of possible min-heaps containing each value from {1, 2, 3, 4, 5, 6, 7}exactly

once is _____. (GATE 2018)

45. Consider the following statements:

I. The smallest element in a max-heap is always at a leaf node

II. The second largest element in a max-heap is always a child of the root node

III. A max-heap can be constructed from a binary search tree in Θ(n)Θ(n) time

IV. A binary search tree can be constructed from a max-heap in Θ(n)Θ(n) time

Which of the above statements are TRUE? (GATE 2019)

46. Consider the array representation of a binary min-heap containing 1023 elements. The

minimum number of comparisons required to find the maximum in the heap ________.

(GATE 2020)

Page 28: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 22

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HEAP - IDENTIFICATION

47. Consider a binary max-heap implemented using an array. Which one of the following array

represents a binary max-heap? GATE-CS-2009

▪ 25,12,16,13,10,8,14

▪ 25,14,13,16,10,8,12

▪ 25,14,16,13,10,8,12

▪ 25,14,12,13,10,8,16

48. A max-heap is a heap where the value of each parent is greater than or equal to the values of

its children. Which of the following is a max-heap? GATE CS 2011

(A) A

(B) B

(C) C

(D) D

Page 29: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 23

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HEAP – SEARCHING TIME COMPLEXITY

49. 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 CS 2007)

(A) Θ(logn)

(B) Θ(LogLogn )

(C) Θ(n)

(D) Θ(nLogn)

50. In a binary max heap containing n numbers, the smallest element can be found in time

(GATE CS 2006)

(A) O(n)

(B) O(logn)

(C) O(loglogn)

(D) O(1)

Page 30: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 24

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HEAP – MAXIMUM DEPTH

51. 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-CS-2016 (Set 2)

[This question was originally asked as Fill-in-the-Blanks question]

(A) 6

(B) 7

(C) 8

(D) 9

52. The number of possible min-heaps containing each value from {1, 2, 3, 4, 5, 6, 7} exactly

once is _______. GATE CS 2018

Note –This was Numerical Type question.

(A) 80

(B) 8

(C) 20

(D) 210

Page 31: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 25

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HEAP – n ary HEAP

53. 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 CS 2006

(A) 1, 3, 5, 6, 8, 9

(B) 9, 6, 3, 1, 8, 5

(C) 9, 3, 6, 8, 5, 1

(D) 9, 5, 6, 8, 3, 1

54. Suppose the elements 7, 2, 10 and 4 are inserted, in that order, into the valid 3- ary max heap

found in the above question, Which one of the following is the sequence of items in the array

representing the resultant heap? GATE CS 2006

(A) 10, 7, 9, 8, 3, 1, 5, 2, 6, 4

(B) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1

(C) 10, 9, 4, 5, 7, 6, 8, 2, 1, 3

(D) 10, 8, 6, 9, 7, 2, 3, 4, 1, 5

Page 32: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 26

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – NUMBER OF VERTICES/ EDGES/ GRAPHS

55. G is undirected graph with n vertices and 25 edges such that each vertex has degree at least 3.

Then the maximum possible value of n is ________ GATE-CS-2017 (Set 2)

(A) 4

(B) 8

(C) 16

(D) 24

56. Let G be a connected planar graph with 10 vertices. If the number of edges on each face is

three, then the number of edges in G is _______________. GATE-CS-2015 (Set 1)

(A) 24

(B) 20

(C) 32

(D) 64

57. How many undirected graphs (not necessarily connected) can be constructed out of a given

set V= {V 1, V 2,…V n} of n vertices ? (GATE CS 2001)

a) n(n-l)/2

b) 2^n

c) n!

d) 2^(n(n-1)/2)

Page 33: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 27

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS –TRAVERSAL (BFS)

58. Breath First Search(BFS) has been implemented using queue data structure.

Which one of the following is a possible order of visiting the nodes in the graph above.

GATE-CS-2017 (Set 2)

(A) MNOPQR

(B) NQMPOR

(C) QMNROP

(D) POQNMR

59. 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 CS 2008

(A) MNOPQR

(B) NQMPOR

(C) QMNPRO

(D) QMNPOR

Page 34: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 28

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS –TRAVERSAL (BFS)

60. Consider an undirected unweighted graph G. Let a breadth-first traversal of G be done

starting from a node r. Let d(r, u) and d(r, v) be the lengths of the shortest paths from r to u

and v respectively, in G. lf u is visited before v during the breadth-first traversal, which of the

following statements is correct? (GATE CS 2001)

a) d(r, u) < d (r, v)

b) d(r, u) > d(r, v)

c) d(r, u) <= d (r, v)

d) None of the above

Page 35: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 29

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – TRAVERSAL (DFS)

61. Suppose depth first search is executed on the graph below starting at some unknown vertex.

Assume that a recursive call to visit a vertex is made only after first checking that the vertex

has not been visited earlier. Then the maximum possible recursion depth (including the initial

call) is _________. GATE-CS-2014-(Set-3)

(A) 17

(B) 18

(C) 19

(D) 20

62. Consider the following graph

Among the following sequences

I) a b e g h f

II) a b f e h g

III) a b f h g e

IV) a f g h b e

Which are depth first traversals of the above graph? (GATE CS 2003)

a) I, II and IV only

b) I and IV only

c) II, III and IV only

d) I, III and IV only

Page 36: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 30

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – GRAPHS – TRAVERSAL (DFS)

63. Let G be an undirected graph. Consider a depth-first traversal of G, and let T be the resulting

depth-first search tree. Let u be a vertex in G and let v be the first new (unvisited) vertex

visited after visiting u in the traversal. Which of the following statements is always true?

(GATE CS 2000)

(a) {u,v} must be an edge in G, and u is a descendant of v in T

(b) {u,v} must be an edge in G, and v is a descendant of u in T

(c) If {u,v} is not an edge in G then u is a leaf in T

(d) If {u,v} is not an edge in G then u and v must have the same parent in T

64. Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running

time on Depth First Search of G? Assume that the graph is represented using adjacency

matrix. CS-2014-(Set-1)

(A) O(n)

(B) O(m+n)

(C) O(n2)

(D) O(mn)

65. Let GG be an undirected complete graph on nn vertices, where nn > 2. Then, the number of

different Hamiltonian cycles in GG is equal to (GATE 2019)

Page 37: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 31

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – TOPOLOGICAL SORT

66. Consider the following directed graph.

The number of different topological orderings of the vertices of the graph is GATE-CS-2016

(Set 1)

Note : This question was asked as Numerical Answer Type.

(A) 1

(B) 2

(C) 4

(D) 6

67. Consider the directed graph given below. Which one of the following is TRUE? CS-2014-

(Set-1)

(A) The graph doesn’t have any topological ordering

(B) Both PQRS and SRPQ are topological ordering

(C) Both PSRQ and SPRQ are topological ordering

(D) PSRQ is the only topological ordering

Page 38: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 32

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – MINIMUM SPANNING TREE- CONSTRUCTION

68. Consider the following graph:

Which one of the following is NOT the sequence of edges added to the minimum spanning tree

using Kruskal’s algorithm? GATE-CS-2009

(A) (b,e)(e,f)(a,c)(b,c)(f,g)(c,d)

(B) (b,e)(e,f)(a,c)(f,g)(b,c)(c,d)

(C) (b,e)(a,c)(e,f)(b,c)(f,g)(c,d)

(D) (b,e)(e,f)(b,c)(a,c)(f,g)(c,d)

69. Consider the following undirected graph G:

Choose a value for x that will maximize the number of minimum weight spanning trees

(MWSTs) of G. The number of MWSTs of G for this value of x is ______.(GATE 2018)

Page 39: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 33

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – MINIMUM SPANNING TREE- CONSTRUCTION

70. Let G be any connected, weighted, undirected graph.

I. G has a unique minimum spanning tree, if no two edges of G have the same weight.

II. G has a unique minimum spanning tree, if, for every cut of G, there is a unique minimum-

weight edge crossing the cut. Which of the above two statements is/are TRUE?

71. Let G = (V, E ) be a weighted undirected graph and let T be a Minimum Spanning Tree

(MST) of G maintained using adjacency lists. Suppose a new weighted edge (u, v) ∈ V × V is

added to G. The worst case time complexity of determining if T is still an MST of the

resultant graph is (GATE 2020)

72. Consider a graph G = (V, E), where V = {v2, v2, ..., v100}, E = {(vi , vj )⏐1 ≤ i < j ≤ 100}

and weight of the edge (vi , vj ) is ⏐i – j⏐. The weight of minimum spanning tree of G is

________. (GATE 2020)

73. Consider the following graph:

Which one of the following cannot be the sequence of edges added, in that order, to a

minimum spanning tree using Kruskal’s algorithm?

(A) (a—b),(d—f),(b—f),(d—c),(d—e)

(B) (a—b),(d—f),(d—c),(b—f),(d—e)

(C) (d—f),(a—b),(d—c),(b—f),(d—e)

(D) (d—f),(a—b),(b—f),(d—e),(d—c)

Page 40: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 34

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS –MINIMUM SPANNING TREE – NUMBER OF TREES

74. Let G be a complete undirected graph on 4 vertices, having 6 edges with weights being 1, 2,

3, 4, 5, and 6. The maximum possible weight that a minimum weight spanning tree of G can

have is. GATE-CS-2016 (Set 1)

[This Question was originally a Fill-in-the-Blanks question]

(A) 6

(B) 7

(C) 8

(D) 9

75. The number of distinct minimum spanning trees for the weighted graph below is ____

GATE-CS-2014-(Set-2)

(A) 4

(B) 5

(C) 6

(D) 7

Page 41: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 35

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS –MINIMUM SPANNING TREE- EDGE WEIGHT

76. Consider the following undirected graph G:

Choose a value for x that will maximize the number of minimum weight spanning trees

(MWSTs) of G. The number of MWSTs of G for this value of x is _________ . GATE CS

2018

Note –This was Numerical Type question.

(A) 4

(B) 5

(C) 2

(D) 3

77. The graph shown below 8 edges with distinct integer edge weights. The minimum spanning

tree (MST) is of weight 36 and contains the edges: {(A, C), (B, C), (B, E), (E, F), (D, F)}.

The edge weights of only those edges which are in the MST are given in the figure shown

below. The minimum possible sum of weights of all 8 edges of this graph is

______________. GATE-CS-2015 (Set 1)

(A) 66

(B) 69

(C) 68

(D) 70

Page 42: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 36

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – MINIMUM SPANNING TREE – EDGE WEIGHT

78. Let G be a weighted connected undirected graph with distinct positive edge weights. If every

edge weight is increased by the same value, then which of the following statements is/are

TRUE? GATE-CS-2016 (Set 1)

P: Minimum spanning tree of G does not change

Q: Shortest path between any pair of vertices does not change

(A) P only

(B) Q only

(C) Neither P nor Q

(D) Both P and Q

79. Let G be connected undirected graph of 100 vertices and 300 edges. The weight of a

minimum spanning tree of G is 500. When the weight of each edge of G is increased by five,

the weight of a minimum spanning tree becomes ________. GATE-CS-2015 (Set 3)

(A) 1000

(B) 995

(C) 2000

(D) 1995

Page 43: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 37

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS – COST OF MINIMUM SPANNING TREE

80. An undirected graph G(V, E) contains n ( n > 2 ) nodes named v1 , v2 ,….vn. Two nodes vi ,

vj are connected if and only if 0 < |i – j| <= 2. Each edge (vi, vj ) is assigned a weight i + j. A

sample graph with n = 4 is shown below.

What will be the cost of the minimum spanning tree (MST) of such a graph with n nodes?

GATE CS 2011

(A) 1/12(11n^2 – 5n)

(B) n^2 – n + 1

(C) 6n – 11

(D) 2n + 1

81. Consider a weighted complete graph G on the vertex set {v1, v2, ..vn} such that the weight of

the edge (vi, vj) is 2|i-j|. The weight of a minimum spanning tree of G is: (GATE CS 2006)

(A) n — 1

(B) 2n — 2

(C) nC2

(D) 2

Page 44: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 38

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS –MINIMUM SPANNING TREE

82. Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry Wij in the matrix

W below is the weight of the edge {i, j}.

What is the minimum possible weight of a spanning tree T in this graph such that vertex 0 is a

leaf node in the tree T? GATE CS 2010

(A) 7

(B) 8

(C) 9

(D) 10

83. In the graph given in above question, what is the minimum possible weight of a path P from

vertex 1 to vertex 2 in this graph such that P contains at most 3 edges? GATE CS 2010

(A) 7

(B) 8

(C) 9

(D) 10

84. G = (V, E) is an undirected simple graph in which each edge has a distinct weight, and e is a

particular edge of G. Which of the following statements about the minimum spanning trees

(MSTs) of G is/are TRUE GATE-CS-2016 (Set 1)

If e is the lightest edge of some cycle in G, then every MST of G includes e

If e is the heaviest edge of some cycle in G, then every MST of G excludes e

(A) I only

(B) II only

(C) both I and II

(D) neither I nor II

Page 45: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 39

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS DATA STRUCTURES AND ALGORITHMS

GRAPHS –SHORTEST PATH

85. Consider the weighted undirected graph with 4 vertices, where the weight of edge {i, j} g is

given by the entry Wij in the matrix W

The largest possible integer value of x, for which at least one shortest path between some pair

of vertices will contain the edge with weight x is ________ GATE-CS-2016 (Set 1)

Note : This question was asked as Numerical Answer Type.

(A) 8

(B) 12

(C) 10

(D) 11

Page 46: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 40

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS –SHORTEST PATH- DIJKSTRA’S ALGORITHM

86. Suppose we run Dijkstra’s single source shortest-path algorithm on the following edge

weighted directed graph with vertex P as the source. In what order do the nodes get included

into the set of vertices for which the shortest path distances are finalized? (GATE CS 2004)

a) P, Q, R, S, T, U

b) P, Q, R, U, S, T

c) P, Q, R, U, T, S

d) P, Q, T, R, U, S

87. There are multiple routes to reach from node 1 to node 2, as shown in the network.

The cost of travel on an edge between two nodes is given in rupees. Nodes ‘a’ ‘b’, ‘c’, ‘d’, ‘e’

and ‘f’ are toll booths. The toll price at toll booths marked ‘a’ and ‘c’ is Rs. 200. and is Rs.

100 for the other toll booths. Which is the cheapest route from node 1 to node 2? (GATE

2020)

(a) 1-a-C-2

(b) 1-b-2

(c) 1-f-b-2

(d) 1-f-e-2

Page 47: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 41

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

GRAPHS –SHORTEST PATH- DIJKSTRA’S ALGORITHM

88. Consider the directed graph shown in the figure below. There are multiple shortest paths

between vertices S and T. Which one will be reported by Dijstra?s shortest path algorithm?

Assume that, in any iteration, the shortest path to a vertex v is updated only when a strictly

shorter path to v is discovered.

(A) SDT

(B) SBDT

(C) SACDT

(D) SACET

Page 48: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 42

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

SEARCHING

89. The minimum number of comparisons required to find the minimum and the maximum of

100 numbers is ______________. CS-2014-(Set-1)

(A) 148

(B) 147

(C) 146

(D) 140

90. 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 CS 2006)

(A) Solves it in linear time using a left to right pass of the array

(B) Solves it in linear time using a right to left pass of the array

(C) Solves it using divide and conquer in time 8(nlogn)

(D) Solves it in time 8(n2)

Page 49: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 43

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

SORTING- SELECTION SORT

91. Which one of the following is the tightest upper bound that represents the number of swaps

required to sort n numbers using selection sort? GATE CS 2013

(A) O(log n)

(B) O(n)

(C) O(nLogn)

(D) O(n^2)

92. What is the number of swaps required to sort n elements using selection sort, in the

worst case? GATE CS 2009

(A) Θ(n)

(B) Θ(n log n)

(C) Θ(n2 )

(D) Θ(nn2 log n)

Page 50: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 44

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

SORTING – MERGE SORT

93. Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 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 ____. GATE-CS-2014-(Set-2)

(A) 358

(B) 438

(C) 568

(D) 664

94. 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-CS-2015 (Set 3)

(A) 256

(B) 512

(C) 1024

(D) 2048

Page 51: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 45

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS DATA STRUCTURES AND ALGORITHMS

SORTING – QUICK SORT

95. 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 2019)

96. Let P be a QuickSort Program to sort numbers in ascending order using the first element as

pivot. Let t1 and t2 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? CS-2014-(Set-1)

(A) t1 = 5

(B) t1 < t2

(C) t1 > t2

(D) t1 = t2

97. 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?

<pre> GATE-CS-2009

(A) (n)

(B) (nLogn)

(C) (n^2)

(D) (n^2 log n) </pre>

(A) A

(B) B

(C) C

(D) D

98. The median of n elements can be found in O(n)time. Which one of the following is correct

about the complexity of quick sort, in which median is selected as pivot?

(A) Θ(n)

(B) Θ(nlogn)

(C) Θ(n^2)

(D) Θ(n^3)

Page 52: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 46

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

SORTING - COMPARISON

99. 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 ? GATE-CS-2016 (Set

2)

I. Quicksort runs in Θ(n2) time

II. Bubblesort runs in Θ(n2) time

III. Mergesort runs in Θ(n) time

IV. Insertion sort runs in Θ(n) time

(A) I and II only

(B) I and III only

(C) II and IV only

(D) I and IV only

100. The worst case running times of Insertion sort, Merge sort and Quick sort,

respectively, are: GATE-CS-2016 (Set 1)

(A) Θ(n log n), Θ(n log n) and Θ(n2)

(B) Θ(n2), Θ(n2) and Θ(n Log n)

(C) Θ(n2), Θ(n log n) and Θ(n log n)

(D) Θ(n2), Θ(n log n) and Θ(n2)

101. Which one of the following in place sorting algorithms needs the minimum number

of swaps? (GATE CS 2006)

(A) Quick sort

(B) Insertion sort

(C) Selection sort

(D) Heap sort

102. Which of the following sorting algorithms has the lowest worst-case

complexity?GATE CS 2007

(A) Merge sort

(B) Bubble sort

(C) Quick sort

(D) Selection sort

Page 53: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 47

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HASHING

103. A hash table of length 10 uses open addressing with hash function h(k)=k mod 10,

and linear probing. After inserting 6 values into an empty hash table, the table is as shown

below.

Which one of the following choices gives a possible order in which the key values could have

been inserted in the table? GATE CS 2010

104. Consider a hash table with 9 slots. The hash function is ℎ(k) = k mod 9. The collisions

are resolved by chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33,

12, 17, 10. The maximum, minimum, and average chain lengths in the hash table,

respectively, are

(A) 3, 0, and 1

(B) 3, 3, and 3

(C) 4, 0, and 1

(D) 3, 0, and 2

A. 46, 42, 34, 52, 23, 33

B. 34, 42, 23, 52, 33, 46

C. 46, 34, 42, 23, 52, 33

D. 42, 46, 33, 23, 34, 52

Page 54: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 48

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HASHING

105. Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the

hash function x mod 10, which of the following statements are true? (GATE CS 2004)

i. 9679, 1989, 4199 hash to the same value

ii. 1471, 6171 hash to the same value

iii. All elements hash to the same value

iv. Each element hashes to a different value

A. i only

B. ii only

C. i and ii only

D. iii or iv

106. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table

of length 10 using open addressing with hash function h(k) = k mod 10 and linear probing.

What is the resultant hash table? GATE-CS-2009

(A) A

(B) B

(C) C

(D) D

107. Consider a hash table of size seven, with starting index zero, and a hash function (3x

+ 4)mod7. Assuming the hash table is initially empty, which of the following is the contents

of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed hashing? Note

that ‘_’ denotes an empty location in the table. GATE CS 2007

(A) 8, _, _, _, _, _, 10

(B) 1, 8, 10, _, _, _, 3

(C) 1, _, _, _, _, _,3

(D) 1, 10, 8, _, _, _, 3

Page 55: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 49

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

HASHING

108. Which one of the following hash functions on integers will distribute keys most

uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020? GATE-CS-2015

(Set 2)

(A) h(i) =i2 mod 10

(B) h(i) =i3 mod 10

(C) h(i) = (11 ∗ i2) mod 10

(D) h(i) = (12 ∗ i) mod 10

109. Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is

__________ GATE-CS-2015 (Set 3)

(A) 80

(B) 0.0125

(C) 8000

(D) 1.25

Page 56: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 50

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

ASYMPTOTIC WORST CASE TIME AND SPACE COMPLEXITY

110. What is the worst case time complexity of inserting n elements into an empty linked list, if

the linked list needs to be maintained in sorted order? (GATE 2020)

(a) Θ(n logn)

(b) Θ(n)

(c) Θ(1)

(d) Θ(n2)

111. Which one of the following correctly determines the solution of the recurrence relation with

T(1) = 1 where T(n) = 2T(n/2) + Log n ? GATE-CS-2014-(Set-2)

(A) Θ(n)

(B) Θ(nLogn)

(C) Θ(n*n)

(D) Θ(log n)

112. For parameters aa and bb, both of which are ω(1), T(n)=T(n1/a)+1,andT(b)=1.

ThenT(n)is (GATE 2019 & GATE 2020)

113. The recurrence relation capturing the optimal execution time of the Towers of Hanoi

problem with n discs is (GATE CS 2012)

(E) T(n) = 2T(n − 2) + 2

(F) T(n) = 2T(n − 1) + n

(G) T(n) = 2T(n/2) + 1

(H) T(n) = 2T(n − 1) + 1

Page 57: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 51

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

GATE QUESTIONS DATA STRUCTURES AND ALGORITHMS

ASYMPTOTIC WORST CASE TIME AND SPACE COMPLEXITY

114. The running time of an algorithm is represented by the following recurrence relation:

if n <= 3 then T(n) = n

else T(n) = T(n/3) + cn

Which one of the following represents the time complexity of the algorithm? <pre> GATE-

CS-2009

(A) (n)

(B) (n log n)

(C) (n^2)

(D) (n^2log n) </pre>

(A) A

(B) B

(C) C

(D) D

115. Consider the following C function.

int fun1 (int n)

{

int i, j, k, p, q = 0;

for (i = 1; i<n; ++i)

{

p = 0;

for (j=n; j>1; j=j/2)

++p;

for (k=1; k<p; k=k*2)

++q;

}

return q;

} Which one of the following most closely approximates the return value of the function fun1?

GATE-CS-2015 (Set 1)

(A) n3

(B) n (logn)2

(C) nlogn

(D) nlog(logn)

GATE QUESTIONS

Page 58: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 52

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

DATA STRUCTURES AND ALGORITHMS

ASYMPTOTIC WORST CASE TIME AND SPACE COMPLEXITY

116. Which of the given options provides the increasing order of asymptotic complexity of

functions f1, f2, f3 and f4? GATE CS 2011

f1(n) = 2^n

f2(n) = n^(3/2)

f3(n) = nLogn

f4(n) = n^(Logn)

(A) f3, f2, f4, f1

(B) f3, f2, f1, f4

(C) f2, f3, f1, f4

(D) f2, f3, f4, f1

117. Consider the following three claims

I (n + k)^m = Θ(n^m), where k and m are constants

II 2^(n + 1) = 0(2^n)

III 2^(2n + 1) = 0(2^n)

Which of these claims are correct? (GATE CS 2003)

(a) I and II

(b) I and III

(c) II and III

(d) I, II and III

GATE QUESTIONS

Page 59: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 53

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

DATA STRUCTURES AND ALGORITHMS

ASYMPTOTIC WORST CASE TIME AND SPACE COMPLEXITY (Number of Operations)

118. Consider the following pseudo code. What is the total number of multiplications to be

performed? CS-2014-(Set-1)

D = 2

for i = 1 to n do

for j = i to n do

for k = j + 1 to n do

D = D * 3

(A) Half of the product of the 3 consecutive integers.

(B) One-third of the product of the 3 consecutive integers.

(C) One-sixth of the product of the 3 consecutive integers.

(D) None of the above.

119. There are n unsorted arrays: A1, A2, …, An. Assume that n is odd. Each of A1, A2,

…, An contains n distinct elements. There are no common elements between any two arrays.

The worst-case time complexity of computing the median of the medians of A1, A2, …, An is

(GATE 2019)

120. The minimum number of arithmetic operations required to evaluate the polynomial

P(X) = X5 + 4X3 + 6X + 5 for a given value of X using only one temporary variable. GATE-

CS-2014-(Set-3)

(A) 6

(B) 7

(C) 8

(D) 9

GATE QUESTIONS

DATA STRUCTURES AND ALGORITHMS

Page 60: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 54

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

ALGORITHM DESIGN TECHNIQUES

121. Let G = (V, E) be any connected undirected edge-weighted graph. The weights of the

edges in E are positive any distinct. Consider the following statements:

I. Minimum Spanning Tree of G is always unique.

II. Shortest path between any two vertices of G is always unique.

Which of the above statements is/are necessarily true? GATE-CS-2017 (Set 1)

(A) I only

(B) II only

(C) both I and II

(D) neither I and II

122. Let G be a simple undirected graph. Let TD be a depth first search tree of G.

Let TB be a breadth first search tree of G. Consider the following statements:

(I) No edge of G is a cross edge with respect to TD. (A cross edge in G is between two nodes

neither of which is an ancestor of the other in TD.)

(II) For every edge (u,v) of G, if u is at depth i and v is at depth j in TB, then |i-j| = 1.

Which of the statements above must necessarily be true? (GATE 2018)

123. Consider the weights and values of items listed below. Note that there is only one unit

of each item.

Item

number

Weight

(in Kgs)

Value

(in Rupees)

1 10 60

2 7 28

3 4 20

4 2 24

The task is to pick a subset of these items such that their total weight is no more than 11 Kg

sand their total value is maximized. Moreover, no item may be split. The total value of items

picked by an optimal algorithm is denoted by Vopt. A greedy algorithm sorts the items by

their value-to-weight ratios in descending order and packs them greedily, starting from the

first item in the ordered list. The total value of items picked by the greedy algorithm is

denoted by Vgreedy.

The value of Vopt − Vgreedy is ____________. (GATE 2018)

124. Consider a sequence of 14 elements: A = [−5, −10, 6, 3, −1, −2, 13, 4, −9, −1, 4, 12,

−3, 0]. The subsequence sum S(i,j)=∑jk=iA[k]S(i,j)=∑k=ijA[k] . Determine the maximum

Page 61: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 55

of S(i,j),S(i,j), where 0≤i≤j<14.0≤i≤j<14. (Divide and conquer approach may be used.)

(GATE 2019)

125. Consider the following table

Match the algorithm to design paradigms they are based on: GATE-CS-2017 (Set 1)

(A) P-(ii), Q-(iii), R-(i)

(B) P-(iii), Q-(i), R-(ii)

(C) P-(ii), Q-(i), R-(iii)

(D) P-(i), Q-(ii), R-(iii)

GATE QUESTIONS

Page 62: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 56

Date : Hour : Mark : /10

Signature of the Student Mentor : Signature of Subject In – Charge:

DATA STRUCTURES AND ALGORITHMS

ALGORITHM DESIGN TECHNIQUES

126. Match the following GATE-CS-2015 (Set 1)

List-I

A. Prim’s algorithm for minimum spanning tree

B. Floyd-Warshall algorithm for all pairs shortest paths

C. Mergesort

D. Hamiltonian circuit

List-II

1. Backtracking

2. Greed method

3. Dynamic programming

4. Divide and conquer

Codes: A B C D

(A) 3 2 4 1

(B) 1 2 4 3

(C) 2 3 4 1

(D) 2 1 3 4

127. Given below are some algorithms, and some algorithm design paradigms

List-I

A. Dijkstra’s Shortest Path

B. Floyd-Warshall algorithm to compute all pairs shortest path

C. Binary search on a sorted array

D. Backtracking search on a graph

List-II

1. Divide and Conquer

2. Dynamic Programming

3. Greedy design

4. Depth-first search

5. Breadth-first search

Match the above algorithms on the left to the corresponding design paradigm they follow

Codes: . GATE-CS-2015 (Set 2)

(A) 1 3 1 5

(B) 3 3 1 5

(C) 3 2 1 4

(D) 3 2 1 5

128. In an unweighted, undirected connected graph, the shortest path from a node S to

every other node is computed most efficiently, in terms of time complexity by

Page 63: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 57

(A) Dijkstra’s algorithm starting from S. (GATE CS 2007)

(B) Warshall’s algorithm

(C) Performing a DFS starting from S.

(D) Performing a BFS starting from S.

Page 64: DATA STRUCTURES ALGORITHMS - kamarajengg.edu.in

GATE – DATA STRUCTURES AND ALGORITHMS Page 58

*** ALL THE BEST ***