Bubble Sort - Data Structures & Algorithms Tutorial Python #14

preview_player
Показать описание
Bubble sort is a sorting technique used to sort a list or an array. In data structures and algorithm tutorials, this technique is covered as the most common technique for performing a sorting. It performs sorting in O(n^2) time complexity so it is not the most efficient but it is probably a very simple technique to understand. In this video we will go over theory behind how bubble sort works and implement bubble sort in python. In the end I have an exercise for you to work upon along with a solution link.

Topics
00:00 Bubble sort explanation
04:25 Python implementatin
13:24 Exercise

#sortingalgorithms #algorithms #bubblesort #datastructures #algorithms #python

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

Really very happy about finding such an obvious and understood funny video series about data structures and algorithms. Everything is 100% clear with deeply explained theories and well-understood practicals. Also, the exercise series with the videos are highly appreciated. Dear sir thank you so much for the fantastic video series. ❤💖

tharindusathsara
Автор

for many months I delayed learning DS but since I have found your channel, now DS seems really easy. Specially the exercise part I like most. Thankyou Sir from the depth of my heart. Saviour of students like me.

naveenchahar
Автор

Hi, if you prefer to make the code a bit shorter, there is actually no need to use a tmp variable.
Instead of:
tmp = elements[j]
elements[j] = elements[j+1]
elements[j+1] = tmp

Use:
elements[j], elements[j+1] = elements[j+1], elements[j]

This is a neat trick in python that allows the value of two variables to be swapped.

alexlu
Автор

U are true guru, people only explain how to do it but they do not explain why. And only a true teacher would explain both how and why. I didn't understand why that -i part, but u made it clear. thankyou so much SIrr

rajmalla
Автор

I loved the way you optimised bubble sort from O(n^2) to O(n) using swapped flag

hrushikeshkulkarni
Автор

Your approach to problem solving is genius.

iwuomasolomonuched
Автор

The swapped flag is a good catch on making sure best case is O(n). Most other implementations I've seen do not have this flag, and thus don't take advantage of a pre-sorted array.

danieltaylor
Автор

sir, thanks a lot!! It's solved my n-1-i problem.
some books said it was actually i+1 and written as n-1-i in code, and i was so confused.
now i know its cause un-efficient for loop to continue, so we need n-1-i to shorten the loop when the last digit was found, thank you !!!

奶油雞雞
Автор

Thank you, Mr. Dhawal, I can't believe this content is free.

LokeshKumar-ddqw
Автор

Hi Sir, I was having difficulty in understanding bubble sort, from your video it is crystal clear now. Thanks

miteshbarnwal
Автор

Amazing step by step explanation! Thank You Sir!

gaganbhattacharya
Автор

Explained so well, love the way you implement DSA efficiently

ij
Автор

i have seen many bubble sort but yours is best

techsavvyinfo
Автор

holy hell. heard a lot about bubble sort. but never knew why it's called so.

sukurcf
Автор

very good explanation, i have been searching for a video just like this, thank You sir

trendinggameplay
Автор

thankyou once again sir for continuing with the series. Take care sir!

tripathi
Автор

excellent sort algo tutorials from bubble to selection. thank you

treksis
Автор

easy solution for above exercise question

def bubblesort(elements, key="name"):
size = len(elements)
for i in range(size-1):
for j in range(size-1):
if (elements[j])[key] > (elements[j+1])[key]:
tmp = elements[j]
elements[j] = elements[j+1]
elements[j+1] = tmp
return elements

jagadeeshchowdary
Автор

You were very grave at the end of the video! I miss the coronavirus prank at each video-endding! Hahaha

johnk
Автор

Your explanation is fantastic, sir. Respect!

a.human.