(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
- Given the visited node for breadth first search , starting with s , given the following adjacency lists adj(s) = [a,c.d] adj(a) = [], adj(c) = [e.b] adj(b) = [d], adj(d) = [c], adj(e) = [s], a) sabdec b) sacdeb c) sadcbe d)sacebdarrow_forwardHow many references must you change to insert a node to a binary search tree? What is the average time complexity for search, insert and delete operations in a balanced Binary Search Tree of size n? What is the worst case time complexity for search, insert and delete operations in a Binary Search Tree of size n? Suppose some numbers (given) are inserted in that order into an initially empty binary search tree. What is the In-order/Pre-order/Post-order traversal sequence of the resultant tree?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
- This assignment is an exercise in finding the average-case complexity of an algorithm.Rather than looking at how long an algorithm can run in the worst case as in worst-case analysis, we are looking at how long an algorithm runs on average. This is doneby computing the average number of comparisons and operations executed until thealgorithm ends.Bogosort is a sorting algorithm that orders a list in increasing order by taking thelist, checking to see if the list is ordered increasingly, if the list is not ordered increasinglythen the list is randomly shuffled, and then repeating this process until the list is orderedincreasingly.Expressed in pseudocode:Algorithm 1 BogosortRequire: list: a1, a2, . . . , an of real numbersEnsure: list is sorted in increasing order1: procedure bogo(list)2: while not sorted(list) do ▷ Checks to see if list is sorted3: shuffle(list) ▷ Shuffle the current list if not sorted4: end while5: end procedure Problem: Consider the Bernoulli trial where a success is…arrow_forwardThis assignment is an exercise in finding the average-case complexity of an algorithm.Rather than looking at how long an algorithm can run in the worst case as in worst-case analysis, we are looking at how long an algorithm runs on average. This is doneby computing the average number of comparisons and operations executed until thealgorithm ends.Bogosort is a sorting algorithm that orders a list in increasing order by taking thelist, checking to see if the list is ordered increasingly, if the list is not ordered increasinglythen the list is randomly shuffled, and then repeating this process until the list is orderedincreasingly.Expressed in pseudocode:Algorithm 1 BogosortRequire: list: a1, a2, . . . , an of real numbersEnsure: list is sorted in increasing order1: procedure bogo(list)2: while not sorted(list) do ▷ Checks to see if list is sorted3: shuffle(list) ▷ Shuffle the current list if not sorted4: end while5: end procedure We will now find the average-case time complexity for…arrow_forwardIn the worst-case scenario, binary tree sort employing a self-balancing binary search tree requires O(n log n) time, which is slower than merge sort.arrow_forward
- Given 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_forwardConsider a (singly) linked list. Describe an algorithm to remove every second elementfrom the list.(HINT: The algorithm is similar to the one that is used when we delete a single node. Here,we need to skip an element after every deletion, and then if we have not reached the end ofthe list repeat this procedure until the list is exhausted.).arrow_forwardGiven 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_forward
- QA1: If we add n sorted items into an initially empty binary search tree, then we would expect what big-oh for a search in this binary search tree? O(1) O(log n) O(n) O(n log n) QA2: If we add n randomly ordered items into an initially empty binary search tree, then we would expect what big-oh for a search in this binary search tree? O(1) O(log n) O(n) O(n log n) QA3: If we add n sorted items into an initially empty AVL tree, then we would expect what big-oh for a search in this AVL tree? O(1) O(log n) O(n) O(n log n) QA4: If we add n sorted items into a initially empty ChainingDict, then we would expect what big-oh for a search in this ChainingDict? Assume the load factor is < 1. O(1) O(log n) O(n) O(n log n)arrow_forwardFor any given AVL tree T of n elements, we need to design an algorithm that finds elements x in T such that a <= x <= b, where a and b are two input values. Assume that T has m elements x satisfying a <= x <= b. What is the best time complexity for such an algorithm? A. O(m) B. O(m log n) C.O(m + log n) D.O(log m + log n)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_forward
- 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