Data Structure Using C (313301) Practical No.10: Write a ‘C’ Program to Sort an Array of numbers using the Insertion Sort Method
Insertion sort is a simple sorting algorithm that works by iteratively inserting each element of an unsorted list into its correct position in a sorted portion of the list. It is a stable sorting algorithm, meaning that elements with equal values maintain their relative order in the sorted output.
C Program Code
Algorithm
Flow Chart
Use the below instructions and draw the flow chart
Result (Output of Program)
Original array:
12 11 13 5 6
Sorted array:
5 6 11 12 13
Practical Related Questions
1. Modify the Insertion Sort algorithm to use binary search to find the correct position to insert the current element. Implement this modified algorithm and compare its performance with the standard Insertion Sort.
Answer:
2. Use the Insertion Sort algorithm to count the number of inversions in an array. An inversion is a pair of elements where the earlier element is greater than the later element.
Answer:
Exercise
1. Write Time and Space Complexities of Insertion Sort.
Answer:
2. List Applications of Insertion Sort
Answer:
3. How does insertion sort handle duplicate values in the array?
Answer:
We successfully completed Data Structure Using C (313301) Practical No.10 and Write a ‘C’ Program to Sort an Array of Numbers using Insertion Sort Method.