Algorithms, Part 1 Course from Princeton — Binary Tree, Binary Heaps, and Week 4 Assignment 8 puzzle

Introduction
Algorithms, Part 1 is a solid course for IT or software engineers to learn algorithms which are provided by Princeton. Of course, we still have to take time to clarify the concepts after completing the class.
Binary search tree and binary heap are fundamental data structure for storing data in the practice. In this article, we will focus on how they works.
About this Series
This series aims to wrap up contents of Algorithms, Part 1.
- week 1: Union-find and Week 1 assignment Percolation
- week 2: Stack, Queue, and Week 2 Assignment Deques and Randomized Queues
- week 3: Sorting and Week 3 assignment Collinear Points
- week 4: this article
- week 5: Hash table and Week 5 Assignment KD-Tree
Agenda
It includes the following topics in this article.
- Symbol table
- Binary search tree
- Binary heap
- Heap sort
- Immutability
- Completed code in JavaScript
- Week 4 Programming Assignment: 8 puzzle
1. Symbol Table
Key-value pair abstraction
- Insert a value with a specific key
- Given a key, search for the corresponding value
Implementations
- sequential search in a linked list (for unordered list) ->
Complexity: O(N) - binary search in an ordered list (when keys are comparable and we can put them in order) ->
Complexity: O(Log N)














