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

Using the worst case scenario for a recursive insertion sort on an array of 5 elements...
Using the worst case scenario for a recursive insertion sort on an array of 5 elements {5, 4, 3, 2, 1} Determine a formula that counts the numbers of nodes in that recursion tree. What is the Big O for execution time. Determine a formula that expresses the height of the recursion tree. What is the Big O for memory?
prove the worst case of quick sort using subsetution, what is T(n) of quick sort and...
prove the worst case of quick sort using subsetution, what is T(n) of quick sort and what is the worst case for it
Sorting (quick) Sort the array using quick sort. Write the array content after each pass (i.e.,...
Sorting (quick) Sort the array using quick sort. Write the array content after each pass (i.e., from pass 1 to pass 7). Each pass is defined as the completion of one partition. We always pick the first array element as the pivot for each partition.
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.
merge sort Determine the best, average, and worst case inputs for merge sort.
merge sort Determine the best, average, and worst case inputs for merge sort.
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.
Q1) Write a program to implement the quick sort algorithm in a one dimensional array? Q2)...
Q1) Write a program to implement the quick sort algorithm in a one dimensional array? Q2) Write a program to implement the merge sort algorithm in a one dimensional array?
Compute the first 4 pivots using quick sort algorithm on an array A=<10,15,17,18,6,120,30,250,95>. Write the content...
Compute the first 4 pivots using quick sort algorithm on an array A=<10,15,17,18,6,120,30,250,95>. Write the content of the array A after each pivot is chosen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT