(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
- A binary search is to be performed on the list, S = [6, 2, 5, 7, 9, 12, 1, 10, 8, 4] How many comparisons would it take to find number 10, worst case?arrow_forwardGiven a linked list L storing n integers, present an algorithm (either in words or in a pseudocode) that decides whether L contains any 0 or not. The output of your algorithm should be either Yes or No. What is the running time of your algorithm in the worst-case, using O notation?arrow_forwardSort the given data in ascending order; 12, 9, 3, 7, 9, 5, 3, 9, 10, 2. Apply one of the sorting algorithms in which there is no comparison of elements. Preferably the algorithm should have a running time of Theta(n).arrow_forward
- Given a set of n numbers, we wish to find the i largest in sorted order using a comparison-based algorithm. Find the algorithm that implements each of the following methods with the best asymptotic worst-case running time, and analyze the running times of the algorithms in terms of n and i. a. Sort the numbers, and list the i largest. Group of answer choices 1. O(ni) 2. O(nlg(n)) 3. O(n + ilg(n)) 4. O(i + nlg(n)) 5. O(n + ilg(i)) b. Build a max-priority queue from the numbers, and call EXTRACT-MAX i times. Group of answer choices 1. O(i + nlg(n)) 2. O(n + ilg(n)) 3. O(nlg(n)) 4. O(ni) 5. O(n + ilg(i)) c. Use an order-statistic algorithm to find the ith largest number, partition around that number, and sort the i largest numbers. Group of answer choices 1. O(n + ilg(i)) 2. O(n + ilg(n)) 3. O(nlg(n)) 4. O(i + nlg(n)) 5. O(ni)arrow_forwardComputer Science Write the PSEUDOCODE for an algorithm that takes as input a list of numbers that are sorted in nondecreasing order, and finds the location(s) of the most frequently occurring element(s) in the list. If there are more than one element that is the most frequently occurring, then return the locations of all of them. Analyze the worst-case time complexity of this algorithm and give the O() estimate. (A list is in nondecreasing order if each number in the list is greater than or equal to the number preceding it.)arrow_forwardFor the 8-queens problem, define a heuristic function, design a Best First Search algorithm in which the search process is guided by f(n) = g(n) + h(n), where g(n) is the depth of node n and h(n) is the heuristic function you define, and give the pseudo code description.arrow_forward
- Given a sorted array of n comparable items A, and a search value key, return the position (array index) of key in A if it is present, or -1 if it is not present. If key is present in A, your algorithm must run in order O(log k) time, where k is the location of key in A. Otherwise, if key is not present, your algorithm must run in O(log n) time.arrow_forwardOn an ordered list, use the binary search and Fibonacci search algorithms. Search for the components in the list "3, 18, 1, 25" for the list L = "2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20." Check how many comparisons were made during the searches.arrow_forwardBinary search is performed on a sorted array of n elements. The search key is not in the array and falls between the elements at positions m and m+1 (where 1 ≤ marrow_forwardtime and grows Assume we have a sorted list. Binary search algorithm takes case as n grows. the linear search algorithm in the worst- O(n), slower than O(log (n)), faster than O(log (n)), it depends O(n), faster than none of the cases are correct O(log (n)), slower than O O(n/2), at the same speed asarrow_forwardWhich one is the true statement? -A hash table can be used to make an algorithm run faster even in the worst case by trading space for time. -An iterative improvement algorithm starts with a sub-optimal feasible solution and seeks to improve it in each iteration until reaching a optimal feasible solution.arrow_forwardGiven an array of elements drawn from a totally ordered set. Present an O(n)-time algorithm that either returns an element that appears at least ||n times in the list or reports that no such an element exists. [Hint: Use Algorithm Select]arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education