Question

Suppose you can use a library that contains two familiar sorting functions: BUBBLESORT(A) and MERGESORT(A) Both...

Suppose you can use a library that contains two familiar sorting functions:
BUBBLESORT(A) and MERGESORT(A)
Both functions take as input an array A of length n and sort it. Their running times are O(n2) and O(n log n) respectively. The library also contains another sorting function, with the following pseudocode:


- function STRANGESORT(A)
- if (length(A)1000) then
- return BUBBLESORT(A)
- else
- return MERGESORT(A)
What is the worst-case running time of STRANGESORT? Please justify your answer.

Homework Answers

Answer #1

First, find the worst case of Bubble Sort and MergeSort

Worst case of bubble sort is: n^2

Worst case of merge sort is: n*log(n)

Worst case of conditional algorithm means, the set of branch of algorithm (only one will select based on some condition), which ever take more time is consider as the worst case of whole algorithm.

If an algorithm consist of two branch (branch by conditions), and only one branch selected for execution, then the largest worst case among both branch worst case, will consider as algorithm worst case.

And the same rule apply for best case or average case.

In the above scenario, bubble sort has highest time complexity in worst case, so the strange sort worst case will be bubble sort worst case.

So, STRANGESORT worst case is: n^2  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
DIRECTIONS: IMPLEMENT QuickSort and MergeSort. You have been provided: 1. Functions to perform Merge (for MergeSort)...
DIRECTIONS: IMPLEMENT QuickSort and MergeSort. You have been provided: 1. Functions to perform Merge (for MergeSort) and Partition (for QuickSort). 2. In class we discussed the body of the recursive functions, the "brakes" needed to stop the recursion. You are expected to develop 2 RECURSIVE programs: 1. Complete the bodies of the sort functions, MergeSort and QuickSort. 2. Complate the main that tests each function. - program should not read inputs - stock the program with multiple arrays (test cases)...
In this problem, you will write an implementation of BubbleSort. Your function should take in a...
In this problem, you will write an implementation of BubbleSort. Your function should take in a single line representing an array of integers, and output a single line containing the list in ascending order. For example, if you receive the following input followed by a newline: 8 7 6 5 4 3 2 1 then you should display the following output followed by a newline: 1 2 3 4 5 6 7 8 Starter code for reading the input and...
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...