Which data structure is most efficient to find the top 10 largest items out of 1 million items stored in file?

**(A)** Min heap

**(B)** Max heap

**(C)** BST

**(D)** Sorted array

**Answer:** **(A)** **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.

## Recommended Posts:

- Data Structures | Misc | Question 1
- Data Structures | Misc | Question 2
- Data Structures | Misc | Question 4
- Data Structures | Misc | Question 5
- Data Structures | Misc | Question 6
- Data Structures | Misc | Question 7
- Data Structures | Misc | Question 8
- Data Structures | Misc | Question 9
- Data Structures | Misc | Question 10
- Introduction to Data Structures | 10 most commonly used Data Structures
- C | Misc | Question 1
- C | Misc | Question 2
- C | Misc | Question 7
- C | Misc | Question 6
- C | Misc | Question 5
- C | Misc | Question 7
- C | Misc | Question 6
- C | Misc | Question 8
- C | Misc | Question 9
- Algorithms | Misc | Question 16