Book Image

Everyday data structures

By : William Smith
Book Image

Everyday data structures

By: William Smith

Overview of this book

Explore a new world of data structures and their applications easily with this data structures book. Written by software expert William Smith, you?ll learn how to master basic and advanced data structure concepts. ? Fully understand data structures using Java, C and other common languages ? Work through practical examples and learn real-world applications ? Get to grips with data structure problem solving using case studies
Table of Contents (20 chapters)
Everyday Data Structures
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Free Chapter
1
Data Types: Foundational Structures

Bubble sort


Bubble sort is another simple algorithm that steps through the list of values or objects to be sorted and compares adjacent items or their keys to determine if they are in the wrong order. The name comes from the way that unordered items seem to bubble to the top of the list. However, some developers sometimes refer to this as a sinking sort, as objects could just as easily appear to be dropping down through the list.

Overall, the bubble sort is just another inefficient comparison sort. However, it does have one distinct advantage over other comparison sorts, in that: inherently determine whether or not the list has been sorted. Bubble sort accomplishes this by not performing comparisons on objects that were sorted in previous iterations and by stopping once the collection proves ordered.

For example, consider the case of ordering a collection in ascending order. A bubble sort algorithm will examine an object at index i and determine if its key is lower in value or priority than...