Draw the recursion tree for bubblesort

Assignment Help Computer Engineering
Reference no: EM133482114

Question:Shown below is the code for the bubble sort consisting of two recursive methods that replace the two nested loops that would be used in its iterative counterpart:

void bubbleSort(int array[]) { sort(array, 0);

} void sort(int[] array, int i) {

if (i < array.length - 1) { bubble(array, i, array.length - 1); sort(array, i + 1);

}

}

void bubble(int[] array, int i, int j) { if (j <= i)

return;

if (array[j] < array[j - 1]) { int temp = array[j];

array[j] = array[j - 1]; array[j - 1] = temp;

}

bubble(array, i, j - 1);

}

Question 1. Draw the recursion tree for bubbleSort when it is called for an array of length 4 with data that represents the worst case. Show the activations of bubbleSort, sort and bubble in the tree. Explain how the recursion tree would be different in the best case.

Question 2. Refer back to the recursion tree you provided in the previous problem. Determine a formula that counts the numbers of nodes in that tree. What is Big-O for execution time? Determine a formula that expresses the height of the tree. What is the Big-O for memory?

Reference no: EM133482114

Questions Cloud

Describe how the estimated variability in selling prices : Describe how the estimated variability in selling prices varies as the mean selling price varies from 100 thousand to 500 thousand dollars
Define business profiles, processes and modeling : Define business profiles, processes, and modeling. Explain the difference between vertical and horizontal systems packages.
What are some examples of form validation we would want : What are some examples of form validation we would want to do solely on the server? When might we do it only on the client?
Develop a strategy for backing up the company : What do you need to consider while deciding the best specifications for processor, memory, and disk space
Draw the recursion tree for bubblesort : List the capabilities that any data and information processor, whether organic, mechanical, electrical, or optical, must have
Discuss key concepts as they may relate to your chosen case : Discuss key concepts as they may relate to your chosen case. Apply facts from your case to support conclusions on the applicability of concepts.
Calculate the accounts receivable turnover : Calculate the accounts receivable turnover and the average collection period ratio for The Coca-Cola Company for the most current year presented.
Why is governance difficult in cyberspace : Why is governance difficult in cyberspace? Share an example and explain your response
Explain how the functions in your program are designed : Can you explain how the functions in your program are designed to improve modularity, code organization and reusability.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Create three stacks of characters

Create three stacks of characters: stk1, stk2, stk3. Read the input infix expression one character at a time and push every character read onto stk1.

  What are the locations of the cluster centroids

What are the locations of the cluster centroids when the algorithm converges? Compute also their overall SSE. Suppose we add 199 equally spaced data points

  Define some data are calculated as functions

Some data are calculated as functions. When will you store data in database and when would you use functions? What is the advantage of storing data in database.

  Write a program to determine the number of edges

Write a program to determine the number of edges in the transitive closure of a given directed graph, using the adjacency list representation.

  Write a program that asks the user for a path to a directory

Write a program that asks the user for a path to a directory, then updates the names of all the files in the directory .

  What are some of the activities involved in the plan

What are some of the activities involved in it? Do you feel confident that your company (or school) is prepared to survive a major disaster? Why or why not?

  Describe the basic security and privacy requirements of glba

Describe the basic security and privacy requirements of HIPAA. Describe the basic security and privacy requirements of GLBA

  Discuss relationship between waterfall model and raci chart

Discuss the relationship between the Waterfall model, work breakdown structure (WBS), RACI chart, scheduling and cost, when a decision has been made to migrate.

  What does new york require? does the addendum have gaps

What does New York require? Does the addendum have gaps? Where? Draft the provisions you would use to close those gaps.

  Data management-erd diagram definition

The entity relationship diagram is crucial to the  creation of a successfully implemented application and database. A good understanding of how to identify the components that define the Entity Relationship Diagram is needed. Select one of the fol..

  Question1 write down a program with a function that returns

question1. write down a program with a function that returns a random integer between 0 and an integer supplied as an

  Explain what the hazard detection unit is doing

You are to identify the problems, if any, which may be encountered in the pipeline. If you do identify any problems you are to explain them by using the instruction format terms , , for those instructions where there are problems.

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