mellysmelly
Active Member
- Joined
- Nov 13, 2023
- Messages
- 117
- Gender
- Female
- HSC
- 2024
Insertion Sortnot me, idek what each of the sort does
- Used when a large part of the data is already sorted
- During each pass the last element from the unsorted part is inserted into the appropriate place in the sorted part of the array
- A linear search is conducted to find the correct place to insert
- As each sorted element is checked it is moved to the left/right to make room for the new elements
- At each pass the sorted section of the array increases by 1
- Process continues until the unsorted section = 0
Description automatically generated"]https://lh7-rt.googleusercontent.co...d1tQc9LjDLs8?key=2Iw8s10gNDfiG5RQCYHfyw[/IMG]
Selection Sort
- During each pass a linear search is performed
- A marker is placed at the first cell in the array and then search through the array from that position onwards looking for the smallest value
- When the smallest value is found, it is swapped with the marker’s cell value. This naturally places the smallest value at the front of the array
- The next step is to increment the marker to the next cell and repeat the process. When the marker reaches the last cell, the array is sorted.
- procedure selection sort
Bubble Sort
- popular amongst novice programmers
- main logical structure is based on traversing an array and switching adjacent pairs of values that are not in the correct order
- after one travers the largest value will have ‘bubbled’ to the end of the array. This is repeated until all values are in the correct cells
Set index to first index of numbers +1
WHILE index <= last index of numbers
IF numbers[index –1] > numbers[index] THEN
Swap(numbers[index –1] and numbers[index])
ENDIF
Increment index
ENDWHILE
END