(a)
To describe the
(a)
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
Therefore, it takes total time of
(b)
To describe the algorithm that built a max-priority queue by calling EXTRACT-MAX and also gives the running time of the algorithm.
(b)
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
Therefore, the running time of the algorithm is
(c)
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)
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
Therefore, the algorithm takes total running time of
Want to see more full solutions like this?
Chapter 9 Solutions
Introduction To Algorithms, Third Edition (international Edition)
- EX:[AE00]=fa50h number of ones =1111 1010 0101 0000 Physical address=4AE00h=4000h*10h+AE00h Mov ax,4000 Mov ds,ax; DS=4000h mov ds,4000 X Mov ax,[AE00] ; ax=[ae00]=FA50h Mov cx,10; 16 bit in decimal Mov bl,0 *: Ror ax,1 Jnc ** Inc bl **:Dec cx Jnz * ;LSB⇒CF Cf=1 ; it jump when CF=0, will not jump when CF=1 HW1: rewrite the above example use another wayarrow_forwardEX2: Write a piece of assembly code that can count the number of ones in word stored at 4AE00harrow_forwardWrite a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a text file named 8_ball_responses.txt. The file contains 12 responses, such as “I don’t think so”, “Yes, of course!”, “I’m not sure”, and so forth. The program should read the responses from the file into a list. It should prompt the user to ask a question, then display one of the responses, randomly selected from the list. The program should repeat until the user is ready to quit. Contents of 8_ball_responses.txt: Yes, of course! Without a doubt, yes. You can count on it. For sure! Ask me later. I'm not sure. I can't tell you right now. I'll tell you after my nap. No way! I don't think so. Without a doubt, no. The answer is clearly NO. (You can access the Computer Science Portal at www.pearsonhighered.com/gaddis.)arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageOperations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT