Sei sulla pagina 1di 120

HomeAptitudeLogicalVerbalCurrent AffairsGKEngineeringInterviewOnline TestsPuzzles

1. what is data structure?

A data structure is a way of organizing data that considers not only the items stored, but also their relationship to
each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms
for the manipulation of data.

2. List out the areas in which data structures are applied extensively?

1. Compiler Design,
2. Operating System,
3. Database Management System,
4. Statistical analysis package,
5. Numerical Analysis,
6. Graphics,
7. Artificial Intelligence,
8. Simulation

3. What are the major data structures used in the following areas : RDBMS, Network data model and
Hierarchical data model.

1. RDBMS = Array (i.e. Array of structures)


2. Network data model = Graph
3. Hierarchical data model = Trees

4. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them.
It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer
to any type as it is a generic pointer type.

5. Minimum number of queues needed to implement the priority queue?

Two. One queue is used for actual storing of data and another for storing priorities.

6. What is the data structures used to perform recursion?

Stack. Because of its LIFO (Last In First Out) property it remembers its 'caller' so knows whom to return when the
function has to return. Recursion makes use of system stack for storing the return addresses of the function calls.

Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative
procedures are written, explicit stack is to be used

7. What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?

Polish and Reverse Polish notations.

8. Convert the expression ((A + B) * C - (D - E) ^ (F + G)) to equivalent Prefix and Postfix notations.

1. Prefix Notation: - * +ABC ^ - DE + FG


2. Postfix Notation: AB + C * DE - FG + ^ -

9. Sorting is not possible by using which of the following methods? (Insertion, Selection, Exchange, Deletion)
Sorting is not possible in Deletion. Using insertion we can perform insertion sort, using selection we can perform
selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting
method can be done just using deletion.

10. What are the methods available in storing sequential files ?

1. Straight merging,
2. Natural merging,
3. Polyphase sort,
4. Distribution of Initial runs.

11. List out few of the Application of tree data-structure?

1. The manipulation of Arithmetic expression,


2. Symbol Table construction,
3. Syntax analysis.

12. List out few of the applications that make use of Multilinked Structures?

1. Sparse matrix,
2. Index generation.

13. In tree construction which is the suitable efficient data structure? (Array, Linked list, Stack, Queue)

Linked list is the suitable efficient data structure.

14. What is the type of the algorithm used in solving the 8 Queens problem?

Backtracking.

15. In an AVL tree, at what condition the balancing is to be done?

If the 'pivotal value' (or the 'Height factor') is greater than 1 or less than -1.

16. What is the bucket size, when the overlapping and collision occur at same time?

One. If there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the
colliding value. This results in the overlapping of values.

17. Classify the Hashing Functions based on the various methods by which the key value is found.

1. Direct method,
2. Subtraction method,
3. Modulo-Division method,
4. Digit-Extraction method,
5. Mid-Square method,
6. Folding method,
7. Pseudo-random method.

18. What are the types of Collision Resolution Techniques and the methods used in each of the type?

1. Open addressing (closed hashing), The methods used include: Overflow block.
2. Closed addressing (open hashing), The methods used include: Linked list, Binary tree.

19. In RDBMS, what is the efficient data structure used in the internal storage representation?

B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds
to the records that shall be stored in leaf nodes.

20. What is a spanning Tree?


A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum
spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized.

21. Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes?

No. The Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesn't mean
that the distance between any two nodes involved in the minimum-spanning tree is minimum.

22. Which is the simplest file structure? (Sequential, Indexed, Random)

Sequential is the simplest file structure.

23. Whether Linked List is linear or Non-linear data structure?

. What does the following function do for a given Linked List with first node as head?

void fun1(struct node* head)


{
if(head == NULL)
return;

fun1(head->next);
printf("%d ", head->data);
}
Prints all nodes of linked lists
A
Prints all nodes of linked list in reverse order
B
Prints alternate nodes of Linked List
C
Prints alternate nodes in reverse order
D
Question 2

Which of the following points is/are true about Linked List data structure when it is compared with
array
Arrays have better cache locality that can make them better in terms of performance.
A
It is easy to insert and delete elements in Linked List
B
Random access is not allowed in a typical implementation of Linked Lists
C
The size of array has to be pre-decided, linked lists can change their size any time.
D
All of the above
E
Question 3
Consider the following function that takes reference to head of a Doubly Linked List as parameter.
Assume that a node of doubly linked list has previous pointer as prev and next pointer as next.
void fun(struct node **head_ref)
{
struct node *temp = NULL;
struct node *current = *head_ref;

while (current != NULL)


{
temp = current->prev;
current->prev = current->next;
current->next = temp;
current = current->prev;
}

if(temp != NULL )
*head_ref = temp->prev;
}
Assume that reference of head of following doubly linked list is passed to above function 1 <--> 2 <-->
3 <--> 4 <--> 5 <-->6. What should be the modified linked list after the function call?
2 <--> 1 <--> 4 <--> 3 <--> 6 <-->5
A
5 <--> 4 <--> 3 <--> 2 <--> 1 <-->6.
B
6 <--> 5 <--> 4 <--> 3 <--> 2 <--> 1.
C
6 <--> 5 <--> 4 <--> 3 <--> 1 <--> 2
D
Question 4

Which of the following sorting algorithms can be used to sort a random linked list with minimum time
complexity?
Insertion Sort
A
Quick Sort
B
Heap Sort
C
Merge Sort
D
Question 5

The following function reverse() is supposed to reverse a singly linked list. There is one line missing
at the end of the function.
/* Link list node */
struct node
{
int data;
struct node* next;
};

/* head_ref is a double pointer which points to head (or start) pointer


of linked list */
static void reverse(struct node** head_ref)
{
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
/*ADD A STATEMENT HERE*/
}
What should be added in place of "/*ADD A STATEMENT HERE*/", so that the function correctly
reverses a linked list.
*head_ref = prev;
A
*head_ref = current;
B
*head_ref = next;
C
*head_ref = NULL;
D
Question 6

What is the output of following function for start pointing to first node of following linked list? 1->2->3-
>4->5->6
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);

if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}
Run on IDE
146641
A
135135
B
1235
C
135531
D
Question 7

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.
Choose the correct alternative to replace the blank line.
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;
}
Run on IDE
q = NULL; p->next = head; head = p;
A
q->next = NULL; head = p; p->next = head;
B
head = p; p->next = q; q->next = NULL;
C
q->next = NULL; p->next = head; head = p;
D
Question 8

The following C function takes a single-linked list of integers as a parameter and rearranges the
elements of the list. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the
given order. What will be the contents of the list after the function completes execution?
struct node
{
int value;
struct node *next;
};
void rearrange(struct node *list)
{
struct node *p, * q;
int temp;
if ((!list) || !list->next)
return;
p = list;
q = list->next;
while(q)
{
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p?p->next:0;
}
}
Run on IDE
1,2,3,4,5,6,7
A
2,1,4,3,6,5,7
B
1,3,2,5,4,7,6
C
2,3,4,5,6,7,1
D
Question 9

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)
log 2 n
A
n/2
B
log 2 n – 1
C
n
D
Question 10

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)
union only
A
intersection, membership
B
membership, cardinality
C
union, intersection
D
Question 11

Consider the function f defined below.


struct item
{
int data;
struct item * next;
};

int f(struct item *p)


{
return (
(p == NULL) ||
(p->next == NULL) ||
(( P->data <= p->next->data) && f(p->next))
);
}
Run on IDE
For a given linked list p, the function f returns 1 if and only if (GATE CS 2003)
the list is empty or has exactly one element
A
the elements in the list are sorted in non-decreasing order of data value
B
the elements in the list are sorted in non-increasing order of data value
C
not all elements in the list have the same data value.
D
Question 12

A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue.
To which node should p point such that both the operations enQueue and deQueue can be
performed in constant time? (GATE

2004)
rear node
A
front node
B
not possible with a single pointer
C
node next to front
D
Question 13

What are the time complexities of finding 8th element from beginning and 8th element from end in a
singly linked list? Let n be the number of nodes in linked list, you may assume that n > 8.
O(1) and O(n)
A
O(1) and O(1)
B
O(n) and O(1)
C
O(n) and O(n)
D
Question 14

Is it possible to create a doubly linked list using only one pointer with every node.
Not Possible
A
Yes, possible by storing XOR of addresses of previous and next nodes.
B
Yes, possible by storing XOR of current node and next node
C
Yes, possible by storing XOR of current node and previous node
D
Question 15

Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not
given, can we delete the node X from given linked list?
Possible if X is not last node. Use following two steps (a) Copy the data of next of X to X. (b)

A Delete next of X.

Possible if size of linked list is even.


B
Possible if size of linked list is odd
C
Possible if X is not first node. Use following two steps (a) Copy the data of next of X to X. (b)

D Delete next of X.
Question 16

You are given pointers to first and last nodes of a singly linked list, which of the following operations
are dependent on the length of the linked list?
Delete the first element
A
Insert a new element as a first element
B
Delete the last element of the list
C
Add a new element at the end of the list
D
Question 17

Consider the following function to traverse a linked list.


void traverse(struct Node *head)
{
while (head->next != NULL)
{
printf("%d ", head->data);
head = head->next;
}
}
Run on IDE
Which of the following is FALSE about above function?
The function may crash when the linked list is empty
A
The function doesn't print the last node when the linked list is not empty
B
The function is implemented incorrectly because it changes head
C
Question 18

Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the
worst-case time complexity of the best known algorithm to delete the node x from the list?
O(n)
A
O(log2 n)
B
O(logn)
C
O(1)
D
Question 19

N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the
record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the
operation is to be performed. An algorithm performs the following operations on the list in this order:
Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key What is the time complexity of all
these operations put together
O(Log2N)
A
O(N)
B
O(N ) 2

C
Θ(N Log N)
2

D
Question 20

Let p be a pointer as shown in the figure in a single linked

list. What do the following assignment


statements achieve ?
q: = p → next
p → next:= q → next
q → next:=(q → next) → next
(p → next) → next:= q
The concatenation of two lists is to be performed in O(1) time. Which of the following implementations
of a list should be used?
singly linked list
A
doubly linked list
B
circular doubly linked list
C
array implementation of lists
D
Question 22
Consider the following piece of 'C' code fragment that removes duplicates from an ordered list of
integers.
Node *remove-duplicates(Node *head, int *j)
{
Node *t1, *t2;
*j=0;
t1 = head;
if (t1! = NULL) t2 = t1 →next;
else return head;
*j = 1;
if(t2 == NULL)
return head;
while t2 != NULL)
{
if (t1.val != t2.val) --------------------------→ (S1)
{
(*j)++; t1 -> next = t2; t1 = t2: ----------→ (S2)
}
t2 = t2 →next;
}
t1 →next = NULL;
return head;
}
Assume the list contains n elements (n≥2) in the following questions. a). How many times is the
comparison in statement S1 made? b). What is the minimum and the maximum number of times
statements marked S2 get executed? c). What is the significance of the value in the integer pointed to
by j when the function completes?
Question 23

Consider the following statements:


i. First-in-first out types of computations are efficiently supported by STACKS.
ii. Implementing LISTS on linked lists is more efficient than implementing LISTS on
an array for almost all the basic LIST operations.
iii. Implementing QUEUES on a circular array is more efficient than implementing
QUEUES
on a linear array with two indices.
iv. Last-in-first-out type of computations are efficiently supported by QUEUES.
Which of the following is correct?
(ii) and (iii) are true
A
(i) and (ii) are true
B
(iii) and (iv) are true
C
(ii) and (iv) are true
D
Question 24

Suppose there are two singly linked lists both of which intersect at some point and become a single
linked list. The head or start pointers of both the lists are known, but the intersecting node and lengths
of lists are not known. What is worst case time complexity of optimal algorithm to find intersecting
node from two intersecting linked lists?
Θ(n*m), where m, n are lengths of given lists
A
Θ(n^2), where m>n and m, n are lengths of given lists
B
Θ(m+n), where m, n are lengths of given lists
C
Θ(min(n, m)), where m, n are lengths of given lists
D
Question 25

S1 : Anyone of the followings can be used to declare a node for a singly linked list. If we use the first
declaration, “struct node * nodePtr;” would be used to declare pointer to a node. If we use the second
declaration, “NODEPTR nodePtr;” can be used to declare pointer to a node.
/* First declaration */
struct node {
int data;
struct node * nextPtr;
};

/* Second declaration */
typedef struct node{
int data;
NODEPTR nextPtr;
} * NODEPTR;
S2 : Anyone of the following can be used to declare a node for a singly linked list and “NODEPTR
nodePtr;” can be used to declare pointer to a node using any of the following
/* First declaration */
typedef struct node
{
int data;
struct node *nextPtr;
}* NODEPTR;

