What is the new time complexity in the array

Assignment Help Data Structure & Algorithms
Reference no: EM13332686

Part 1 - Ulam

Given the following function:
public static int Ulam(int num)
{
if (num < 2)
return 1;
else
{
if (num % 2 == 0)
return Ulam(num/2);
else
return Ulam(3*num + 1);
}
}

1) What problems come up in verifying this function?
2) How many recursive calls are made by the following initial calls?
a. Ulam(22);
b. Ulam(16);
c. UIam(46);

Part 2 - Bubblesort

Consider your textbook's implementation of bubblesort from chapter 8. The method is included below for your convenience.

3) What is the time complexity of running the below bubblesort on an array of random integers?
4) What is the time complexity of running the below bubblesort on an array of sequential integers (1,2,3,4,5,..)?
5) Show a simple modification that can be made to the below bubblesort that significantly improves the time complexity for an array of sequential integers.
6) What is the new time complexity in the array of sequential integer's condition? Explain why this modification improved the run-time.

Part 3 - Quicksort

Consider your textbook's implementation of quicksort from chapter 8. The corrected findPartition method is included below for your convenience.

7) What is the time complexity of running quicksort using this partition method on an array of random integers?
8) What is the time complexity of running quicksort using this partition method on an array of sequential integers (1,2,3,4,5,..)?
9) Robert Sedgewick suggests using the median of the first, last and middle elements as the partition element. Explain why this modification is important.
10) Show what modifications are needed to convert the findPartition method to use the median element as the partition.

Reference no: EM13332686

Questions Cloud

Compute the companys net sales for the year : Compute the company’s net sales for the year. Compute the company’s total cost of merchandise purchased for the year. Prepare a multiple-step income statement that includes separate categories for selling expenses and for general and administrative e..
Advantage of the presidential election campaign : Take advantage of the presidential election campaign check-off. John is an accountant. Other relevant information includes
Explain the reaction of 2,4-hexadiene : Give the major product(s) (there are three of them) of the reaction of 2,4-hexadiene with Cl2(low concentration). 1-chloro-2,4-hexadiene is one of the products
Circumstances under which global investments : The appropiate discount rate of the projects is 10 percent. Global Investments chose to undertake project A. At a luncheon for shareholders, the manager of a pension fund that owns a substantial amount of the firm's stock asks you why the firm chose ..
What is the new time complexity in the array : What is the time complexity of running the below bubblesort on an array of random integers?
Determine the stress in the post : A vertical solid steel post of diameter d = 23.1cm and length L = 2.36m is required to support a load of mass m = 8260kg. What is the stress in the post
Compute the molar concentration of mg2+ in the tap water : A 200.0-mL sample of the same tap water required 47.86 mL of the standard EDTA for titration at pH 10 using calmagite indicator. Calculate the molar concentration of Mg2+ in the tap water
Explain the ionization constant for hcio after addition : Calculate the pH for each of the following cases in the titration of 50.0 mL of 0.100 M HCLO with 0.100 M KOH. The ionization constant for HCIO is 4.0 x 10^-8 a) after addition of 50.0 ml of KOH
What is the players speed : A 70.5kg football player is gliding across very smooth ice at 1.75 m/s. What is the player's speed afterward if the ball is thrown at 12.5m/s relative to the player

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Write a context-free grammar for arithmetic expressions

Transform the context-free grammar obtained in Activity 5 to a pushdown automaton using the algorithm in Section 12.2.2. Turn in your solution by the date when Section 12.3 is finished.

  Creating financial tracking program

Acme Inc. is making next generation financial tracking program, and Alice has been provided the task of writing encryption component.

  Threat model to describe risk of attack vector

Construct a simple threat model that describes the risk this represents: attacker(s), attack vector, vulnerability, assets, and likelihood of occurrence, likely impact, and plausible mitigations.

  Universalist rationality theory

Universalist rationality theory supposes that actors within an institution are rational. They function with their own material interests in mind, maximizing efficiency and resources.

  Algorithm for partitioning a set of n weights into k

give a greedy algorithm for partitioning a set of n weights into k bins. b) does it find the perfect solution?

  Users and it organizations arm against phishing attacks

How users and IT organizations must arm themselves against these attacks?

  An independent set in a graph g

An independent set in a graph G is a set of vertices I in G such that no two vertices in I are adjacent (neighbors). The maximum independent set problem is, given a graph G, to compute an independent set of maximum size (maximum number of vertices) i..

  Creating an exception class and applet file

Create an applet document that prompts the user for an ID number and an age. Construct an Exception class and throw an Exception of that class if the ID is not in the range of valid ID numbers.

  You assign each int with a particular id

You assign each int with a particular ID.Array (4, 5, 6, 5, 4, 6) ID (1, 2, 3, 4, 5, 6)

  Program to create huffman codes

Write a C++ program to create Huffman codes. Program input is a file called freq.txt (make up your own file for testing) that contains data on the characters in some cleartext file in the form of each character's non-zero frequency of occurrence i..

  Implement a queue as a circular array

Implement a queue as a circular array as follows: Use two index variables head and tail that contain the index of the next element to be removed and the next element to be added.

  Explain dynamic array as big oh in terms of n

If we presently have n items in the dynamic array, how many doubling operations will we have executed so far? Explain this as Big Oh in terms of n.

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