Concept explainers
(a)
To prove that exactly
(a)
Explanation of Solution
The input array has distinct elements and each element is equally likely so the distribution is uniformly supported on the array.
As the array has n elements then the probability of each element occurs as
Since, there are distinct n elements so thepermutation of the leaf nodes is exactly
(b)
To shows
(b)
Explanation of Solution
Suppose the tree T then the depth of particular elements of LT is one less than the depth of the tree so the
Since the minimum length of the left leaf and the minimum length of the right leaf are equals to the length of the tree there is another variable k which defines the constant increasing in the path defined in the minimum path of the length.
Therefore,
(c)
To show that
(c)
Explanation of Solution
Suppose a tree T having leaves node k, LT and RT be minimum length path of left and right leaves then the equation of the tree is defined as follows:
Suppose the minimum path length equation of the tree as follows:
Now, suppose the LT have
For the minimum external path length the value of the equation is consider as minimum value of the i value of the
(d)
To show that the function
(d)
Explanation of Solution
Suppose i is a continuous variable and it finds the critical points using derivatives of the tree equation
Suppose it picks the two sub-trees of approx. equal sizes then the depth of the tree is equals to
Suppose the tree equation
Taking the log on both sides with derivate of the equation.
Putting the value
As
Therefore, the equation
(e)
To show that
(e)
Explanation of Solution
Suppose that a tree with k leaves needs to have external length
The average-case is the situation in which the
Since the average-case run time is the depth of a leaf weighted by the probability of that leaf being the one that occurs.
Therefore, the running time is
(f)
To show that for any randomized comparison sort B , there is a deterministic comparison sort A whose expected number of comparisons is no more than those made by B .
(f)
Explanation of Solution
The expected running time is the average over all possible results from the random bits. The equation of the tree is defined as follows:
The comparisons sort of B has the randomness that has higher value than the deterministic comparisons of A. The random sorting algorithm uses the partition of the array and uses the random sorting values for the dividing the array.
The possible fixing of the randomness resulted in a higher runtime, the average would have to be higher than the other so comparisons sort of B has higher value.
Want to see more full solutions like this?
Chapter 8 Solutions
Introduction to Algorithms
- Algorithm for Testing MembershipInput : a group G acting on f~ = { 1,2 ..... n };a permutation g of f~ = { 1,2 ..... n };a base and strong ~enerating set for G;Schreier vectors v (i) , 1 < i < k, for the stabiliser chain;Output: a boolean value answer, indicating whether g ~ G;function is_in_group(p : permutation; i : 1..k+l ) : boolean;(* return true if the permutation p is in the group G (i) *)arrow_forwardAlgebraic Preis’ AlgorithmAlgorithm due to Preis provides a different way to solve the maximal weightedmatching problem in a weighted graph. The algorithm consists of the followingsteps.1. Input: A weighted graph G = (V, E, w)2. Output: A maximal weighted matching M of G3. M ← Ø4. E ← E5. V ← V6. while E = Ø7. select at random any v ∈ V8. let e ∈ E be the heaviest edge incident to v9. M ← M ∪ e10. V ← V {v}11. E ← E \ {e and all adjacent edges to e} show two ways of implementing this algorithm in Pythonarrow_forwardAlgebraic Preis’ AlgorithmAlgorithm due to Preis provides a different way to solve the maximal weightedmatching problem in a weighted graph. The algorithm consists of the followingsteps.1. Input: A weighted graph G = (V, E, w)2. Output: A maximal weighted matching M of G3. M ← Ø4. E ← E5. V ← V6. while E = Ø7. select at random any v ∈ V8. let e ∈ E be the heaviest edge incident to v9. M ← M ∪ e10. V ← V {v}11. E ← E \ {e and all adjacent edges to e}show two ways of implementing this algorithm in Pythonarrow_forward
- Computer Science Consider the d-Independent Set problem: Input: an undirected graph G = (V,E) such that every vertex has degree less or equal than d. Output: The largest Independent Set. Describe a polynomial time algorithm Athat approximates the optimal solution by a factor α(d). Your must write the explicit value of α, which may depend on d. Describe your algorithm in words (no pseudocode) and prove the approximation ratio α you are obtaining. Briefly explain why your algorithm runs in polytime.arrow_forwardAny random element from the given Binary Search Tree is to be searched using the standard algorithm. In the Binary Search Tree given in the above problem (i) Determine the average or expected number of comparisons required to locate the element. (ii) determine the number of comparisons in the worst case. O 2.8 and 3.5 O 2,89 and 3 2 and 3 2 and 4 2.89 and 4arrow_forwardWrite Algorithm for Testing MembershipInput : a group G acting on f~ = { 1,2 ..... n };a permutation g on ~ = { 1,2 ..... n };a base and strong generating set for G;Schreier vectors v (i) ,1 < i < k, for the stabiliser chain;Similarly a non-re, cursiveOutput : a boolean value answer, indicating whether g ~ G;function is_in_group(p : permutation; i : 1..k+l ) : boolean;(* return true if the permutation p is in the group G (i) *)arrow_forward
- Consider the d-Independent Set problem:Input: an undirected graph G = (V,E) such that every vertex has degree less or equal than d.Output: The largest Independent Set. Describe a polynomial time algorithm Athat approximates the optimal solution by a factor α(d). Your mustwrite the explicit value of α, which may depend on d. Describe your algorithm in words (no pseudocode) andprove the approximation ratio α you are obtaining. Briefly explain why your algorithm runs in polytime.arrow_forwardAlgorithm for LLP-GAN training algorithmInput: The training set L = {(Bi, pi)}n i=1; L: number of total iterations; λ: weight parameter.Input: The parameters of the final discriminator D.Set m to the total number of training data pointsarrow_forwardYou are given a weighted tree T.(As a reminder, a tree T is a graph that is connected and contains no cycle.) Each node of the tree T has a weight, denoted by w(v). You want to select a subset of tree nodes, such that weight of the selected nodes is maximized, and if a node is selected, then none of its neighbors are selected.arrow_forward
- Given an undirected weighted graph G with n nodes and m edges, and we have used Prim’s algorithm to construct a minimum spanning tree T. Suppose the weight of one of the tree edge ((u, v) ∈ T) is changed from w to w′, design an algorithm to verify whether T is still a minimum spanning tree. Your algorithm should run in O(m) time, and explain why your algorithm is correct. You can assume all the weights are distinct. (Hint: When an edge is removed, nodes of T will break into two groups. Which edge should we choose in the cut of these two groups?)arrow_forwardWe know that when we have a graph with negative edge costs, Dijkstra’s algorithm is not guaranteed to work. (a) Does Dijkstra’s algorithm ever work when some of the edge costs are negative? Explain why or why not. (b) Find an algorithm that will always find a shortest path between two nodes, under the assumption that at most one edge in the input has a negative weight. Your algorithm should run in time O(m log n), where m is the number of edges and n is the number of nodes. That is, the runnning time should be at most a constant factor slower than Dijkstra’s algorithm. To be clear, your algorithm takes as input (i) a directed graph, G, given in adjacency list form. (ii) a weight function f, which, given two adjacent nodes, v,w, returns the weight of the edge between them. For non-adjacent nodes v,w, you may assume f(v,w) returns +1. (iii) a pair of nodes, s, t. If the input contains a negative cycle, you should find one and output it. Otherwise, if the graph contains at least one…arrow_forwardLet V be an array containing n distinct integer elements. Suppose there is an algorithm that needs to find a pair of elements from V such that the sum of the elements is equal to k. We may assume that the algorithm always finds such a pair. Explain using the number of leaf nodes in a decision tree why the algorithm must take omega(log n) worst case time.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