/* Second declaration */
struct node
{
int data;
struct node * nextPtr;
};
typedef struct node * NODEPTR;
Statement S1 is true and statement S2 is false
A
Statement S2 is true and statement S1 is false
B
Both statements S1 and S2 are true
C
Neither statement S1 nor statement S2 is true
D
Question 26

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?
Θ(1), Θ(1)
A
Θ(1), Θ(n)
B
Θ(n), Θ(1)
C
Θ(n), Θ(n)
D
Question 27

In a doubly linked list, the number of pointers affected for an insertion operation will be
4
A
0
B
1
C
None of these
D
Question 28

Consider an implementation of unsorted single linked list. Suppose it has its representation with a
head and a tail pointer (i.e. pointers to the first and last nodes of the linked list). Given the
representation, which of the following operation can not be implemented in O(1) time ?
Insertion at the front of the linked list.
A
Insertion at the end of the linked list.
B
Deletion of the front node of the linked list.
C
Deletion of the last node of the linked list.
D
Question 29

Consider a single linked list where F and L are pointers to the first and last elements respectively of
the linked list. The time for performing which of the given operations depends on the length of the

linked list?
Delete the first element of the list
A
Interchange the first two elements of the list
B
Delete the last element of the list
C
Add an element at the end of the list
D
Question 30

The following steps in a linked list


p = getnode()
info (p) = 10
next (p) = list
list = p
result in which type of operation?
pop operation in stack
A
removal of a node
B
inserting a node
C
modifying an existing node
D
Question 31

Consider the following conditions: (a)The solution must be feasible, i.e. it must satisfy all the supply
and demand constraints. (b)The number of positive allocations must be equal to m1n21, where m is
the number of rows and n is the number of columns. (c)All the positive allocations must be in
independent positions. The initial solution of a transportation problem is said to be non-degenerate
basic feasible solution if it satisfies: Codes:
(a) and (b) only
A
(a) and (c) only
B
(b) and (c) only
C
(a), (b) and (c)
D
Question 32

The time required to search an element in a linked list of length n is


O (log n)
A
O (n)
B
O (1)
C
O(n ) 2

D
Question 33

Which of the following operations is performed more efficiently by doubly linked list than by linear
linked list?
Deleting a node whose location is given
A
Searching an unsorted list for a given item
B
Inserting a node after the node with a given location
C
Traversing the list to process each node
D
Question 34

The time required to search an element in a linked list of length n is


O (log n)
A
O (n)
B
O (1)
C
O(n2)
D
Question 35

The minimum number of fields with each node of doubly linked list is
1
A
2
B
3
C
4
D
Question 36

A doubly linked list is declared as


struct Node {
int Value;
struct Node *Fwd;
struct Node *Bwd;
);
Where Fwd and Bwd represent forward and backward link to the adjacent elements of the list. Which
of the following segments of code deletes the node pointed to by X from the doubly linked list, if it is
assumed that X points to neither the first nor the last node of the list?
X->Bwd->Fwd = X->Fwd; X->Fwd->Bwd = X->Bwd ;
A
X->Bwd.Fwd = X->Fwd ; X.Fwd->Bwd = X->Bwd ;
B
X.Bwd->Fwd = X.Bwd ; X->Fwd.Bwd = X.Bwd ;
C
X->Bwd->Fwd = X->Bwd ; X->Fwd->Bwd = X->Fwd;
D
Question 37

Consider a singly linked list of the form where F is a pointer to the first element in the linked list and L
is the pointer to the last element in the list. The time of which of the following operations depends on
the length of the list?
Delete the last element of the list
A
Delete the first element of the list
B
Add an element after the last element of the list
C
Interchange the first two elements of the list
D
Question 1
Following is C like pseudo code of a function that takes a number as an argument, and uses a stack
S to do processing.
void fun(int n)
{
Stack S; // Say it creates an empty stack S
while (n > 0)
{
// This line pushes the value of n%2 to stack S
push(&S, n%2);

n = n/2;
}

// Run while Stack S is not empty


while (!isEmpty(&S))
printf("%d ", pop(&S)); // pop an element from S and print it
}
Run on IDE
What does the above function do in general?
Prints binary representation of n in reverse order
A
Prints binary representation of n
B
Prints the value of Logn
C
Prints the value of Logn in reverse order
D
Stack
Discuss it

Question 2

Which one of the following is an application of Stack Data Structure?


Managing function calls
A
The stock span problem
B
Arithmetic expression evaluation
C
All of the above
D
Stack
Discuss it

Question 3

Which of the following is true about linked list implementation of stack?


In push operation, if new nodes are inserted at the beginning of linked list, then

A in pop operation, nodes must be removed from end.


In push operation, if new nodes are inserted at the end, then in pop operation,

B nodes must be removed from the beginning.

Both of the above


C
None of the above
D
Stack
Discuss it

Question 4

Consider the following pseudocode that uses a stack


declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}
Run on IDE
What is output for input "geeksquiz"?
geeksquizgeeksquiz
A
ziuqskeeg
B
geeksquiz
C
ziuqskeegziuqskeeg
D
Stack
Discuss it

Question 5

Following is an incorrect pseudocode for the algorithm which is supposed to determine whether a
sequence of parentheses is balanced:
declare a character stack
while ( more input is available)
{
read a character
if ( the character is a '(' )
push it on the stack
else if ( the character is a ')' and the stack is not empty )
pop a character off the stack
else
print "unbalanced" and exit
}
print "balanced"
Run on IDE
Which of these unbalanced sequences does the above code think is balanced?
Source: http://www.cs.colorado.edu/~main/questions/chap07q.html
((())
A
())(()
B
(()()))
C
(()))()
D
Stack
Discuss it

Question 6

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:
6, 1
A
5, 7
B
3, 2
C
1, 5
D
Stack
Discuss it

Question 7

Let S be a stack of size n >= 1. Starting with the empty stack, suppose we push the first n natural
numbers in sequence, and then perform n pop operations. Assume that Push and Pop operation take
X seconds each, and Y seconds elapse between the end of one such stack operation and the start of
the next operation. For m >= 1, define the stack-life of m as the time elapsed from the end of Push(m)
to the start of the pop operation that removes m from S. The average stack-life of an element of this
stack is
n(X+ Y)
A
3Y + 2X
B
n(X + Y)-X
C
Y + 2X
D
Stack
Discuss it

Question 8

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)
(top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)
A
top1 + top2 = MAXSIZE
B
(top1= MAXSIZE/2) or (top2 = MAXSIZE)
C
top1= top2 -1
D
Stack
Discuss it

Question 9

Assume that the operators +, -, × are left associative and ^ is right associative. The order of
precedence (from highest to lowest) is ^, x , +, -. The postfix expression corresponding to the infix
expression a + b × c - d ^ e ^ f is
abc × + def ^ ^ -
A
abc × + de ^ f ^ -
B
ab + c × d - e ^ f ^
C
- + a × bc ^ ^ def
D
Stack GATE-CS-2004
Discuss it

Question 10

To evaluate an expression without any embedded function calls:


One stack is enough
A
Two stacks are needed
B
As many stacks as the height of the expression tree are needed
C
A Turing machine is needed in the general case
D
Stack GATE-CS-2002
Discuss it

Stack
123
Question 11

The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is


284
A
213
B
142
C
71
D
Stack GATE-CS-2015 (Set 3)
Discuss it

Question 12

A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i))
= max (f(S), 0) + i for all stacks S and integers i.
If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?
6
A
4
B
3
C
2
D
Stack Gate IT 2005
Discuss it

Question 13

Consider the following C program:


#include
#define EOF -1
void push (int); /* push the argument on the stack */
int pop (void); /* pop the top of the stack */
void flagError ();
int main ()
{ int c, m, n, r;
while ((c = getchar ()) != EOF)
{ if (isdigit (c) )
push (c);
else if ((c == '+') || (c == '*'))
{ m = pop ();
n = pop ();
r = (c == '+') ? n + m : n*m;
push (r);
}
else if (c != ' ')
flagError ();
}
printf("% c", pop ());
}
Run on IDE
What is the output of the program for the following input ? 5 2 * 3 3 2 + * +
15
A
25
B
30
C
150
D
Stack C Quiz - 113 Gate IT 2007
Discuss it

Question 14

Suppose a stack is to be implemented with a linked list instead of an array. What would be the effect
on the time complexity of the push and pop operations of the stack implemented using linked list
(Assuming stack is implemented efficiently)?
O(1) for insertion and O(n) for deletion
A
O(1) for insertion and O(1) for deletion
B
O(n) for insertion and O(1) for deletion
C
O(n) for insertion and O(n) for deletion
D
Stack GATE 2017 Mock
Discuss it

Question 15

Consider n elements that are equally distributed in k stacks. In each stack, elements of it are
arranged in ascending order (min is at the top in each of the stack and then increasing downwards).
Given a queue of size n in which we have to put all n elements in increasing order. What will be the
time complexity of the best known algorithm?
O(n logk)
A
O(nk)
B
O(n ) 2

C
O(k ) 2

D
Stack GATE 2017 Mock
Discuss it

Question 16

A priority queue Q is used to implement a stack S that stores characters. PUSH(C) is implemented as
INSERT(Q, C, K) where K is an appropriate integer key chosen by the implementation. POP is
implemented as DELETEMIN(Q). For a sequence of operations, the keys chosen are in
Non-increasing order
A
Non-decreasing order
B
strictly increasing order
C
strictly decreasing order
D
Stack GATE CS 1997
Discuss it

Question 17

Consider the following statements:


i. First-in-first out types of computations are efficiently supported by STACKS.
ii. Implementing LISTS on linked lists is more efficient than implementing LISTS on
an array for almost all the basic LIST operations.
iii. Implementing QUEUES on a circular array is more efficient than implementing
QUEUES
on a linear array with two indices.
iv. Last-in-first-out type of computations are efficiently supported by QUEUES.
Which of the following is correct?
(ii) and (iii) are true
A
(i) and (ii) are true
B
(iii) and (iv) are true
C
(ii) and (iv) are true
D
Linked List Stack Queue GATE CS 1996
Discuss it

Question 18

Which of the following permutation can be obtained in the same order using a stack assuming that
input is the sequence 5, 6, 7, 8, 9 in that order?
7, 8, 9, 5, 6
A
5, 9, 6, 7, 8
B
7, 8, 9, 6, 5
C
9, 8, 7, 5, 6
D
Stack ISRO CS 2017
Discuss it

Question 19

The minimum number of stacks needed to implement a queue is


3
A
1
B
2
C
4
D
Stack Queue ISRO CS 2017
Discuss it

Question 20

The best data structure to check whether an arithmetic expression has balanced parenthesis is a
Queue
A
Stack
B
Tree
C
List
D
Question 11

Consider the following code snippet in C. The function print() receives root of a Binary Search Tree
(BST) and a positive integer k as arguments.

Question 21

A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of
keys.

I. 81, 537, 102, 439, 285, 376, 305

II. 52, 97, 121, 195, 242, 381, 472

III. 142, 248, 520, 386, 345, 270, 307

IV. 550, 149, 507, 395, 463, 402, 270

Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences
list nodes in the order in which we could have encountered them in the search?
II and III only
A
I and III only
B
III and IV only
C
III only
D
Binary Search Trees Gate IT 2008
Discuss it

Question 22

A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of
keys.
I. 81, 537, 102, 439, 285, 376, 305
II. 52, 97, 121, 195, 242, 381, 472
III. 142, 248, 520, 386, 345, 270, 307
IV. 550, 149, 507, 395, 463, 402, 270
Which of the following statements is TRUE?
I, II and IV are inorder sequences of three different BSTs
A
I is a preorder sequence of some BST with 439 as the root
B
II is an inorder sequence of some BST where 121 is the root and 52 is a leaf
C
IV is a postorder sequence of some BST with 149 as the root
D
Binary Search Trees Gate IT 2008
Discuss it
Question 23

How many distinct BSTs can be constructed with 3 distinct keys?


4
A
5
B
6
C
9
D
Binary Search Trees Gate IT 2008
Discuss it

Question 24

A binary search tree is generated by inserting in order the following integers:


50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
The number of nodes in the left subtree and right subtree of the root respectively is
(4, 7)
A
(7, 4)
B
(8, 3)
C
(3, 8)
D
Binary Search Trees GATE CS 1996
Discuss it

Question 25

A binary search tree is used to locate the number 43. Which of the following probe sequences are
possible and which are not? Explain
61 52 14 17 40 43
A
2 3 50 40 60 43
B
10 65 31 48 37 43
C
81 61 52 14 41 43
D
17 77 27 66 18 43
E
Binary Search Trees GATE CS 1996
Discuss it
Question 26

The postorder traversal of a binary tree is 8, 9, 6, 7, 4, 5, 2, 3, 1. The inorder traversal of the same
tree is 8, 6, 9, 4, 7, 2, 5, 1, 3. The height of a tree is the length of the longest path from the root to any
leaf. The height of the binary tree above is ________ . Note -This was Numerical Type question.
2
A
3
B
4
C
5
D
Binary Search Trees GATE CS 2018
Discuss it

