Lecture: Analysis of Algorithm >> Matrix Chain Multiplication << Please write C code of the matrix chain multiplication (A1.A2.A3) by using dynamic programming as given below. Then calculate the algorithmic complexity. A1: 3x4 P0=3 P1=4 P2=2 P3=5 A2: 4x2 A3: 2x5
Q: 1. Please solve Traveling Salesman Problem (TSP) by using Ant Colony Optimization (ACO), Dynamic…
A: stage 1 Given a 2D grid tsp[][], where each column has the variety of good ways from that ordered…
Q: Matrix multiplication plays an important role in a number of applications. Two matrices can only be…
A: For addition and (m*p*n) for multiplication, the equations involved here are (m*p(n-1)). Both are…
Q: Q1) Gram-Schmidt Algorithm and QR decomposition ii) Write python code (without numpy) to decide if…
A: Gram Schmidt Algorithm Gram–Schmidt is a method for orthonormalizing a set of vectors in an inner…
Q: Suppose there are memory partitions of 200 KB, 600 KB, 300 KB, 400 KB and 700 KB. These partitions…
A: In given question, we have partitions and i have assumed partitions are fixed that means only one…
Q: An MxN matrix can be represented by a 1-D array of size M*N as follows: The elements at index 0…
A: Take the input : 1. r1, c1 and matrix of size r1 X c1. 2. r2, c2 and matrix of size r2 X c2. Output…
Q: 1.4. Considering the following system, check whether the system is safe or not. Using Bankers's…
A: Using banker's algorithm system safe or not
Q: 1. Consider two strings A and B. Take string A as your First name and Last name without space…
A: #include <iostream>#include<bits/stdc++.h>using namespace std; void lcsAlgo(char *A,…
Q: Let x = [3 26 8]' and y = [4 1 3 5) (NB. xand y should be column vectors). a. Add the sum of the…
A: Given:
Q: compiled MIPS code of the following C code: While (vector[j] != M)…
A: Here is an answer to your question.Hope it helps.
Q: a) Consider the following KB and Goal: KB: R1: Y = -R R2: -Y = RAM R3: -R v M = H R4: H = G Goal:…
A: Convert any of the above clauses that is not already in CNF to CNF. here in the question: R1, R2 can…
Q: An MxN matrix can be represented by a 1-D array of size M*N as follows: The elements at index 0…
A: 1. Take input of row r1, column c1 of matrix and matrix itself of size r1 X c1 2. Output matrix…
Q: IMPORTANT: For part 3, implement an iterative dynamic programming solution. You are driving from…
A: The required code in Python3 for the given problem: #function to find minimum toll def…
Q: Matrics_Multiplication (A, B) // n x m matrix A I тxрmatrixВ // n× p matrix C /| C=AB 1. Let C be a…
A: Task :- Write the time functions for given code snippet.
Q: We consider ptr as a 2D matrix. Whereas, number of rows would be fixed but make number of columns…
A: C++ is an extensively used Object oriented Programming language used to solve this once using…
Q: 9.17 A rectangular shelf is attached to a wall by two brackets 12 inches apart at points A and B, as…
A: Here is the answer:-
Q: Matrics_Multiplication (A, B) { Il nx m matrix A // m x p matrix B // nx p matrix C /l C= AB 1. Let…
A: Task :- find the time function for given code snippet.
Q: A- [11 I. Let A = 4 -2 4; B 51 31 -5 [5 -2 7 12 0 ; C %3D 3 -6 E = [1 3 5 76 8 0 9 4 2] a. Write a…
A: Command for the Following question as follows: a.) Multiplication of CD b.) arrange in Ascending…
Q: The following function represents the relation between C(x) (the cost of production in JOD) and x…
A: Hey there, i have read the question carefully and will be providing you the required solution based…
Q: Write a program to implement the following operations (the ones mentioned in comments) on Matrix.…
A: Sample Response: //C++ program of Matrix class#include<iostream>using namespace std;//matrix…
Q: to solve the integrl knapsack problem using dynamic programing. if we modify this procedure by…
A: To fill dp table we only need first row and first column and set to 0, and and in above same is…
Q: Example: If A = [3, 2, 5, 1] and B = [5,7, 2, 9], we can re-order A to [1,2,3, 5] and B to [2, 5,…
A: Hi there, Please find your solution below, I hope you would find my solution useful and helpful.…
Q: The following is MATLAB/Octave script that would solve a system of linear equations and requires an…
A: The corrected code is given in step 2.
Q: Provide a time complexity analysis for this code #include int main(){ //Required matrices and…
A: We have to determine the time complexity analysis for this code.
Q: IF X is a matrix with unknown dimensions, write a single MATLAB code to satisfy the following:…
A: Note : As per guidelines we are authorized to answer 3 sub parts of a question when multiple…
Q: We have N jobs and N workers to do these jobs. It is known at what cost each worker will do each job…
A: I have answered this question in step 2.
Q: 4) From X = [18 4 10 5 3 12 8 15]; find indices of the elements greater than 5 by using an…
A: Here, we have to provide programs for the above question. So, I am providing answers in python…
Q: Suppose there are memory partitions of 525 KB, 425 KB, 275 KB and 575 KB. These partitions are in…
A: solution :Using the given data :Using First fit =:
Q: 5.06-3 Bellman Ford Algorithm (3, part 3). Consider the grid network shown below. All links have a…
A: According to the information given:- We have to perform and find out the distance vector algorithm…
Q: One important application of the Longest Common Subsequences problem is to compare DNA sequences.…
A: In the longest common sequence problem given are two strings and the maximum length is to be…
Q: Suppose there are memory partitions of 455S KB, 305 KB, 355 KB and 655 KB. These partitions are in…
A: Here in this question we have given some free partition and some processes in some given order..so…
Q: Problem C. Incomplete sorting Input file: Output file: Time limit: Memory limit: standard input…
A: #include <iostream> using namespace std; int main(){ int n,m; int a[100][100]; //to…
Q: Assuming that you have a non-empty matrix C of size n x m (assume n > 2 and m > 2; assume n and m…
A: First, we will create a random matrix with the condition given in the question.(m > 2 and n >…
Q: Consider the following problem. INPUT: Positive integers r1, ··· , rn and c1, ··· , cn . OUTPUT: An…
A: If a Greedy Algorithm can solve a problem, then it generally becomes the best method to solve that…
Q: (B) ) What is the significance of using Bankers algorithm? Consider the following snapshot of a…
A: Given:
Q: 1. Consider the following flow diagram 40 x1 60 x3 x2 x4 30 x5 10 in which the flow into any vertex…
A: Answer
Q: [Problem 4] Consider a tree Y in which each node has at most 3 descendants, called A node, B node,…
A: The time complexity recurrence relation algorithm that has been generated with logarithmic equations…
Q: 1. Usc the polyfit function to fit the data for z = 15 to a first-order polynomial. 2. Create a…
A: clc clear all close all format long x=[10:10:100]; y=[23,45,60,82,111,140,167,198,200,220];…
Q: The following formulas shows how to calculate the (1,2) element and the (3,3) element of AB if A is…
A: PROGRAM: //Header file #include <stdio.h> //Defining the get_elements() function void…
Q: 1. When dealing with large dense symmetric matrix it is recommended that to either store upper right…
A: Given: 1. When dealing with large dense symmetric matrix it is recommendedthat to either store upper…
Q: 1.4. Considering the following system, check whether the system is safe or not. Using Bankers's…
A: Banker's algorithm: A system is said to be in safe state if processes are executed in a sequence in…
Q: iven an unlimited supply of coins of given denominations represented by an array D[1, . . . , n],…
A: The code below is in java .
Q: onsider the following elements 25,88,47,8,34,56,19,39 Perform bubblesort and merge sort on the above…
A: Program: #include<iostream>#include<conio.h>int main(){ int…
Q: 2 Consider the following KB: S1. ?∨? S2. ¬?∨¬? S3. ¬?∨? S4. ?∨¬? S5. ¬?∨? a) Use the…
A: In proof by resolution we include the negation of the conclusion in the knowledge Base (KB) and try…
Q: Question 1: Choose the correct option: 1-The most common way of repeating a sequence of statements…
A: 1) When there is repeated sequence of statement for specific time for loop is used. With a for loop…
Q: To solve the Integral Knapsack problem using dynamic programming, we generate a DP table (array V)…
A: 1. False. All columns of a DP table is in increasing order. since we are considering more elements…
Q: Please read the following piece of codes. Choose the correct choices. A = rand(4); B = ones(1,4);…
A: There are 4 options and there is possibility that any of four can be true So, let's explore each of…
Q: Consider the Fibonacci-like sequence defined by Fo = 0, F¡ = 1, F2 = 2, F,+3 = F, + F,+1 + F,+2 for…
A: It is defined as a interpreted, object-oriented, high-level programming language with dynamic…
Q: 1. /15 points] Consider the following function: Func1(A, n) * A is an array of integers 1 80; 2 for…
A: a)Worst case running time of Func1:The random number between 1 to “n” is assigned to “k” in the…
Q: d = (2 4 6 8] dl = [-3 -3 - 3] d2 = [-1 - 1] Create a matrix D by putting d on the main diagonal, dl…
A: Provided the Matlab Program in order to create a matrix D by putting d on the main diagonal, dl on…
Lecture: Analysis of
>> Matrix Chain Multiplication <<
Please write C code of the matrix chain multiplication (A1.A2.A3) by using dynamic
A1: 3x4 P0=3 P1=4 P2=2 P3=5
A2: 4x2
A3: 2x5
Step by step
Solved in 3 steps with 2 images
- Matrix multiplication plays an important role in a number of applications. Two matrices can only be multiplied if the number of columns of the fi rst matrix is equal to the number of rows in the second.Let’s assume we have an m × n matrix A and we want to multiply it by an n × p matrix B. We can express their product as an m × p matrix denoted by AB (or A ⋅ B). If we assign C = AB, and ci,j denotes the entry in C at position (i, j), then for each element i and j with 1 ≤ i ≤ m and 1 ≤ j ≤ p. Now we want to see if we can parallelize the computation of C. Assume that matrices are laid out in memory sequentially as follows: a1,1, a2,1, a3,1, a4,1, ..., etc.Assume that we are going to compute C on both a single core shared memory machine and a 4-core shared-memory machine. Compute the speedup we would expect to obtain on the 4-core machine, ignoring any memory issues.Repeat above Exercise, assuming that updates to C incur a cache miss due to false sharing when consecutive elements are in a…Computer Science Given 2 arrays X[1...n] and Y[1...m], provide time analysis in term n and m successor (X[1...n]. Y[1...m]): set sucessor[1...m] to infinitive for each 1<= i <=n: for each 1<= j <=m: if Y[j] < X[i] and X[i] < successor[j]: successor[j] = X[i] return successorGiven an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. You must find a solution with a memory complexity better than O(n2). Example 1: Input: matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8 Output: 13 Explanation: The elements in the matrix are [1,5,9,10,11,12,13,13,15], and the 8th smallest number is 13 Example 2: Input: matrix = [[-5]], k = 1 Output: -5
- Computer Science Given an N x N matrix M with binary entries i.e every entry is either 1 or 0. You are told that every row and every column is sorted in increasing order. You are required to output a pair (i,j) with 1 <= i and j <= n corresponding to the entry of the matrix satisfying Mij = 1 and Mrs = 0 for all 1 <= r <= i and 1 <= s <= j except for Mij Informally this includes the entry of M = 1 and is closest to the top left corner. for example: M = [ 0 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1] output is (2,3) or (1,4) M = [ 0 1 1 1 1 1 1 1 1] output could be (1,2) or (2,1) Design a divide and conquer algorithm, explain correctness and runtime of the algorithm.Correct and detailed answer will be Upvoted In C Question: How can the function, matrix_initialize_unopt, be optimized and rewritten with loop collapsing? n has a size of 3000 struct fn_args { int n; int *mem1; int *mem2; }; int check(int x, int y) { return x < y; } void set(int *mat, int i, int num) { mat[i] = num; } void matrix_initialize_unopt(struct fn_args *args) { int i, j, n; int *mat1, *mat2; n = args->n; mat1 = args->mem1; mat2 = args->mem2; for (i = 0; check(i, n); i++){ for (j = 0; check(j, n); j++){ set(mat1, i * n + j, i); set(mat2, i * n + j, i+1); } } }Write a report in which you discuss and compare your Gauss elimination and Gauss-Jordan programs. Gauss elimination #include<stdio.h> int main ( ) { int i, j, k, n; float A[20] [20], c, x [10], sum=0.0; printf("\Enter the order of matrix: "); Sacnf("%d,&n); prinf("\n Enter the elements of augmented matrix row-wise: \n\n"); for(i =1; i<=n; i++) { for(j=1; j<(n+1); j++) { printf("A[%d][%d] : ", i, j); scanf("%f", [i][j]); } } for(j=1; j<n; j++) { for(i=1; j<n; i++) { if(i>j) { c=A[i][j]/A[j][j]; for(k=1; k<=n+!; k++) { A[i][k] = A[i][k]-c*A[j][k]; } } } } x[n]= A[n] [n+1]/A[n][n]; for(i=n-1; i>=1; i--) { sum=0;…
- Provide a time complexity analysis for this code #include<stdio.h> int main(){//Required matrices and variablesint matrix1[6][6];int matrix2[6][6];int matrix3[6][6]; int i,j,k,n,m,l;//Reads number from userprintf("Enter a number : ");scanf("%d", &n);//Value for diagonalm = 2*n;//Temperary variable of 'n'l = n;//Creates matrix 1for(i = 0; i< 6; i++){k = l;for(j = 0; j<6; j++){if(j == (6-i-1))matrix1[i][j] = m;else if(j > (6-i-1))matrix1[i][j] = (k++ + 1);else matrix1[i][j] = k--;}l--;}//Prints matrix 1 for(i = 0; i< 6; i++){ printf("[");for(j = 0; j<6; j++)printf("%c ", (char)matrix1[i][j]);printf("]\n");}printf("\n\n");//Creates matrix 2l = n;for(i = 0; i<6 ; i++)for(j = 0; j<6; j++){if(i < 3 && j < 3)matrix2[i][j] = l;else if(i < 3 && j >= 3)matrix2[i][j] = l + 1;else if(i >= 3 && j < 3)matrix2[i][j] = l + 2;else matrix2[i][j] = l + 3;} //Prints matrix 2 for(i = 0; i< 6; i++){ printf("[");for(j = 0; j<6;…Question 2 Using the incomplete programming code given, complete the code using dynamic programming with memory function, to reproduce the results in the following Table 1. (C++) #include<iostream>using namespace std; // max knapsack capacity // *** WRITE YOUR CODE HERE ***// num of items // *** WRITE YOUR CODE HERE ***// weight of each item // *** WRITE YOUR CODE HERE ***// value of each item // *** WRITE YOUR CODE HERE ***// variable for dynamic programming matrix // *** WRITE YOUR CODE HERE *** //==========================================// Dynamic programming function: recursive// ========================================= // ALGORITHM F(i,j) // int value // if F[i,j] is not filled yet (-1): // (start with j = W, i = n) // if capacity j < current item's weight w[i]: // value = recall F(i-1, j) // else: // we can include current item,…For the problems given below, determine whether it is more efficient to use a divide and conquer strategy or a dynamic programming strategy, explain your reason. Give the recursion formula for each. (3*4=12) Find the average of a given set of unsorted numbers. Find whether there is a subset of integers in a given set that adds up to 8 Given a set of numbers, can they set be partitioned into two groups such that the sum of each group is equal; i.e 1,5,11,5 can be partitioned to 1,5,5 and 11
- Here is my homwork problem: Problem 3. In the following array of C-strings char* names[] = { “DEF”, “BBB” , “EE”, “AA”, “CAB”, “AAA”, “DDDD”, “BBB”, “FFFF”, “CCCC”}; char* favoriteName= “AA”; Use generic binary search both iterative and recursive to find the favoriteName in the names array. If char names[][5] = { “DEF”, “BBB” , “EE”, “AA”, “CAB”, “AAA”, “DDDD”, “BBB”, “FFFF”, “CCCC”}; char* favoriteName= “AA”; What will be your call for search and explain any difference? Now dynamically allocate char**names and copy with all the names above and dynamically allocate char*favoriteName and copy with “AA” Make a call for the search _______________ *I am using C programming language for this problem* I made some code with iterative and recursive binary search functions, but only the iterative one finds the favorite name. Can you let me know what is wrong with my recursive binary search function as well as how to get it to work with the double array names[][5]? Here is my code:…Question: Based on the C code given below, matrix_initialize_unopt is an unoptimized version of matrix initialiaztion and matrix_initialize_opt is an optimized version of matrix initialization. How would matrix_initialize_opt be written? #define X 500 #define Y 12 #define Z 8 struct fn_args { int n; int *mem1; int *mem2; }; void set(int *mat, int i, int num) { mat[i] = num; } void matrix_initialize_unopt(struct fn_args *args) { int i, j, n; int *mat1, *mat2; n = args->n; mat1 = args->mem1; mat2 = args->mem2; for (i = 0; check(i, n); i++){ for (j = 0; check(j, n); j++){ set(mat1, i * n + j, i); set(mat2, i * n + j, i+1); } } } void matrix_initialize_opt(struct fn_args *args) { // XXX: optimized implementation goes here }Consider the following problem. INPUT: Positive integers r1, ··· , rn and c1, ··· , cn . OUTPUT: An n by n matrix A with 0/1 entries such that for all i the sum of the ith row in A is ri and the sum of the ith column in A is ci , if such a matrix exists. Think of the problem this way. You want to put pawns on an n by n chessboard so that the ith row has ri pawns and the ith column has ci pawns. Consider the following greedy algorithm that constructs A row by row. Assume that the first i-1 rows have been constructed. Let aj be the number of 10 s in the jth column in the first i-1 rows. Now the ri columns with with maximum cj -aj are assigned 1’s in row i, and the rest of the columns are assigned 00 s. That is, the columns that still needs the most 1’s are given 1’s. Formally prove that this algorithm is correct using an exchange argument.