Sorting Algorithm Report
Sorting Algorithm Report
FE23A043
Algorithm:
Below is the code snippet and result for a sample data arr[]= {15, 9, 29, 3,
10, 0}
Recursive:
Base Case: When the unsorted array contains only one element, Therefore
the array is already sorted. Return the function
Recursive case: Repeatedly call the function with smaller values of n,
following the same algorithm for iterative version. Below is the code snippet
and result for a sample data arr[]= {15, 9, 29, 3, 10, 0}
Base case: When the unsorted array contains only one element, Therefore
the array is already sorted. Return the function
Recursive case: Repeatedly call the function with smaller values of n,
following the same algorithm for iterative version. Below is the code snippet
and result for a sample data arr[]= {15, 9, 29, 3, 10, 0
3. Sequential Insertion Sort:
Algorithm:
Start with the second element in the array, as the first element is already
sorted.
Compare the selected element to each element in the sorted part of the
array.
Move any elements that are larger than the selected element one position to
the right.
Place the selected element in the correct position.
Repeat the process until all elements are sorted.
Below is the code snippet and result for a sample data arr[]= {15, 9, 29, 3,
10, 0}
4. Binary Insertion Sort:
Algorithm:
Iterate the array from the second element to the last element.
Store the current element A[i] in a variable key.
Find the position of the element just greater than A[i] in the subarray
from A [0] to A[i-1] using binary search. Say this element is at index
pos.
Shift all the elements from index pos to i-1 towards the right.
A[pos] = key.
Below is the code snippet and result for a sample data arr[]= {15, 9, 29, 3,
10, 0