Insertion Sort - Data Structures & Algorithms Tutorial Python #16

preview_player
Показать описание
Insertion sort is a simple sorting algorithm (Very few lines of code) that is best for small lists. If your array is very big insertion sort might not be the perfect choice as it performs in O(n^2) time complexity. In this video we will go over how insertion sort work and implement insertion sort in python.

Topics

00:00 Theory
06:49 Coding
11:05 Exercise

#insertionsort #datastructures #algorithms #python

DISCLAIMER: All opinions expressed in this video are of my own and not that of my employers'.
Рекомендации по теме
Комментарии
Автор

The world changed, ppl studied and revolutionalized the world's technology; every day, a new algorithm is released and ppl try to improve themselves to become better person. Every second a person dies and borns, and yet, here I am, as always, trying to learn everything just before the night of exams... some things never changed... and your videos have helped me a lot. Thank you for the hard work!

meatball
Автор

My best part was the very last commentary, I'm cracking up. Greate Video!!

josiahdavid
Автор

Just finished the whole series. Very informative. Thank you very much.

npvlong
Автор

Thank You Sir. I just completed the whole Data Structure and Algorithms Playlist. Your videos are very informative and well explained.

SatyamSingh-zmes
Автор

In every video, i will laugh in middle..that is the beauty of your videos...loved it..

jiyabyju
Автор

well I tried it by myself first, wrot a 30-35 lines of code still was'nt able to pull this off, and you did it in within 5-6 lines truly amazing love your videos.

ridhamsuhagiya
Автор

Thank you Sir. 🙏🙏
Very helpful and detailed explaination and also easy to understand. 🙏🙏

nimishakhadilkar
Автор

your powerpoint skills seems so good, can you make a powerpoint tutorial on how you make these slides in powerpoint it would be really helpful

binary_
Автор

You are a phenomenal teacher, thank you so much. And hilarious lol

vivekpujaravp
Автор

Very helpful Sir. Looks like you are continuing both the Dara Structures and Deep Learning series. Thank you sir😁

rishavbhattacharjee
Автор

Hi Sir, your videos are explanatory and quite informative. I request you to kindly share other sorts such as shell sort, comb sort, counting sorts etc as well.

somasreebiswas
Автор

beautiful found it difficult understanding the question in the exercise

valentinemadu
Автор

It's most beautiful video on DSA actually your explanation makes us motivated learn best practice of Software Industry

vinaynaik
Автор

why am I paying to attend university, when I get classes like this !! This series is really helpful!!

karthikeyani
Автор

my solution to exercise
def insertion_sort(element):
total = 0
for i in range(len(element)):
for x in range(i):
if element[i] < element[x]:
element.insert(x, element.pop(i))
break
if i%2 ==0:
index = i/2
print(element[int(index)])
else:
index = i//2
print((element[int(index)] + element[int(index)+1]) /2)

mohammadpatel
Автор

If this would have been pretty big unsorted list then which algorithm you would have suggested?

nvasudeva
Автор

Hi Dhaval, We can write sort function in this way as well, it passed the edge cases, let me know if you found any bug in this: def insertion_sort(lst):

for i in range(len(lst)):
for j in reversed(range(i)):
if lst[j+1] < lst[j]:
lst[j+1], lst[j] = lst[j], lst[j+1]
return lst

swatiahlawat
Автор

exercise
def insertion_sort(arr):
for i in range(1, len(arr)):
count = i
while count > 0 and arr[count - 1] >= arr[i]:
count -= 1
arr.insert(count, arr.pop(i))
a = len(arr)
return arr[int(a / 2)] if a % 2 == 1 else (arr[int(a / 2)] + arr[int((a / 2) - 1)]) / 2
# for median


if __name__ == '__main__':
elements = [9, 5, 3, 2, 1, 10, 11, 12]
print('median: ', insertion_sort(elements))
print(elements)

muhammedjafer
Автор

I can't tell you what pain I went through to solve the exercise on my own. Took me 3 hours of trial and error.

awsomeslayer
Автор

Self-note: tricky concept, come back and review again.

a.human.