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
Question
Chapter 7.1, Problem 1E
Program Plan Intro
To illustrate the operation of PARTITION on the array
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3. Unimodal Sequence
Given n2 1, a sequence of n integers a[0],. . ., a[n-1] is
unimodal if there exists t (with 0 st a[t+1] > . . . > a[n=1]
The element a[t] is called the top of the sequence.
For example, the sequence 1, 3, 5, 9, 4, 1 is unimodal,
and its top is 9 (t = 3).
Write a function
get Toplndex_UnimodelSequence that takes a
unimodal sequence & returns the index of the top of
the sequence. The solution must have cost O(log(n)) in
time in the worst case.
write a C++ program to Given a matrix of dimension m*n where each cell in the matrix can have values 0, 1 or 2 whichhas the following meaning:0: Empty cell1: Cells have fresh oranges2: Cells have rotten orangesSo we have to determine what is the minimum time required so that all the oranges becomerotten. A rotten orange at index [i,j] can rot other fresh orange at indexes [i-1,j], [i+1,j], [i,j-1],[i,j+1] (up, down, left and right). If it is impossible to rot every orange then simply return -1.Examples:Input: arr[][C] = { {2, 1, 0, 2, 1},{1, 0, 1, 2, 1},{1, 0, 0, 2, 1}};Output:All oranges can become rotten in 2 time frames.Input: arr[][C] = { {2, 1, 0, 2, 1},Tahir Iqbal Department of Computer Sciences. BULC{0, 0, 1, 2, 1},{1, 0, 0, 2, 1}};Output:All oranges cannot be rotten.Below is algorithm.1) Create an empty Q.2) Find all rotten oranges and enqueue them to Q. Also enqueuea delimiter to indicate beginning of next time frame.3) While Q is not empty do following3.a) While delimiter in…
7. (a) Show that E3x(Px x Px).
(b) Show that {Qx,Vy(Qy → Pz)} EVx Px.
Chapter 7 Solutions
Introduction to Algorithms
Knowledge Booster
Similar questions
- The vector x ∈ R N has L different entries. For example, L = 4 for x = [3,4,4,5,3,1,5,3]T . One can express x as x = S u, where u ∈ R L satisfies (u)i < (u)j if i < j and S is a matrix that contains only zeros and ones. Write the function repeated_entries, which takes x as input and returns S and u.arrow_forwardTitle: Comparison of Exhaustive, Greedy, and Dynamic Programming approaches for the Partition problem.Description: In this assignment, we are given a set S containing n integers and we are expected to output a partition with two subsets such that they have the minimumdifference in their sums. For this purpose, we can use the simple exhaustive approach, which takes every subset A of S and compare the difference d of the sums: d =sum(A)-sum(S-A). The greedy approach is to use the numbers in S in pairs in descending order as described in class (you can also see the Wikipedia entry for thepartition problem). The dynamic programming algorithm that we covered in class is also to be implemented.We are also asked to compare the three algorithms in their runtime (in msecs) and difference found (d) for various values of k=log2(n). Your program will produce theseperformance measures, and then using any utility such as Excel, draw the plots of their runtimes versus k and d versus k (use…arrow_forwardConsider an n by n matrix, where each of the n2 entries is a positive integer. If the entries in this matrix are unsorted, then determining whether a target number t appears in the matrix can only be done by searching through each of the n2 entries. Thus, any search algorithm has a running time of O(n²). However, suppose you know that this n by n matrix satisfies the following properties: • Integers in each row increase from left to right. • Integers in each column increase from top to bottom. An example of such a matrix is presented below, for n=5. 4 7 11 15 2 5 8 12 19 3 6 9 16 22 10 13 14 17 24 1 18 21 23 | 26 | 30 Here is a bold claim: if the n by n matrix satisfies these two properties, then there exists an O(n) algorithm to determine whether a target number t appears in this matrix. Determine whether this statement is TRUE or FALSE. If the statement is TRUE, describe your algorithm and explain why your algorithm runs in O(n) time. If the statement is FALSE, clearly explain why no…arrow_forward
- Q1. Design a generic matrix multiplier. Here ‘generic’ means the design should work for anymatrix multiplication X∙Y = Z, where the matrices X, Y, and Z are of sizes a×b, b×c, and a×crespectively. Now, pick a, b, c from the last three digits of your roll number. ( If any of the digitsis 0, take 3 instead of it; if two digits are 0s, then take 3 for the first 0, and 5 for the second 0)For Example, if the last three digits are 123 then a = 1, b = 2, and c = 3; if the last three digitsare 204 then a = 2, b = 3, c = 4; f the last three digits are 100 then a = 1, b = 3, c = 5.arrow_forward5. Consider removing the "strict" restriction in our definition of strict majority element. That is, we define r as a majority element of an array A if greater than or equal to half of the elements of A are equal to r. (In our more formal definition, we replace the > by > .) The claim that A has at most one strict majority element is no longer true if we remove the “strict". That is, it might be the case that A has more than one majority element. (Can you think of an example? What restrictions on n must there be to have more than 1?) Since the claim is no longer true, our proof for the strict majority element can no longer work. Which line of the proof is the earliest line that is no longer true (i.e. it no longer follows from the previous line or from given assumptions). You should assume that we replace our contradiction assumption with “suppose that array A has at least two distinct majority elements r and y". a. The definitions of A, and Ay b. That n 2 |Az|+ |Ay| c. That the…arrow_forwardm U=((x,y.2) : x-y-z = 0 (mod 2)} A collection of 3-vectors, U, is defined over Z₂ by the condition Which of the following statements holds true of ? O (1,1,1) EU OU is not a vector space since it does not satisfy closure under scalar multiplication. OU is not a vector space since it is not closed under vector addition. O (1,0,1) U O U is a vector space with basis {(0, 0, 1), (0, 1,0). (1,0,0)) CY ve haber Sharearrow_forward
- 1. [20 points] [MID] The subset21 problem is stated as follows. Given a set of N positive integers X elements of P is equal to 21. For example, if N=5 and the set X = {12, 17, 3, 24, 6}, the set P = {12, 3, 6} is a valid solution for the subset21 problem in this example. {x1, x2, ..., xm}. Find a subset P of the set X such that the sum of the Formulate the subset21 problem as a Genetic or Evolutionary Algorithm optimization. You may use binary representation, OR any representation that you think is more appropriate. you should specify: • A fitness function. Give 3 examples of individuals and their fitness values if are solving the above example (i.e. X you {12, 17, 3, 24, 6}). • A set of mutation and/or crossover and/or repair operators. Intelligent operators that are suitable for this particular domain will earn more credit. • A termination criterion for the evolutionary optimization which insures that you terminate with a valid solution for the subset21 problem if possible without…arrow_forward4.1-5 Use the following ideas to develop a nonrecursive, linear-time algorithm for the maximum-subarray problem. Start at the left end of the array, and progress toward the right, keeping track of the maximum subarray seen so far. Knowing a maximum subarray of A[1.. j], extend the answer to find a maximum subarray ending at in- dex j +1 by using the following observation: a maximum subarray of A[1 .. j + 1] is either a maximum subarray of A[1…. j] or a subarray A[i …. j + 1], for some 1 ≤ i ≤ j + 1. Determine a maximum subarray of the form A[i.. j + 1] in constant time based on knowing a maximum subarray ending at index j.arrow_forwardA[i][j] = 1 where i = j how do I translate this to c++ programing?It is for a two dimentional matrix, trying to print a diagonal with ones and rest zeros. ex. 1 0 0 0 1 0 0 0 1 ************************************* could you show me this as a pointer function?arrow_forward
- Question 5 Refer to the following graph and choose the option that reflects the row for node 3 of the D(2) matrix generated by the Floyd-Warshall Algorithm. If you are solving this programmatically, be careful about zero-based indices in most languages. The graph below has 1-based indexing. 1 O 32042-8 3 O-42 327620 -5 Infinity O 87 Infinity 9 0 Infinity O 0204-1-8 10 5 -8arrow_forward3. Simplify the following function using K-map: F(A,B,C,D)= E(1,5,6,7,9,11,12,13,14)+E (0,3,4,8)arrow_forwardThe ColumnChoice problem takes as input a two-dimensional array A[1..m, 1..n] of Os and 1s with m rows and n columns along with a non-negative integer k < n. It asks whether there exists a subset SC {1, ..., n} of k columns such that for each row i e {1,..., m} there exists at least one column j e S where A[i, j] = 1. Prove that ColumnChoice is NP- complete.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