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.
“Life is not a race, but a journey to be savoured each step of the way” by Brian Dyson
Basic programming - Heap Sort
Heap is a complete binary tree. And, heap feature is that parent node must bigger than its child nodes. It also calls max-heap.
Basic programming - Merge Sort
It is a Divide and Conquer problem. Divide the vector into small group to sort, and merge each small groups to the vector.
Basic programming - Quick Sort
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.
Basic programming - Bubble Sort
Compare with each elements in the range [0: n]
and if vector[i]
is bigger than vector[i + 1]
, call swap().
Basic programming - Insertion Sort
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
.
23. Merge k Sorted Lists
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one sorted linked-list and return it.
287. Find the Duplicate Number
Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.
There is only one repeated number in nums, return this repeated number.
Basic programming - Selection Sort
Declare two variables, i
likes the end pointer of sorted vector and j
likes the scanning pointer.