Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 16.1, Problem 16.1CP

Explanation of Solution

Bubble sort:

This is simple sorting algorithm to sort the elements in ascending order or descending order.

  • This algorithm makes the several passes through the elements of the array and the smallest elements are “bubble up” to the top of the array.
  • On each pass, the larger elements are “bubbled” towards the end of the array.
  • After all the passes are completed, the elements are arranged from smallest to biggest in order.

Example:

Consider the list of elements (4, 8, 2, 6) to perform the bubble sort.

Pass 1:

  • Compare the elements in the first pair (4 and 8); no swap is needed because the pair is already in order.
  • Now compare the elements in the second pair (8 and 2); the value 8 is higher than the value 2. So, swap the values 8 and 2.
  • Compare the elements in the third pair (8 and 6); the value 8 is higher than the value 6. So, swap the values 8 and 6.

Blurred answer
Students have asked these similar questions
Write a modified version of the selection sort algorithm that selects the largest element each time and moves it to the end of the array, rather than selecting the smallest element and moving it to the beginning. Will this algorithm be faster than the standard selection sort? What will its complexity class (big-Oh) be?
Write a program that compares all four advanced sorting algorithms discussed in this chapter. To perform the tests, create a randomly generatedarray of 1,000 elements. What is the ranking of the algorithms? What happens when you increase the array size to 10,000 elements and then 100,000elements?
Develop a sort implementation that counts the number of different key values,then uses a symbol table to apply key-indexed counting to sort the array. (This methodis not for use when the number of different key values is large.)

Chapter 16 Solutions

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education