ease calculate the running time and please discuss the best-case and worst case of Shellsort algorithm. Running time may pertain to Big-Oh notation. See attached photo fo

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question
Please calculate the running time and please discuss the best-case and worst case of Shellsort algorithm.
Running time may pertain to Big-Oh notation. See attached photo for the program
 
 
// Shell Sort in C++ programming
#include <iostream>
using namespace std;
// Shell sort
void shellSort(int array[], int n) {
// Rearrange elements at each n/2, n/4, n/8, ... intervals
for (int interval = n / 2; interval > 0; interval /= 2) {
for (int i
interval; i < n; i += 1) {
array[i];
int temp
int j;
for (j = i; j >= interval && array[j
array[j]
}
array[j]
}
}
interval] > temp; j
interval) {
-=
array[j - interval];
temp;
}
// Print an array
void printArray(int array[], int size) {
int i;
for (i = 0; i < size; i++)
cout « array[i] « " ";
cout <« endl;
}
// Driver code
int main() {
int data[] = {29, 18, 33, 27, 35, 46, 34, 21};
int size =
sizeof (data) sizeof(data[0]);
shellSort(data, size);
cout <« "Sorted array: \n";
printArray (data, size);
}
Transcribed Image Text:// Shell Sort in C++ programming #include <iostream> using namespace std; // Shell sort void shellSort(int array[], int n) { // Rearrange elements at each n/2, n/4, n/8, ... intervals for (int interval = n / 2; interval > 0; interval /= 2) { for (int i interval; i < n; i += 1) { array[i]; int temp int j; for (j = i; j >= interval && array[j array[j] } array[j] } } interval] > temp; j interval) { -= array[j - interval]; temp; } // Print an array void printArray(int array[], int size) { int i; for (i = 0; i < size; i++) cout « array[i] « " "; cout <« endl; } // Driver code int main() { int data[] = {29, 18, 33, 27, 35, 46, 34, 21}; int size = sizeof (data) sizeof(data[0]); shellSort(data, size); cout <« "Sorted array: \n"; printArray (data, size); }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Matrix multiplication
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning