# Data Structures Misc

Please wait while the activity loads.

If this activity does not load, try refreshing your browser. Also, this page requires javascript. Please visit using a browser with javascript enabled.

If this activity does not load, try refreshing your browser. Also, this page requires javascript. Please visit using a browser with javascript enabled.

Question 1 |

Which data structure is used for balancing of symbols?

Stack | |

Queue | |

Tree | |

Graph |

**Data Structures 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 |

**Data Structures 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 |

**Data Structures 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 |

**Data Structures 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.
Stack is a straightforward choice for checking if left and right parentheses are balanced. Here is a algorithm to do the same.

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 |

**Data Structures 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 Find the minimum element in a Binary Search Tree 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 |

**Data Structures 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 |

**Data Structures 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 |

**Data Structures 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 |

**Data Structures 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 |

**Data Structures Misc**

**Discuss it**

Question 10 Explanation:

There are 36 questions to complete.