Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to explore several strategies for shellsort gap sequences and write a paper explaining your results. You are to explore

The purpose of this assignment is to explore several strategies for shellsort gap sequences and write a paper explaining your results. You are to explore Shells original gap sequence (gap sequence type 1; see below), Hibbards sequence (type 2), and one other that you find by researching the topic (type 3).

You will need to write a program that implements shellsort. You must use the exact algorithm for shellsort (Given below), except that you must alter the gap array handling as described below.

Your main program must run in two different modes. In mode 1, the command line specifies the size of a randomly generated array and the gap sequence to be used. For example, the command line: ./program 1 500000 2 means to run the program in mode 1 with an array of 500,000 randomly generated values using Hibbards sequence.

In mode 2, the command line specifies the name of the file to use containing the data to load into the array (whitespace separated) and the gap sequence to be used. For example, the command line: ./program 2 ascending.dat 3 means to run the program in mode 2, with the array filled with the values in the file ascending.dat, using the sequence you found via research .

In each case, your program must output the final sorted array space separated on one line of the cout stream, newline terminated, and the input size and number of basic operations on one line of the cerr stream, newline terminated.

Shell Sort Algorithm:

void shellsort(vector& array) { size_t n = array.size(); vector gaps {5, 3, 1}; for (auto gap : gaps) { for (size_t i = gap; i < n; i++) { unsigned temp = array.at(i); size_t j = i; while (j >= gap && temp < array.at(j - gap)) { array.at(j) = array.at(j - gap); j -= gap;} array.at(j) = temp; } } }

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

Students also viewed these Databases questions