EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Question
Chapter 2, Problem 9E
Program Plan Intro
Matrix operations:
The conditions for matrix operations are shown below:
Matrix Addition:
- Matrices must have same order.
- Corresponding elements are added together
- Matrix addition operation is commutative
- Matrix addition operation is associative
Matrix Multiplication:
- The column count of first matrix and row count of second matrix should be equal.
- The row count in first matrix by column count in second matrix denotes order of matrix.
- An element in the product matrix is obtained by taking sum of products obtained from row “i” of first matrix and column “j” of second matrix.
- To obtain each element of product matrix “n” number of products are been summed.
Matrix transposition:
- A matrix formed by converting all rows of a matrix into columns and vice-versa.
- The transpose for A is written as AT.
- The transpose of transpose matrix is original matrix.
- The matrix transpose exchanges an element at row “r” and column “c” with an element at row “c” and column “r”.
Explanation of Solution
Matrix Multiplication:
- Here, all three for loops are executing “n” times.
- All three counters, “i”, “j”, and “k” in algorithm for matrix multiplication are independent of each other...
Explanation of Solution
Matrix transposition:
- Here, the external for loop is executing “n-1” times.
- The internal for loop is executing “n-1” times.
- To transpose a matrix “n2” assignments are needed...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Sparse matrix-vector multiplication in Python is similar to numpy.dot operation,
however the provided @ operator is used. Let us consider multiplying a 5 by 5
sparse matrix with a 5 by 3 sparse matrix shown below.
01000
00010
10001
10000
01000
100
001
x 000
010
100
The Python code to implement multiplication of these two sparse matrices
Write a JAVA program to add two matrix using pointers. JAVA program to input two matrix from user and find sum of both matrices using dynamic array.Example InputInput matrix1: 123456789Input matrix2: 987654321 OutputSum of both matrices:10 10 1010 10 1010 10 10
Using Java
Modify the program 1 to compute the multiplication of two vectors with the sizes mx1 and 1xn. The result is a matrix mxn computed as follows: the element on the position r and c in the product will be equal with m1[r][0]*m2[0][c].
Chapter 2 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
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
- can this code be changed to perform the same thing, but it is a square matrix in cpp void sort(int arr[], int n){for (int i=0; i<n; i++){if (arr[i]&1){arr[i]*=-1;}}sort(arr,arr+n); for (int i=0; i<n; i++){if (arr[i]&1){arr[i]*=-1;}}}int main{int arr[]={79,10,89,66,67};int n=sizeof(arr)/sizeof(int);sort(arr,n);cout<<"\nThe numbers: ";for(int i=0; i<n; i++){cout<<arr[i]<<" ";}cout<<endl;cout<<"\nEven numbers in ascending order: ";for (int i=0; i<n; i++){if(arr[i]%2==0){cout <<arr[i]<<" ";}}cout<<endl;cout<<"Odd numbers in descending order: ";for (int i=0; i<n; i++){if(arr[i]%2!=0){cout<<arr[i]<<" ";}}}arrow_forwardWrite a java program to take the elements of n xn matrix from the user and print it's transpose matrixarrow_forwardGet 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");}arrow_forward
- In the following recursive function, A is the input array with size n. RANDOM(n) produces a uniformly random number between 1 and n. 1: function RECALG2(A, n) if n < 5 then return A[1] 2: for i + 1 to | yn] do A[i] <- A[i] – A[[i * /n]] s– A[1] k + RANDOM(n) if k < 2n/3 then s+ s+RECALG2(A,n) 3: 4: 5: 6: 7: 8: return s (a) Determine its worst case asymptotic time complexity. (b) Using probabilistic analysis, determine its average asymptotic time complexity.arrow_forward) Consider an n x n array ARR stored in memory consisting of 0’s and 1’s such that, in a row of ARR, all 0’s comes before any of 1’s in the row. Write an algorithm having complexity O(n), if exists, that finds the row that contains the most 0’s. Step by step explain r algorithm with an illustrative example. 6arrow_forwardMerge sort is an efficient sorting algorithm with a time complexity of O(n log n). This means that as the number of elements (chocolates or students) increases significantly, the efficiency of merge sort remains relatively stable compared to other sorting algorithms. Merge sort achieves this efficiency by recursively dividing the input array into smaller sub-arrays, sorting them individually, and then merging them back together. The efficiency of merge sort is primarily determined by its time complexity, which is , where n is the number of elements in the array. This time complexity indicates that the time taken by merge sort grows logarithmically with the size of the input array. Therefore, even as the number of chocolates or students increases significantly, merge sort maintains its relatively efficient performance. Regarding the distribution of a given set of x to y using iterative and recursive functions, the complexity analysis depends on the specific implementation of each…arrow_forward
- Given an array arr[] of N non-negative integers representing the height of blocks. If width of each block is 1, compute how much water can be trapped between the blocks during the rainy season. Example 1: Input: N = 6 arr[] Output: 10 = {3,0,0,2,0,4}arrow_forwardGet the time complexity function from the pseudocode for adding 2 matrices below // add two matrices for(i = 0; i< rows; i++){ for(j = 0; j< columns; j++) matrix2[i][j] = matrix1[i][j] + matrix2[i][j]; } // display the result for(i = 0; i< rows; i++){ for(j = 0; j< columns; j++){ printf("%d ", matrix2[i][j]); } printf("\n"); }arrow_forwardGet the time complexity function from the pseudocode for adding 2 matrices below // 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");}arrow_forward
- Find a (generating matrix) for the following code and find the parameters [n, k, d], code. C = {10101010, 1100, 11110000,01100110,00111100}arrow_forwardSolve the following recursive function and describe it in terms of Big-O using expansion. T(n) = T(n-1)+1 T(0) = 0arrow_forwardDetermind the complexity of the following implementations of the algorithms for adding, multiplying, and transposing n x n matricesarrow_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
Binary Numbers and Base Systems as Fast as Possible; Author: Techquikie;https://www.youtube.com/watch?v=LpuPe81bc2w;License: Standard YouTube License, CC-BY
Binary Number System; Author: Neso Academy;https://www.youtube.com/watch?v=w7ZLvYAi6pY;License: Standard Youtube License