What would be the slowest time the algorithm can run

Assignment Help Data Structure & Algorithms
Reference no: EM13762533

Analysis of Algorithms

Consider the following code for doing insertion sort

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

int count = 0;

void insertionSort (int a[], int n) { int i, j, copy;

count++; // for the initialization of i in the for loop

for (i = 0; count++, i < n-1; count++, i++)

{

j = i+1; count++; copy = a[j]; count++;

while (j > 0 && copy < a[j-1] )

{

count++;

// for the test to get into the body of the loop

a[j] = a[j-1];

count++; j--;

count++;

}

a[j] = copy;

count++;

}

}

void print(int a[], int n);

{

int i;

cout << "sorted in " << count << "steps: ";

for (i = 0; i < n; i++)

cout << a[i] << ' ';

cout << endl;

}

int main ();
{ int a[] = {34, 3343, 334, 644, 33, 31, 112, 119};

int n = sizeof(a) / sizeof(int);

insertionSort (a,n);

print (a,n);

return 0;

}

For the insertionSort subroutine only, do a full summation analysis similar to the one that is done for selection sort, given in the notes to determine the number of steps the sorting algorithm takes. You should end up with a formula in terms of n.

Now answer the following questions:

Plug the size of the the array into your formula and compute the number of steps the algorithm would be predicted to take. Compare this with the actual count printed by the algorithm.

Are they the same?

If not, why not?

What would be the slowest time the algorithm can run (in terms of n)? What input would cause this slowest time.

What would be the fastest time your algorithm could run (in terms of n)? For what input would this fastest time be achieved?

Reference no: EM13762533

Questions Cloud

Write paper on use of semiotics in criminology and forensics : Write a four pages paper on The use of semiotics in criminology and forensics.
Vertical and conglomerate mergers differ from joint venture : Discuss how horizontal, vertical and conglomerate mergers differ from a joint venture.
Construct a scenario to address those concerns : Transfer pricing is a significant area of concern for the IRS. Assess the concerns the IRS may have and construct a scenario to address those concerns.
Problems based on crime : Prepare a list of evidence that will be collected from the scene and from the body.
What would be the slowest time the algorithm can run : What would be the slowest time the algorithm can run (in terms of n). What input would cause this slowest time. What would be the fastest time your algorithm could run (in terms of n). For what input would this fastest time be achieved.
Identify the type of merger activity in industry : Identify the type of merger activity in industry or one with which you are familiar-horizontal, vertical, or conglomerate-and explain why you made that choice.
How macbeth corresponds to a characters development : Respond to one of the following and provide specific textual examples: Describe a key conflict in the play and how Macbeth corresponds to a character's development.
Promote a more ethical corporate culture : Write a 1-2 page memo in which you advise the board of directors how to correct past problems and set up internal policies that will help promote a more ethical corporate culture.
Analyze the use of gestures in ipads : Analyze the use of gestures in iPads. Address how users feel about gestures. Evaluate how users feel about the user input when it comes to filling out complicated forms on the iPad. Assess the usability of back buttons and thumbnails on the iPad

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd