Btw there is no need to take a temp variable for swapping. Python allows a very easy swapping method, just use: num[ j ] , num[ j+1 ] = num[ j+1] , num[ j ]
@pravintulsijw95133 жыл бұрын
👍
@FukraInsaanLiveShorts2 жыл бұрын
I Need help @nikita
@jeelaghera56282 жыл бұрын
he has mentioned this code in his series but he is going with old school approach for who are watching bubble sort directly
@eclinicalWorks292 жыл бұрын
Thanx ❤️
@rubbish92312 жыл бұрын
This is why Phython called scripting language. The syntax you using is using sort function underneath .. basically its doing all steps there in bavkground.
@AaryanPakhrani5 жыл бұрын
Did he just call me an Alien?
@david-04 жыл бұрын
yup
@muhammadilyas21794 жыл бұрын
i was thinking this in previous video.
@indianyoyoer4 жыл бұрын
Ya
@ayushjhanwar36964 жыл бұрын
But why???
@SktechnicalSumit4 жыл бұрын
He is calling us alien since his first day python lecture.
@shamirroy6063 жыл бұрын
This guys should've been our university teacher. He's so good in explaining complex topics. Thanks a lot Navin Reddy.
@KeremAli-cm3pj2 ай бұрын
he wouldve called his students aliens.
@g17choudhary5 жыл бұрын
we can directly swap the values no need to temp variable if arr[j] > arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j]
@Sachin_Kumar-bn1ql4 жыл бұрын
haha...>> a,b=b,a
@shubhlaabh63424 жыл бұрын
Yea, it can be done
@himanshurajput86034 жыл бұрын
but you can only do it in python
@adirajsingh67384 жыл бұрын
Himanshu Rajput this is a python course, that’s the whole point lol
@srishtiagarwal34714 жыл бұрын
I guess sir is trying to tell the common method of bubble sort rather than just telling how to do this in python
@codewithenthronekingsleyАй бұрын
Navin you are just exceptional. I have been cracking my head about this up until now I watched this tutorial. It strange when some tutors claim they teach to beginners and use complex words. Thank you Navin
@RebeccaNamiya9 ай бұрын
This is the best bubble explanation I have heard in my research. Keep it up . Good work 👍🏾
@shenkuulover3 жыл бұрын
Your editing and speaking skills are amazing. Straight to the point and really showcases what you need to understand. Good job!
@nellaiappan89694 жыл бұрын
It had been very very useful for my son during lockdown Thank you sir😊☺️
@parthbhodia95753 жыл бұрын
This is a really good explanation. I can suggest you to use while loop as well to break out of the for loop if the items in the list are already sorted maybe in the 2nd or 3rd iteration. In that case you will not need to loop through n times.
@gunasekaranguna1888 Жыл бұрын
def Bubble_sort(n): for i in range(len(n)-1,0,-1): for j in range(i): if n[j]>n[j+1]: n[j],n[j+1]=n[j+1],n[j] print(n) c=int(input("Enter the number of elements in list:")) n=[] for k in range(c): d=int(input("Enter an value:")) n.append(d) print(n) print("The sorted list is",Bubble_sort(n)) "small modification"
@harshaddaingade97844 жыл бұрын
def sort(nums): for i in range(len(nums) - 1, 0, -1): for j in range (i): if nums[j] < nums[j + 1]: continue else: nums[j+1], nums[j] = nums[j], nums[j+1] nums = [5, 8, 9, 71, 10, 2,589,1,0] sort(nums) print(nums)
@glorysonhorace32652 жыл бұрын
Telusko, you really deserve a thumbs up. DSA never gets easier than this!!!
@pratikb81314 жыл бұрын
What's difference between bubble and insertion sorting
@sagnikray53915 жыл бұрын
sir, pls make a video on insertion sort
@sreekanthk94125 жыл бұрын
Instead of using 3rd variable directly we can swap two values nums[j],nums[j+1]=nums[j+1],nums[j]
@abdulfareed25853 жыл бұрын
Hi telusko. The outer loop and inner loop s range is a bit confusing for me. I just made the range as simple and it works but IDK whether is this right or not! def sort(nums): for i in range(len(nums)-1): for j in range(len(nums)-1): if(nums[j]>nums[j+1]): temp = nums[j] nums[j] = nums[j+1] nums[j+1] = temp return nums nums = [9,0,1,8,2,7,3,12,5] result = sort(nums) print(result)
@muhsinshah65025 жыл бұрын
#Some changes applied def sort(list): for i in range(len(list)-1,0,-1): for j in range(i): if list[j] > list[j+1]: #look here list[j],list[j+1] = list[j+1],list[j] nums = [4,7,3,6,2,3,1] sort(nums) print(nums)
@EritreanGamerOfficial2 жыл бұрын
i did it like this . it works def bubbleSwap(lst): x, y = 0, 0 h = 0 while h < len(lst): for i in range(1,len(lst)): if lst[i - 1] > lst[i]: x, y = lst[i - 1], lst[i] lst[i - 1] = y lst[i] = x h += 1 return lst
@kapilsingh72323 жыл бұрын
How we are getting the sorted values as we are not returning values from sort function?
@zakiasmaa6834Ай бұрын
I want to express my heartfelt gratitude for all the effort you put into simplifying the topics. Your presence and the way you explain things in the videos bring us joy and radiate positive energy. I hope you continue in this way, and I wish you all the best in everything you do.
@telugu_rockzz2 күн бұрын
Are you a girl?
@arvitech74195 жыл бұрын
Sir I have a doubt I assumed that a=bin(7) type(a) o/p Then I assume a=0b111 type(a) o/p = How sir both a= bin(7) = 0b111 are equal. But how that is str it is int becz both of the value is 0b111
@akhilkrishna52823 жыл бұрын
Navin can we do it this way? - we create a empty list and do linear search for the greatest value or lowest value and append it to the empty list and remove it from the original list .....do this a few more times and the original list becomes empty and the empty list becomes sorted....i tried and it worked so i thought commenting would help other programmers get different ideas on how to solve the same problem...
@vintage-flix-movies5 жыл бұрын
python is one line code lang so swap will be num[j],num[j+1]=num[j+1],num[j]
@bonysmoke91905 жыл бұрын
Maybe in some cases it will work, but not always. What this "line of code" does is it reverses a list and you get a something like this : list = [3,2,5,1] - before sorting, and after reversing it, you get list = [1,5,2,3]. If i'm not right, please, let me know :)
@pranavrk97523 жыл бұрын
@@bonysmoke9190 it works in all cases dude. its a python one liner. Because of the way python is build there are tons of one liner, In this case the in the video he use an extra variable temp and 3 lines of code, which can be done with the one liner.
@isaachossain28073 жыл бұрын
He was probably trying to teach an algorithm that would apply to all programming languages where a temporary variable is required for swapping. Not all programming languages will support a,b=b,a.
@DeepakKumar-uz4xy5 жыл бұрын
why take second for loop. can't we use if function directly by direct puttind swap function. for i in range(len(list)): if list[i]>list[i+1]: list[i], list[i+1] = list[i+1], list[i]
@sagarrao795 жыл бұрын
if we use only one for loop, only one value sorted to last like below [3, 5, 6, 2, 4, 8] to repeat same thing we need to use second for loop. yes we can use swap a,b= b,a def sort(list): for i in range(len(list)-1,0,-1): for j in range(i): if list[j] > list[j+1]: list[j],list[j+1]=list[j+1],list[j] nums=[5,3,6,8,2,4] sort(nums) print(nums)
@alexw.e.13905 жыл бұрын
@@sagarrao79 Please explain this to me: for i in range(len(list)-1,0,-1): I am so confused as to how this works and can't seem to figure it out on my own. Thanks
@navinyadav96935 жыл бұрын
@@alexw.e.1390we need to check the values from start till end. when i=5(in this program) j runs from 0 till 5 and the largest value, i.e 8 gets shifted to last place. now i becomes 4( since -1) and j runs from 0 to 4 and the next largest value gets shifted to second last place. this goes on until nums is sorted. i is taken in reverse so that j can check until last value. if this didn't help please debug the program. It will help you understand what is happening step by step.
@chandrashekhartigercharla16333 жыл бұрын
Finally I did with one loop.. Num=[3,6,2,16,11,17,8] Def sort(list): For i in range(len(num)-1): If num[I] > num[I+1]: Num[I],num[I+1] = num[I+1],num[I] Sort(num) Sort(num) Print (num)
@sharathnani64062 жыл бұрын
This is just sort not a bubble sort
@xathunalwarrior82874 жыл бұрын
why to make swapping complicated, when you can do this: a,b=b,a
@nawazmalik54354 жыл бұрын
U have one glass of juice And a cup of tea If u want to shift (swap) both . U need a cup called temp U put juice in temp Then tea to empty juice glass And finally juice to cup .
@EylulTurksever4 жыл бұрын
@@nawazmalik5435 no you don't. in python, you can do it without an extra cup. Xanthunal Warrior's way is correct and better.
@kaushalJainer4 жыл бұрын
lol he also knew that, its just in other languages u dnt have the luxary of swapping this way thats why, once u know the logic u can implement it anywhere you want
@madhavbhardwaj25273 жыл бұрын
@@kaushalJainer It is but than you have to remember the variables which have been swapped which will become a more complicated thing. As you have to put b where you are putting a after swapping and vice versa.... If you are putting a simple logic it is ok and will definitely run on any python software...
@anushkasingh17283 жыл бұрын
Due to the differences in Cs and Ip
@chinmaydas40536 жыл бұрын
Nice sir.. waiting for your video..
@balajiverma.sc-arn-25362 жыл бұрын
Sir, you are the best teacher, but why do you tell programmers "Aliens"? Pls explain
@rohitmalap55994 жыл бұрын
in the function sort, nums is local variable and is valid only for that particular suite. So how does changes in nums in sort function will reflect in nums outside sort? Could you please explain this?
@DeepakKumar-cq6jm2 жыл бұрын
Num is passed in sort so we can use it as local variable
@gaurikosamkar3824 жыл бұрын
I didn't understand the concept of range varying from -1to 0 and then again -1
@batteryjuicy42312 жыл бұрын
you could also have a variable = 0 at the start of every iteration and inciment it by 1 when you swap, therefore if at the end of an iteration the variable is 0 means the list is sorted and you don't have to try to sort the rest of the already sorted list
@hamidfarooq72425 жыл бұрын
you are amazing took me 7 mins to understand what i have been trying to understand for days
@memesv3.0934 жыл бұрын
Here's the easiest way: arr = [] a = int(input("Enter the no of elements")) for i in range(a): x = int(input()) arr.append(x) for i in range(a-1): for j in range(a-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] print("Sorted array is:", arr)
@tatapramod2774 жыл бұрын
could u please explain the a-i-1 part please
@jeetsutaria68025 жыл бұрын
thank you sir . tomorrow is my practicals and i have learned from from this video than i have learnt in my entire semister
@Rohan-c6y7 ай бұрын
throw back to 4 years ago when you were learning from this video any outputs now? what are you doing now after 4 years are you a full fledged python developer
@shahvipul74594 жыл бұрын
def Bubble(list_a): indexing_length = len(list_a) - 1 sorted = False while not sorted: sorted = True for i in range(0, indexing_length): if list_a[i] > list_a[i + 1]: sorted = False list_a[i], list_a[i + 1] = list_a[i + 1], list_a[i] return list_a print(Bubble([5, 3, 8, 6, 7, 2]))
@bedbyashlamichhane15414 жыл бұрын
we could use :am = [5,8,2,4,8,1] aw = sorted(am) print(aw)
@umxng4 жыл бұрын
4:00
@obbinenireddy41846 жыл бұрын
Thank you sir .....sir will you cover all data structure concepts????
@tusharkaushik95545 жыл бұрын
No sir will not
@ruomengtian42024 жыл бұрын
@@tusharkaushik9554 lol
@AmarjeetSingh-ammy6 жыл бұрын
Eagerly waiting sir, You are awesome,, I'm going to give you the name "KNOWLEDGE STACK " love from delhi
@shubhampawar97454 жыл бұрын
Also Using sorted function N=[1,4,5,5,7, 8,7,5,9,7] Print (sorted(N))
@shubhampawar97454 жыл бұрын
Python provide us inbuilt function
@sameerroshan95428 ай бұрын
for the outer loop you can also do: for i in reversed(range(len(nums))): and for swapping you can do this: if nums[j] > nums[j+1]: nums[j], nums[j+1] = nums[j+1], nums[j]
@chamarthiyashwanth40603 жыл бұрын
def bubble_sort(seq): min_value = 0 for i in range(len(seq)-1): for j in range(i): if seq[j] > seq[j+1]: seq[j],seq[j+1] = seq[j+1],seq[j] return seq is this considered as bubble sort, as in this the sorting is done by taking out the minimum values just like selection sort but with more iterations.
@jackwan358 Жыл бұрын
It save me the day to learn this in 10mins! Million thanks!!
@tanujgandhi89384 жыл бұрын
unable to understand the -1 , 0 ,-1
@anastasiagavrilita65674 жыл бұрын
You are a savior in every single way! (I refer to all of your tutorials!) So grateful that you are doing these tutorials!
@SachinParasharny4 жыл бұрын
I do the same. He is amazing
@எதுக்கு-த8ண3 жыл бұрын
why should we put -1in end part of the range declaration (starting)
@Rajadahana2 жыл бұрын
We have covered swapping in an earlier lesson in detail. There we discussed 3 methods as I remembered. So it is time to put that knowledge to work, without using a 3rd variable. (I learnt this from you) nums[j], nums[j+1] = nums[j+1], nums[j]
@shreyagodson2432 ай бұрын
Thank you for showing in user defined module 😊
@aakarshjain70266 жыл бұрын
Can you give tutorial of c++ for beginners
@shreenidhis24964 жыл бұрын
Hi Sir, why this code needs to return ?? def fact(n): f=1 for i in range(1,n+1): f=f*i return f x=5 res=fact(x) print(res) and y bubble sort doesn't need return??
@yaminipriya37424 жыл бұрын
i didn't understand y he used that range(-1,0,-1) anyone plz explain
@yaminipriya37424 жыл бұрын
Go to Amuls academy and search bubble sort you will understand in that
@sourabhhukkeri82863 жыл бұрын
Wth you answered your own question
@subhamoydey38675 жыл бұрын
sir you solve my doubt in just 7 minutues just like laminar flow of water
@saqulainkhan67173 жыл бұрын
Sir do you have live classes for ds in python or notes kindly reply
@akshaykatta36064 жыл бұрын
# Bubble Sort class Sorting: def __init__(self, list): self.list = list def sort(self): for i in range(len(self.list)-1): for j in range(i+1, len(self.list)): if self.list[i] > self.list[j]: self.list[i], self.list[j] = self.list[j], self.list[i] return list1 list1 = [] number = int(input("Enter Size of List: ")) for i in range(number): print("Enter", (i+1), "element:", end="") list1.append(int(input())) print(" List before Sorting: ", end="") for i in list1: print(i, end=" ") s1 = Sorting(list1) list1 = s1.sort() print(" List After Sorting: ", end="") for i in list1: print(i, end=" ")
@manojs25464 жыл бұрын
Why you using this much process? simply we can do nums.sort() print(nums) by it it sort very simple way ,please you may clarify it.
@sahilsurve53614 жыл бұрын
Navin sir actually have explained what happens inside 'nums.sort()' function It was d basic method to understand how the built in functions like 'nums.sort()' are created There is one more way to swap: a,b=b,a
@MAVERIKTOFA3 жыл бұрын
def sort(nums): for index1,value1 in enumerate(nums): for index2,value2 in enumerate(nums): if value1
@TANUJAS-y6o2 ай бұрын
li=[5,3,8,6,7,2] for i in range(len(li)): for j in range(len(li)-1): temp=0 if li[j]>li[j+1]: li[j],li[j+1]=li[j+1],li[j] print(li)
@piyushvaidya31283 жыл бұрын
For outer loop can we take range(0,len(nums)-1,1)?
@luzzaro4158 Жыл бұрын
It won't work that way
@vishnuvardhanreddy85845 жыл бұрын
sir u r awsomee i love this python tutorials and i shared to my friends
@persianleague399 Жыл бұрын
why not just use nums.sort() ? is it just for practice purpose? or it has different uses in real projects?
@viveksundaray68373 жыл бұрын
shouldn't it be: for j in range(i+1) but sir has written for j in range(i) which means that if i = 5 then the value of j will be 4 instead of four ??
@kartik.sharma.223 жыл бұрын
sir please tell me whether my this program is right or not it is giving right output but please check my method def sort(val): for i in range(len(val)): for j in range(len(val)-1): if val[j] > val[j+1]: temp = val[j] val[j] = val[j+1] val[j+1] = temp return val n = int(input("Enter the size of array ")) val = array('i', []) for i in range(n): value = int(input("Enter the value ")) val.append(value) sort(val) print(val)
@giuseppepala86684 жыл бұрын
I've found more elegant to substitute lines 6, 7 and 8 with list[j], list[j + 1] = list[j + 1], list[j] (i've learned that from my favourite Python on-line teacher 😉)
@jjiiee96364 жыл бұрын
It works man thanks, its like a short cut
@creativebeing11084 жыл бұрын
Learn code academy
@ikrajmohammad89995 жыл бұрын
Ots good work sir, keep.making more videos on python
@gamesgames33182 жыл бұрын
Im dumb at coding so this is a life saver when I can't understand certain parts of the code.
@abhiprit203 жыл бұрын
What if instead of list, I used tuples, dictionary as a input data structures, so time complexity will remain same or change?
@hruthik18343 жыл бұрын
This can be done through the normal sorting method which u explained in the lists concept
@sirikilohit20772 жыл бұрын
In Fact, We don't need to type complex logic: for i in range(len(nums)-1,0,-1): for j in range(i): if nums[j] > nums[j+1]: nums[j],nums[j+1] = nums[j+1],nums[j] Instead we can type like this: for i in range(len(nums)-1,0,-1): for j in range(i): if nums[j] > nums[j+1]: nums[j],nums[j+1] = nums[j+1],nums[j]
@kushagragupta43814 жыл бұрын
Mind blowing explanation!
@johndu92554 жыл бұрын
Also isn't there is a build in keyword "sort" ? Should we change the def to something else ?
@sandeeppareek89414 жыл бұрын
FOR SORTING IN ASCENDING ORDER ls = [7, 3, 3, 6, 5, 9, 2] ls.sort() print(ls)
@avinashtammali61304 жыл бұрын
amazing
@pritishchavan16712 жыл бұрын
very good
@sumitgupta-wf4db6 жыл бұрын
Sir you are giving my quarry answer Thanks for that I have find my answer without your help
@vaishalirathi55303 жыл бұрын
I tried to import both module in one file first I sort the list then find particular value it gives correct answer but position value is not coming right can someone help me in tha code is same as in video for both import file from Binarysearch import* from Bubblesort import* list=[4,6,1,3,5,9] sort(list) print('list=',list) n=9 if search(list,n): print('Found',pos) else: print('Not Found')
@gnanendraprakash8475 жыл бұрын
Sir, why don't we use nums[j] , nums[j+1] = nums[j+1] , nums[j] instead of t=a a=b b=t for swapping purpose.
@telugucinemastudio12223 жыл бұрын
Thanks bro this video is very helpful for me. I am studying engineering Would you suggest some tips to enhance my coding and communication skills.
@akshay40815 жыл бұрын
No need of temp..Directly swapping def sort(lst): for i in range(len(lst)-1,0,-1): for j in range(i): if lst[j]>lst[j+1]: lst[j],lst[j+1]=lst[j+1],lst[j] print[lst] lst=[3,2,6,4,9,7,5] sort(lst)
@abhijeetshikharvlog14445 жыл бұрын
Hey i will join your course but i have an one question can you teach me data structure in python all the topic sir
@moazelsawaf20005 жыл бұрын
Great topics and very good explanation ❤
@prasadshete7812 жыл бұрын
Hey well explained . But I didn't get range(numa)-1,0,-1 ?? What it does
@raviteja873 жыл бұрын
Included 0 in the list but wrong o/p is coming [1,0,2,3,] like this it is coming why is it like this
@srirajaniswarnalatha23063 жыл бұрын
is there any built-in function for bubble sorting please reply navin
@sapnajain13325 жыл бұрын
Sir , I m want to download Python Interpreter but it's version is 3.7.1 which is the latest one . Your videos are based on the version 3.7.0 . I want to ask you that it will create difference or not ❓
@riadhasan36834 жыл бұрын
output is [3, 2, 4, 6, 7, 7, 65] what is the problem.. ?? def sort(nums): for i in range(len(nums)): for j in range(i): if nums[j]>nums[j+1]: temp = nums[j] nums[j]=nums[j+1] nums[j+1]=temp nums=[7,4,3,6,2,7,65] sort(nums) print(nums)
@withharshvadhiya2 жыл бұрын
def sort(a): for i in range(len(a)-1,0,-1): for j in range(i): if a[j] > a[i]: a[i], a[j] = a[j], a[i] this also works same : )
@anuragtiwari97933 жыл бұрын
If there is an inbuilt function to sort, then why. Use these algorithms???
@misan20024 жыл бұрын
How would i do this for lists with elements which are made up if both strings and integers? Please help me
@rajshah17975 жыл бұрын
hello sir, i have one question. how did the nums got updated? we didn't returned it from the function and neither we used globals in the function.
@seyedfayaz4 жыл бұрын
Is this correct ? Please urgent a = [] number = int(input("Please Enter the Total Number of Elements : ")) for i in range(number -1): for j in range(number - i - 1): if(a[j] > a[j + 1]): temp = a[j] a[j] = a[j + 1] a[j + 1] = temp print("The Sorted List in Ascending Order : ", a)
@AmazingVideoGaming6 жыл бұрын
Plz make a video on pygame. Plz sir🙏🙏🙏
@ankushsarkar17465 жыл бұрын
Flask or django?
@Skaxarrat5 жыл бұрын
pygrame, I guess
@apurbasarkar69183 жыл бұрын
while running the code you didn't call the function, you just used the built-in sorted function
@vipulchauhan26114 жыл бұрын
thank you so much sir.i will be thankful to you.with the help of you i easily learn python
@isaachossain28073 жыл бұрын
Navin Reddy, you are my hero.
@Perplexedsouvik4 жыл бұрын
Sorry, but I got confused in this. Specially the outer loop logic. Can you please elaborate using outer and inner loops.
@arshgupta57374 жыл бұрын
def sort(self): for i in range(a-1,0,-1): for j in range(i): if list[j]>list[j+1]: temp=list[j] list[j]=list[j+1] list[j+1]=temp a=int(input("Enter the no. of elements you want to enter in the list ")) list=[] for i in range(a): li=int(input()) list.append(li) print("Unsorted list is: ",list) sort(list) print ("Sorted list is: ",list)
@shams64743 жыл бұрын
vowwww.....I never understood it i college but u made my life easy.
@KeremAli-cm3pj2 ай бұрын
*wowwww..... I never understood it in college but you made my life easy.
@justbelieve97543 жыл бұрын
Just outstanding. Love from Pakistan.
@rakshitrakshit60223 жыл бұрын
why to make sorting so complex when you can do this print(sorted(nums))
@Hassam_Haider2 жыл бұрын
thank you very much Sir really, you helped me so much with this
@anuthomas51842 жыл бұрын
I am searching for all the sorting algorithms in java telusko. But it's getting python... Can u provide the Bubble sort link in java. Now I became an addict of telusko java learning. It's really Amazing
@Game-nr3sr Жыл бұрын
check in another YT playlist
@bharathvaj27604 жыл бұрын
5:14 sir we are going from 5 to 0 right?
@sagardixit84324 жыл бұрын
yes bro
@abhinavshaw46563 жыл бұрын
0 is for index no. But here we consider as 1 for himan understanding