RUVIDEO
Поделитесь видео 🙏

Bubble Sort in Python || Lesson 26.7 || Python || Learning Monkey ||

📁 Обучение 👁️ 17 📅 02.12.2023

#pytho #learningmonke #pythoncodin #placement #pythontutorial #pythoncours #pythonforbeginner #pythonfordatascienc #pythonfullcours #pythonprogrammin #pythonfreecourse
Bubble Sort in Python
In this class, we write a program for bubble sort in python.
Bubble Sort
Q1) Write a program to take a list of integers and sort them in ascending order using bubble sort.
Example:
Input: [8,2,5,1,7,4,9,6]
Output: [1,2,4,5,6,7,8,9]
Logic
The reader should have an idea about bubble sort. Here we concentrate on implementation in python.
If you do not have any knowledge of bubble sort. Please go to our data structure course.
To implement bubble sort, one should be good in the nested loops concept. Click here.
Example:
input=[8,2,5,1,7,4,9,6]
Total eight elements present from index position zero to index position seven.
First iteration:
Start from index position zero.
Compare the element present in index position zero with the element in index position one.
If an element in index position zero is greater. Swap the elements in positions zero and one.
Next, compare the element present in index position one with the element in index position two.
Suppose an element in index position one is greater. Swap the elements in positions one and two.
Repeat this to the last element is compared with the last before element.
After first iteration the elements in the list look like [2,5,1,7,4,8,6,9].
We observe from the first iteration. The largest element is moved to the last location.
Second iteration
In the second iteration, leave the last element position and repeat the above process done in the first iteration.
In the second iteration, we move the second largest element to the last before position.
Each iteration is moving the largest element to the right side.
To implement this, we need a nested loop.
To do one iteration, we need a loop.
Repeat the same logic for n-1 times. Here n is the number of elements.
In each iteration, reduce the size of the list to be considered. Because elements are moving right need not be considered again.
The program is given below. Understand the logic for better coding practice.
elements=[]
n=int(input("enter no of elements"))
for i in range(n):
ele=int(input("enter element"))
elements.append(ele)
for i in range(n-2,-1,-1):
for j in range(i+1):
if(elements[j]elements[j+1]):
temp=elements[j]
elements[j]=elements[j+1]
elements[j+1]=temp
print(elements)

Link for playlists:
https://www.youtube.com/channel/UCl8x4Pn9Mnh_C1fue-Yndig/playlists



Link for our website: https://learningmonkey.in

Follow us on Facebook @ https://www.facebook.com/learningmonkey

Follow us on Instagram @ https://www.instagram.com/learningmonkey1/

Follow us on Twitter @ https://twitter.com/_learningmonkey

Mail us @ [email protected]

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Bubble Sort in Python || Lesson 26.7 || Python || Learning Monkey ||», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.