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 25.1, Problem 8E
Program Plan Intro
To modify the fastest all pair shortest path
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Generate random matrices of size n ×n where n = 100, 200, . . . , 1000.Also generate a random b ∈ Rnfor each case. Each number must beof the form m.dddd (Example : 4.5444) which means it has 5 Signif-icant digits in total. Perform Gaussian elimination with and withoutpartial pivoting for each n value (10 cases) above. Report the numberof additions, divisions and multiplications for each case in the form ofa table. No need of the code and the matrices / vectors.
Consider 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…
Get the time complexity function from the pseudocode for the addition of the 2 matrices below, and prove whether the big-oh is O(n^2) so that it satisfies the rule f(n) <= c g(n);
/ add two matricesfor(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++)matrix2[i][j] = matrix1[i][j] + matrix2[i][j];}// display the resultfor(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++){printf("%d ", matrix2[i][j]);}printf("\n");}
Chapter 25 Solutions
Introduction to Algorithms
Ch. 25.1 - Prob. 1ECh. 25.1 - Prob. 2ECh. 25.1 - Prob. 3ECh. 25.1 - Prob. 4ECh. 25.1 - Prob. 5ECh. 25.1 - Prob. 6ECh. 25.1 - Prob. 7ECh. 25.1 - Prob. 8ECh. 25.1 - Prob. 9ECh. 25.1 - Prob. 10E
Ch. 25.2 - Prob. 1ECh. 25.2 - Prob. 2ECh. 25.2 - Prob. 3ECh. 25.2 - Prob. 4ECh. 25.2 - Prob. 5ECh. 25.2 - Prob. 6ECh. 25.2 - Prob. 7ECh. 25.2 - Prob. 8ECh. 25.2 - Prob. 9ECh. 25.3 - Prob. 1ECh. 25.3 - Prob. 2ECh. 25.3 - Prob. 3ECh. 25.3 - Prob. 4ECh. 25.3 - Prob. 5ECh. 25.3 - Prob. 6ECh. 25 - Prob. 1PCh. 25 - Prob. 2P
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 two sorted arrays A and B, design a linear (O(IA|+|B|)) time algorithm for computing the set C containing elements that are in A or B, but not in both. That is, C = (AU B) \ (AN B). You can assume that elements in A have different values and elements in B also have different values. Please state the steps of your algorithm clearly, prove that it is correct, and analyze its running time. Pls give the code in C++, or very clear steps of the algorithmarrow_forwardCreate a 3-by-3 matrix. A = [1 7 3; 2 9 12; 5 22 7]; Calculate the right eigenvectors, V, the eigenvalues, D, and the left eigenvectors, W. [V,D,W] eig(A) %3!arrow_forwardLet m be a matrix with n rows and n columns whose entries are either 1 or 0. recall that the element of m on row i and column j is denoted by mij . the diagonal entries of m are {mii} for 1 ≤ i ≤ n. We call M permutable if it is possible to swap some of the rows and some of columns so that all diagonal entries are 1. Design a polynomial time algorithm that decides whether a binary matrix M is permutable or not. Note that we can swap any two rows or two columns. Also, the order in which these swaps are done is not important.arrow_forward
- Give a MPI program segment to convert a n-by-n matrix distributed on a n-by-n 2D mesh such that allits rows and columns get sorted in ascending order. Show only the iterative loop. Only communicationsallowed are to the four direct neighbors. (Hint: You may employ a variant of odd-even transpositionsort, but the whole matrix does not need to be sorted.)arrow_forwardYou are given an unsorted array A[1, ..., n].We know that the maximum (or minimum) element in the array can be found in (n-1) comparisons.Write an algorithm that finds both the maximum and the minimum element in the array in ~(3n/2) comparisons, i.e., (3n/2) + THETA(1) comparisons.arrow_forwardWe are given a code symmetry, that takes an n x n matrix as its argument. It returns true if the matrix is symmetric and false if it is not. The run time of the code is calculated by counting how many times the /= comparison is executed. procedure symmetry(M) for x:=1 to (n-1) for y:=(i+1) to n if mxy /= myx then return false else return true (a) Calculate the best case run time for symmetry (will be a number). (b) Calculate the worst case run time for symmetry (will be a polynomial in n, it will be helpful to draw matrices of different sizes and compare the number of comparisons to find a pattern). (c) Determine the worst case run time in big O notation (d) Using the following definition of big O notation, prove the answer to (c) Definition: Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x) is O(g(x)) if there are constants C and k such that whenever x > k. [This is…arrow_forward
- Get the time complexity function from the pseudocode for the addition of the 2 matrices below, and prove whether the big-oh is O(n^2) so that it satisfies the rule f(n) <= c g(n) for(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++)matrix2[i][j] = matrix1[i][j] + matrix2[i][j];} for(i = 0 ; i < rows; i++){for(j = 0; j < columns; j++){printf("%d ", matrix2[i][j]);}printf("\n");}arrow_forwardGiven an array of numbers X₁ = {x₁, x2, ..., n } an exchanged pair in X is a pair xi, xj such that i x¡ . Note that an element x; can be part of up to n - 1 exchanged pairs, and that the maximal possible number of exchanged pairs in X is n(n − 1)/2, which is achieved if the array is sorted in descending order. Give a divide-and-conquer algorithm that counts the number of exchanged pairs in X in O(nlogn) time.arrow_forwardWrite an algorithm called MatrixRowMultiple(A[0…n – 1, 0… n – 1]) which takes an n x n matrix A and outputs if true, if each element in the first row is twice the value of the corresponding element of row 2. Otherwise, it returns false. (ii) Determine the worst case complexity of the algorithm which you have developed.arrow_forward
- Write a program that can inverse a matrix by using an approach to find its minor, cofactor and adjugate matrix. Test your program with the given matrix ?arrow_forwardTo have random-access lookup, a grid should have a scheme for numbering the tiles.For example, a square grid has rows and columns, which give a natural numberingfor the tiles. Devise schemes for triangular and hexagonal grids. Use the numberingscheme to define a rule for determining the neighbourhood (i.e. adjacent tiles) of agiven tile in the grid. For example, if we have a four-connected square grid, wherethe indices are i for rows and j for columns, the neighbourhood of tile i, j can bedefined asneighbourhood(i, j) = {i ± 1, j,i, j ± 1}arrow_forwardRecall that np.dot (a,b) performs a matrix multiplication on a and b, whereas ab performs an element-wise multiplication. Consider the two following random arrays "a" and "b": a = np.random.randn (12288, 150) a.shape (12288, 150) b = np.random.randn(150, 45) b.shape= (150, 45) c = np.dot (a, b) What is the shape of c?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