Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Shell sort is a variation of the bubble sort. Instead of comparing adjacent values, the Shell sort adapts a concept from the binary search

The Shell sort is a variation of the bubble sort. Instead of comparing adjacent values, the Shell sort adapts a concept from the binary search to determine a gap across which values are compared before any swap takes place. In the first pass, the gap is half the size of the array. For each subsequent pass, the gap size is cut in half. For the final pass(es), the gap size is 1, so it would be the same as a bubble sort. The passes continue until no swaps occur.

Below is the same set of values as per the bubble sort example in Chapter 18 (p. 681), showing the first pass of the Shell sort:image text in transcribed

The pseudo-code for the Shell sort is as follows:

image text in transcribed

  1. Create a class called ShellArray. It should create and populate an array of random integers based on a size supplied to the constructor. Implement the Shell sort as a method of this class. Create a driver class to instantiate and sort several different arrays of different sizes.

    Hint: Implement a toString method for the ShellArray class, so it is easy to output the results of each swap to demonstrate that your algorithm is working correctly.

Do the whole question in java language.

9 6 8 12 3 1 7 -- size of array is 7, so gap would be 3 9 6 8 12 3 1 7 -- 9 and 12 are already in order, so no swap A - - - LA 9 6 8 12 3 1 7 -- 6 and 3 are not in order, so swap - - - - LA ! 1 9 12 6 1 7 CO num( 3 + gap] swap num [s] with num (3 + gap] swapflag = true end-if end-for end-do gap = gap / 2 end-do

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago