GOEDUHUB Online Courses || Last Batch Student's Projects || COVID-19 Projects(AI-ML) || Universities  ||  Placement Preparation  
+91-7976731765 Free Online Tutorials ||  MACHINE LEARNING || Python || DBMS || OOPs || DSA || Java || Linux/Unix ||  C Programming
0 like 0 dislike
172 views
in Python Programming by Goeduhub's Expert (8k points)

1 Answer

0 like 0 dislike
by Goeduhub's Expert (8k points)
 
Best answer

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order and make them in ascending order .

Worst and Average Case Time Complexity: O(n*n). Worst case occurs when array is reverse sorted.

Best Case Time Complexity: O(n). Best case occurs when array is already sorted.

Auxiliary Space: O(1)

Bubble-sort-algorithm-explaination

Python program for implementation of Bubble Sort 

arr=[5,1,4,2,8]

n = len(arr)

 for i in range(n):

    for j in range(0, n-i-1):

        if arr[j] > arr[j+1] :

            arr[j], arr[j+1] = arr[j+1], arr[j]

 print(arr)

Related questions

0 like 0 dislike
0 answers 24 views
0 like 0 dislike
1 answer 26 views
0 like 0 dislike
1 answer 49 views
0 like 0 dislike
1 answer 73 views
 Placements:   List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Important Lists: List of NITsList of IITsList of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG)College ReviewsCollege Fest, Events & WorkshopsKnowledge ShareTrainees/Interns After 15-04-2020
Exams & Cutoffs: JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs || Cutoff-GATECutoff_IIT-JEECS-ScopeECE ScopeEE-Scope
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
 Goeduhub
About Us | Contact Us   Social::   |  | 
...