week-3

What i learned this week?
Insertion Sort
Cyclic Sort Basics
Insertion Sort – The “Hand of Cards” Method
What is it?
Insertion Sort works like how we sort playing cards in our hands — by comparing one card with the ones before it and inserting it at the correct position.
How it works:
Start from index
1
.Compare it with all previous elements.
Shift bigger elements to the right.
Insert the current element in the right place.
When to use:
When the array is nearly sorted.
Simple and easy to implement.
Cyclic Sort – Sorting Numbers in a Range [1, n]
What is it?
Cyclic Sort is used when the array has numbers from 1 to n (or 0 to n-1) and we need to sort them in linear time.
How it works:
Loop through the array.
Place each number at its correct index.
Swap until all numbers are at their correct place.
When to use:
When the array is guaranteed to have elements from 1 to n with no duplicates.
Very useful in problems like:
Find missing number
Find duplicate number
Learning Source
A big shoutout to Kunal Kushwaha for his beginner-friendly and crystal-clear DSA playlist on YouTube.
https://youtu.be/By_5-RRqVeE?si=RXQdy0O0pyCuygSg
My Takeaway
Sorting is more than just bubble sort!
Insertion sort is great for nearly sorted arrays.
Cyclic sort is for solving many DSA problems in O(n).
👉 Stay tuned for Week 4!
Subscribe to my newsletter
Read articles from Berjin Sujith directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
