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

  Create algorithm to accept current salary

Create the algorithm which will prompt for and accept current salary for each of faculty members, then compute and show their individual pay increases.

  What is the running time of your algorithm

Give an ef?cient algorithm to determine if there exists an integer i such that Ai = i in an array of integers A1

  Hash values

Suppose these names have the following hash values. Insert them into the extendible hash table shown below. Each leaf can only hold 4 entries.

  Implementing ajax programming

In the AJAX scripts construct, refer to the DSN datasource as flamingo. Even though its not in your own folder or directory, it has been set up as SYSTEM DSN, so your AJAX script will have access to it.

  Describe ambiguity in proposed algorithm

Describe the distinction between an ambiguity in a proposed algorithm and an ambiguity in the representation of an algorithm. Describe how the use of primitives helps remove ambiguities in an algorithm's representation.

  Create algorithm to calculate union of two input sets-array

Create algorithm to calculate union of two input sets given as arrays, both of size O(n). The output must be array of distinct elements that form union of the sets.

  Design analgorithm that decides for each node

Design an O(n) algorithm that decides (schedules) for each node at which time slot to start sending data such that the total number of time (slots) is minimized.

  What are some likely future uses and enhancements

Describe a specific web or mobile application'spurpose. How is it used? What changes has it brought about to its users? What are some likely future uses and enhancements

  How to write a story into an array

Find a popular children's story and store it into an array. Prompt a user to search for a string within the array, returning the position of the search item within the array.

  I this assignment you will implement the compact

in this assignment you will implement the compact representation of the compressed suffix trie adt for dna analyses.a

  Advantage of fast running time of insertion sort

Running time of quicksort can be enhanced in practice by taking advantage of fast running time of insertion sort when its input is "nearly" sorted.

  Describe the term heuristic optimization algorithms

question 1 list the cost functions for the select and join operations.question 2 what are the cost functions of the

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