Algorithms in Python | Insertion Sort| Full Code | Telugu

Опубликовано: 25 Май 2026
на канале: Naveen V
73
1

#pythonintelugu #algorithms #naveenv
Algorithms in Python | Insertion Sort|Full Code with Time Complexity explanation| Telugu using Recursion

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

Advantages:
In-place sorting and doesn't require extra space
Simple implementation
Efficient for Small Datasets
Adaptive if the list is semi sorted

Time Code
00:00 Intro to Insertion Sort
02:34 Python Implementation
06:00 Stepwise Iteration

Python Code:
---------------------
list_num = [99, 222, 33, 6, 12, 11, 23, 5, 4, 7, 2, 0]
def insertion_sort(sequence):
for i in range(1, len(sequence)):
compare = sequence[i]

while sequence[i - 1] GT compare and i GT 0:
sequence[i], sequence[i - 1] = sequence[i - 1], sequence[i]
i = i - 1
print(sequence)
return sequence
print(insertion_sort(list_num))


Best Case - In a sorted list - O(n)
Average/ Worst Case - O(n2)

Time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm

Time Complexity is commonly expressed using big O notation, typically O(n), O (logn), O(n^2), O(2^n), O(n!) etc where n is the input size in units of bits needed to represent the input.

If you like this content, please like, share and subscribe. Motivates me to create more such content.