C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
In python
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
Similar questions
- The goal of this problem is to walk from cell (0, 0) to cell (m, n) of a two-dimensional array. Each step must be either to the right or downward. So you can step from cell (1, 1) to cell (1, 2) or (2, 1). but not from (1, 1) to (0, 1) or (1,0). You are given a toll matrix, where each cell contains a toll that must be paid upon entry into that cell. The goal is to make it from cell (0, 0) to cell (m, n) while paying the smallest possible total toll. Does a greedy algorithm work? Think it out. Write a dynamic programming algorithm that finds the minimum possible total toll. It does not need to do reconstruction and say how to achieve that total toll.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_forwardSuppose that you are given an m X n integer-valued matrix, with each entry denoting the amount of dollars you earn by visiting that entry. You start from the upper-left corner. At each move you can either go down or go right by one step. Design an efficient algorithm that finds the maximum number of dollars you can earn by traversing the matrix.arrow_forward
- Imagine you have a square matrix, where each cell (pixel) is either black or white. Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels.arrow_forwardCompute the code that return the matrix M = AT A for a given matrix A - the superscript T denoted the transpose. I have started the code for you, which gets the dimension of the matrix, and creates the zero matrix of the correct size. I have also provided some of the loops involved. : # perform and return the multiplication of $A^TA$ import numpy as np def multiply_At_A(A): # these lines set up the correct dimensions #of the returned matrix. # the matrix A is of dimension diml dim2 - # the matrix A^T (transpose of A) is dim2 x diml # the matrix (A^T A) is of dimension dim2 x dim2 dim1 = A. shape [0] dim2 = A. shape [1] matrix = np.zeros([dim2, dim2]) for i in range (dim2): for j in range (dim2): # complete the final loop to #compute matrix[i,j] # YOUR CODE HERE return matrixarrow_forwardHi I need help writing a java program that implements Prim's algorithm. The imput of the program is given by the scanner with an undirected graph. First input line is the number of vertices, second input is the number of undirected edges. After that the input is a matrix of 3 by the number of undirected edges. The matrix firt 2 column contain the end points and the third column contains the weight . The output of the program is an integer representing the sum of all the edges that make up the minimum spanning tre. I have attach a picture for farther details. THANKSarrow_forward
- In Python, generate a random matrix A with 100 entries each of which is an independent numberpseudo-randomly drawn (uniformly) from the interval (0, 1). Let B = A + AT . Use Python to calculatethe diagonal matrix D with the same eigenvalues as B. Then use the QR method to block-diagonalize Bover R. Do at least 100 steps of the QR switching. You should end up with a matrix E which is differentthan D. Answer the question of why.arrow_forwardImplement a program that will populate a 6x5 matrix with randomly generated integers from 100 to 500. (1) print your matrix in a table form. (2) modify your code to multiply all odd numbers by 2 and print the matrix. Sample run: Initial Matrix: 145 | 437 | 222 | 101 | 100 | 278 500 | 190 | 415 | 288 | 466 322 377 | 240 | 451 | 331 186 186 432 102 | 106 | 105 249 248 | 117 | 213 | 499 488 355 | 266 | 396 | New Matrix: 290 | 874 | 222 | 101 | 100 | 278 500 | 190 | 830 288 | 466 322 754 | 240 | 902 | 662 186 432 | 102 | 106 | 210| 498 248 | 234 | 426 | 998 488 710 | 266 | 396 |arrow_forwardIn java figuring out to solve a matrix see image belowarrow_forward
- A matrix is a rectangle of numbers in rows and columns. A 1xN matrix has one row and N columns. An NxN matrix has N rows and N columns. Multiplying a 1xN matrix A and an NxN matrix B produces a 1xN matrix C. To determine the Nth element of C multiply each element of A by each element of the Nth column of B and sum the results. Helpful information can be found at matrix multiplication. Write a program that reads a 1xN matrix A and an NxN matrix B from input and outputs the 1xN matrix product, C. The first integer input is N, followed by one row of N integers for matrix A and then N rows of N integers for matrix B. N can be of any size >= 2. For coding simplicity, follow each output integer by a space, even the last one. The output ends with a newline. Ex: If the input is: 2 2 3 1 2 3 4 A contains 2 and 3, the first row of B contains 1 and 2, and the second row of B contains 3 and 4. The first element of C is (2 * 1) + (3 * 3), and the second element of C is (2 * 2) + (3 * 4). The…arrow_forwardCreate a row vector of 1's that has 4 rows. Now Create a column vector of 1's that has 4 columns. Using matrix multiplication, multiply both of these to get a 4x4 matrix and display the resulting matrix. Using matlab, do this. Please answer it correctly and don’t copy from anywhere otherwise it will be downvoted.arrow_forwardIN PYTHON! Given an n×n matrix A and n×1 right-hand side b, write a function that carries out q iterations of the Gauss elimination outer loop (without pivoting), where q is an integer between 1 and n, and returns the resulting augmented matrix with all below-diagonal elements transformed to zero in the left-most q columns. ##The code format given below may help # def gaussq (A, b, q): '''Apply Gauss elimination (without pivoting) to first q columns of a given linear system Inputs: A, coefficient matrix, size n by n b, vector of constants, n by 1 q, number of columns to apply Gauss elimination to, an integer between 1 and n Output: Aa, augmented matrix with all below-diagonal elements transformed to zero in the left-most q columns, n by n+1 #to check the workarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning