Question

I found a scrap of paper with this Java implementation of a sorting algorithm on it:...

I found a scrap of paper with this Java implementation of a sorting algorithm on it:

    // This will get me the Turing Award for sure!!
    public static void sort (int[] A) {
        sort(A, 0, A.length);
    } 

    // Sorts the subarray A[lo .. hi-1] into ascending order
    private static void sort (int[] A, int lo, int hi) {
        int size = hi - lo;
                  if (size == 2) {
            if (A[lo] > A[lo+1]) {
                int temp = A[lo];
                A[lo] = A[lo+1];
                A[lo+1] = temp;
            }
        }
        else if (size > 2) {
            int chunk = size / 3;
            sort(A, lo, hi-chunk);
            sort(A, lo+chunk, hi);
            sort(A, lo, hi-chunk);
        }        
    }

The recurrence relation for this algorithm is T(n) = a T(n/b) + O(nd)

we know that a = 3

what is b?

what is d?

Use the Master Theorem to put the tightest possible upper bound on the running time of the algorithm.

Homework Answers

Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Firstly this algorithm won't sort correctly since it has no merging of divided arrays.

So, for the sake of solving

It is

T(n)=3T(2*n/3)+O(n^0)

So, b=3/2 and d=0

Please note d is 0 since there is no merging of arrays

logb(a)=2.7095

Since f(n)=O(n^0)

SO, since c=0 c<2.7095

So, it is

T(n)=theta(n^(logba))=theta(n^(log1.5(3)))=theta(n^2.7095)

Kindly revert for any queries

Thanks.

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
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    //...
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    // STEP 1 -- Make sorting methods generic    ///////////////////////////////////////////////       /**    * Re-orders the contents given array using the insertion sort algorithm.    *    * @param data The array to be sorted.    */    //TODO: Make me generic to work on any kind of Comparable data!    public static void insertionSort(int[] data)    {        int insert; // temporary...
An online/anytime sorting algorithm is one that reads its input numbers one at a time, and...
An online/anytime sorting algorithm is one that reads its input numbers one at a time, and maintains a sorted array of all the inputs it has seen so far, so that if it is interrupted at any time, it will still output the correct answer for the inputs that it has processed. Not all sorting algorithms are amenable to modification to make them anytime. But one sorting algorithm, Bubble Sort, is easy to so modify. First, understand the ascending order...
Implement the selection sort algorithm on a Queue of long-type items. Specifically, you are given the...
Implement the selection sort algorithm on a Queue of long-type items. Specifically, you are given the Queue class implementation and you need to write a method that takes a Queue and sorts it using the selection sort idea. The implementation of the Queue class for long data type is given in the lecture slides (the code skeleton including the implementation of the Queue class is provided below for your convenience). You should go over the Queue and use enqueue(), dequeue(),...
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the...
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int *readData( )   The function returns a pointer that points to the locations with integers reading from the file data.txt. arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array...
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
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...
Hi, can you make me rotate method for this class just I need rotate method? this...
Hi, can you make me rotate method for this class just I need rotate method? this is Circularly Linked Lists code. public class Node {    int data;    Node next;    public Node(int data) {        this.data = data;    } } // this is implement class public class CircularLinkList {       public int size = 0;    public Node head = null;    public Node tail = null;       // add to the front of...
* _Example commands for running this file_ * Compilation: javac Assignment1.java * Execution: java Assignment1 <...
* _Example commands for running this file_ * Compilation: javac Assignment1.java * Execution: java Assignment1 < input.txt * * Reads in a text file and for each line verifies whether the word has * unique characters. * * % cat input.txt * Hello * World * * % java Assignment1 < input.txt * False * True * ******************************************************************************/ import java.util.*; public class SortInput { /* a function for checking uniqueness of characters in a word */ private static boolean isUniqueChar(String...
C++. This program is giving me a wrong quicksort sorting plz fix. use the function that...
C++. This program is giving me a wrong quicksort sorting plz fix. use the function that it already have. don't add new function comment everything that you do thanks #include<iostream> #include<cstdlib> using namespace std; // Intercambiar dos valores. // Arranges the first, middle, and last entries in an array into ascending order. void sortFirstMiddleLast(int a[], int first, int mid, int last) {       if (a[first] > a[mid])    {        int temp;        temp = a[first];   ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT