Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 30.1, Problem 7E
Program Plan Intro
To find the elements of C and total number of times, each element of C can be represented as sum of elements, in A and B. To show how the problem can be solved in O(logn) time.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
) Let O be the set of odd numbers and O’ = {1, 5, 9, 13, 17, ...} be its subset. Definethe bijections, f and g as:f : O 6 O’, f(d) = 2d - 1, d 0 O.g : ø 6 O, g(n) = 2n + 1, n 0 ø.Using only the concept of function composition, can there be a bijective map from øto O’? If so, compute it. If not, explain in details why not...................................................................................................................................... [2+8]b) A Sesotho word cannot begin with of the following letters of alphabet: D, G, V, W,X, Y and Z.We define the relation: A Sesotho word x is related to another Sesotho word y if xbegins with the same letter as y.Determine whether or not this is an equivalence relation.If it is an equivalence relation then1. Compute C(sekatana)2. How many equivalence classes are there in all, and why?3. What is the partition of the English words under this relation?If it is NOT an equivalence relation then explain in details why it is not
Given g = {(1,c),(2,a),(3,d)}, a function from X = {1,2,3} to Y = {a,b,c,d}, and f = {(a,r),(b,p),(c,δ),(d,r)}, a function from Y to Z = {p, β, r, δ}, write f o g as a set of ordered pairs.
Given a set of n positive integers, C = {c1,c2, ..., cn} and a positive integer K, is there a subset of C whose elements sum to K? A dynamic program for solving this problem uses a 2-dimensional Boolean table T, with n rows and k + 1 columns. T[i,j] 1≤ i ≤ n, 0 ≤ j ≤ K, is TRUE if and only if there is a subset of C = {c1,c2, ..., ci} whose elements sum to j. Which of the following is valid for 2 ≤ i ≤ n, ci ≤ j ≤ K?
a) T[i, j] = ( T[i − 1, j] or T[i, j − ci])
b) T[i, j] = ( T[i − 1, j] and T[i, j − ci ])
c) T[i, j] = ( T[i − 1, j] or T[i − 1, j − ci ])
d) T[i, j] = ( T[i − 1, j] and T[i − 1, j − cj ])
In the above problem, which entry of the table T, if TRUE, implies that there is a subset whose elements sum to K?
a) T[1, K + 1]
b) T[n, K]
c) T[n, 0]
d) T[n, K + 1]
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Given a set of n positive integers, C = {c1,c2, ..., cn} and a positive integer K, is there a subset of C whose elements sum to K? A dynamic program for solving this problem uses a 2-dimensional Boolean table T, with n rows and k + 1 columns. T[i,j] 1≤ i ≤ n, 0 ≤ j ≤ K, is TRUE if and only if there is a subset of C = {c1,c2, ..., ci} whose elements sum to j. Which of the following is valid for 2 ≤ i ≤ n, ci ≤ j ≤ K? a) ?[?, ?] = ( ?[? − 1, ?] ?? ?[?, ? − ?? ]) b) ?[?, ?] = ( ?[? − 1, ?] ??? ?[?, ? − ?? ]) c) ?[?, ?] = ( ?[? − 1, ?] ?? ?[? − 1, ? − ?? ]) d) ?[?, ?] = ( ?[? − 1, ?] ??? ?[? − 1, ? − ?? ]) In the above problem, which entry of the table T, if TRUE, implies that there is a subset whose elements sum to K? a) ?[1, ? + 1] b) ?[?, ?] c) ?[?, 0] d) ?[?, ? + 1]arrow_forwardWe now consider two sound waves with different frequencies which have to the same amplitude. The wave functions of these waves are as follows: y1 (t) = A sin (2πf1t) y2 (t) = A sin (2πf2t) 1) Using any computer program, construct the wave dependency graph resultant y (t) from time t in the case when the frequencies of the two sound waves are many next to each other if the values are given: A = 1 m, f1 = 1000 Hz and f2 = 1050 Hz. Doing the corresponding numerical simulations show what happens with the increase of the difference between the frequencies of the two waves and vice versa.arrow_forwardIf the first number in a sequence is a positive integer, x Let ao= x, an is defined as follows if an is even, then an+1 = an/2 if an is odd, then an+1 =3 *an+ 1 Then there exists an integer k, such that ak =1 For example, if: 75, then k = 14 and the numbers in the sequence are: 75, 226, 113, 340, 170, 85, 256, 128, 64, 32, 16, 8, 4, 2, 1. The largest number in the sequence is 340 and it is a position 4 in the sequence (assuming 75 is at position 1) Design and implement a complete C++ program that will • read a series of integers (greater than 0) from a file and for each integer display (to the screen) − the integer − the number of steps it takes to reach 1 − the largest value in the sequence and its positionarrow_forward
- we consider a problem where we are given a set of coins andour task is to form a sum of money n using the coins. The values of the coins arecoins = {c1, c2,..., ck}, and each coin can be used as many times we want. Whatis the minimum number of coins needed?For example, if the coins are the euro coins (in cents){1,2,5,10,20,50,100,200}and n = 520, we need at least four coins. The optimal solution is to select coins200+200+100+20 whose sum is 520.arrow_forwardProblem Alice was given a number line containing every positive integer, x, where 1<=x<=n. She was also given m line segments, each having a left endpoint, l (1<=l<=n), a right endpoint, r (1<=r<=n), and an integer weight, w. Her task is to cover all numbers on the given number line using a subset of the line segments, such that the maximum weight among all the line segments in the chosen subset is minimal. In other words, let S=(l1,r1,w1),(l2,r2,w2),....,(lk,rk,wk), represent a set of k line segments chosen by Alice, max(w1,w2,...,wk) should be minimized. All numbers 1,2,....n should be covered by at least one of k the chosen line segments. It is okay for the chosen line segments to overlap. You program should output the minimized maximum weight in the chosen subset that covers all the numbers on the number line, or -1 if it is not possible to cover the number line. Input format The first line of the input contains an integer, n - denoting the range of numbers…arrow_forwardImplement 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_forward
- The format P(X) represents as a power set of given "X", (of all X's subsets) Now, assume there are two sets A= {q, w, e, r} and B = {w, r, f}. (a) What are the elements of P(A) ∩P(B )?(b) What is the cardinality of P(A ∪B )?(c) What is |P(A) ∪P(B )|?arrow_forwardFor this question, you will be required to use the binary search to find the root of some function f(x)f(x) on the domain x∈[a,b]x∈[a,b] by continuously bisecting the domain. In our case, the root of the function can be defined as the x-values where the function will return 0, i.e. f(x)=0f(x)=0 For example, for the function: f(x)=sin2(x)x2−2f(x)=sin2(x)x2−2 on the domain [0,2][0,2], the root can be found at x≈1.43x≈1.43 Constraints Stopping criteria: ∣∣f(root)∣∣<0.0001|f(root)|<0.0001 or you reach a maximum of 1000 iterations. Round your answer to two decimal places. Function specifications Argument(s): f (function) →→ mathematical expression in the form of a lambda function. domain (tuple) →→ the domain of the function given a set of two integers. MAX (int) →→ the maximum number of iterations that will be performed by the function. Return: root (float) →→ return the root (rounded to two decimals) of the given function. START FUNCTION def binary_search(f,domain, MAX =…arrow_forwardFor this question, you will be required to use the binary search to find the root of some function f(x)f(x) on the domain x∈[a,b]x∈[a,b] by continuously bisecting the domain. In our case, the root of the function can be defined as the x-values where the function will return 0, i.e. f(x)=0f(x)=0 For example, for the function: f(x)=sin2(x)x2−2f(x)=sin2(x)x2−2 on the domain [0,2][0,2], the root can be found at x≈1.43x≈1.43 Constraints Stopping criteria: ∣∣f(root)∣∣<0.0001|f(root)|<0.0001 or you reach a maximum of 1000 iterations. Round your answer to two decimal places. Function specifications Argument(s): f (function) →→ mathematical expression in the form of a lambda function. domain (tuple) →→ the domain of the function given a set of two integers. MAX (int) →→ the maximum number of iterations that will be performed by the function. Return: root (float) →→ return the root (rounded to two decimals) of the given function. START FUNCTION def binary_search(f,domain, MAX =…arrow_forward
- If five integers are chosen from the set {1, 2, 3, 4, 5, 6, 7, 8}, must there be at least two integers with the property that the larger minus the smaller is 2? Write an answer that would convince a good but skeptical fellow student who has learned the statement of the pigeonhole principle but not seen an application like this one. Describe the pigeons, the pigeonholes, and how the pigeons get to the pigeonholes.arrow_forwardConsider the set F = {1, −1, i, −i} with an operation ✕ defined by the table. ✕ 1 −1 i −i 1 1 −1 i −i −1 −1 1 −i i i i −i −1 1 −i −i i 1 −1 a ✕ b means find the entry in row a and column b; for example, −1 ✕ (−i) = i (the entry in row −1 and column −i). Find each of the following. (a) −1 ✕ i (b) i ✕ i (c) −i ✕ i (d) −i ✕ 1 (e) 1 ✕ i (f) −i ✕ −iarrow_forwardIf sets A={10,20,30,40} B ={30,40,50,60} C= {50,60,70} U = {10,20,30,40,50,60,70}What is the cardinality of A? DO NOT FORGET TO ENCLOSE YOUR ANSWERS IN A BRACKET { } IF IT IS A SET.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education