PHP 7 Data Structures and Algorithms by Mizanur Rahman
Author:Mizanur Rahman
Language: eng
Format: epub, azw3
Publisher: Packt Publishing
Published: 2017-05-26T06:37:43+00:00
We will keep our discussion limited to the preceding list, as they are the most commonly used sorting algorithms and can be grouped and classified under different criteria such as simple sorting, efficient sorting, distribution sorting, and so on. We will now explore each of the sorting functionalities, their implementations, and complexity analysis, along with their pros and cons. Let's get started with the most commonly used sorting algorithm - bubble sort.
Understanding bubble sort
Bubble sort is the most commonly used sorting algorithm in the programming world. Most of the programmers start learning about sorting with this algorithm. It is a comparison-based sorting algorithm, which is always referred to as one of the most inefficient sorting algorithms. It requires maximum number of comparisons, and the average, and worst case complexity are the same.
In bubble sort, each item of the list is compared with the rest of the items and swapped if required. This continues for each item in the list. We can sort either in ascending or descending order. Here is the pseudo algorithm for bubble sort:
procedure bubbleSort( A : list of sortable items )
n = length(A)
for i = 0 to n inclusive do
for j = 0 to n-1 inclusive do
if A[j] > A[j+1] then
swap( A[j], A[j+1] )
end if
end for
end for
end procedure
As we can see from the preceding pseudocode, we are running one loop to ensure that we iterate each item of the list. The inner loop ensures that, once we point to an item, we are comparing the item with other items in the list. Based on our preference, we can swap the two items. The following image shows a single iteration to sort one item of the list. Let's assume our list has the following items: 20, 45, 93, 67, 10, 97, 52, 88, 33, 92. For the first pass (iteration) to sort out the first item, the following steps will be taken:
Download
PHP 7 Data Structures and Algorithms by Mizanur Rahman.azw3
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(10988)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(8763)
Hello! Python by Anthony Briggs(8647)
The Mikado Method by Ola Ellnestam Daniel Brolund(8567)
Dependency Injection in .NET by Mark Seemann(8205)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7190)
Grails in Action by Glen Smith Peter Ledbrook(6711)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(6385)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5212)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(4752)
Kotlin in Action by Dmitry Jemerov(3998)
Practical Vim (for Kathryn Amaral) by Drew Neil(3491)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3243)
Learn Windows PowerShell in a Month of Lunches by Don Jones(2794)
Learning Java by Patrick Niemeyer & Daniel Leuck(2616)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2524)
Mastering Java 9 by Dr. Edward Lavieri(2325)
Learning Concurrency in Python by Elliot Forbes(2251)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2068)
