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
- Implement the algorithm for an optimal parenthesization of a matrix chain product as dis-cussed in the class.Use the following recursive function as part of your program to print the outcome, assumethe matrixes are namedA1, A2, ..., An.PRINT-OPTIMAL-PARENS(s, i, j){if (i=j) thenprint “A”i else{print “(”PRINT-OPTIMAL-PARENS(s,i,s[i, j])PRINT-OPTIMAL-PARENS(s, s[i, j] + 1, j)print “)”} }a- Test your algorithm for the following cases:1. Find and print an optimal parenthesization of a matrix-chain product whose sequenceof dimensions is<5,10,3, X,12,5,50, Y,6>.2. Find and print an optimal parenthesization of a matrix-chain product whose sequenceof dimensions is<5,10,50,6, X,15,40,18, Y,30,15, Z,3,12,5>. 3. Find and print an optimal parenthesization of a matrix-chain product whose sequenceof dimensions is<50,6, X,15,40,18, Y,5,10,3,12,5, Z,40,10,30,5>. X=10 Y=20 Z=30arrow_forwardExercise c. Strict matchingConsider the following generalization of the maximum matching problem, which we callStrict-Matching. Recall that a matching in an undirected graph G = (V, E) is a setof edges such that no distinct pair of edges {a, b} and {c, d} have endpoints that areequal: {a, b} ∩ {c, d} = ∅. Say that a strict matching is matching with the propertythat no pair of distinct edges have endpoints that are connected by an edge: {a, c} ̸∈ E,{a, d} ̸∈ E, {b, c} ̸∈ E, and {b, d} ̸∈ E. (Since a strict matching is also a matching, wealso require {a, b} ∩ {c, d} = ∅.) The problem Strict-Matching is then given a graphG and an integer k, does G contain a strict matching with at least k edges.Prove that Strict-Matching is NP-complete.arrow_forwardYou use your favorite decision tree algorithm to learn a decision tree for binary classification. Your tree hasJ leaves indexed j = 1, . . . , J. Leaf j contains nj training examples, mj of which are positive. However,instead of predicting a label, you would like to use this tree to predict the probability P(Y = 1 | X) (whereY is the binary class and X are the input attributes). Therefore, you decide to have each leaf predict a realvalue pj ∈ [0, 1]. -What are the values pj that yield the largest log likelihood? Show your work.arrow_forward
- Suppose a candidate solution p, where p is a phenotype consisting of 4 vertices. Suppose that minimum fitness occurs when no pair of vertices in p are connected, and maximum fitness occurs when all pairs of vertices in p are connected. Write a pseudocode on how to calculate the fitness F of p.arrow_forwardConsider the vacuum-world problem defined as shown in the following figure-1. a. Which of the algorithms defined in this chapter would be appropriate for this problem? Should the algorithm use tree search or graph search? b. Apply your chosen algorithm to compute an optimal sequence of actions for a 3×3 world whose initial state has dirt in the three top squares and the agent in the center. c. Construct a search agent for the vacuum world, and evaluate its performance in a set of 3×3 worlds with probability 0.2 of dirt in each square. Include the search cost as well as path cost in the performance measure, using a reasonable exchange rate. d. Compare your best search agent with a simple randomized reflex agent that sucks if there is dirt and otherwise moves randomly. e. Consider what would happen if the world were enlarged to n × n. How does the performance of the search agent and of the reflex agent vary with n?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_forward
- Algebraic 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_forwardWrite The Rank-Maximal Matching Algorithm. Let G = (AUP, EU... UE). Initialize G₁ = G₁, and M to any maximum matching in G. For i = 1 tor-1 solve \ the steps, and output.arrow_forwardConsider the vacuum-world problem defined as shown in the following figure. a. Which of the algorithms defined in this chapter would be appropriate for this problem? Should the algorithm use tree search or graph search? b. Apply your chosen algorithm to compute an optimal sequence of actions for a 3×3 world whose initial state has dirt in the three top squares and the agent in the center. c. Will you prefer an agent with state/ memory in this scenario? d. Compare your best search agent with a simple randomized reflex agent that sucks if there is dirt and otherwise moves randomly. e. Consider what would happen if the world were enlarged to n × n. How does the performance of the search agent and of the reflex agent vary with n?arrow_forward
- Consider the following problem for path finding where S is the source, G is the Goal and O are obstacles. We can only move horizontally and vertically (not diagonally). We will not re-visit an already visited cell. - Simulate the application of Breadth-first search tree to find all paths from S to G. Provide the order of visit for each node. - Simulate the application of Depth-first search tree to find all paths from S to G. Provide the order of visit for each node. S O G Oarrow_forwardIf you are given a set S of integers and a number t, prove that this issue falls into the NP class. Is there a subset of S where the total number of items is t? Note: Complexity in Data Structures and Algorithmsarrow_forwardLet T be a tree. Let a be the minimum weight and b be the maximum weight over all the edge weights in T. Then the strength of T is (a2+b2). Input: An undirected weighted graph G. Task: Give an efficient algorithm for computing a spanning tree of G that maximizes the strength of the tree. Give an efficient algorithm (to the best of your knowledge) and a formal proof of correctness for your algorithm. An answer without any formal proof will be considered incomplete. Analyze the running time of the algorithm. You must write down your algorithm as pseudocodearrow_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