Question 27

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5,
15, 12, 16 What is the height of the binary search tree ?
3
A
4
B
5
C
6
D
Binary Search Trees UGC-NET CS 2017 Nov - II
Discuss it

Question 28

Postorder traversal of a given binary search tree T produces following sequence of keys: 3, 5, 7, 9, 4,
17, 16, 20, 18, 15, 14 Which one of the following sequences of keys can be the result of an in-order
traversal of the tree T?
3, 4, 5, 7, 9, 14, 20, 18, 17, 16, 15
A
20, 18, 17, 16, 15, 14, 3, 4, 5, 7, 9
B
20, 18, 17, 16, 15, 14, 9, 7, 5, 4, 3
C
3, 4, 5, 7, 9, 14, 15, 16, 17, 18, 20
D
Binary Search Trees UGC-NET CS 2017 Nov - II
Discuss it
Question 29

A binary search tree is used to locate the number 43. Which one of the following probe sequence is
not possible?
61, 52, 14, 17, 40, 43
A
10, 65, 31, 48, 37, 43
B
81, 61, 52, 14, 41, 43
C
17, 77, 27, 66, 18, 43
D
Binary Search Trees ISRO CS 2017
Discuss it

Question 30

Which of the following statements is false ? (A) Optimal binary search tree construction can be
performed efficiently using dynamic programming. (B) Breadth-first search cannot be used to find
connected components of a graph. (C) Given the prefix and postfix walks of a binary tree, the tree
cannot be re-constructed uniquely. (D) Depth-first-search can be used to find the connected
components of a graph.
A
A
B
B
C
C
D
D
Binary Search Trees UGC NET CS 2017 Jan -

Binary Search Trees


1234
Question 31

Access time of the symbolic table will be logarithmic if it is implemented by


Linear list
A
Search tree
B
Hash table
C
Self organization list
D
Binary Search Trees ISRO CS 2016
Discuss it

Question 32

Consider the following binary search tree T given below: Which node contains the fourth smallest

element in T?
Q
A
V
B
W
C
X
D
Binary Search Trees ISRO CS 2014
Discuss it

Question 33

Consider the following binary search tree: If we remove the root node, which of the node from
the left subtree will be the new root?
11
A
12
B
13
C
16
D
Binary Search Trees UGC NET CS 2016 July – II
Discuss it

Question 34

Suppose that we have numbers between 1 and 1,000 in a binary search tree and want to search for
the number 364. Which of the following sequences could not be the sequence of nodes examined ?
925, 221, 912, 245, 899, 259, 363, 364
A
3, 400, 388, 220, 267, 383, 382, 279, 364
B
926, 203, 912, 241, 913, 246, 364
C
3, 253, 402, 399, 331, 345, 398, 364
D
Binary Search Trees UGC NET CS 2016 July – III
Discuss it

Question 35

The number of disk pages access in B - tree search, where h is height, n is the number of keys, and t
is the minimum degree, is:
θ(logn h * t)
A
θ(log n * h)
t

B
θ(log n)
h

C
θ(log n)
t

D
Binary Search Trees UGC NET CS 2015 Dec - II
Discuss it

Question 36

How many distinct binary search trees can be created out of 4 distinct keys?
5
A
14
B
24
C
35
D
Binary Search Trees ISRO CS 2011
Discuss it

Question 37

The average depth of a binary search tree is:


O(n0.5)
A
O(n)
B
O(log n)
C
O(n log n)
D
Binary Search Trees ISRO CS 2011
Discuss it
Question 38

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5,
15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf
node from the root)?
2
A
3
B
4
C
6
D
Binary Search Trees ISRO CS 2009
Discuss it
uestion 1

The worst case running time to search for an element in a balanced in a binary search tree with n2^n
elements is
(A)
(B)
(C)
(D)
A
A
B
B
C
C
D
D
Balanced Binary Search Trees
Discuss it

Question 2

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.
2
A
3
B
4
C
5
D
Balanced Binary Search Trees
Discuss it

Question 3

What is the worst case possible height of AVL tree?


2Logn

A Assume base of log is 2

1.44log n

B Assume base of log is 2

Depends upon implementation


C
Theta(n)
D
Balanced Binary Search Trees
Discuss it

Question 4

Which of the following is AVL Tree?


A
100
/
50 200
/
10 300

B
100
/
50 200
/ /
10 150 300
/
5

C
100
/
50 200
/ /
10 60 150 300
/
5 180 400
Only A
A
A and C
B
A, B and C
C
Only B
D
Balanced Binary Search Trees
Discuss it

Question 5

Consider the following AVL tree.


60
/
20 100
/
80 120
Which of the following is updated AVL tree after insertion of 70
A
70
/
60 100
/ /
20 80 120

B
100
/
60 120
/ /
20 70 80

C
80
/
60 100
/
20 70 120

D
80
/
60 100
/ /
20 70 120
A
A
B
B
C
C
D
D
Balanced Binary Search Trees
Discuss it

Question 6

Which of the following is a self-adjusting or self-balancing Binary Search Tree


Splay Tree
A
AVL Tree
B
Red Black Tree
C
All of the above
D
Balanced Binary Search Trees
Discuss it

Question 7

Consider the following left-rotate and right-rotate functions commonly used in self-adjusting BSTs
T1, T2 and T3 are subtrees of the tree rooted with y (on left side)
or x (on right side)
y x
/ Right Rotation /
x T3 – - – - – - – > T1 y
/ < - - - - - - - /
T1 T2 Left Rotation T2 T3
Which of the following is tightest upper bound for left-rotate and right-rotate operations.
O(1)
A
O(Logn)
B
O(LogLogn)
C
O(n)
D
Balanced Binary Search Trees
Discuss it

Question 8

Which of the following is true


The AVL trees are more balanced compared to Red Black Trees, but they may

A cause more rotations during insertion and deletion.

Heights of AVL and Red-Black trees are generally same, but AVL Trees may

B cause more rotations during insertion and deletion.

Red Black trees are more balanced compared to AVL Trees, but may cause

C more rotations during insertion and deletion.


Heights of AVL and Red-Black trees are generally same, but Red Black rees

D may cause more rotations during insertion and deletion.


Balanced Binary Search Trees
Discuss it

Question 9

Which of the following is true about Red Black Trees?


The path from the root to the furthest leaf is no more than twice as long as the

A path from the root to the nearest leaf

At least one children of every black node is red


B
Root may be red
C
A leaf node may be red
D
Balanced Binary Search Trees
Discuss it

Question 10

Which of the following is true about AVL and Red Black Trees?
In AVL tree insert() operation, we first traverse from root to newly inserted

A node and then from newly inserted node to root. While in Red Black tree
insert(), we only traverse once from root to newly inserted node.

In both AVL and Red Black insert operations, we traverse only once from root

B to newly inserted node,

In both AVL and Red Black insert operations, we traverse twiceL first traverse

C root to newly inserted node and then from newly inserted node to root.
None of the above
D
Balanced Binary Search Trees
Question 11

What is the worst case possible height of Red-Black tree? Assume base of Log as 2 in all options
2Log(n+1)
A
1.44 Logn
B
4Logn
C
None of the above
D
Balanced Binary Search Trees
Discuss it

Question 12

Is the following statement valid? A Red-Black Tree which is also a perfect Binary Tree can have all
black nodes
Yes
A
No
B
Balanced Binary Search Trees
Discuss it

Question 13

Which of the following operations are used by Red-Black trees to maintain balance
during insertion/deletion?

a) Recoloring of nodes
b) Rotation (Left and Right)
Only a
A
Only b
B
Both a and b
C
Neither a nor b
D
Balanced Binary Search Trees
Discuss it

Question 14

A program takes as input a balanced binary search tree with n leaf nodes and computes the value of
a function g(x) for each node x. If the cost of computing g(x) is min{no. of leaf-nodes in left-subtree of
x, no. of leaf-nodes in right-subtree of x} then the worst-case time complexity of the program is
Θ(n)
A
Θ(nLogn)
B
Θ(n ) 2

C
Θ(n log n)
2

D
Balanced Binary Search Trees GATE-CS-2004
Discuss it

Question 15

Which of the following is TRUE?


The cost of searching an AVL tree is θ (log n) but that of a binary search tree is

A O(n)

The cost of searching an AVL tree is θ (log n) but that of a complete binary

B tree is θ (n log n)

The cost of searching a binary search tree is O (log n ) but that of an AVL tree

C is θ(n)
The cost of searching an AVL tree is θ (n log n) but that of a binary search tree

D is O(n)
Analysis of Algorithms Balanced Binary Search Trees Gate IT 2008
Discuss it
Question 16

Given two Balanced binary search trees, B1 having n elements and B2 having m elements, what is
the time complexity of the best known algorithm to merge these trees to form another balanced binary
tree containing m+n elements ?
O(m+n)
A
O(mlogn)
B
O(nlogm)
C
O(m + n )
2 2

D
Balanced Binary Search Trees GATE 2017 Mock
Discuss it

Question 17

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary
search tree. The binary search tree uses the reversal ordering on natural numbers i.e. 9 is assumed
to be smallest and 0 is assumed to be largest. The in-order traversal of the resultant binary search
tree is
9, 8, 6, 4, 2, 3, 0, 1, 5, 7
A
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
B
0, 2, 4, 3, 1, 6, 5, 9, 8, 7
C
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
D
Balanced Binary Search Trees Tree Traversals ISRO CS 2017
Discuss it

Question 18

The recurrence relation that arises in relation with the complexity of binary search is:
T(n) = 2T(n/ 2) + k , where k is constant
A
T(n) = T(n / 2) + k , where k is constant
B
T(n) = T(n / 2) + log n
C
T(n) = T(n / 2) + n
D
Balanced Binary Search Trees Searching ISRO CS 2017 - May
Discuss it
Question 19

A data structure is required for storing a set of integers such that each of the following operations can
be done in O(log n) time, where n is the number of elements in the set. I. Deletion of the smallest
element II. Insertion of an element if it is not already present in the set Which of the following data
structures can be used for this purpose?
A heap can be used but not a balanced binary search tree
A
A balanced binary search tree can be used but not a heap
B
Both balanced binary search tree and heap can be used
C
Neither balanced search tree nor heap can be used
D
Question 1

Which of the following is an advantage of adjacency list representation over adjacency matrix
representation of a graph?
In adjacency list representation, space is saved for sparse graphs.
A
DFS and BSF can be done in O(V + E) time for adjacency list representation.

These operations take O(V^2) time in adjacency matrix representation. Here is


B
V and E are number of vertices and edges respectively.

Adding a vertex in adjacency list representation is easier than adjacency matrix

C representation.
All of the above
D
Graph
Discuss it

Question 2

The degree sequence of a simple graph is the sequence of the degrees of the nodes in the graph in
decreasing order. Which of the following sequences can not be the degree sequence of any graph?

I. 7, 6, 5, 4, 4, 3, 2, 1
II. 6, 6, 6, 6, 3, 3, 2, 2
III. 7, 6, 6, 4, 4, 3, 2, 2
IV. 8, 7, 7, 6, 4, 2, 1, 1

I and II
A
III and IV
B
IV only
C
II and IV
D
Graph
Discuss it

Question 3

The time complexity of computing the transitive closure of a binary relation on a set of n elements is
known to be:
O(n)
A
O(nLogn)
B
O(n ^ (3/2))
C
O(n^3)
D
Graph
Discuss it

Question 4

The most efficient algorithm for finding the number of connected components in an undirected graph
on n vertices and m edges has time complexity. (A) (n) (B) (m) (C) (m + n) (D) (mn)
A
A
B
B
C
C
D
D
Graph
Discuss it

Question 5

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)
d(r, u) < d (r, v)
A
d(r, u) > d(r, v)
B
d(r, u) <= d (r, v)
C
None of the above
D
Graph
Discuss it

Question 6

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 ?
n(n-l)/2
A
2^n
B
n!
C
2^(n(n-1)/2)
D
Graph
Discuss it

Question 7

Which of the following statements is/are TRUE for an undirected graph? P: Number of odd degree
vertices is even Q: Sum of degrees of all vertices is even
P Only
A
Q Only
B
Both P and Q
C
Neither P nor Q
D
Graph
Discuss it

Question 8

Consider an undirected random graph of eight vertices. The probability that there is an edge between
a pair of vertices is 1/2. What is the expected number of unordered cycles of length three?
1/8
A
1
B
7
C
8
D
Graph
Discuss it

Question 9

Given an undirected graph G with V vertices and E edges, the sum of the degrees of all vertices is
E
A
2E
B
V
C
2V
D
Graph
Discuss it

Question 10

How many undirected graphs (not necessarily connected) can be constructed out of a given set V =
{v1, v2, ... vn} of n vertices?
n(n-1)/2
A
2 n

B
n!
C
2 n(n-1)/2

D
Graph GATE-CS-2001
Discuss it

Question 11

What is the maximum number of edges in an acyclic undirected graph with n vertices?
n-1
A
n
B
n+1
C
2n-1
D
Graph GATE-IT-2004
Discuss it

Question 12

Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is
a minimum weight spanning tree in G containing the edge e. Which of the following statements is
always TRUE?
There exists a cutset in G having all edges of maximum weight.
A
There exists a cycle in G having all edges of maximum weight
B
Edge e cannot be contained in a cycle.
C
All edges in G have the same weight
D
Graph Gate IT 2005
Discuss it

Question 13

Q84 Part_B
A sink in a directed graph is a vertex i such that there is an edge from every vertex j ≠ i to i and there
is no edge from i to any other vertex. A directed graph G with n vertices is represented by its
adjacency matrix A, where A[i] [j] = 1 if there is an edge directed from vertex i to j and 0 otherwise.
The following algorithm determines whether there is a sink in the graph G.
i = 0
do {
j = i + 1;
while ((j < n) && E1) j++;
if (j < n) E2;
} while (j < n);

flag = 1;
for (j = 0; j < n; j++)
if ((j! = i) && E3)
flag = 0;

if (flag)
printf("Sink exists");
else
printf("Sink does not exist");
Choose the correct expressions for E3
(A[i][j] && !A[j][i])
A
(!A[i][j] && A[j][i])
B
(!A[i][j] | | A[j][i])
C
(A[i][j] | | !A[j][i])
D
Graph Gate IT 2005
Discuss it

Question 14

Q85 Part_A Consider a simple graph with unit edge costs. Each node in the graph represents a
router. Each node maintains a routing table indicating the next hop router to be used to relay a packet
to its destination and the cost of the path to the destination through that router. Initially, the routing
table is empty. The routing table is synchronously updated as follows. In each updation interval, three
tasks are performed.
1. A node determines whether its neighbours in the graph are accessible. If so, it sets the tentative
cost to each accessible neighbour as 1. Otherwise, the cost is set to ∞.
2. From each accessible neighbour, it gets the costs to relay to other nodes via that neighbour (as
the next hop).
3. Each node updates its routing table based on the information received in the previous two steps
by choosing the minimum cost.

For the graph given above, possible routing tables for various nodes after they have stabilized, are
shown in the following options. Identify the correct table.
Table for node A

A - -
1)
B B 1

C C 1
D B 3

E C 3

F C 4

Table for node C

A A 1

B B 1

2) C - -

D D 1

E E 1

F E 3

Table for node B

A A 1

B - -

3) C C 1

D D 1

E C 2

F D 2

Table for node D

A B 3

B B 1

4) C C 1

D - -

E E 1

F F 1

A
A
B
B
C
C
D
D
Graph Gate IT 2005
Discuss it

Question 15

Q85 Part_B Consider a simple graph with unit edge costs. Each node in the graph represents a
router. Each node maintains a routing table indicating the next hop router to be used to relay a packet
to its destination and the cost of the path to the destination through that router. Initially, the routing
table is empty. The routing table is synchronously updated as follows. In each updation interval, three
tasks are performed.
1. A node determines whether its neighbours in the graph are accessible. If so, it sets the tentative
cost to each accessible neighbour as 1. Otherwise, the cost is set to ∞.
2. From each accessible neighbour, it gets the costs to relay to other nodes via that neighbour (as
the next hop).
3. Each node updates its routing table based on the information received in the previous two steps
by choosing the minimum cost.

For the graph given above, possible routing tables for various nodes after they have stabilized, are
shown in the following options. Identify the correct table.
Table for node A

A - -

B B 1
1)
C C 1

D B 3

E C 3
F C 4

Table for node C

A A 1

B B 1

2) C - -

D D 1

E E 1

F E 3

Table for node B

A A 1

B - -

3) C C 1

D D 1

E C 2

F D 2

Table for node D

A B 3

B B 1

4) C C 1

D - -

E E 1

F F 1

Continuing from the earlier problem, suppose at some time t, when the costs have stabilized, node A
goes down. The cost from node F to node A at time (t + 100) is
>100 but finite
A

B
3
C
>3 and ≤100
D
Graph Gate IT 2005
Discuss it

Question 16

The cyclomatic complexity of the flow graph of a program provides


an upper bound for the number of tests that must be conducted to ensure that

A all statements have been executed at most once

a lower bound for the number of tests that must be conducted to ensure that all

B statements have been executed at most once

an upper bound for the number of tests that must be conducted to ensure that

C all statements have been executed at least once


a lower bound for the number of tests that must be conducted to ensure that all

D statements have been executed at least once


Graph Software Engineering GATE IT 2006
Discuss it

Question 17

What is the largest integer m such that every simple connected graph with n vertices and n edges
contains at least m different spanning trees?
1
A
2
B
3
C
n
D
Graph Graph Minimum Spanning Tree Gate IT 2007
Discuss it

Question 18
For the undirected, weighted graph given below, which of the following sequences of edges
represents a correct execution of Prim's algorithm to construct a Minimum Spanning Tree?

(a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)
A
(c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)
B
(d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)
C
(h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)
D
Graph Gate IT 2008
Discuss it

Question 19

Consider a directed graph with n vertices and m edges such that all edges have same edge weights.
Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?
O(m+n)
A
O(m logn)
B
O(mn)
C
O(n logm)
D
Graph GATE 2017 Mock
Discuss it

Question 20

You are given a graph containing n vertices and m edges and given that the graph doesn’t contain
cycle of odd length. Time Complexity of the best known algorithm to find out whether the graph is
bipartite or not is ?
O(m+n)
A
O(1)
B
O(mn)
C
O(n2)
D
Graph GATE 2017 Mock
Discuss it
Question 21

Let G be a simple graph with 20 vertices and 8 components. If we delete a vertex in G, then number
of components in G should lie between ____.
8 and 20
A
8 and 19
B
7 and 19
C
7 and 20
D
Graph GATE 2017 Mock
Discuss it

Question 22

Let G be the graph with 100 vertices numbered 1 to 100. Two vertices i and j are adjacent
iff |i−j|=8 or |i−j|=12. The number of connected components in G is
8
A
4
B
12
C
25
D
Graph GATE CS 1997
Discuss it

Question 23

A complete, undirected, weighted graph G is given on the vertex {0, 1,...., n−1} for any fixed ‘n’. Draw
the minimum spanning tree of G if a) the weight of the edge (u,v) is ∣ u−v ∣ b) the weight of the edge
(u,v) is u + v
Analysis of Algorithms Graph GATE CS 1996
Discuss it

Question 24
Let G be the directed, weighted graph shown in below

figure We are interested in the shortest paths from A. (a)


Output the sequence of vertices identified by the Dijkstra’s algorithm for single source shortest path
when the algorithm is started at node A. (b) Write down sequence of vertices in the shortest path from
A to E. (c) What is the cost of the shortest path from A to E?
Divide and Conquer Graph GATE CS 1996
Discuss it

Question 25

Which of the following data structure is useful in traversing a given graph by breadth first search?
Stack
A
List
B
Queue
C
None of the above.
D
Graph Graph Shortest Paths ISRO CS 2017 - May
Discuss it

Question 26

In the following graph, discovery time stamps and finishing time stamps of Depth First Search (DFS)

are shown as x/y, where x is discovery time stamp and y is finishing time stamp.
It shows which of the following depth first forest?
{a, b, e} {c, d, f, g, h}
A
{a, b, e} {c, d, h} {f, g}
B
{a, b, e} {f, g} {c, d} {h}
C
{a, b, c, d} {e, f, g} {h}
D
Question 1

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?
46, 42, 34, 52, 23, 33
A
34, 42, 23, 52, 33, 46
B
46, 34, 42, 23, 52, 33
C
42, 46, 33, 23, 34, 52
D
Hash
Discuss it

Question 2

How many different insertion sequences of the key values using the same hash function and linear
probing will result in the hash table shown above?
10
A
20
B
30
C
40
D
Hash
Discuss it

Question 3
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?
A
A
B
B
C
C
D
D
Hash
Discuss it

Question 4

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.
8, _, _, _, _, _, 10
A
1, 8, 10, _, _, _, 3
B
1, _, _, _, _, _,3
C
1, 10, 8, _, _, _, 3
D
Hash
Discuss it

Question 5

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.
8, _, _, _, _, _, 10
A
1, 8, 10, _, _, _, 3
B
1, _, _, _, _, _,3
C
1, 10, 8, _, _, _, 3
D
Hash
Discuss it

Question 6

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? i. 9679, 1989, 4199 hash to the same value ii.
1471, 6171 has to the same value iii. All elements hash to the same value iv. Each element hashes to
a different value (GATE CS 2004)
i only
A
ii only
B
i and ii only
C
iii or iv
D
Hash
Discuss it

Question 7

Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple
uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?
(97 × 97 × 97)/1003
A
(99 × 98 × 97)/100 3

B
(97 × 96 × 95)/100 3

C
(97 × 96 × 95)/(3! × 100 ) 3

D
Hash GATE-CS-2014-(Set-3)
Discuss it

Question 8

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?
h(i) =i2 mod 10
A
h(i) =i mod 10
3

B
h(i) = (11 ∗ i ) mod 10
2

C
h(i) = (12 ∗ i) mod 10
D
Hash GATE-CS-2015 (Set 2)
Discuss it

Question 9

Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is __________
80
A
0.0125
B
8000
C
1.25
D
Hash GATE-CS-2015 (Set 3)
Discuss it

Question 10

Which of the following statement(s) is TRUE?


1. A hash function takes a message of arbitrary length and generates a fixed length code.
2. A hash function takes a message of fixed length and generates a code of variable length.
3. A hash function may give the same hash value for distinct messages.

I only
A
II and III only
B
I and III only
C
II only
D
Hash GATE IT 2006 Python Data Type
Discuss it
Question 11

Consider a hash table with n buckets, where external (overflow) chaining is used to resolve collisions.
The hash function is such that the probability that a key value is hashed to a particular bucket is 1/n.
The hash table is initially empty and K distinct values are inserted in the table. a. What is the
probability that bucket number 1 is empty after the Kth insertion? b. What is the probability that no
collision has occurred in any of the K insertions? c. What is the probability that the first collision
occurs at the Kth insertion?
Hash Probability GATE CS 1997
Discuss it

Question 12

An advantage of chained hash table (external hashing) over the open addressing scheme is
Worst case complexity of search operations is less
A
Space used is less
B
Deletion is easier
C
None of the above
D
Hash GATE CS 1996
Discuss it

Question 13

Insert the characters of the string K R P C S N Y T J M into a hash table of size 10. Use the hash
function
h(x) = ( ord(x) – ord("a") + 1 ) mod10
and linear probing to resolve collisions. (a) Which insertions cause collisions? (b) Display the final
hash table.
Hash GATE CS 1996
Discuss it

Question 14

The characters of the string K R P C S N Y T J M are inserted into a hash table of size 10 using hash
function
h(x) = ((ord(x) - ord(A) + 1)) mod 10
If linear probing is used to resolve collisions, then the following insertion causes collision
Y
A
C
B
M
C
P
D
Hash ISRO CS 2017
Discuss it
Question 15

A hash table with ten buckets with one slot per bucket is shown in the following figure. The symbols
S1 to S7 initially entered using a hashing function with linear probing.The maximum number of

comparisons needed in searching an item that is not present is


4
A
5
B
6
C
3
D
Hash ISRO CS 2015
Discuss it

Question 16

Consider a hash table of size m = 10000, and the hash function h(K) = floor (m(KA mod 1)) for A = (
√(5) – 1)/2. The key 123456 is mapped to location ______.
46
A
41
B
43
C
48
D
Hash UGC NET CS 2016 Aug - III
Discuss it

Question 17

Consider a 13 element hash table for which f(key)=key mod 13 is used with integer keys. Assuming
linear probing is used for collision resolution, at which location would the key 103 be inserted, if the
keys 661, 182, 24 and 103 are inserted in that order?
0
A
1
B
11
C
12
D
Hash ISRO CS 2014
Discuss it
Question 18

What will be the cipher text produced by the following cipher function for the plain text ISRO with key
k =7. [Consider 'A' = 0, 'B' = 1, .......'Z' = 25]. Ck(M) = (kM + 13) mod 26
RJCH
A
QIBG
B
GQPM
C
XPIN
D
Hash ISRO CS 2013
Discuss it

Question 19

Consider a hash table of size m = 100 and the hash function h(k) = floor(m(kA mod 1))
for Compute the location to which the key k = 123456 is placed
in hash table.
77
A
82
B
88
C
89
D
Hash UGC NET CS 2015 Jun - III
Discuss it

Question 20

A hash table with 10 buckets with one slot per bucket is depicted here. The symbols, S1 to 57 are
initially entered using a hashing function with linear probing. The maximum number of comparisons

needed in searching an item that is not present is


4
A
5
B
6
C
3
D
Hash ISRO CS 2018
Discuss it
Question 21

A hash function h defined h(key)=key mod 7, with linear probing, is used to insert the keys 44, 45, 79,
55, 91, 18, 63 into a table indexed from 0 to 6. What will be the location of key 18 ?
3
A
4
B
5
C
6
D
Hash UGC NET CS 2018 July - II
Discuss it

Question 22

Consider a hash table of size seven, with starting index zero, and a hash function (7x+3) mod 4.
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 ? Here “__” denotes an empty
location in the table.
3, 10, 1, 8, __ , __ , __
A
1, 3, 8, 10, __ , __ , __
B
1, __ , 3, __ , 8, __ , 10
C
3, 10, __ , __ , 8, __ , __
D
Hash

Array
12
Question 1

A program P reads in 500 integers in the range [0..100] exepresenting the scores of 500 students. It then prints
the frequency of each score above 50. What would be the best way for P to store the frequencies? (GATE CS
2005)
An array of 50 numbers
A
An array of 100 numbers
B
An array of 500 numbers
C
A dynamically allocated array of 550 numbers
D
Array
Discuss it

Question 2

Which of the following operations is not O(1) for an array of sorted data. You may assume that array elements
are distinct.
Find the ith largest element
A
Delete an element
B
Find the ith smallest element
C
All of the above
D
Array
Discuss it

Question 3

The minimum number of comparisons required to determine if an integer appears more than n/2 times in a
sorted array of n integers is
Θ(n)
A
Θ(logn)
B
Θ(log*n)
C
Θ(1)
D
Array GATE CS 2008
Discuss it

Question 4

Let A be a square matrix of size n x n. Consider the following program. What is the expected output?
C = 100
for i = 1 to n do
for j = 1 to n do
{
Temp = A[i][j] + C
A[i][j] = A[j][i]
A[j][i] = Temp - C
}
for i = 1 to n do
for j = 1 to n do
Output(A[i][j]);
Run on IDE
The matrix A itself
A
Transpose of matrix A
B
Adding 100 to the upper diagonal elements and subtracting 100 from diagonal

C elements of A
None of the above
D
Array GATE-CS-2014-(Set-3)
Discuss it

Question 5

An algorithm performs (logN)1/2 find operations, N insert operations, (logN)1/2operations, and (logN)1/2 decrease-
key operations on a set of data items with keys drawn from a linearly ordered set. For a delete operation, a
pointer is provided to the record that must be deleted. For the decrease-key operation, a pointer is provided to
the record that has its key decreased. Which one of the following data structures is the most suited for the
algorithm to use, if the goal is to achieve the best total asymptotic complexity considering all the operations?
Unsorted array
A
Min-heap
B
Sorted array
C
Sorted doubly linked list
D
Array GATE-CS-2015 (Set 1)
Discuss it

Question 6

Consider an array consisting of –ve and +ve numbers. What would be the worst time comparisons an algorithm
can take in order to segregate the numbers having same sign altogether i.e all +ve on one side and then all -ve
on the other ?
N-1
A
N
B
N+1
C
(N*(N-1))/2
D
Array GATE 2017 Mock
Discuss it
Question 7

Let A[1...n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of
A. What is the expected number of inversions in any permutation on n elements ?
θ(n)
A
θ(lgn)
B
θ(nlgn)
C
θ(n ) 2

D
Array UGC NET CS 2016 July – III
Discuss it

Question 8

A three dimensional array in ‘C’ is declared as int A[x][y][z]. Here, the address of an item at the location
A[p][q][r] can be computed as follows (where w is the word length of an integer):
&A[0][0][0] + w(y * z * q + z * p + r)
A
&A[0][0][0] + w(y * z * p + z*q + r)
B
&A[0][0][0] + w(x * y * p + z * q+ r)
C
&A[0][0][0] + w(x * y * q + z * p + r)
D
Array UGC NET CS 2015 Dec - II
Discuss it

Question 9

Which of the following is an illegal array definition?


Type COLONGE : (LIME, PINE, MUSK, MENTHOL); var a : array

A [COLONGE] of REAL;

var a : array [REAL] of REAL;


B
var a : array [‘A’…’Z’] of REAL;
C
var a : array [BOOLEAN] of REAL;
D
Array ISRO CS 2008
Discuss it
Question 10

Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is 100. What is
the address of A[11, 5] ? Assume row major storage.
560
A
565
B
570
C
D
Question 11

An array A consists of n integers in locations A[0], A[1] ....A[n-1]. It is required to shift the elements of
the array cyclically to the left by k places, where 1 <= k <= (n-1). An incomplete algorithm for doing
this in linear time, without using another array is given below. Complete the algorithm by filling in the
blanks. Assume alt the variables are suitably declared.
min = n; i = 0;
while (___________) {
temp = A[i]; j = i;
while (________) {
A[j] = ________
j= (j + k) mod n ;
If ( j< min ) then
min = j;
}
A[(n + i — k) mod n] = _________
i = __________
i > min; j!= (n+i)mod n; A[j + k]; temp; i + 1 ;
A
i < min; j!= (n+i)mod n; A[j + k]; temp; i + 1;
B
i > min; j!= (n+i+k)mod n; A[(j + k)]; temp; i + 1;
C
i < min; j!= (n+i-k)mod n; A[(j + k)mod n]; temp; i + 1;
D
Array ISRO CS 2018 Data Structures Misc
1234
Question 1

Which data structure is used for balancing of symbols?


Stack
A
Queue
B
Tree
C
Graph
D
Data Structures Misc
Discuss it

Question 2

Which data structure is used in redo-undo feature?


Stack
A
Queue
B
Tree
C
Graph
D
Data Structures Misc
Discuss it

Question 3

Which data structure is most efficient to find the top 10 largest items out of 1 million items stored in
file?
Min heap
A
Max heap
B
BST
C
Sorted array
D
Data Structures Misc
Discuss it

Question 4

The best data structure to check whether an arithmetic expression has balanced parentheses is a
(GATE CS 2004)
queue
A
stack
B
tree
C
list
D
Data Structures Misc
Discuss it

Question 5

A data structure is required for storing a set of integers such that each of the following operations can
be done in (log n) time, where n is the number of elements in the set.
o Delection of the smallest element
o Insertion of an element if it is not already present in the set
Which of the following data structures can be used for this purpose?
A heap can be used but not a balanced binary search tree
A
A balanced binary search tree can be used but not a heap
B
Both balanced binary search tree and heap can be used
C
Neither balanced binary search tree nor heap can be used
D
Data Structures Misc
Discuss it

Question 6

The most appropriate matching for the following pairs


X: depth first search 1: heap
Y: breadth-first search 2: queue
Z: sorting 3: stack
is (GATE CS 2000):
X—1 Y—2 Z-3
A
X—3 Y—1 Z-2
B
X—3 Y—2 Z-1
C
X—2 Y—3 Z-1
D
Data Structures Misc
Discuss it
Question 7

Which among the following data structures is best suited for storing very large numbers (numbers that
cannot be stored in long long int). Following are the operations needed for these large numbers.
Array
A
Linked List
B
Binary Tree
C
Hash
D
Data Structures Misc
Discuss it

Question 8

Which data structure is best suited for converting recursive implementation to iterative implementation
of an algorithm?
Queue
A
Stack
B
Tree
C
Graph
D
Data Structures Misc
Discuss it

Question 9

Consider a situation where a client receives packets from a server. There may be differences in
speed of the client and the server. Which data structure is best suited for synchronization?
Circular Linked List
A
Queue
B
Stack
C
Priority Queue
D
Data Structures Misc
Discuss it

Question 10
Which of the following data structures is best suited for efficient implementation of priority queue?
Array
A
Linked List
B
Heap
C
Stack
D
Data Structures Misc
Discuss it

uestion 11

Which data structure in a compiler is used for managing information about variables and their
attributes?
Abstract syntax tree
A
Symbol table
B
Semantic stack
C
Parse Table
D
Data Structures Misc GATE CS 2010
Discuss it

Question 12

An Abstract Data Type (ADT) is:


Same as an abstract class
A
A data type that cannot be instantiated
B
A data type type for which only the operations defined on it can be used, but

C none else
All of the above
D
Data Structures Misc GATE-CS-2005
Discuss it

Question 13

A data structure is required for storing a set of integers such that each of the following operations can
be done in (log n) time, where n is the number of elements in the set.
o Delection of the smallest element
o Insertion of an element if it is not already present in the set
Which of the following data structures can be used for this purpose?
A heap can be used but not a balanced binary search tree
A
A balanced binary search tree can be used but not a heap
B
Both balanced binary search tree and heap can be used
C
Neither balanced binary search tree nor heap can be used
D
Data Structures Misc GATE-CS-2003
Discuss it

Question 14

A Young tableau is a 2D array of integers increasing from left to right and from top to bottom. Any
unfilled entries are marked with ∞, and hence there cannot be any entry to the right of, or below a ∞.
The following Young tableau consists of unique entries.
1 2 5 14
3 4 6 23
10 12 18 25
31 ∞ ∞ ∞
When an element is removed from a Young tableau, other elements should be moved into its place
so that the resulting table is still a Young tableau (unfilled entries may be filled in with a ∞). The
minimum number of entries (other than 1) to be shifted, to remove 1 from the given Young tableau is
____________
2
A
5
B
6
C
18
D
Data Structures Misc GATE-CS-2015 (Set 2)
Discuss it

Question 15

What is the value of


-1
A
1
B
0
C
π
D
Data Structures Misc Gate IT 2005
Discuss it

Question 16

A language L is a subset of Pascal with the following constructs: a). Expressions involving the
operators '+' and '<' only b). Assignment statements c). 'while' statements and d). Compound
statements with the syntax 'begin..............end' Give an unambiguous grammar for L.
Data Structures Misc GATE CS 1997
Discuss it

Question 17

Consider the following program fragment in Pascal:


Program Main;
var X : integer;
procedure A:
var Y : integer;
procedure B:
var Z : integer;
procedure C:
var Z : integer;
begin(*Procedure C*)
.
.
end(*Procedure C*)
begin(*Procedure B*)
.
.
C; (*call to C*)
A; (*call to A*)
.
.
end(*Procedure B*)
begin(*Procedure A*)
.
.
B; (*call to B*)
.
.
end(*Procedure A*)
begin (*Main*)
Assume that there are no calls to any procedures other than the ones indicated above. It is known
that at some point of time during the execution of this program five activation records exist on the run-
time stack. Describe the run-time stack at this point of time by clearly indicating the following: the top
of the stack, the contents of the static link and dynamic link, and allocation of the local variables in
each record.
Data Structures Misc GATE CS 1997
Discuss it

Question 18

Match the pairs in the following

questions:
A – 2, B – 1, C – 4, D – 3
A
A – 3, B – 4, C – 1, D – 2
B
A – 3, B – 1, C – 4, D – 2
C
A – 2, B – 4, C – 1, D – 3
D
Data Structures Misc Recursion GATE CS Mock 2018 | Set 2
Discuss it

Question 19

Consider a 2D-array A[10][20] using row major order in memory and the memory location we want to
access is A[y, z]. Known that each memory address occupies 4-bytes. Below is the 3-address code
for the same, fill the blank spaces with correct value :
x : A[y, z]
t1 = ---(1)--- * ---(2)---
t2 = t1 + z
t3 = t2 * ---(3)---
---(4)--- = base address of A
x = t4[---(5)---]
(1) : x (2) : 10 (3) : 4 (4) : t4 (5) : t3
A
(1) : y (2) : 10 (3) : t4 (4) : 4 (5) : t3
B
(1) : y (2) : 20 (3) : 4 (4) : t4 (5) : t3
C
None of these
D
Data Structures Misc GATE CS Mock 2018 | Set 2
Discuss it

Question 20

The number of possible min-heaps containing each value from {1, 2, 3, 4, 5, 6, 7} exactly once is
_______. Note -This was Numerical Type question.
80
A
8
B
20
C
210
D
Data Structures Misc Graph Theory GATE CS 2018
Discuss it
Question 21

Let G be a simple undirected graph. Let TD be a depth first search tree of G. Let TBbe 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 T D). (II)
For every edge (u, v) of G, if u is at depth i and v is at depth j in T B, then ∣i − j∣ = 1. Which of the
statements above must necessarily be true?
I only
A
II only
B
Both I and II
C
Neither I nor II
D
Data Structures Misc Tree Traversals GATE CS 2018
Discuss it

Question 22

A list of n strings, each of length n, is sorted into lexicographic order using merge - sort algorithm. The
worst case running time of this computation is :
O(n log n)
A
O(n log n)
2

B
O(n + log n)
2

C
O(n ) 3

D
Data Structures Misc UGC-NET CS 2017 Nov - II
Discuss it

Question 23

Heap allocation is required for languages that


use dynamic scope rules
A
support dynamic data structures
B
support recursion
C
support recursion and dynamic data structures
D
Data Structures Misc UGC-NET CS 2017 Nov - III
Discuss it

Question 24

If h is chosen from a universal collection of hash functions and is used to hash n keys into a table of
size m, where n ≤ m, the expected number of collisions involving a particular key x is less than
_______.
1
A
1/n
B
1/m
C
n/m
D
Data Structures Misc UGC NET CS 2017 Jan - II
Discuss it

Question 25

Below are the few steps given for scan-converting a circle using Bresenham’s Algorithm. Which of the
given steps is not correct ?
Compute d = 3 – 2r (where r is radius)
A
Stop if x > y
B
If d < 0, then d = 4x + 6 and x = x + 1
C
If d ≥ 0, then d = 4 ∗ (x – y) + 10, x = x + 1 and y = y + 1
D
Data Structures Misc UGC NET CS 2017 Jan - III
Discuss it

Question 26

Consider a line AB with A = (0, 0) and B = (8, 4). Apply a simple DDA algorithm and compute the first
four plots on this line.
[(0, 0), (1, 1), (2, 1), (3, 2)]
A
[(0, 0), (1, 1.5), (2, 2), (3, 3)]
B
[(0, 0), (1, 1), (2, 2.5), (3, 3)]
C
[(0, 0), (1, 2), (2, 2), (3, 2)]
D
Data Structures Misc UGC NET CS 2017 Jan - III
Discuss it

Question 27

The minimum number of scalar multiplication required, for parenthesization of a matrix-chain product
whose sequence of dimensions for four matrices is <5, 10, 3, 12, 5> is
630
A
580
B
480
C
405
D
Data Structures Misc UGC NET CS 2017 Jan - III
Discuss it

Question 28

Consider the following AO graph: Which is the best node to expand next by AO* algorithm?
A
A
B
B
C
C
B and C
D
Data Structures Misc UGC NET CS 2017 Jan - III
Discuss it

Question 29

A t-error correcting q-nary linear code must satisfy: Where M is the number of code words and X
is
qn
A
q t

B
q -n

C
q -t

D
Data Structures Misc UGC NET CS 2017 Jan - III
Discuss it

Question 30

Consider the following statements: S1: A queue can be implemented using two stacks. S2: A stack
can be implemented using two queues. Which of the following is correct?
S1 is correct and S2 is not correct.
A
S is not correct and S is correct.
1 2

B
Both S and S are correct.
1 2

C
Both S and S are incorrect.
1 2

D
Data Structures Misc
Question 31

Given the following prefix expression: * + 3 + 3 ↑ 3 + 3 3 3 What is the value of the prefix expression ?
2178
A
2199
B
2205
C
2232
D
Data Structures Misc UGC NET CS 2016 Aug – II
Discuss it

Question 32

In how many ways can the string A ∩ B – A ∩ B – A be fully parenthesized to yield an infix
expressionp?
15
A
14
B
13
C
12
D
Data Structures Misc UGC NET CS 2016 July – II
Discuss it

Question 33

Consider a source with symbols A, B, C, D with probabilities 1/2, 1/4, 1/8, 1/8 respectively. What is
the average number of bits per symbol for the Huffman code generated from above information ?
2 bits per symbol
A
1.75 bits per symbol
B
1.50 bits per symbol
C
1.25 bits per symbol
D
Data Structures Misc UGC NET CS 2016 July – III
Discuss it
Question 34

Match the following:


(1)
A
(2)
B
(3)
C
(4)
D
Data Structures Misc UGC NET CS 2015 Jun - II
Discuss it

Question 35

A symbol table of length 152 is processing 25 entries at any instant. What is occupation density?
0.164
A
127
B
8.06
C
6.08
D
Data Structures Misc ISRO CS 2011
Discuss it

Question 36

Given the symbols A, B, C, D, E, F, G and H with the probabilities 1 / 30, 1 / 30, 1 / 30, 2 / 30, 3 / 30,
5 / 30, 5 / 30, and 12 / 30 respectively. The average Huffman code size in bits per symbol is:
67 / 30
A
70 / 30
B
76 / 30
C
78/ 30
D
Data Structures Misc UGC NET CS 2015 Jun - III
Discuss it

Question 37
A 5-ary tree is tree in which every internal node has exactly 5 children. The number of left nodes in
such a tree with 8 internal nodes will be:
30
A
33
B
45
C
130
D
Data Structures Misc UGC NET CS 2018 July - II
Discuss it

Question 38

Consider the following two sentences : (a) The planning graph data structure can be used to give a
better heuristic for a planning problem. (b) Dropping negative effects from every action schema in a
planning problem results in a relaxed problem. Which of the following is correct with respect to the
above sentences ?
Both sentence (a) and sentence (b) are false.
A
Both sentence (a) and sentence (b) are true.
B
Sentence (a) is true but sentence (b) is false.
C
Sentence (a) is false but sentence (b) is true.
D
Data Structures Misc UGC NET CS 2018 July - II
Discuss it
Question 1

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)
1
A
2
B
3
C
4
D
B and B+ Trees
Discuss it

Question 2

Which one of the following is a key factor for preferring B-trees to binary search trees for indexing
database relations?
Database relations have a large number of records
A
Database relations are sorted on the primary key
B
B-trees require less memory than binary search trees
C
Data transfer form disks is in blocks.
D
B and B+ Trees
Discuss it

Question 3

B+ trees are preferred to binary trees in databases because (GATE CS 2000)


Disk capacities are greater than memory capacities
A
Disk access is much slower than memory access
B
Disk data transfer rates are much less than memory data transfer rates
C
Disks are more reliable than memory
D
B and B+ Trees
Discuss it

Question 4

Which of the following is FALSE about B/B+ tree


B/B+ trees grow upward while Binary Search Trees grow downward.
A
Time complexity of search operation in B/B+ tree is better than Red Black

B Trees in general.

Number of child pointers in a B/B+ tree node is always equals to number of

C keys in it plus one.


A B/B+ tree is defined by a term minimum degree. And minimum degree

D depends on hard disk block size, key and address sizes.


B and B+ Trees
Discuss it

Question 5
A B-tree of order 4 is built from scratch by 10 successive insertions. What is the maximum number of
node splitting operations that may take place?
3
A
4
B
5
C
6
D
B and B+ Trees GATE CS 2008
Discuss it

Question 6

The order of a leaf node in a tree B+ ? is the maximum number of (value, data record pointer) pairs it
can hold. Given that the block size is 1K bytes, data record pointer is 7 bytes long, the value field is 9
bytes long and a block pointer is 6 bytes long, what is the order of the leaf node?
63
A
64
B
67
C
68
D
B and B+ Trees GATE-CS-2007
Discuss it

Question 7

The order of an internal node in a B+ tree index is the maximum number of children it can have.
Suppose that a child pointer takes 6 bytes, the search field value takes 14 bytes, and the block size is
512 bytes. What is the order of the internal node?
24
A
25
B
26
C
27
D
B and B+ Trees GATE-CS-2004
Discuss it

Question 8
Consider the following 2-3-4 tree (i.e., B-tree with a minimum degree of two) in which each data item
is a letter. The usual alphabetical ordering of letters is used in constructing the

tree. What is the result of inserting G in the above tree ?

A)

B)

C)

D) None of the above


A
A
B
B
C
C
D
D
B and B+ Trees GATE-CS-2003
Discuss it

Question 9

A B+ -tree index is to be built on the Name attribute of the relation STUDENT. Assume that all student
names are of length 8 bytes, disk block are size 512 bytes, and index pointers are of size 4 bytes.
Given this scenario, what would be the best choice of the degree (i.e. the number of pointers per
node) of the B+ -tree?
16
A
42
B
43
C
44
D
B and B+ Trees GATE-CS-2002
Discuss it

Question 10

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

________
4
A
5
B
6
C
7
D
B and B+ Trees GATE-CS-2015 (Set 2)
Discuss it

B and B+ Trees
12
Question 11

Consider B+ tree in which the search key is 12 bytes long, block size is 1024 bytes, record pointer is
10 bytes long and block pointer is 8 bytes long. The maximum number of keys that can be
accommodated in each non-leaf node of the tree is
49
A
50
B
51
C
52
D
B and B+ Trees GATE-CS-2015 (Set 3)
Discuss it

Question 12

A B-Tree used as an index for a large database table has four levels including the root node. If a new
key is inserted in this index, then the maximum number of nodes that could be newly created in the
process are:
5
A
4
B
3
C
2
D
B and B+ Trees Gate IT 2005
Discuss it

Question 13

B+ Trees are considered BALANCED because


the lengths of the paths from the root to all leaf nodes are all equal.
A
the lengths of the paths from the root to all leaf nodes differ from each other by

B at most 1.

the number of children of any two non-leaf sibling nodes differ by at most 1.
C
the number of records in any two leaf nodes differ by at most 1.
D
B and B+ Trees GATE-CS-2016 (Set 2)
Discuss it

Question 14

Which of the following is correct?


B-trees are for storing data on disk and B+ trees are for main memory.
A
Range queries are faster on B+ trees.
B
B-trees are for primary indexes and B+ trees are for secondary indexes.
C
The height of a B+ tree is independent of the number of records.
D
B and B+ Trees File structures (sequential files, indexing, B and B+ trees) GATE CS
1999
Discuss it

Question 15

A B-Tree used as an index for a large database table has four levels including the root node. If a new
key is inserted in this index, then the maximum number of nodes that could be newly created in the
process are
5
A
4
B
1
C
2
D
B and B+ Trees ISRO CS 2017 - May
Discuss it

Question 16

In a file which contains 1 million records and the order of the tree is 100, then what is the maximum
number of nodes to be accessed if B+ tree index is used?
5
A
4
B
3
C
10
D
B and B+ Trees ISRO CS 2018
Discuss it
Question 1

What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary
heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.
O(nLogn)
A
O(n^2)
B
O(Logn)
C
O(n)
D
Heap
Discuss it

Question 2

Suppose we are sorting an array of eight integers using heapsort, and we have just finished some
heapify (either maxheapify or minheapify) operations. The array now looks like this: 16 14 15 10 12
27 28 How many heapify operations have been performed on root of heap?
1
A
2
B
3 or 4
C
5 or 6
D
Sorting Heap HeapSort
Discuss it

Question 3

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
Heap
Discuss it

Question 4

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?
1, 3, 5, 6, 8, 9
A
9, 6, 3, 1, 8, 5
B
9, 3, 6, 8, 5, 1
C
9, 5, 6, 8, 3, 1
D
Heap
Discuss it

Question 5

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?
10, 7, 9, 8, 3, 1, 5, 2, 6, 4
A
10, 9, 8, 7, 6, 5, 4, 3, 2, 1
B
10, 9, 4, 5, 7, 6, 8, 2, 1, 3
C
10, 8, 6, 9, 7, 2, 3, 4, 1, 5
D
Heap
Discuss it

Question 6

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
A
25,12,16,13,10,8,14
B
25,14,16,13,10,8,12
C
25,14,12,13,10,8,16
D
Heap
Discuss it

Question 7

What is the content of the array after two delete operations on the correct answer to the previous
question?
14,13,12,10,8
A
14,12,13,8,10
B
14,13,8,12,10
C
14,13,12,8,10
D
Heap
Discuss it

Question 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 (A) (logn) (B) (n) (C) (nlogn) (D) (n^2)
A
A
B
B
C
C
D
D
Heap
Discuss it

Question 9

In a min-heap with n elements with the smallest element at the root, the 7th smallest element can be
found in time a) (n log n) b) (n) c) (log n) d) (1) The question was not clear in original GATE
exam. For clarity, assume that there are no duplicates in Min-Heap and accessing heap elements
below root is allowed.
a
A
b
B
c
C
d
D
Heap
Discuss it

Question 10

In a binary max heap containing n numbers, the smallest element can be found in time (GATE CS
2006)
0(n)
A
O(logn)
B
0(loglogn)
C
0(1)
D
Heap
Discuss it
Question 11

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.


a
A
b
B
c
C
d
D
Heap
Discuss it

Question 12

Given two max heaps of size n each, what is the minimum possible time complexity to make a one max-heap of
size from elements of two max heaps?
O(nLogn)
A
O(nLogLogn)
B
O(n)
C
O(nLogn)
D
Heap
Discuss it

Question 13

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:
10, 8, 7, 3, 2, 1, 5
A
10, 8, 7, 2, 3, 1, 5
B
10, 8, 7, 1, 2, 3, 5
C
10, 8, 7, 5, 3, 2, 1
D
Heap GATE-CS-2014-(Set-2)
Discuss it

Question 14

Which of the following Binary Min Heap operation has the highest time complexity?
Inserting an item under the assumption that the heap has capacity to

A accommodate one more item

Merging with another heap under the assumption that the heap has capacity to

B accommodate items of other heap

Deleting an item from heap


C
Decreasing value of a key
D
Heap
Discuss it

Question 15

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 (i <= n), the index of the parent is
i-1
A
floor(i/2)
B
ceiling(i/2)
C
(i+1)/2
D
Heap GATE-CS-2001
Discuss it

Question 16

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
40, 30, 20, 10, 15, 16, 17, 8, 4, 35
A
40, 35, 20, 10, 30, 16, 17, 8, 4, 15
B
40, 30, 20, 10, 35, 16, 17, 8, 4, 15
C
40, 35, 20, 10, 15, 16, 17, 8, 4, 30
D
Heap GATE-CS-2015 (Set 1)
Discuss it

Question 17
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
4
A
5
B
2
C
3
D
Heap GATE-CS-2015 (Set 3)
Discuss it

Question 18

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?
O(1)
A
O(d) but not O(1)
B
O(2 ) but not O(d)
d

C
O(d2 ) but not O(2 )
d d

D
Heap GATE-CS-2016 (Set 1)
Discuss it

Question 19

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 _____________ [This question was originally asked as Fill-in-
the-Blanks question]
6
A
7
B
8
C
9
D
Heap GATE-CS-2016 (Set 2)
Discuss it
Question 20

Which of the following sequences of array elements forms a heap?


{23, 17, 14, 6, 13, 10, 1, 12, 7, 5}
A
{23, 17, 14, 6, 13, 10, 1, 5, 7, 12}
B
{23, 17, 14, 7, 13, 10, 1, 5, 6, 12}
C
{23, 17, 14, 7, 13, 10, 1, 12, 5, 7}
D
Heap GATE IT 2006
Discuss it

There are 27 questions to complete.


123
Question 21

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
0
A
1
B
2
C
3
D
Heap GATE CS 1996
Discuss it

Question 22

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
10, 8, 7, 5, 3, 2, 1
A
10, 8, 7, 2, 3, 1, 5
B
10, 8, 7, 1, 2, 3, 5
C
10, 8, 7, 3, 2, 1, 5
D
Heap ISRO CS 2017
Discuss it
Question 23

Which languages necessarily need heap allocation in the run time environment?
Those that support recursion
A
Those that use dynamic scoping
B
Those that use global variables
C
Those that allow dynamic data structures
D
C Dynamic Memory Allocation Heap ISRO CS 2017
Discuss it

Question 24

Which of the following is a valid heap ? (A) (B) (C) (D)


A
A
B
B
C
C
D
D
Heap UGC NET CS 2017 Jan - II
Discuss it

Question 25

Which one of the following array represents a binary max-heap?


[26, 13, 17, 14, 11, 9, 15]
A
[26, 15, 14, 17, 11, 9, 13]
B
[26, 15, 17, 14, 11, 9, 13]
C
[26, 15, 13, 14, 11, 9, 17]
D
Heap UGC NET CS 2016 July – III
Discuss it

Question 26

The number of nodes of height h in any n - element heap is __________.


h
A
z h

B
C
D
Heap UGC NET CS 2015 Jun - III
Discuss it

Question 27

Given a binary-max heap. The elements are stored in an arrays as 25, 14, 16, 13, 10, 8, 12. What is
the content of the array after two delete operations?
14,13,8,12,10
A
14,12,13,10,8
B
14,13,12,8,10
C
14,13,12,10,8
D
Heap ISRO CS 2018
Discuss it

uestion 21

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
0
A
1
B
2
C
3
D
Heap GATE CS 1996
Discuss it

Question 22

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
10, 8, 7, 5, 3, 2, 1
A
10, 8, 7, 2, 3, 1, 5
B
10, 8, 7, 1, 2, 3, 5
C
10, 8, 7, 3, 2, 1, 5
D
Heap ISRO CS 2017
Discuss it

Question 23

Which languages necessarily need heap allocation in the run time environment?
Those that support recursion
A
Those that use dynamic scoping
B
Those that use global variables
C
Those that allow dynamic data structures
D
C Dynamic Memory Allocation Heap ISRO CS 2017
Discuss it

Question 24

Which of the following is a valid heap ? (A) (B) (C) (D)


A
A
B
B
C
C
D
D
Heap UGC NET CS 2017 Jan - II
Discuss it

Question 25

Which one of the following array represents a binary max-heap?


[26, 13, 17, 14, 11, 9, 15]
A
[26, 15, 14, 17, 11, 9, 13]
B
[26, 15, 17, 14, 11, 9, 13]
C
[26, 15, 13, 14, 11, 9, 17]
D
Heap UGC NET CS 2016 July – III
Discuss it

Question 26

The number of nodes of height h in any n - element heap is __________.


h
A
z h

B
C
D
Heap UGC NET CS 2015 Jun - III
Discuss it

Question 27

Given a binary-max heap. The elements are stored in an arrays as 25, 14, 16, 13, 10, 8, 12. What is
the content of the array after two delete operations?
14,13,8,12,10
A
14,12,13,10,8
B
14,13,12,8,10
C
14,13,12,10,8
D
Heap ISRO CS 2018
Discuss it
Question 1

Following function is supposed to calculate the maximum depth or height of a Binary tree -- the
number of nodes along the longest path from the root node down to the farthest leaf node.
int maxDepth(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the depth of each subtree */
int lDepth = maxDepth(node->left);
int rDepth = maxDepth(node->right);

/* use the larger one */


if (lDepth > rDepth)
return X;
else return Y;
}
}
Run on IDE
What should be the values of X and Y so that the function works correctly?
X = lDepth, Y = rDepth
A
X = lDepth + 1, Y = rDepth + 1
B
X = lDepth - 1, Y = rDepth -1
C
None of the above
D
Tree Traversals
Discuss it

Question 2

What is common in three different types of traversals (Inorder, Preorder and Postorder)?
Root is visited before right subtree
A
Left subtree is always visited before right subtree
B
Root is visited after left subtree
C
All of the above
D
None of the above
E
Tree Traversals
Discuss it

Question 3

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:
debfgca
A
edbgfca
B
edbfgca
C
defgbca
D
Tree Traversals
Discuss it
Question 4

What does the following function do for a given binary tree?


int fun(struct node *root)
{
if (root == NULL)
return 0;
if (root->left == NULL && root->right == NULL)
return 0;
return 1 + fun(root->left) + fun(root->right);
}
Run on IDE
Counts leaf nodes
A
Counts internal nodes
B
Returns height where height is defined as number of edges on the path from

C root to deepest node


Return diameter where diameter is number of edges on the longest path

D between any two nodes.


Tree Traversals
Discuss it

Question 5

Which of the following pairs of traversals is not sufficient to build a binary tree from the given
traversals?
Preorder and Inorder
A
Preorder and Postorder
B
Inorder and Postorder
C
None of the Above
D
Tree Traversals
Discuss it

Question 6

Consider two binary operators ' ' and ' ' with the precedence of operator being lower than that of
the operator. Operator is right associative while operator is left associative. Which one of the
following represents the parse tree for expression (7 3 4 3 2)? (GATE CS 2011)
A
A
B
B
C
C
D
D
Tree Traversals
Discuss it

Question 7

Which traversal of tree resembles the breadth first search of the graph?
Preorder
A
Inorder
B
Postorder
C
Level order
D
Tree Traversals
Discuss it

Question 8

Which of the following tree traversal uses a queue data structure?


Preorder
A
Inorder
B
Postorder
C
Level order
D
Tree Traversals
Discuss it

Question 9

Which of the following cannot generate the full binary tree?


Inorder and Preorder
A
Inorder and Postorder
B
Preorder and Postorder
C
None of the above
D
Tree Traversals
Discuss it

Question 10

Consider the following C program segment


struct CellNode
{
struct CelINode *leftchild;
int element;
struct CelINode *rightChild;
}

int Dosomething(struct CelINode *ptr)


{
int value = 0;
if (ptr != NULL)
{
if (ptr->leftChild != NULL)
value = 1 + DoSomething(ptr->leftChild);
if (ptr->rightChild != NULL)
value = max(value, 1 + DoSomething(ptr->rightChild));
}
return (value);
}
Run on IDE
The value returned by the function DoSomething when a pointer to the root of a non-empty tree is
passed as argument is (GATE CS 2004)
The number of leaf nodes in the tree
A
The number of nodes in the tree
B
The number of internal nodes in the tree
C
The height of the tree
D
Tree Traversals
Discuss it
Question 11

Let LASTPOST, 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)
LASTIN = LASTPOST
A
LASTIN = LASTPRE
B
LASTPRE = LASTPOST
C
None of the above
D
Tree Traversals
Discuss it

Question 12

The array representation of a complete binary tree contains the data in sorted order. Which traversal
of the tree will produce the data in sorted form?
Preorder
A
Inorder
B
Postorder
C
Level order
D
Tree Traversals
Discuss it

Question 13

Consider the following rooted tree with the vertex P labeled as root

The order in which the nodes are visited during in-order


traversal is
SQPTRWUV
A
SQPTURWV
B
SQPTWUVR
C
SQPTRUWV
D
Tree Traversals GATE-CS-2014-(Set-3)
Discuss it

Question 14

Consider the pseudocode given below. The function DoSomething() takes as argument a pointer to
the root of an arbitrary tree represented by the leftMostChild-rightSibling representation. Each node of
the tree is of type treeNode.
typedef struct treeNode* treeptr;
struct treeNode
{
treeptr leftMostChild, rightSibling;
};
int DoSomething (treeptr tree)
{
int value=0;
if (tree != NULL)
{
if (tree->leftMostChild == NULL)
value = 1;
else
value = DoSomething(tree->leftMostChild);
value = value + DoSomething(tree->rightSibling);
}
return(value);
}
Run on IDE
When the pointer to the root of a tree is passed as the argument to DoSomething, the value returned
by the function corresponds to the
number of internal nodes in the tree.
A
height of the tree.
B
number of nodes without a right sibling in the tree.
C
number of leaf nodes in the tree.
D
Tree Traversals GATE-CS-2014-(Set-3)
Discuss it

Question 15

Level order traversal of a rooted tree can be done by starting from the root and performing
preorder traversal
A
inorder traversal
B
depth first search
C
breadth first search
D
Tree Traversals GATE-CS-2004
Discuss it

Question 16

Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree.
Which of these pairs identify a tree uniquely ?
(i) preorder and postorder
(ii) inorder and postorder
(iii) preorder and inorder
(iv) level order and postorder
(i) only
A
(ii), (iii)
B
(iii) only
C
(iv) only
D
Tree Traversals GATE-CS-2004
Discuss it

Question 17

Let LASTPOST, 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?
LASTIN = LASTPOST
A
LASTIN = LASTPRE
B
LASTPRE = LASTPOST
C
None of the above
D
Tree Traversals GATE-CS-2000
Discuss it

Question 18

Which one of the following binary trees has its inorder and preorder traversals as BCAD and ABCD,
respectively?
A
A
B
B
C
C
D
D
Tree Traversals GATE-IT-2004
Discuss it

Question 19

The numbers 1, 2, .... n are inserted in a binary search tree in some order. In the resulting tree, the
right subtree of the root contains p nodes. The first number to be inserted in the tree must be
p
A
p+1
B
n-p
C
n-p+1
D
Tree Traversals Gate IT 2005
Discuss it

Question 20

A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed in pre-
order and the values in each node printed out, the sequence of values obtained is 5, 3, 1, 2, 4, 6, 8, 7.
If the tree is traversed in post-order, the sequence obtained would be
8, 7, 6, 5, 4, 3, 2, 1
A
1, 2, 3, 4, 8, 7, 6, 5
B
2, 1, 4, 3, 6, 7, 8, 5
C
2, 1, 4, 3, 7, 8, 6, 5
D
Tree Traversals Gate IT 2005
Discuss it

There are 43 questions to complete.


12345
Question 11
Let LASTPOST, 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)
LASTIN = LASTPOST
A
LASTIN = LASTPRE
B
LASTPRE = LASTPOST
C
None of the above
D
Tree Traversals
Discuss it

Question 12

The array representation of a complete binary tree contains the data in sorted order. Which traversal
of the tree will produce the data in sorted form?
Preorder
A
Inorder
B
Postorder
C
Level order
D
Tree Traversals
Discuss it

Question 13

Consider the following rooted tree with the vertex P labeled as root

The order in which the nodes are visited during in-order


traversal is
SQPTRWUV
A
SQPTURWV
B
SQPTWUVR
C
SQPTRUWV
D
Tree Traversals GATE-CS-2014-(Set-3)
Discuss it

Question 14

Consider the pseudocode given below. The function DoSomething() takes as argument a pointer to
the root of an arbitrary tree represented by the leftMostChild-rightSibling representation. Each node of
the tree is of type treeNode.
typedef struct treeNode* treeptr;
struct treeNode
{
treeptr leftMostChild, rightSibling;
};
int DoSomething (treeptr tree)
{
int value=0;
if (tree != NULL)
{
if (tree->leftMostChild == NULL)
value = 1;
else
value = DoSomething(tree->leftMostChild);
value = value + DoSomething(tree->rightSibling);
}
return(value);
}
Run on IDE
When the pointer to the root of a tree is passed as the argument to DoSomething, the value returned
by the function corresponds to the
number of internal nodes in the tree.
A
height of the tree.
B
number of nodes without a right sibling in the tree.
C
number of leaf nodes in the tree.
D
Tree Traversals GATE-CS-2014-(Set-3)
Discuss it

Question 15

