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
Question
Book Icon
Chapter 16, Problem 6SA
Program Plan Intro

Bubble sort:

This is a 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.

Insertion sort:

  • This is a sorting algorithm in which the first two elements of the array are taken and these elements are compared. If the swap is required, then it swaps the elements and places the elements in proper order.
  • Now, this becomes a sorted portion of an array. Then it starts with the third element of the array and it is compared with the already sorted portion.
  • This is done to insert the elements relatively in correct position according to first two elements.
  • If the swap is required on comparison, then it is need to shift the elements until the third elements is placed in it correct position.
  • Now, the first three elements will be in sorted manner.
  • This process is continued for the fourth and subsequent elements until all of the elements are inserted into proper positions.

Blurred answer
Students have asked these similar questions
How to implement an Insertion Sort Algorithm?
Which among bubble sort, selection sort, and insertion sort is the most efficient to use and why?
The optimised bubble sort offers none of the following benefits over conventional sorts for items that have already been sorted.

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
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage