Algorithms and Data Structures 79

[Data Structures] Binary Heaps (Min-Heaps and Max-Heaps)

Min Heap: A complete binary tree (that is filled other than the rightmost elements on the last level) where each node is smaller than its children. The root, therefore, is the minimum element in the tree. We have two key operations on a min-heap: insert and extract_min Insert When we insert into a min-heap, we always start by inserting the element at the bottom. We insert it at the rightmost spo..

[Data Structures] Binary Tree Traversals with Implementations

In Order: visit the left branch, then the current node, and finally visit the right branch. When performed on a binary search tree, it visits the nodes in ascending order (hence the name "in-order") void inOrderTraversal(Node node) { if (node != null){ inOrderTraversal(node.left); visit(node); inOrderTraversal(node.right); } } Pre Order: visits the current node before its child nodes (hence the ..