Egbert Lin's Blog

“Life is not a race, but a journey to be savoured each step of the way” by Brian Dyson

Basic programming - Heap Sort

Approach:

Heap is a complete binary tree. And, heap feature is that parent node must bigger than its child nodes. It also calls max-heap.

Read more »

Basic programming - Quick Sort

Approach:

Take one element as the pivot to separate two parts from another elements. For the convenient, we always takes the last element as the pivot.

Read more »

Basic programming - Insertion Sort

Approach:

Need to use two for-loop. One is unsorted data in the range [i:n] and the other is sorted data in the range [0:i].

Take one element from unsorted data to compare with sorted data.
Step 1: use temp variable to store this element
Step 2: search value from sorted data which is bigger than temp , if true, move the bigger value to current position vector[j] = vector[j - 1]
Step 3: Until if-statement returns false, it means the value of j - 1 is smaller than temp, so insert temp to current position vector[j] = temp.

Read more »