#71 Python Tutorial for Beginners | Selection Sort using Python

  Рет қаралды 332,186

Telusko

Telusko

Күн бұрын

Пікірлер: 212
@anupampatro3711
@anupampatro3711 4 жыл бұрын
No one has ever explained to me sorting and search in such a simple way. Thanks a lot for explaining all the concepts in simple ways.
@nikunjlohiya5160
@nikunjlohiya5160 3 жыл бұрын
Sir i have completed your entire course on python and it is one of the best courses to learn python available on KZbin. Your teaching makes the concepts very easy to understand. It is really commendable that such a quality of content can be accessed for free. Once again hat's off to you sir and your teaching...
@placement3608
@placement3608 6 жыл бұрын
Accordingly to me u changed my life in programming .u are god sir ...thank u Navin sir .....
@harshaddaingade9784
@harshaddaingade9784 4 жыл бұрын
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)
@hrishikeshhasabnis8111
@hrishikeshhasabnis8111 4 жыл бұрын
This can be a possible optimization : def selection_sort(list): for i in range(len(list)): for j in range(i+1, len(list)): if list[i] > list[j]: list[i], list[j] = list[j], list[i] Btw, Great video Sir as always! Thank you!!
@kartikkalia01
@kartikkalia01 4 жыл бұрын
yeah, he taught this in his earlier video
@hrishikeshhasabnis8111
@hrishikeshhasabnis8111 4 жыл бұрын
@@kartikkalia01 Glad to know that..
@AnkitKumar-gg2zs
@AnkitKumar-gg2zs 4 жыл бұрын
It could be simple like list=[10,5,8,2,1] For i in range(len(list)): min_value=min(list[i:]) min_index=list.index(min_value) list[i] , list[min_index]= list[min_index], list[i] Print (list)
@hasibkhan8600
@hasibkhan8600 5 жыл бұрын
for i in range(10): print("At the end to watching all the video, I want to say, take my salam inside my heart. Thank you so much Navin Reddy Sir.God bless you.")
@lsrinivasamurthy
@lsrinivasamurthy 4 жыл бұрын
This can be optimized a little bit as below : The code for swapping logic is always getting executed, This can be executed only if we really find the small number , else the existing will be as it is. def sort(my_list): for i in range(5): min = i for j in range(i, 6): if my_list[j] < my_list[min]: min = j if my_list[i] != my_list[min]: print("Swapping Logic") temp = my_list[i] my_list[i] = my_list[min] my_list[min] = temp print(my_list) my_list = [5, 3, 8, 6, 7, 2] print(my_list) sort(my_list) print(my_list)
@guptasubas1530
@guptasubas1530 3 жыл бұрын
numberList = [23,45,2,3,4,23,1,28,41] def selectionsort(numberlist): for i in range(len(numberlist)): for j in range(i+1,len(numberlist)): if(numberlist[j]
@abhishekjaiswar4669
@abhishekjaiswar4669 5 жыл бұрын
def sort(num): for i in range(len(num)): for j in range(i,len(num)): if num[j]
2 жыл бұрын
Thanks for this great tutorial. I wanna point to something, you've missed an edge case in case this : list=[1,2,6,5,4,3] loop min_index=2 i=2 swap so here we didn't find a less value than min_index=2, so we don't need to do swapping to solve this issue, we need to add a condition : loop min_index=2 i=2 if i != min_index then do swap ===> first case we swap 6 times ===> the second one, we swap 3 times
@FactsDiscoveryyoutube
@FactsDiscoveryyoutube 5 жыл бұрын
if you want to clear the video concept look the output of my coding: Thank you Navin Sir def sort(l): n = len(l) for i in range(n): print("The value of i",i) minpos = i for j in range(i+1,n): print("Print the value of j",j) if l[j]< l[minpos]: minpos = j l[i] ,l[minpos] = l[minpos],l[i] list = [2, 5, 6, 7, 4, 3] sort(list) print("Sorted list is") for i in range(len(list)): print(list[i]) o/p: The value of i 0 Print the value of j 1 Print the value of j 2 Print the value of j 3 Print the value of j 4 Print the value of j 5 The value of i 1 Print the value of j 2 Print the value of j 3 Print the value of j 4 Print the value of j 5 The value of i 2 Print the value of j 3 Print the value of j 4 Print the value of j 5 The value of i 3 Print the value of j 4 Print the value of j 5 The value of i 4 Print the value of j 5 The value of i 5 Sorted list is 2 3 4 5 6 7 Process finished with exit code 0
@benerjeverse
@benerjeverse 4 жыл бұрын
for i in range(n) this u can put n-1 in the place of n
@guptasubas1530
@guptasubas1530 3 жыл бұрын
numberList = [23,45,2,3,4,23,1,28,41] def selectionsort(numberlist): for i in range(len(numberlist)): for j in range(i+1,len(numberlist)): if(numberlist[j]
@jagsexe
@jagsexe 2 жыл бұрын
@@guptasubas1530 this is bubble sort isnt it ?
@arnavgupta7392
@arnavgupta7392 Жыл бұрын
for j in range(i+1,n) change this to for j in range(i,n) otherwise it will through an error of index out of range for the last index of the list
@aakashjana6225
@aakashjana6225 4 жыл бұрын
In Python you can swap by writing just nums[i], nums[minpos]=nums[minpos], nums[i]
@chinmaydas4053
@chinmaydas4053 6 жыл бұрын
We want these types of indepth, easily discussed great topics videos like data structures, different algorithms writing and analysis techniques.. lots of love and respect for you sir 🙏🙏🙏...
@mdbhardwaj5005
@mdbhardwaj5005 4 жыл бұрын
analysed the code using debugger and understood the concept. Love your videos, Sir.
@fawadkhan8905
@fawadkhan8905 5 жыл бұрын
Thank you sir so much, now we are able to refined the code up to somehow it' s by watching your videos. So i would like to share the script that took me almost 2 hours and get me succeed in it. def selct(x): for i in range(len(x)): #minIndex=i (No need of this) for k in range(i, len(x)): if x[k] < x[i]: (x[k],x[i])=(x[i],x[k]) print(x) x=[2,4,5,1000,7,8,1,99] selct(x)
@ashmitgajwani6086
@ashmitgajwani6086 4 жыл бұрын
Dude that was great!!!
@RK_97
@RK_97 4 жыл бұрын
you are missing the concept of selection sort, that is swap once per iteration. Your solution is more like the bubble sort.
@pranav9339
@pranav9339 2 жыл бұрын
for i in range(len(a)): m=min(a[i:]) u=a.index(m) a[i],a[u]=a[u],a[i] alternate way
@guptasubas1530
@guptasubas1530 3 жыл бұрын
Simple version : numberList = [23,45,2,3,4,23,1,28,41] def selectionsort(numberlist): for i in range(len(numberlist)): for j in range(i+1,len(numberlist)): if(numberlist[j]
@divyankakanyal6802
@divyankakanyal6802 11 ай бұрын
for j in range (i+1 , n) should have been used to make the iteration short. Thank you sir for explaining in such simple way ✨😊
@madhvishrivastava3646
@madhvishrivastava3646 8 ай бұрын
I never knew that sorting is that simple. Thank you so much sir.
@infotech3180
@infotech3180 4 жыл бұрын
Thanks sir , I completed my whole concept of python from you Love from Pakistan
@thorhilda
@thorhilda 4 жыл бұрын
Teaching future Python users to use and conceive for..loops as if they similar to other language's loops is instilling bad habits and poor reasoning that will hinder their progress greatly. In Python, for...loops are iterators not counters, and they ought to be understood as "for each_elements in a_set do something on each_elements", not "for index from 0 to len(nums)) do something on nums[index]" as in C language. --------- Python code starts here --------- def selection_sort(unsorted_list): """ A far better way that mimics the actual principle behind 'selection sort', that is sorting by selecting items one after the other according to an ordering function """ # (optional) work on a copy to keep the original list unmodified lst = unsorted_list.copy() while lst: # for as long there are items in the list extracted_value = min(lst) # find the smallest value del lst[lst.index(extracted_value)] # remove it from the list yield extracted_value # outputs it on demand numbers = [5, 3.14159, 8, 6, 7, 2] print(list(selection_sort(numbers))) # [2, 3.14159, 5, 6, 7, 8] # the above function can be easily generalized to use any arbitrary ordering function def extract(n, *, func=min): while n: extracted_value = func(n) del n[n.index(extracted_value)] yield extracted_value # Some examples from functools import partial reverse = partial(extract, func=max) characters = list("Python".upper()) # in reverse alphabetical order print(list(reverse(characters))) # ['Y', 'T', 'P', 'O', 'N', 'H'] import random shuffle = partial(extract, func=random.choice) players = ["Alice", "Bob", "Charles"] print("The first to be randomly chosen is", next(shuffle(players))) print("The second to be chosen is", next(shuffle(players))) print("And the last to be chosen is", next(shuffle(players)))
@arshgupta5737
@arshgupta5737 4 жыл бұрын
def sort(self): for i in range(a): minpos=i for j in range(i+1): if list[j]
@AlankritIndia
@AlankritIndia 4 жыл бұрын
selection sort using maximum element- def ssortmax(l): for i in range(len(l)): maxpos=len(l)-1-i for j in range(len(l)-i-1): if l[j]>l[maxpos]: maxpos=j l[maxpos],l[len(l)-i-1]=l[len(l)-i-1],l[maxpos]
@sampratickroy2055
@sampratickroy2055 6 жыл бұрын
after all u r the best trainer as an indian youtuber
@rohinisingh6916
@rohinisingh6916 2 жыл бұрын
All videos are awesome sir. Outstanding teaching way.
@alhaquekhan938
@alhaquekhan938 3 жыл бұрын
You should use j in range(i+1,len(arr))
@blackcrocodilehunter204
@blackcrocodilehunter204 4 жыл бұрын
Liked your video but I wish you made the code completely dynamic, instead of having for i in range(5) have for i in range(len(list))
@LakshmiPR-hp4bp
@LakshmiPR-hp4bp 9 ай бұрын
You are great sir. Very good tutorial for python beginners. Thanks a lot
@sarat4chan
@sarat4chan 5 жыл бұрын
Hi Navin, You are a great teacher, I gained lot of knowledge from your python series. Can share us separate series dedicated to algorithm and data structures?
@vinoddiwan5792
@vinoddiwan5792 5 жыл бұрын
Agreed with you we need full data structures and algorithm playlist
@swethagopu3708
@swethagopu3708 4 жыл бұрын
Sir I completed all the videos on python you done an excellent job sir tku soo much for work will u plz tell the address of Ur telusko branch coaching center. U plz tell me in which CLG u studied. Tku soo much sir . I have desire Ur channel go to million subscribers😍😍😍😍😍👏👏👏👏
@syedaquratulain1443
@syedaquratulain1443 2 жыл бұрын
best explanation ever
@deepaktiwari38
@deepaktiwari38 5 жыл бұрын
thank you so much ..Can you please upload the data structures like (linked list,stack,queue,tree,graphs) implementation in python as well ..your explanation is always to the point ...You are a great teacher..Respect
@sailapellakuru6488
@sailapellakuru6488 5 жыл бұрын
this video made me clear about the topic
@hendroheng9336
@hendroheng9336 Жыл бұрын
def sort(nums): for i in range(5): minpos = 1 for j in range(i,6): if nums[j] < nums[minpos]: minpos = j temp = nums[i] nums[i] = nums[minpos] nums[minpos] = temp nums = [5,3,8,6,7,2] sort(nums) print(nums) The result comes out as below instead. Number 8 is on the second. Does anyone know why? [2, 8, 3, 5, 6, 7]
@RythemOFFICIAL
@RythemOFFICIAL 4 жыл бұрын
Is selection sort = insertion sort ?
@lloyd8465
@lloyd8465 3 жыл бұрын
list[i], list[pos] = list[pos], list[i] ... This can be also consider as swapping right?
@balajiragu9127
@balajiragu9127 Жыл бұрын
1) May I know why the outer loop runs till 5 and the inner loop runs till 6. 2) In this scenario 2nd, 4th, 5th and 6th iteration is doing nothing. Which sorting will avoid unnecessary actions.
@Rajadahana
@Rajadahana 2 жыл бұрын
At 7:25 - as I have understood, the advantage of Selection sort, over bubble sort, we have to do swapping LESS number of times. Hope I have got it right.
@12josephsaviopereira2
@12josephsaviopereira2 3 жыл бұрын
PLZ make a viedo on insertion sort....u guys are doing a grt job
@satyaswarupojha224
@satyaswarupojha224 4 жыл бұрын
That was well explained...May i know your qualifications Mr.Reddy!
@kartikkalia01
@kartikkalia01 4 жыл бұрын
MTech from IITB and Post Doc from Cornell University.
@prathammishra4480
@prathammishra4480 4 жыл бұрын
@@kartikkalia01 IIT Bangalore ???????????
@kartikkalia01
@kartikkalia01 4 жыл бұрын
@@prathammishra4480 Bombay
@prathammishra4480
@prathammishra4480 4 жыл бұрын
@@kartikkalia01 Ohh Ok
@dharma3404
@dharma3404 2 жыл бұрын
BSc from vikas college mumbai and MSC from Vidyalankar School of IT mumbai
@anitgahlot5749
@anitgahlot5749 3 жыл бұрын
thanks bro, u make me fully understand the code
@rezaulhasan2705
@rezaulhasan2705 2 жыл бұрын
Awesome sir with full explanation
@akshbansal7715
@akshbansal7715 6 жыл бұрын
pls continue this series, i really love your python vids
@sauravgarg001
@sauravgarg001 5 жыл бұрын
use i+1 to reduce one iteration
@rajmohammed8134
@rajmohammed8134 5 жыл бұрын
Thank you, Sir, you have explained in an easy way.
@zakiasmaa6834
@zakiasmaa6834 2 ай бұрын
Thanks a lot Sir Navin
@sampratickroy2055
@sampratickroy2055 6 жыл бұрын
sir full data structure in python
@maedre9330
@maedre9330 3 жыл бұрын
data structures in python is not a good idea. Python is not a good language for data structures as it has several issues
@pavanmaddala1609
@pavanmaddala1609 3 жыл бұрын
@@maedre9330 🙄🙄
@vishutiwari99
@vishutiwari99 6 жыл бұрын
Sir Heap sort also please.🙏🙏🙏
@aswinks
@aswinks 2 жыл бұрын
can u please add DS playlist also because we aliens can easily understand those concepts when you teach.
@krishnapawar2056
@krishnapawar2056 2 жыл бұрын
Thank you so much sir i have watched previous all the python videos🙏 and they are great
@KiranA-jw7dy
@KiranA-jw7dy 2 жыл бұрын
Sir can you please upload videos on other sorting algorithms
@srinivasaraghavansm4355
@srinivasaraghavansm4355 4 жыл бұрын
sir could you make a lecture on insertion sort
@nishantviknis3173
@nishantviknis3173 2 жыл бұрын
Sir, Thank you so much. Very useful
@khabibali4967
@khabibali4967 3 жыл бұрын
Sir, you almost cover all searching algorithm techniques but you forgot to make a video on the quick Sort and Insertion Sort algorithm. please make on it.
@amitkumarpradhan9858
@amitkumarpradhan9858 3 жыл бұрын
Hope he was our teacher at college
@khushi_sandhu
@khushi_sandhu 4 жыл бұрын
isn't this an easier method: and tell me if we can cal it selection sort or not def sort(lst): lst1=[] for i in range(0, len(lst)): mini=min(lst) lst1.append(mini) lst.remove(mini) return lst1 lst=[34,76,23,56,24,3] lst1=sort(lst) print(lst1)
@mistakefftw
@mistakefftw 2 жыл бұрын
Extremely helpful! Thank you!
@jayeshsingh7764
@jayeshsingh7764 6 жыл бұрын
Sir, The Videos are Amazing but, Please try to discuss the Time complexity of each algorithm and compare Time Complexitis of different algorithms....
@MarvaDeen
@MarvaDeen 6 ай бұрын
It was very useful . Tnk u so much sir
@mdtanzinislam1185
@mdtanzinislam1185 6 жыл бұрын
I watched your java vedio and python now what should i doshould i start project or start making app
@mathchithra5488
@mathchithra5488 4 жыл бұрын
Sir one more video for if we get values in while function, then repeat the process with the values we get in while. How to repeat the process.
@punitsehrawat2902
@punitsehrawat2902 4 жыл бұрын
Best explanation sir
@anjankumargoud7856
@anjankumargoud7856 Жыл бұрын
Thanks Alot Sir 💝.
@054_ritesh3
@054_ritesh3 4 жыл бұрын
Excellence at its top
@anusmitasamanta2608
@anusmitasamanta2608 5 жыл бұрын
sir you're the best
@mekalapavankumar8343
@mekalapavankumar8343 Жыл бұрын
What if a list have duplicate values?
@sghosh5904
@sghosh5904 3 жыл бұрын
very nicely explained
@Alberta_Farmer
@Alberta_Farmer Жыл бұрын
Such a great lesson!
@TarunKumar-xu1jb
@TarunKumar-xu1jb 3 жыл бұрын
sir can you please explain the range...How we are taking the range in this case
@harshraj6264
@harshraj6264 5 жыл бұрын
I had seen all the series of your python.
@piyushbagani9244
@piyushbagani9244 4 жыл бұрын
please upload a video on list comprehension and its use cases....
@autotechtraveller8787
@autotechtraveller8787 2 жыл бұрын
In second for loop range (i+1 or i and 6 y we to take)?
@shashanksinghsisodiya514
@shashanksinghsisodiya514 6 жыл бұрын
Hi Sir..your videos made me a good full stack developer..I am understanding the concept very well and rapidly tho ur videos..thank you so much🙂
@dharshanakanniappan9926
@dharshanakanniappan9926 Жыл бұрын
Thank you❤
@nandyalanaveenreddy7598
@nandyalanaveenreddy7598 5 жыл бұрын
You helped me a lot sir
@msprabhu.sudhi526gmail.commsp
@msprabhu.sudhi526gmail.commsp 6 жыл бұрын
Sir, can you please do videos on data structures in python
@vigneshbathini5862
@vigneshbathini5862 2 жыл бұрын
Sir, Make videos of sql
@gayathrinallam4487
@gayathrinallam4487 4 жыл бұрын
sir please do explain us merge , quick, insertion,heap sort techniques too . please sir!
@Harpreetkaur-fd5fu
@Harpreetkaur-fd5fu 4 жыл бұрын
Sir also make video on insertion sort
@jawadmuhammadali8831
@jawadmuhammadali8831 6 жыл бұрын
Please upload a lecture on merge sort
@Tanvi2022-hu3st
@Tanvi2022-hu3st 6 ай бұрын
Sir I have a doubt can't we just use the list function sort to get the output as increasing and decreasing order ??
@tushargoyaliit
@tushargoyaliit 6 жыл бұрын
Please discuss one que of good level like on codechef every week
@harshraj6264
@harshraj6264 5 жыл бұрын
Hey in python I think we do not need a temporaray variable to swap Here how it you can do it >> num[¡], num[minpos] = num[minpos], num[¡] If there is something wrong please tell me I am a student of class 11.
@sarat4chan
@sarat4chan 5 жыл бұрын
yes, you can ... but he is explaining using temporary variable so that we understand the algorithm
@dr.sujathaelumalai37
@dr.sujathaelumalai37 Жыл бұрын
KIndly explain all programs with input variable instead of constants
@christopherverdejo696
@christopherverdejo696 5 жыл бұрын
Thanks for the video man 👊 i understand how it works but I don't know how it works the swapping
@lohithdonthamshetti7944
@lohithdonthamshetti7944 4 жыл бұрын
Sir please teach about the data structures using python
@014_nasreenparween5
@014_nasreenparween5 4 жыл бұрын
Great sir 👍👍
@prateekmaurya4187
@prateekmaurya4187 3 жыл бұрын
please make series on python turtle
@Seftehandle
@Seftehandle 11 ай бұрын
I love this guy
@johndermon5979
@johndermon5979 5 жыл бұрын
Why not in line 6 for j in range(i+1,6): otherwise you always begin each loop by comparing an element to itself
@nandyalanaveenreddy7598
@nandyalanaveenreddy7598 5 жыл бұрын
J can be in range(i+1,5)
@Its-Not-Funny
@Its-Not-Funny 4 жыл бұрын
We can use i+1 also. But the thing is when we use this, we are not comparing the value it self . But if we use 'i' we are comparing the value itself.
@AnilTikoo
@AnilTikoo 6 жыл бұрын
Can we use=> list.sort(reverse=True/False) in order to sort directly in ascending or descending order?
@silverblade41
@silverblade41 6 жыл бұрын
Yes thats a much quicker way of doing it but most cs courses require you to learn this mehtod so that you understand gow the sort function works
@mudassirfarooq375
@mudassirfarooq375 5 жыл бұрын
Very nice bro, I am really impressed...
@heenasharma5076
@heenasharma5076 3 жыл бұрын
I think there wasn't much diff between selection and bubble sort both were of order of n^2
@Sam-ro3ce
@Sam-ro3ce 6 жыл бұрын
Bro send me pyhthon software link I learned from u more tnks bro, I have basic laptop so I want suggestion from u which python version suit fr me
@swapnil771
@swapnil771 3 жыл бұрын
Plz try in hindi also
@arushisinghonelove9394
@arushisinghonelove9394 6 жыл бұрын
thanku...sooo much ...sir ...plz..upload the program of all sorting algo..
@krishnarajanlakshanya7546
@krishnarajanlakshanya7546 5 жыл бұрын
amazing explanaition
@krishanbiharipathak6362
@krishanbiharipathak6362 4 жыл бұрын
Great
@arunaagt8229
@arunaagt8229 5 жыл бұрын
THANK YOU SO MUCH SIR
@akanshazutshi1011
@akanshazutshi1011 Жыл бұрын
Insertion sort tutorial sir ??
#72 MySQL Workbench Setup | Python Database Connection
8:01
Telusko
Рет қаралды 405 М.
I tricked MrBeast into giving me his channel
00:58
Jesser
Рет қаралды 29 МЛН
World’s strongest WOMAN vs regular GIRLS
00:56
A4
Рет қаралды 31 МЛН
Человек паук уже не тот
00:32
Miracle
Рет қаралды 3,9 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
#63 Python Tutorial for Beginners | Exception Handling
15:59
Telusko
Рет қаралды 526 М.
Selection Sort In Python Explained (With Example And Code)
8:27
FelixTechTips
Рет қаралды 65 М.
Lec-45: SELECTION SORT in PYTHON 🐍 | DSA Concepts in PYTHON 🐍
10:23
7.4 Insertion Sort Algorithm |Explanation with C Program| Data Structure Tutorials
28:13
Merge Sort In Python Explained (With Example And Code)
13:35
FelixTechTips
Рет қаралды 222 М.
Merge Sort in Python Programming | Program | Detailed Explanation
32:42
Amulya's Academy
Рет қаралды 98 М.
I tricked MrBeast into giving me his channel
00:58
Jesser
Рет қаралды 29 МЛН