Question

Directions: Problem 1: Write (using pen-and-paper rather than code) the list after each pass of quick...

Directions:

Problem 1: Write (using pen-and-paper rather than code) the list after each pass of quick and merge sort for the following list of numbers. Assume that you are sorting the numbers into ascending order. For quick sort, assume that the first number from the sublist is chosen as the pivot.

54 17 21 18 4 7 19 41

Problem 2: Write the list after each pass of the quick sort algorithm for the following list of numbers, using the following pivot selection strategies: first value of the sublist, middle (not median) value of the sublist, and the median of the first, middle, and last values. Assume you are sorting the numbers into ascending order.

For example, in the first pass of the algorithm on these numbers, the first pivot selection strategy chooses 54, the middle strategy chooses 18 (because 18 and 4 are in the middle of the list; when the list is of even length, we can just choose to go with the first of the two middle values), and the median of the first, last and middle values chooses 41 as the pivot value, because 41 is the median of 54, 18 and 41.

54 17 21 18 4 7 19 41

Repeat the above for this list of numbers. Remember that you are sorting into ascending order.

92 47 29 22 21 20 16 14

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Quicksort is best and faster algo.

  • It is inplace
  • not stable
  • practically used sorting technique.

に另oble«Ο β.ufck Sort っ. ldr alu compare-SV叶o 17,01 , 18 ,4,7,19,4 Smalle them sy 41 (仔31 18 4 구 19) (Sy Nous 919 19 ( co co c

is on ascending order-by quick so enge.. Sort ,3,1チ 18 , l9 , 21, 41 , sy 4, ㅋ, 19, 41 18, 91 구 S.4) (汗) (δί ) (18) (4 ) (T

9s 14 1604012089 uㅋ qs_ Nos, P.ss 2 C3 321316 and on2 14 16 0 47 09 4-793

best case average case worst case
Quick sort nlogn

n^2

nlogn
merge sort nlogn nlogn nlogn
Add a comment
Know the answer?
Add Answer to:
Directions: Problem 1: Write (using pen-and-paper rather than code) the list after each pass of quick...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Each of the following 6 questions refer to the following list of values in the...

    JAVA Each of the following 6 questions refer to the following list of values in the order as shown. 555 288 633 666 444 422 399 477 21. Print the values in the order they would have after the first round of bubble sort’s bubbling operation low to high. 22. Print the values in the order they would have after the first round of selection sort for sorting low to high, assuming it selects the max. 23. Print the values...

  • Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8...

    Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...

  • _______________________________________________________________________________________________ java language-trace instructions". (20 points) Show the contents of the array below, once the contents...

    _______________________________________________________________________________________________ java language-trace instructions". (20 points) Show the contents of the array below, once the contents of the array below, once the "pivot" element is placed at its location after each call of the "Partition” algorithm, in the process of running Quick-Sort on said array. Arrange the data in ascending order (Trom Arrange the data in ascending order (from smallest to largest value). Always select the first element of the partition as "pivot" in data cat B. Apply sorting on...

  • Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch...

    Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...

  • Programming language: Java Home Work No.2 due 09.11.2019 either ascending or descending SORTING: An array is...

    Programming language: Java Home Work No.2 due 09.11.2019 either ascending or descending SORTING: An array is said to be ordered if its values order. In an ascending ordered array, the value of each element is less than or equal to the value of the next element. That is, [each element] <= [next element]. A sort is an algorithm for ordering an array. Of the many different techniques for sorting an array we discuss the bubble sort It requires the swapping...

  • please answer all parts and code thanks . - PART 1-Introduction to Sorting, 21 points Use...

    please answer all parts and code thanks . - PART 1-Introduction to Sorting, 21 points Use this array of integer for the problems 1A, 1B, and 1c: 9 57 8324761 Each of these problems is worth 3 points A. Show the contents of the array each time a selection sort changes it while sorting the array into B. Show the contents of the array each time an insertion sort changes it while sorting C. Show the contents of the array...

  • 1. a. Using C++, represent the following graph using adjacency matrix, and implement depth first searching...

    1. a. Using C++, represent the following graph using adjacency matrix, and implement depth first searching (DFS) by stack (define it with class) to traverse the graph. 6 7 2 4 b. If starting with node 2, when node 7 is printed, what numbers are in the stack (for DFS)? Please draw the stack step by step to show how the numbers are pushed into and popped out of it. 2. a. Given a set of integer numbers as int...

  • C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential...

    C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential search of a list assumes that the list elements are sorted in ascending order. b. A binary search of a list assumes that the list is sorted. 2. Consider the following list: 63 45 32 98 46 57 28 100 Using a sequential search, how many comparisons are required to determine whether the following items are in the list or not? (Recall that comparisons...

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT