Question 1 |

Which data structure is used for balancing of symbols?

Stack | |

Queue | |

Tree | |

Graph |

**Misc**

**Discuss it**

Question 1 Explanation:

Stack is used for balancing of symbols. This is extensively used by the compiler to check for missing or additional symbols. The start of the symbol(like (, [, {) are pushed to the stack. When the end of the symbol(like ), \, }) are encountered, it is matched with the corresponding peek element of the stack. If the match is found, the element is popped, else error is flashed.

Question 2 |

Which data structure is used in redo-undo feature?

Stack | |

Queue | |

Tree | |

Graph |

**Misc**

**Discuss it**

Question 2 Explanation:

Stack data structure is most suitable to implement redo-undo feature. This is because the stack is implemented with LIFO(last in first out) order which is equivalent to redo-undo feature i.e. the last re-do is undo first.

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

Max heap | |

BST | |

Sorted array |

**Misc**

**Discuss it**

Question 3 Explanation:

Min heap of size 10 is sufficient to find the top 10 largest items. The algorithm can be given as follows:
1. Create the min heap with first 10 items.
2. For each remaining item, check if
2.1 The item is greater than the item stored in the head of the min heap.
2.1.1 If yes, replace it with this new item. Balance the min heap.
2.1.2 If no, do nothing.
At last, the min heap will contain the top 10 largest items.

Question 4 |

The best data structure to check whether an arithmetic expression has balanced parentheses is a (GATE CS 2004)

queue | |

stack | |

tree | |

list |

**Misc**

**Discuss it**

Question 4 Explanation:

There are three types of parentheses [ ] { } (). Below is an arbit c code segment which has parentheses of all three types.
1
Stack is a straightforward choice for checking if left and right parentheses are balanced. Here is a algorithm to do the same.
1

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 setWhich of the following data structures can be used for this purpose?

A heap can be used but not a balanced binary search tree | |

A balanced binary search tree can be used but not a heap | |

Both balanced binary search tree and heap can be used | |

Neither balanced binary search tree nor heap can be used |

**Misc**

**Discuss it**

Question 5 Explanation:

A self-balancing balancing binary search tree containing n items allows the lookup, insertion, and removal of an item in O(log n) worst-case time. Since it's a BST, we can easily find out minimum element in O(nlogn). See our post http://geeksforgeeks.org/?p=1333 for details.
Since Heap is a balanced binary tree (or almost complete binary tree), insertion complexity for heap is O(logn). Also complexity to get minimum in a min heap is O(logn) because removal of root node causes a call to heapify (after removing the first element from the array) to maintain the heap tree property. But a heap cannot be used for the above purpose as the question says - insert an element if it is not already present. For a heap, we cannot find out in O(logn) if an element is present or not. Thanks to game for providing the correct solution.

Question 6 |

The most appropriate matching for the following pairs

is (GATE CS 2000):X: depth first search 1: heap Y: breadth-first search 2: queue Z: sorting 3: stack

X—1 Y—2 Z-3 | |

X—3 Y—1 Z-2 | |

X—3 Y—2 Z-1 | |

X—2 Y—3 Z-1 |

**Misc**

**Discuss it**

Question 6 Explanation:

Stack is used for Depth first Search
Queue is used for Breadth First Search
Heap is used for sorting

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

Linked List | |

Binary Tree | |

Hash |

**Misc**

**Discuss it**

Question 7 Explanation:

The only two choices that make sense are Array and Linked List. Since array sizes are limited, they can create problems for following operations.
X = X*Y where X and Y are very large numbers.

Question 8 |

Which data structure is best suited for converting recursive implementation to iterative implementation of an algorithm?

Queue | |

Stack | |

Tree | |

Graph |

**Misc**

**Discuss it**

Question 8 Explanation:

Since function calls are executed in

**L**ast**I**n**F**irst**O**ut order, stack is the data structure for converting recursive to iterative implementation.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 | |

Queue | |

Stack | |

Priority Queue |

**Misc**

**Discuss it**

Question 9 Explanation:

Since packets need to be processed in First In First Out order, a queue can be used for synchronization.

Question 10 |

Which of the following data structures is best suited for efficient implementation of priority queue?

Array | |

Linked List | |

Heap | |

Stack |

**Misc**

**Discuss it**

Question 10 Explanation:

Question 11 |

Which data structure in a compiler is used for managing information about variables and their attributes?

Abstract syntax tree | |

Symbol table | |

Semantic stack | |

Parse Table |

**Misc**

**GATE CS 2010**

**Discuss it**

Question 11 Explanation:

Symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating to its declaration or appearance in the source, such as its type, scope level and sometimes its location (Source: http://en.wikipedia.org/wiki/Symbol_table)

Question 12 |

An Abstract Data Type (ADT) is:

Same as an abstract class | |

A data type that cannot be instantiated | |

A data type type for which only the operations defined on it can be used, but none else | |

All of the above |

**Misc**

**GATE-CS-2005**

**Discuss it**

Question 12 Explanation:

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 setWhich of the following data structures can be used for this purpose?

A heap can be used but not a balanced binary search tree | |

A balanced binary search tree can be used but not a heap | |

Both balanced binary search tree and heap can be used | |

Neither balanced binary search tree nor heap can be used |

**Misc**

**GATE-CS-2003**

**Discuss it**

Question 13 Explanation:

First we’ll discuss about heap and balanced bst and its time complexities for basic operations like
insertion, deletion, find.

**Heap:-**Let us consider it as min heap 1) Insertion: O(logn) 2) Delete Min: O(logn) (Just replace root with INT_MAX and heapify) 3) Find: O(n)**Balanced BST:-**1) Insertion: O(logn) 2) Delete Min: O(logn) 3) Find: O(logn)**Statement 1:**1) Deletion of smallest element can be done in O(logn) in both data structures**Statement 2:**1) Insertion of an element if it is not already present in the set In heap, we can perform this operation in O(n) because we have to perform linear search here, where as in BST we can perform this in O(logn) See Question 4 of http://www.geeksforgeeks.org/data-structures-and-algorithms-set-3/ This solution is contributed by**Anil Saikrishna Devarasetty**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 | |

5 | |

6 | |

18 |

**Misc**

**GATE-CS-2015 (Set 2)**

**Discuss it**

Question 14 Explanation:

Initially

When 1 is removed, it is replaced by the smallest adjacent which is 2.12 5 14 3 4 6 23 10 12 18 25 31 ∞ ∞ ∞

2When 2 is moved in place of 1, it is replaced by smallest adjacent which is 425 14 3 4 6 23 10 12 18 25 31 ∞ ∞ ∞

2 4 5 14 3When 4 is moved in place of 2, it is replaced by smallest adjacent which is 646 23 10 12 18 25 31 ∞ ∞ ∞

2 4 5 14 3 6When 6 is moved in place of 4, it is replaced by smallest adjacent which is 18.623 10 12 18 25 31 ∞ ∞ ∞

2 4 5 14 3 6 18 23 10 12When 18 is moved in place of 6, it is replaced by smallest adjacent which is 25.1825 31 ∞ ∞ ∞

2 4 5 14 3 6 18 23 10 12 25When 25 is moved in place of 18, it is replaced by smallest adjacent which is ∞.2531 ∞ ∞ ∞

2 4 5 14 3 6 18 23 10 12 25 ∞ 31 ∞ ∞ ∞Shifted numbers are 2, 4, 6, 18, 25

There are 15 questions to complete.