H Lecture Notes - Lecture 2: Bubble Sort, Sorting Algorithm, Comparison Sort

7 views5 pages

Document Summary

Bubble sort, also referred to as comparison sort, is a simple sorting algorithm that repeatedly goes through the list, compares adjacent elements and swaps them if they are in the wrong order. This is the most simplest algorithm and inefficient at the same time. Yet, it is very much necessary to learn about it as it represents the basic foundations of sorting. Consider the following array: arr=14, 33, 27, 35, 10. We need to sort this array using bubble sort algorithm. Check if 14 > 33 which is false. We proceed with the second and third element i. e. , arr[1] and arr[2]. Check if 33 > 27 which is true. We proceed with the third and fourth element i. e. , arr[2] and arr[3]. Check if 33 > 35 which is false. We proceed with the fourth and fifth element i. e. , arr[3] and arr[4]. Check if 35 > 10 which is true.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents