Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
Question
Book Icon
Chapter 9, Problem 1P

(a)

Program Plan Intro

To describe the algorithm that sorts the number to list the largest and also give the running time of the algorithm.

(a)

Expert Solution
Check Mark

Explanation of Solution

The algorithm that sort the number by finding the largest number from the list is based on the dividing the list into some part to find the largest from the number and then divide the whole list into two parts that is, one part consists of largest number and other part consists rest of the numbers.

The algorithm uses the largest number and find the correct position of that number by comparing to all the number then it find the largest number from the rest of the number.

The algorithm placed that largest number to their correct position and allows this procedure until the last element is remaining in the array then combined all the number as it is placed by the algorithm and the merged array consists of sorted number.

The dividing of number takes the time of lgn with the linear time equals to the size of the array and the listing of the elements takes constant time of i.

Therefore, it takes total time of O(nlgn+i) .

(b)

Program Plan Intro

To describe the algorithm that built a max-priority queue by calling EXTRACT-MAX and also gives the running time of the algorithm.

(b)

Expert Solution
Check Mark

Explanation of Solution

The algorithm that uses max-priority queue and calling the EXTRACT-MAX is the Heap-sort. The algorithm is based on the creating the in-order tree by the numbers and calls the MAX-HEAPIFY at the nodes that are not leaf.

The algorithm arranged the tree in such a way that the root of the tree has largest number then the algorithm removes the root and stores it in the priority queue.

The algorithm again calls the EXTRACT-MAX on the remaining tree and arranged the tree such that root has largest number and remove the root and stored to the priority-queue where previous element is stored and continued the procedures again and again until the tree has only no elements.

The EXTRACT-MAX algorithm extracts the maximum or largest number from the given number by calling MAX-HEAPIFY.

The heapify of the algorithm takes the time of nlgn and the extraction takes the time of lgn as it considered the whole tree with height lgn .

Therefore, the running time of the algorithm is O(nlgn) where n=size+i .

(c)

Program Plan Intro

To describe the algorithm that uses an order-statistic algorithm to find the largest, partition around that number and also give the running time of the algorithm.

(c)

Expert Solution
Check Mark

Explanation of Solution

The algorithm considers all the numbers and stores the number into an array. It selects the largest by comparing the numbers and uses the finding function to find the largest number that is based on the comparisons of the numbers.

Then the algorithm partition the array into several parts using the partition algorithm. The partition algorithm recursively called itself and compared the element until it partitioned the array into single elements.

After the partition the algorithm merged the subparts in the sorted order of array that is i times. The merging of all the sorte3d parts gives the array of sorted number that is the output of the algorithm.

The finding and partition of the i -array takes the linear time of n . The sorting of the sub-parts of the array is based on the dividing and merging that takes the time of ilgi where i is the i -largest number.

Therefore, the algorithm takes total running time of O(n+ilgi) .

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Inserting a node in an unordered doubly linked list of N nodes. What is the Worst-Case Complexity(in O notation) and When does the worst case happen(under what conditions)?
A sequential search of a sorted list can halt when the target is less than a givenelement in the list. Define a modified version of this algorithm and state thecomputational complexity, using big-O notation, of its best-, worst-, and average-case performances. Using this template in python: def sequential_search(input_list, target):target_index = -1#TODO: Your work here# Return target_index. If not found, -1return target_indexif __name__ == "__main__":my_list = [1, 2, 3, 4, 5]print(sequential_search(my_list, 3)) # Correct Output: 2print(sequential_search(my_list, 0)) # Correct Output: -1
Binary tree sort employing a self-balancing binary search tree takes O(n log n) time in the worst scenario, slower than merge sort.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education