Level order traversal of a rooted tree can be done by starting from the root and performing
preorder traversal
A
inorder traversal
B
depth first search
C
breadth first search
D
Tree Traversals GATE-CS-2004
Discuss it

Question 16

Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree.
Which of these pairs identify a tree uniquely ?
(i) preorder and postorder
(ii) inorder and postorder
(iii) preorder and inorder
(iv) level order and postorder
(i) only
A
(ii), (iii)
B
(iii) only
C
(iv) only
D
Tree Traversals GATE-CS-2004
Discuss it

Question 17

Let LASTPOST, 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?
LASTIN = LASTPOST
A
LASTIN = LASTPRE
B
LASTPRE = LASTPOST
C
None of the above
D
Tree Traversals GATE-CS-2000
Discuss it

Question 18
Which one of the following binary trees has its inorder and preorder traversals as BCAD and ABCD,
respectively?

A
A
B
B
C
C
D
D
Tree Traversals GATE-IT-2004
Discuss it

Question 19

The numbers 1, 2, .... n are inserted in a binary search tree in some order. In the resulting tree, the
right subtree of the root contains p nodes. The first number to be inserted in the tree must be
p
A
p+1
B
n-p
C
n-p+1
D
Tree Traversals Gate IT 2005
Discuss it

Question 20

A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed in pre-
order and the values in each node printed out, the sequence of values obtained is 5, 3, 1, 2, 4, 6, 8, 7.
If the tree is traversed in post-order, the sequence obtained would be
8, 7, 6, 5, 4, 3, 2, 1
A
1, 2, 3, 4, 8, 7, 6, 5
B
2, 1, 4, 3, 6, 7, 8, 5
C
2, 1, 4, 3, 7, 8, 6, 5
D
Tree Traversals Gate IT 2005
Discuss it
Question 21

If all the edge weights of an undirected graph are positive, then any subset of edges that connects all
the vertices and has minimum total weight is a
Hamiltonian cycle
A
grid
B
hypercube
C
tree
D
Tree Traversals Graph Theory GATE IT 2006
Discuss it

Question 22

When searching for the key value 60 in a binary search tree, nodes containing the key values 10, 20,
40, 50, 70 80, 90 are traversed, not necessarily in the order given. How many different orders are
possible in which these key values can occur on the search path from the root to the node containing
the value 60?
35
A
64
B
128
C
5040
D
Binary Search Trees Tree Traversals Gate IT 2007
Discuss it

Question 23

The following three are known to be the preorder, inorder and postorder sequences of a binary tree.
But it is not known which is which.
MBCAFHPYK
KAMCBYPFH
MABCKYFPH
Pick the true statement from the following.
I and II are preorder and inorder sequences, respectively
A
I and III are preorder and postorder sequences, respectively
B
II is the inorder sequence, but nothing more can be said about the other two

C sequences
II and III are the preorder and inorder sequences, respectively
D
Binary Trees Tree Traversals Gate IT 2008
Discuss it

Question 24

Consider the following sequence of nodes for the undirected graph given below.
abefdgc
abefcgd
adgebcf
adbcgef
A Depth First Search (DFS) is started at node a. The nodes are listed in the order they are first
visited. Which all of the above is (are) possible output(s)?
1 and 3 only
A
2 and 3 only
B
2, 3 and 4 only
C
1, 2, and 3
D
Tree Traversals Gate IT 2008
Discuss it

Question 25

Which of the following statement is false?


A tree with n nodes has (n-1) edges.
A
A labeled rooted binary tree can be uniquely constructed given its postorder

B and preorder traversal results.

A complete binary tree with n internal nodes has (n+1) leaves.


C
The maximum number of nodes in a binary tree of height h is (2^(h+1) -1).
D
Tree Traversals GATE CS 1998
Discuss it

Question 26

A complete n-ary tree is one in which every node has 0 or n sons. If x is the number of internal nodes
of a complete n-ary tree, the number of leaves in it is given by
x(n-1)+1
A
xn-1
B
xn+1
C
x(n+1)
D
Tree Traversals GATE CS 1998
Discuss it

Question 27

[5 Marks question] Answer the following: a. Derive a recurrence relation of the size of the smallest
AVL tree with height h. b. What is the size of the smallest AVL tree with height 8.
Tree Traversals GATE CS 1998
Discuss it

Question 28

Which of the following sequences denotes the post order traversal sequence of the given tree?
a
/
b e
/ /
c d f
/
g
fegcdba
A
gcbdafe
B
gcdbfea
C
fedgcba
D
Binary Trees Tree Traversals GATE CS 1996
Discuss it

Question 29

Which of following option is not correct regarding depth first searching?


In a depth-first traversal of a graph G with V vertices, E edges are marked as

A tree edges. The number of connected components in G is (E - V).

Depth-first search requires O(V^2) time if implemented with an adjacency

B matrix.

Depth-first search requires O(V + E) time if implemented with adjacency lists


C
None of these
D
Tree Traversals GATE CS Mock 2018 | Set 2
Discuss it

Question 30
The post-order traversal of a binary search tree is given by 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12.
Then the pre-order traversal of this tree is:
2, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20
A
7, 6, 2, 10, 9, 8, 15, 16, 17, 20, 19, 12
B
7, 2, 6, 8, 9, 10, 20, 17, 19, 15, 16, 12
C
12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20
D
Tree Traversals GATE CS Mock 2018 | Set 2
Di
Question 31

Let G be a simple undirected graph. Let TD be a depth first search tree of G. Let TBbe 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 T D). (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?
I only
A
II only
B
Both I and II
C
Neither I nor II
D
Data Structures Misc Tree Traversals GATE CS 2018
Discuss it

Question 32

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary
search tree. The binary search tree uses the reversal ordering on natural numbers i.e. 9 is assumed
to be smallest and 0 is assumed to be largest. The in-order traversal of the resultant binary search
tree is
9, 8, 6, 4, 2, 3, 0, 1, 5, 7
A
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
B
0, 2, 4, 3, 1, 6, 5, 9, 8, 7
C
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
D
Balanced Binary Search Trees Tree Traversals ISRO CS 2017
Discuss it
Question 33

The in-order and pre-order traversal of a binary tree are d b e a f c g and a b d e c f g respectively.
The post order traversal of a binary tree is
edbgfca
A
edbfgca
B
debfgca
C
defgbca
D
Binary Trees Tree Traversals ISRO CS 2017
Discuss it

Question 34

Consider the following tree If the post order traversal gives ab-cd*+ then the label of the nodes
1,2,3,… will be
+,-,*,a,b,c,d
A
a,-,b,+,c,*,d
B
a,b,c,d,-,*,+
C
-,a,b,+,*,c,d
D
Tree Traversals ISRO CS 2017 - May
Discuss it

Question 35

Choose the equivalent prefix form of the following expression (a + (b − c))* ((d − e)/(f + g − h))
* +a − bc /− de − +fgh
A
* +a −bc − /de − +fgh
B
* +a − bc /− ed + −fgh
C
* +ab − c /− ed + −fgh
D
Tree Traversals ISRO CS 2017 - May
Discuss it

Question 36
The number of rotations required to insert a sequence of elements 9,6,5,8,7,10 into an empty AVL
tree is?
0
A
1
B
2
C
3
D
Tree Traversals ISRO CS 2013
Discuss it

Question 37

Consider the following statements: (a) Depth - first search is used to traverse a rooted tree. (b) Pre -
order, Post-order and Inorder are used to list the vertices of an ordered rooted tree. (c) Huffman’s
algorithm is used to find an optimal binary tree with given weights. (d) Topological sorting provides a
labelling such that the parents have larger labels than their children. Which of the above statements
are true?
(a) and (b)
A
(c) and (d)
B
(a), (b) and (c)
C
(a), (b), (c) and (d)
D
Tree Traversals UGC NET CS 2015 Jun - II
Discuss it

Question 38

The inorder and preorder Traversal of binary Tree are dbeafcg and abdecfg respectively. The post-
order Traversal is __________.
dbefacg
A
debfagc
B
dbefcga
C
debfgca
D
Tree Traversals UGC NET CS 2015 Jun - II
Discuss it
Question 39

Level order Traversal of a rooted Tree can be done by starting from root and performing:
Breadth First Search
A
Depth First Search
B
Root Search
C
Deep Search
D
Tree Traversals UGC NET CS 2015 Jun - II
Discuss it

Question 40

The in-order traversal of a tree resulted in FBGADCE. Then the pre-order traversal of that tree would
result in
FGBDECA
A
ABFGCDE
B
BFGCDEA
C
AFGBDEC
D
Tree Traversals ISRO C
scuss it
Question 31

Let G be a simple undirected graph. Let TD be a depth first search tree of G. Let TBbe 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 T D). (II)
For every edge (u, v) of G, if u is at depth i and v is at depth j in T B, then ∣i − j∣ = 1. Which of the
statements above must necessarily be true?
I only
A
II only
B
Both I and II
C
Neither I nor II
D
Data Structures Misc Tree Traversals GATE CS 2018
Discuss it

Question 32
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary
search tree. The binary search tree uses the reversal ordering on natural numbers i.e. 9 is assumed
to be smallest and 0 is assumed to be largest. The in-order traversal of the resultant binary search
tree is
9, 8, 6, 4, 2, 3, 0, 1, 5, 7
A
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
B
0, 2, 4, 3, 1, 6, 5, 9, 8, 7
C
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
D
Balanced Binary Search Trees Tree Traversals ISRO CS 2017
Discuss it

Question 33

The in-order and pre-order traversal of a binary tree are d b e a f c g and a b d e c f g respectively.
The post order traversal of a binary tree is
edbgfca
A
edbfgca
B
debfgca
C
defgbca
D
Binary Trees Tree Traversals ISRO CS 2017
Discuss it

Question 34

Consider the following tree If the post order traversal gives ab-cd*+ then the label of the nodes
1,2,3,… will be
+,-,*,a,b,c,d
A
a,-,b,+,c,*,d
B
a,b,c,d,-,*,+
C
-,a,b,+,*,c,d
D
Tree Traversals ISRO CS 2017 - May
Discuss it
Question 35

Choose the equivalent prefix form of the following expression (a + (b − c))* ((d − e)/(f + g − h))
* +a − bc /− de − +fgh
A
* +a −bc − /de − +fgh
B
* +a − bc /− ed + −fgh
C
* +ab − c /− ed + −fgh
D
Tree Traversals ISRO CS 2017 - May
Discuss it

Question 36

The number of rotations required to insert a sequence of elements 9,6,5,8,7,10 into an empty AVL
tree is?
0
A
1
B
2
C
3
D
Tree Traversals ISRO CS 2013
Discuss it

Question 37

Consider the following statements: (a) Depth - first search is used to traverse a rooted tree. (b) Pre -
order, Post-order and Inorder are used to list the vertices of an ordered rooted tree. (c) Huffman’s
algorithm is used to find an optimal binary tree with given weights. (d) Topological sorting provides a
labelling such that the parents have larger labels than their children. Which of the above statements
are true?
(a) and (b)
A
(c) and (d)
B
(a), (b) and (c)
C
(a), (b), (c) and (d)
D
Tree Traversals UGC NET CS 2015 Jun - II
Discuss it
Question 38

The inorder and preorder Traversal of binary Tree are dbeafcg and abdecfg respectively. The post-
order Traversal is __________.
dbefacg
A
debfagc
B
dbefcga
C
debfgca
D
Tree Traversals UGC NET CS 2015 Jun - II
Discuss it

Question 39

Level order Traversal of a rooted Tree can be done by starting from root and performing:
Breadth First Search
A
Depth First Search
B
Root Search
C
Deep Search
D
Tree Traversals UGC NET CS 2015 Jun - II
Discuss it

Question 40

The in-order traversal of a tree resulted in FBGADCE. Then the pre-order traversal of that tree would
result in
FGBDECA
A
ABFGCDE
B
BFGCDEA
C
AFGBDEC
D
Tree Traversals ISRO CS 2011
Question 41

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary
search tree. The binary search tree uses the usual ordering on natural numbers. What is the inorder
traversal sequence of the resultant tree?
7510324689
A
0243165987
B
0123456789
C
9864230157
D
Tree Traversals ISRO CS 2009
Discuss it

Question 42

Assume that the operators +, −, × are left associative and ^ is right associative. The order of
precedence (from highest to lowest) is ^, ×, +, −. The postfix expression corresponding to the infix
expression is
a + b × c − d ^ e ^ f
abc x + def ^ ^ −
A
abc x + de ^ f ^ −
B
ab + c × d − e^f^
C
− + a × b c^^ def
D
Tree Traversals ISRO CS 2009
Discuss it

Question 43

If Tree-1 and Tree-2 are the trees indicated below : Which traversals of Tree-1 and Tree-2,
respectively, will produce the same sequence?
Preorder, postorder
A
Postorder, inorder
B
Postorder, preorder
C
Inorder, preorder
D
Tree Traversals ISRO CS 2018
Discuss it

Potrebbero piacerti anche