DSA Python Course 2025 - Insertion Sort in Python - Part 21 [Hindi] | Code & Debug

preview_player
Показать описание
Welcome to Part 21 of Code & Debug’s DSA Python Course 2025! 🎉 In this video, we’ll learn about Insertion Sort, a simple and intuitive sorting algorithm, and implement it step-by-step in Python. Sorting techniques like Insertion Sort are crucial for mastering Data Structures and Algorithms (DSA).

Here’s what you’ll learn:
📌 What is Insertion Sort, and how does it work?
📌 Step-by-step explanation of the Insertion Sort algorithm
📌 Python implementation with practical examples

👉 Refer the article below for better understanding of Insertion Sort:

👉 📄 Access the full YouTube DSA Playlist Sheet (All Questions in Order):

👉 Enroll in the free DSA Python course here:

👉 Enroll for Self-Paced Advance DSA course here:

👉 Don’t forget to subscribe and hit the 🔔 to stay updated with all our lectures.

#DSAPythonCourse #InsertionSortPython #PythonDSA #DSA2025 #CodeAndDebug #PythonProgramming #LearnDSA #SortingAlgorithms
Рекомендации по теме
Комментарии
Автор

briliant explaination!! ngl i understood everything! thanks

LuckywithluckYT
Автор

Using for loop instead of while loop

def insertion_sort(arr):
limit = len(arr)

for i in range(1, limit):
if arr[i] < arr[i-1]:
key = arr[i]
for j in range(i-1, -2, -1):
if j < 0 or arr[j] <= key:
arr[j+1] = key
break
else:
arr[j+1] = arr[j]

TheDark_Knight_rises
Автор

can this code be considered as insertion sort

for i in range(0, len(arr)):
for j in range(len(arr[:i+1])):
if arr[j]>arr[i]:
arr.insert(j, arr[i])
arr.pop(i+1)

nidheshgomai
Автор

I m still confused on Line8. what i did is i used nums[i] instead of nums[j+1]. arewe copying elements here or making space? and how does it makes space, .

x = [6, 9, 2, 1, 5, 7, 4]
def inertion_sort(nums):
n = len(nums)
for i in range(1, n):
key = nums[i]
j = i-1
while j>=0 and nums[j]<key:
nums[j+1] = nums[j]
j-=1
nums[j+1]= key
return nums

print(inertion_sort(x))

pushkarawasthi
visit shbcf.ru