Lec-45: SELECTION SORT in PYTHON 🐍 | DSA Concepts in PYTHON 🐍

preview_player
Показать описание
00:00 – Selection sort
00:32 – algorithm with example

Selection sort is another simple sorting algorithm that works by repeatedly finding the minimum (or maximum) element from the unsorted part of the array and putting it at the beginning (or end) of the sorted part. At the end of the video explain their algorithm with example.

► Python For Beginners(Complete Playlist):

Other Subject-wise Playlist Links:
--------------------------------------------------------------------------------------------------------------------------------------
►Computer Networks :
►Design and Analysis of algorithms (DAA):
►Database Management System:
► Theory of Computation
►Artificial Intelligence:
►Computer Architecture:
►Operating System:
►Structured Query Language (SQL):
►Discrete Mathematics:
►Compiler Design:
►Number System:
►Cloud Computing & BIG Data:
►Software Engineering:
►Data Structure:
►Graph Theory:
►Programming in C:
►Digital Logic:
► Class XI Computer Science(Full Syllabus)
► Microprocessor Playlist:

---------------------------------------------------------------------------------------------------------------------------------------
Our social media Links:
--------------------------------------------------------------------------------------------------------------------------------------
►For Any Query, Suggestion or notes contribution:
#selectionsort #python #pythonprogramming
Рекомендации по теме
Комментарии
Автор

Hi, Thanks for the explanation . Somehow, i think, a little change in indentation needed. Bcz, its not working for all the elements. so we have to change the index like i have shown below.

def selectionsort(arr):
n = len(arr)
for i in range(n-1):
mini = i
for j in range(i+1, n): #<<---
if arr[j]<arr[mini]: # }
mini = j # }
arr[i], arr[mini]=arr[mini], arr[i] #<<---


arr = [20, 30, 3, 2, 1]
selectionsort(arr)
print(arr)

Niki-uefk
Автор

sir iss video ko agar aap edit ya delete kar denge to bahut achha hoga kyunki isme error hai jisko aur bhi logo ne point out kiya hai aur jo pahli bar dekhenge wo samjhenge ki likha hua code hi sahi hai isliye please take a proper
swapping second loop complete hone ke baad ki jayegi...

unknownstudentkkn
Автор

Sir there is a mistake in pass 2, at 07:59 mini = 2 so after swapping in 09:07 when we will compare 42 we will compare it with 41 because mini = 2 and arr1[mini] = 41

yajushvyas
Автор

where the increment code of j exists in program?

talhajawad
Автор

Hey,
The line which you use for swapping will inside the first loop only as it's inside the second loop it could give wrong answer when there is a bigger array

gtsumit
Автор

You consider n=5 but you run Nested For loop of j just 4 times why?

Shaikh_Imran
Автор

There is a typing mistake in line no 8.
The swapping must be done in the same indentation of the second for loop.
Hope everyone evaluates correctly.

wbinvestor
Автор

it should be arr[j]<arr[i] ..not arr[j]<arr[mini]

AmishaJaiswal-qmek
Автор

Sir baaki sorting program b karwa do ... pgt k exam se phle

niharikakadiyan
Автор

I appreciate you taking the time to explain that. Thank you.

JupudiManikantaSwamy
Автор

This program is not giving proper output for some arrays

md.mansoor
Автор

The 1st comment in Sir's video ❤️

shitikanthparida
Автор

This code is not working for more than 5 elements.Could u help sir 🙏

RajRaj-spxw
Автор

I've attended multiple classes but ur simplicity is osam

RoshanSingh-kjfy