Question

Use the following sequence as the list to sort: [ T, H, A, N, K, F,...

Use the following sequence as the list to sort: [ T, H, A, N, K, F, U, L ] You need to display the contents of the list during the execution of the algorithm. a) Sort the list using selection sort. b) Sort the list using heap sort. You do not need to draw the heap diagram unless you find it helpful, but you must still show the contents on the list during execution. c) What is the worst-case runtime complexity of selection sort? d) What is the worst-case runtime complexity of heap sort?

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

A. SELECTION SORT

  1. [ T, H, A, N, K, F, U, L ]
  2. [ A, T, H, N, K, F, U, L ]
  3. [ A, F, T, H, N, K, U, L ]
  4. [ A, F, H, T, N, K, U, L ]
  5. [ A, F, H, K, T, N, U, L ]
  6. [ A, F, H, K, L, T, N, U ]
  7. [ A, F, H, K, L, N, T, U ]

The time complexity of Selection Sort is O(n2).

A. HEAP SORT

T H A N K F U L 
T H U N K F A L 
T N U L K F A H 
U N T L K F A H 
U N T L K F A H 
H N T L K F A U 
T N H L K F A U 
A N H L K F T U 
N L H A K F T U 
F L H A K N T U 
L K H A F N T U 
F K H A L N T U 
K F H A L N T U 
A F H K L N T U 
H F A K L N T U 
A F H K L N T U 
F A H K L N T U 
A F H K L N T U 
A F H K L N T U 
A F H K L N T U 
A F H K L N T U 
Sorted array is 
A F H K L N T U 

The time complexity of Heap Sort is O(nlogn).

Add a comment
Know the answer?
Add Answer to:
Use the following sequence as the list to sort: [ T, H, A, N, K, F,...
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
  • (Selection Sort). Selection sort finds the largest number in the list and places it last. It...

    (Selection Sort). Selection sort finds the largest number in the list and places it last. It then finds the largest number remaining and places it next to last, and so on until the list contains only a single number. Describe the selection sort algorithm in pseudocode What is the worst-case time complexity (w.c.t.c) of the selection sort in terms of the number of comparisons made? What is the exact order complexity of the selection sort algorithm? Explain.

  • problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to...

    problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1, n). You also need to provide the worst case time complexity analysis of your algorithm. 2. (20 points) Given a set of n distinct numbers, we wish to find the k largest in sorted order using a comparison-based algorithm. Give an algorithm that implements each of the following methods, and...

  • List the worst case and average case Big O for each algorithm below and describe how...

    List the worst case and average case Big O for each algorithm below and describe how the algorithm works. You can diagram or write a short paragraph. Bubble Sort Modified Bubble Sort Insertion Sort Merge Sort Selection Sort Shell Heap Quick

  • a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n...

    a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...

  • 7. (14 points) Use LSD-first Radix Sort algorithm to sort the following array of numbers. Write...

    7. (14 points) Use LSD-first Radix Sort algorithm to sort the following array of numbers. Write the worst case, the best case time complexity and discuss if these sorting algorithms are stable and in-place? In what cases using these algorithms would not be efficient? (You must run Counting Sort for each digit explicitly.) A=[22,15,16,13,23,45,0,23,123]

  • For [Select], there are three choices: worse than, the same as, better than Answer the following...

    For [Select], there are three choices: worse than, the same as, better than Answer the following questions about the computational properties of divide-and-conquer sorting algorithms, based on tight big-Oh characterizations of the asymptotic growth rate of the functions for the running time or space size, depending on the question. Assume that the input sequence is given as a list, and the output sequence is also a list. Also assume a general implementation of the sorting algorithms, as opposed to an...

  • You have to sort a sequence of N elements. The N elements have N/K subsequences of...

    You have to sort a sequence of N elements. The N elements have N/K subsequences of size K each. The subsequences have the following property: All elements of a subsequence are less than those of the preceding one and greater than those of the following subsequence. Example: A sequence of 6 elements with K = 2 is 6; 10; 11; 26; 17). The subsequences here are (7; 6); 110; 11) and (26; 17): Note that all elements of (7; 6)...

  • 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...

  • Puodace a char showing the number of moves required to solve the Towers of Hanoi puzle using t 30...

    Puodace a char showing the number of moves required to solve the Towers of Hanoi puzle using t 30. What is an execution frame? What is an activation record? What is contained in it? 31. Write a recursive Java method that computes the factorial of a number 2. Linear search may require up to comparisons while binary search will only require roughly comparisons 33. Sort sorts a list of values by repetitively putting a particular value into its final, sorted,...

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