Question

In: Computer Science

6. The worst case scenario in the quick sort occurs when the array is partitioned to...

6. The worst case scenario in the quick sort occurs when the array is partitioned to two equal sized subarray every time that a recursive call takes place.

True

False

7.Suppose that we want to sort an array of n elements, where each element is a string of at most 1000 characters. What is the time requirement for applying radix sort to sort this array?

O(n2)

O(1000n)

O(l000logn)

O(nlogn)

8.Suppose we want to sort the following array of integers using radix sort:

a=[14 682 120 50 327]

What are the intermediate steps?

pass1: 14 682 120 50 327

pass2: 14 50 120 682 327

pass3: 14 50 120 327 682

pass1: 14 682 120 50 327

pass2: 14 120 682 50 327

pass3: 14 50 120 682 327

pass4:14 50 120 327 680

pass1: 14 50 120 327 682

pass1: 120 50 682 14 327

pass2: 14 120 327 50 682

pass3: 14 50 120 327 682

9.What are the intermediate steps for patitioning the folloiwng array when taking the pivot as the median of the first,middle, and last items (suppse that the threshold for calling insertion sort is an array of size 2)

a= [12 5 8 6 9 11 10 ]

[6 5 8 10 9 11 12]

[6 5 8 11 9 10 12]

[6 5 8 9 11 10 12]

[6 5 8 9 10 11 12]

[12 5 8 11 9 6 10 ]

[5 12 8 11 9 6 10]

[5 6 12 8 11 9 10]

[12 11 8 6 9 5 10 ]

[5 11 8 6 9 12 10]

[12 5 8 6 11 9 10 ]

[6 5 8 12 11 9 10]

[6 5 8 9 11 12 10]

10.Although radix sort has the best time efficiency among other sorting algorithm it is not always applicable because it imposes some restrictions on the type of the data that can be sorted.

True

False

Solutions

Expert Solution

  1. FALSE
    • Quicksort has the worst-case scenario when all the items in the list are already sorted.
    • In this case, we have the array partitioned to two subarrays of length 1 and N-1.
    • Hence, we will apply Quicksort on N-1 items again.
    • This will give us the worst-case complexity of O(N2)
  2. OPTION B
    • In radix sort, we will take the last digit and map it to some temporary bucket.
    • Then based on the last digit, we will sort.
    • This will be repeated for N times
    • Since we are having 1000 elements as the size of the strings, we will get the complexity of O(1000 n)
  3. OPTION A:
    • We will take the last digit.
    • We will apply the radix sort and get the intermediate values as:
      • pass1: 14 682 120 50 327

    • In pass2, we take the second digit from last:

      • pass2: 14 50 120 682 327

    • In pass3, we will check the rightmost digit,

      pass3: 14 50 120 327 682

    • Hence, the correct answer is OPTION A

  4. OPTION B

    If we take the pivot as the median, we will get the value of 11

    • Then we will get 9

    • Then we will get 8

    • Then we will get 6

    • So, we choose these values as fixed and use this information and get the intermediate values as:

      [12 5 8 11 9 6 10 ]

      [5 12 8 11 9 6 10]

      [5 6 12 8 11 9 10]

  5. TRUE

    • Radix sort has the best time complexity of O(N)

      But, we have the restriction of the length of the data we can sort.

      If the data is very lengthy, then it will increase the time taken for sorting


Related Solutions

Write a MIPS program that uses an implementation of quick sort to sort an array of...
Write a MIPS program that uses an implementation of quick sort to sort an array of numbers (Translate the following code into (Mars Assembly language). Quicksort Implementation - C int partition(int arr [] , int left , int right) { int i=left, j=right; int tmp; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr [ i ] < pivot) i ++; while (arr [ j ] > pivot) j −−; if (i <= j)...
Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
use quick sort to sort the following array. show each pass and what the pivot is...
use quick sort to sort the following array. show each pass and what the pivot is during the pass. please explain why you are swapping positions. do not use a compiler. 30 5 40 11 20 9 15 2 60 25 80 3 73 35 4 75 20 6
Give a worst-case input sequence of 6 numbers for Insertion Sort, containing the numbers 68, 12,...
Give a worst-case input sequence of 6 numbers for Insertion Sort, containing the numbers 68, 12, 43, 13, 58, and 21. No explanation/proof required.
Suppose you are given the following array X = [7, 9, 1, 6] Sort the array...
Suppose you are given the following array X = [7, 9, 1, 6] Sort the array in ascending order using the selction sort algorithm. Write the state of the array after each pass. Pass1: Pass2: Pass3: Suppose you are given the following array X = [7, 9, 1, 6] Sort the array in ascending order using the selction sort algorithm. Write the state of the array after each pass. Pass1: Pass2: Pass3:
QUESTION 8 In a base-case scenario, the output is determined by assuming a. worst values that...
QUESTION 8 In a base-case scenario, the output is determined by assuming a. worst values that can be expected for the random variables of a model. b. the most likely values for the random variables of a model. c. the mean trial values for the random variables of a model. d. best values that can be expected for the random variables of a model. e. None of the above 1.5 points    QUESTION 9 The points where constraints intersect on...
The bubble sort described in AS 7e is inefficient when perform on a larger array. To...
The bubble sort described in AS 7e is inefficient when perform on a larger array. To improve the efficiency, we have to observe the basic mechanism of Bubble Sort. Each inner loop of the Bubble sort always move the largest item on the unsorted left side to the sorted right side. When a list is sorted, we say the list is in ascending order by convention. We can enhance the efficiency of traditional Bubble sort by making only one swapping...
In the worst-case scenario, you've got an elevator with a mass 2420 kg moving a speed...
In the worst-case scenario, you've got an elevator with a mass 2420 kg moving a speed 4.29 m/s when it reaches the bottom of the shaft. Your first idea is to put a spring, with spring constant 1.068×104 N/m, at the bottom of the shaft. a)Assuming the spring obeys Hooke's Law perfectly, how far will it compress to stop the elevator? b)When the elevator comes to a stop with the spring compressed, what is the net force on the elevator?...
We saw that Quicksort actually won’t be “quick” when it attempts to sort some types of...
We saw that Quicksort actually won’t be “quick” when it attempts to sort some types of inputs (e.g., it will take O(n2) time to sort n numbers that are already sorted). List two different ways to improve Quicksort so that it will run “quickly” (on average, in linear time) regardless of the characteristics of the input pattern.
How much could NPV be affected by a worst-case scenario of 25 percent reduction from the...
How much could NPV be affected by a worst-case scenario of 25 percent reduction from the $3 million in expected annual cash flows on a five-year project with 10 percent cost of capital compounded quarterly? A)$4,317,832 B)$3,249,557 C)$2,843,090 D)$2,815,611
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT