(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 a sorted array of n comparable items A, create a binary search tree from the items in A which has height h <= log: n. Your algorithm must create the tree in O(n) time.arrow_forward3. Show how the binary search algorithm searches for 25 in the sorted listbelow: 4 6 17 25 32 39 41 43 45 49 let i = be the first number j = be the last number m = be the middle number I need to see how this is done and how the numbers narrow down to 25. Please break this down in described steps. I'm really confused.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
- Implement the Divide and Conquer-based algorithm to find the minimum andmaximum elements in a list L of n elements.arrow_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_forwardLet T be a sorted array of n elements. An element x is said to be a majority element in T if the number of elements i, with T[i] = x, is greater than n/2. Give an algorithm (code or pseudo-code) that can decide whether T includes a majority element (it cannot have more than one), and if so, find it. Your algorithm must run in linear time.arrow_forward
- Analysis of Linear search (Worst, Average and Best Cases)#include <stdio.h>// Linearly search x in arr[]. If x is present then return the index,// otherwise return -1int search(int arr[], int n, int x){ int i; for (i=0; i<n; i++) { if (arr[i] == x) return i; } return -1;}arrow_forwardLet C(n) denote the number of comparisons performed by quicksort in sorting an array of size n in the worst case. Write the recurrence relation for C(n) and solve.arrow_forwardThe median m of a sequence of n elements is the element that would fall in the middle if the sequence was sorted. That is, e ≤ m for half the elements, and m ≤ e for the others. Clearly, one can obtain the median by sorting the sequence, but one can do quite a bit better with the following algorithm that finds the kth element of a sequence between a (inclusive) and b (exclusive). (For the median, use k = n/2, a = 0, and b = n.) select(k, a, b)Pick a pivot p in the subsequence between a and b.Partition the subsequence elements into three subsequences: the elements <p, =p, >p Let n1, n2, n3 be the sizes of each of these subsequences.if k < n1 return select(k, 0, n1).else if (k > n1 + n2) return select(k, n1 + n2, n).else return p. c++arrow_forward
- On 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.The number of critical comparisons performed during the searches should be compared.arrow_forwardWe have n elements {x1, ..., xn} we want to hash into a table T of size s = 2n. Let us consider the following method of hashing these n elements into T: For each i = 1,..., n, do the following: 1. Pick a permutation of [1,..., s] uniformly at random. Call this permutation T; : [s] → [s], which maps each index to the element which ends up in that index. 2. Set j : : 1. 3. While T[T;(j)] has an element in it, increment j. 4. Place x; in T[T;(j)]. 1.1 Show that while inserting any ;, the probability that there are at least t iterations of the while loop in Step 3 is at most 2-t.arrow_forwardPerform an experiment with alternately applying insertion and deletion of random elements in a randomly created binary search tree. Apply asymmetric and symmetric deletions. For both these variants of the deletion algorithm, alternate deletions strictly with insertions and alternate these operations randomly. This gives four different combinations. Also, use two different random number generators to ensure randomness. This leads to eight combinations. Run all of these combinations for these combinations for tress of heights 500,100,1500, and 2000. Plot the results. Use a java program onlyarrow_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