
Real-Life Situation/Scenerio: VIDEO EDITOR OPTIMIZING WORKFLOW
You are a video editor managing a collection of edited video files for different categories of content, including wedding events, vlogs, and infomercials. Each category contains 10 video files, and you need to organize and name them for easy access and retrieval. To efficiently sort and name the video files, you decide to implement the Insertion Sort algorithm, applying the Decrease and Conquer approach.


INSERTION SORTING USAGE
Insertion Sort is a straightforward sorting algorithm that builds the final sorted array one item at a time by repeatedly taking the next element and inserting it into the sorted portion of the array. It is suitable for small datasets and is easy to implement, making it ideal for situations where efficiency is less of a concern compared to simplicity.
Why Insertion Sort
Insertion Sort is chosen for sorting the video files into categories because of its simplicity and effectiveness for small datasets.
-
Small Dataset: With only 10 videos in each category, the dataset is relatively small. Insertion Sort's time complexity of O(n^2) is less of a concern for smaller datasets compared to larger ones.
-
Stability: Insertion Sort is a stable sorting algorithm, meaning it preserves the relative order of equal elements. In the context of sorting video files for categories, stability ensures that videos with the same name or similar attributes remain in the same order after sorting.
-
Ease of Implementation: Insertion Sort is straightforward to implement, making it a suitable choice for this scenario where simplicity is prioritized over performance optimization. The code is easy to understand and maintain, which is beneficial for managing video files in a video editing workflow.
-
Efficiency for Almost Sorted Data: Since the video files may already be partially sorted by their names or other attributes, Insertion Sort's efficiency increases when dealing with nearly sorted data. This property makes it particularly suitable for situations where the input data is already partially ordered.
CODE BREAKDOWN
-
def insertion_sort(video_files): Defines a function insertion_sort that takes a list of video files as input.
-
The algorithm iterates through each element of the list starting from index 1.
-
For each element, it compares it with the elements to its left in the sorted portion of the list.
-
If the current element is less than the element to its left, it shifts the elements to the right to make space for insertion.
-
Finally, it inserts the current element into its correct position in the sorted portion of the list.
REFLECTION
GAINED KNOWLEDGE
Implementing the Insertion Sort algorithm in this project provided valuable insights into sorting techniques and their application in real-world scenarios. I gained a deeper understanding of how Insertion Sort works, particularly its approach of building the final sorted array one element at a time by comparing and inserting elements into their correct positions. Additionally, I learned about the stability of sorting algorithms and its significance in maintaining the order of equal elements.