@@ -62,7 +62,9 @@ For eg storing the minimum so far in another stack so that each time when a numb
62
62
### Heaps (methods that can be applied):
63
63
- A large heap can be delcared and only a small portion of it can always be included in the heap operations.
64
64
- Whenever a heap is built, swapping etc. will be there if elements do not follow the heap property (max or min)
65
-
65
+ - Sometimes to find largest element in an array, min heap can be made, for few first elements, and each
66
+ time comparisons can be done with remaining element to eliminate the minimum elements.
67
+ - Methods where min and max heap can be applied BST can also be used (depends on question)
66
68
67
69
# Topic0: Programming Questions
68
70
@@ -183,6 +185,7 @@ For eg storing the minimum so far in another stack so that each time when a numb
183
185
- [ Write a program for heap sort] ( /heaps/question3.c )
184
186
- [ Find a max element in a min-heap] ( /heaps/question4.c )
185
187
- [ Build a min-heap and write algo to delete an arbitrary element] ( /heaps/question5.c )
188
+ - [ Find k largest elements from an array] ( /heaps/question6.c )
186
189
187
190
## Some important concepts to solve algos better
188
191
@@ -218,6 +221,8 @@ For eg storing the minimum so far in another stack so that each time when a numb
218
221
- There is an O(n) time algo to convert an element into a heap. So no need to sort as sorting take O(nlogn)
219
222
- Recursion adds to the space complexity as well as time complexity.
220
223
- In a max heap, finding min, deleting random element or searching an element will take O(n) time because here max heap is as good as an array.
224
+ - For Binary Search tree implementation using an array, space complexity is O(2^n), but using linked list, it
225
+ is O(n)
221
226
222
227
# Topic1: Introduction
223
228
0 commit comments