Data structures Flashcards
Implementation of Breadth First Search uses what?
Queue - add child nodes . shift off node from front.
repeat until queue is empty
Implementation of Depth First Search uses?
Stack - add nodes. remove end nodes from end.
Often recursion.
what is a heap? (2 types)
binary tree where children are smaller (max heap) or larger (min heap) than parent. Root node is smallest (min heap) or largest (max heap)
what is heapifying?
looping through heap and swapping up/down nodes depending on min/max
insert into heap?
add as leaf node, then heapify
heap sort?
1 - build a heap from unsorted array
2 - take root node and swap with last element, then remove that last element to ‘sorted’ array
3 - re-heapify the heap
4 - repeat
index of heap last parent node in an array
array.length (rounded down) - 1