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
The coordinates of a polygon can be represented as a list of tuples: [(x1, y1), (x2, y2), .., (xn, yn)], where (x1, y1), ., (xn, yn) are points of the polygon in a counterclockwise order.
Find the area of such a polygon using using shoelace formula. It is no longer required to take absolute value.
п-1
п—1
A =
> xi+1Yi ) – x1Yn
i=1
i=1
1
x142 + x2Y3 + + xn-1Yn + xnY1 - x2y1 – X3Y2 – ··- xn Yn-1 – x1Yn|
>>> area ([(0,0), (1,0), (0,1)])
0.5
>>> area ([(0,0), (1,0),(1,1),(0,1)])
1.0
>> area([(0,0),(2,0), (2,2),(1,2), (0,1)])
3.5
Write the function area(C) to find the area of a triangle with vertices at c = [(x1, y1), (x2, y2),..., (xn, yn)].
Dingyu is playing a game defined on an n X n board. Each cell (i, j) of the board (1 2, he may only go to (2, n).) The reward he earns for
a move from cell C to cell D is |value of cell C – value of cell D|. The game ends when he reaches (n, n). The total reward
-
is the sum of the rewards for each move he makes.
For example, if n =
1
2 and A =
3
the answer is 4 since he can visit (1, 1) → (1, 2) → (2, 2), and no other solution
will get a higher reward.
A. Write a recurrence relation to express the maximum possible reward Dingyu can achieve in traveling from cell (1, 1) to cell
(n, n). Be sure to include any necessary base cases.
B. State the asymptotic (big-O) running time, as a function of n, of a bottom-up dynamic programming algorithm based on
your answer from the previous part. Briefly justify your answer. (You do not need to write down the algorithm itself.)
In a company, there are several branches. Let us consider a branch of that company having N
employees, if the manager is allotted to that branch(s) then he is known to everyone else in that
branch. Note that the property of "known to everyone" is unique to a manager. Your task is to find
the manager in that branch. Input from the user in main ( ), the square matrix M where if an element
of row i and column j is set to 1 it means that ith person knows jth person. You need to write a
function managerId ( ) which returns the id of the manager if present or else returns -1. The function
managerId ( ) takes two arguments - the square matrix of N *N and its size N. Call managerId ( )
from the main ( ) output the information about the manager. Assume all diagonal elements to be 1
(as everyone knows him/herself) and there is at most one manager in the company.
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
- ) 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 notarrow_forwardLet A={+,x,a,b}. Show that (a*V ba)+ b is regular over A.arrow_forwardCorrect answer will be upvoted else Multiple Downvoted. Computer science. You are given an arrangement an of length n comprising of integers from 1 to n. The grouping may contain duplicates (for example a few components can be equal). Track down the number of tuples of m=3 components with the end goal that the maximum number in the tuple varies from the base by close to k=2. Formally, you want to view as the number of triples of lists i<j<z with the end goal that max(ai,aj,az)−min(ai,aj,az)≤2. For example, on the off chance that n=4 and a=[1,2,4,3], there are two such triples (i=1,j=2,z=4 and i=2,j=3,z=4). In the event that n=4 and a=[1,1,1,1], all four potential triples are suitable. Input The principal line contains a solitary integer t (1≤t≤2⋅105) — the number of experiments. Then, at that point, t experiments follow. The principal line of each experiment contains an integer n (1≤n≤2⋅105) — the length of the succession a. The following line contains n…arrow_forward
- | Consider the elliptic curve group based on the equation y? = x' + ax + b mod p where a = 4, b = 1, and p = 7. This curve contains the point P = (0, 1). The order of this elliptic curve group is the prime number 5, and therefore we can be sure that P is a primitive element. Another element in this group is Q = (0,6). The index of Q with respect to P is the least positive integer d such that Q = dP. What is d, the index of Q?arrow_forwardThis problem is taken from the delightful book "Problems for Mathematicians, Young and Old" by Paul R. Halmos. Suppose that 931 tennis players want to play an elimination tournament. That means: they pair up, at random, for each round; if the number of players before the round begins is odd, one of them, chosen at random, sits out that round. The winners of each round, and the odd one who sat it out (if there was an odd one), play in the next round, till, finally, there is only one winner, the champion. What is the total number of matches to be played altogether, in all the rounds of the tournament? Your answer: Hint: This is much simpler than you think. When you see the answer you will say "of course".arrow_forwardWrite a program that inputs a matrix and displays the trans- pose of that matrix. A transpose of a matrix is obtained by converting all the rows of a given matrix into columns and vice versa.arrow_forward
- Given A = {1,2,3} and B={u,v}, determine. a. A X B b. B X Barrow_forwardThe zero vector 0 = (0, 0, 0) can be written as a linear combination of the vectors v,, v,, and v, because 0 = Ov, + Ov, + 0va. This is called the trivial solution. Can you find a nontrivial way of writing 0 as a linear combination of the three vectors? (Enter your answer in terms of v,, v,, and v. If not possible, enter IMPOSSIBLE.) v, = (1, 0, 1), v, = (-1, 1, 2), v3 = (0, 1, 2) 0 =arrow_forwardImagine a 3D plane P in your 3D scene. An infinite number of lines can lie on that plane. Consider one set of parallel lines on this 3D plane. This set will produce one vanishing point when projected on the image plane. Consider now all possible sets of parallel line on the plane P. What is the locus of all vanishing points produced by all sets of parallel lines? [Note that you do not have to right down a formula in order to solve this. You need to use a geometric argument.]arrow_forward
- A = {0, 1, 2, 3, 4} B = {2, 3, 4, 5}Given the sets A and B, how many constants maps are there from A into B.arrow_forwardImagine there are N teams competing in a tournament, and that each team plays each of the other teams once. If a tournament were to take place, it should be demonstrated (using an example) that every team would lose to at least one other team in the tournament.arrow_forwardAdam begins to master programming. The main undertaking is drawing a fox! Notwithstanding, that ends up being excessively hard for a novice, so she chooses to draw a snake all things being equal. A snake is an example on a n by m table. Mean c-th cell of r-th column as (r, c). The tail of the snake is situated at (1, 1), then, at that point, it's body reaches out to (1, m), then, at that point, goes down 2 lines to (3, m), then, at that point, goes left to (3, 1, etc. Your undertaking is to draw this snake for Adam: the unfilled cells ought to be addressed as speck characters ('.') and the snake cells ought to be loaded up with number signs ('#'). Consider test tests to comprehend the snake design for the programming concepts.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