Skip to Content
A Common-Sense Guide to Data Structures and Algorithms
book

A Common-Sense Guide to Data Structures and Algorithms

by Jay Wengrow
August 2017
Intermediate to advanced
222 pages
5h 3m
English
Pragmatic Bookshelf
Content preview from A Common-Sense Guide to Data Structures and Algorithms

Bubble Sort in Action

Let’s walk through a complete example. Assume that we wanted to sort the array [4, 2, 7, 1, 3]. It’s currently out of order, and we want to produce an array containing the same values in the correct, ascending order.

Let’s begin Passthrough #1:

This is our starting array:

images/chapter5/new/speeding_up_your_code-fixed-width-no-text_Part5.png

Step #1: First, we compare the 4 and the 2. They’re out of order:

images/chapter5/new/speeding_up_your_code-fixed-width-no-text_Part6.png

Step #2: So we swap them:

images/chapter5/new/speeding_up_your_code-fixed-width-no-text_Part7.png

Step #3: Next, we compare the 4 and the 7:

They’re in the correct ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition

A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition

Jay Wengrow

Publisher Resources

ISBN: 9781680502794Errata Page