DSU 313301 Practical No.11: Write a ‘C’ Program to Sort an Array of Strings 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 relative order in the sorted output.
C Program Code
Algorithm
Use the below instructions to draw a flow chart
Output of code
Original array of strings:
banana
apple
orange
mango
pear
Sorted array of strings:
apple
banana
mango
orange
pear
Practical Related Questions
1. Create an interactive game where the user enters a list of strings, and the program sorts them using insertion sort. Allow the user to add or remove strings dynamically and see the sorting process step by step.
Answer:
2. Implement insertion sort with a custom comparison function that sorts strings based on a specific criterion (e.g., number of vowels, number of consonants, etc.).
Answer:
Exercise
1. Write when it is suitable to use Insertion Sort
Answer:
2. List Applications of Insertion Sort
Answer:
3. Explain how insertion sort handles strings with different lengths?
Answer:
It works by building a sorted array one element at a time, picking each element from the unsorted section, and inserting it into its correct position in the sorted part.
Conclusion
We successfully completed DSU 313301 Practical No.11 and Wrote a ‘C’ Program to Sort an Array of Strings using the Insertion Sort Method.