C: Sorting & Searching

Sorting

Bubble sort
- compare two values, swap if necessary
- continue until sorted

Selection sort
- pick the lowest value, put it in the first slot
- then the next lowest value, put it in the second slot
- and so on
- continue until sorted

Insertion sort
- compare values, take the lowest into a temp value
- move the temp value to the front
- continue until sorted

Quick sort
- pick a pivot
- divide the other values into values less than the pivot and values greater than the pivot
- repeat the process with the split groups
- continue until sorted

Merge sort
- divide the value group into two until only two values remain in each subgroup
- sort each subgroup
- merge subgroups, sorting again
- continue until sorted


Searching

Linear search
- normal search, compare each value with the key until found

Binary search
- only for sorted arrays
- search from the middle
- if key is greater than middle value, go right
- if key is lesser than middle value, go left

Interpolation search
- only for sorted arrays
- search from an approximated location
- if key is greater than starting point value, go right
- if key is lesser than starting point value, go left


2201757635
skyconnectiva.com
binus.ac.id
Juanda P. G.

Comments

Popular posts from this blog

C: Review

C: Selection