Question

In: Computer Science

Question 3.[10 pt] As indicated in the course book and discussed in the class extensively, there...

Question 3.[10 pt]

As indicated in the course book and discussed in the class extensively, there is

generally an efficiency trade-off among execution time, memory usage and communication

overhead for a given algorithm. Please give at least two examples where such a trade-off occurs.

For example, can you give an algorithm example wherein more storage permits faster execution,

or vice versa? Similarly, can you exemplify another algorithm wherein there are trade-offs

among communication and/or memory and/or execution time?

Algorithm Trade-off Example Brief Discussion 1 [5pt]:

Write a paragraph here by explaining the

name of the algorithm and how the performance trade-off.

Algorithm Trade-off Example Brief Discussion 2 [5pt]:

Write a paragraph here by explaining the

5

name of the algorithm and how the performance trade-off occurs.

Question 4. [30 pt]

In this exercise, we start getting familiar withtwo-dimensional arrays, i.e., a

matrix (remember that matrices are nothing but 2D arrays).Matrices are one of the most

fundamental data structures, and they are used in every aspect of Information Technology

including but not limited to AI, cyber-security and software engineering. The most basic

definition of a matrix is here:

https://www.mathsisfun.com/algebra/matrix-introduction.html

Specifically, as an example was given in the above link for 2x2 matrix, you will perform the

most basic arithmetic operation on a matrix,

adding two matrices entry-wise

. Please see the link

below and read

“Entrywise Sum”.

Each corresponding cell in a matrix is added and put into 3

rd

target matrix.

https://en.wikipedia.org/wiki/Matrix_addition

Write a program named “

hw2.py

” that will add two matrices entry-wise. The matrix dimension

is fixed and 5x5 for this exercise. Your program should print an error if the dimensions of the

two matrices are different. In this case, print a message stating that the matrix dimensions does

not match. There are two matrices to be added. One is shown in “hw2-m1.txt”

5 2 0 3 4

2 4 1 1 0

3 0 5 6 1

0 2 6 0 1

4 1 1 0 0

6

The other one is shown in “hw2-m2.txt”

2 0 4 0 1

2 2 1 0 5

0 0 1 0 3

2 1 0 4 1

0 0 4 0 1

Read these two matrices from “.txt” files, and use your own codes to add them,

donot use built-

in functions

. Finally, you should print the result on the screen as

The result is:

7 2 4 3 5

4 6 2 1 5

3 0 6 6 4

2 3 6 4 2

4 1 5 0 1

Solutions

Expert Solution

If you have any doubts, please give me comment...

mat1 = []

fp = open("hw2-m1.txt")

for line in fp.readlines():

    mat1.append([int(x) for x in line.split()])

fp.close()

mat2 = []

fp = open("hw2-m2.txt")

for line in fp.readlines():

    mat2.append([int(x) for x in line.split()])

fp.close()

isValid = True

if len(mat1)==len(mat2):

    for row in range(len(mat1)):

        if len(mat1[row])!=len(mat2[row]):

            isValid = False

            break

if not isValid:

    print("the matrix dimensions does not match")

else:

    result = []

    for row in range(len(mat1)):

        result.append([mat1[row][col]+mat2[row][col] for col in range(len(mat1[row]))])

    print("The result is:")

    for row in result:

        for col in row:

            print(col, end=' ')

        print()



Related Solutions

This question is about the class Set, as discussed in the lectures. It represents a finite...
This question is about the class Set, as discussed in the lectures. It represents a finite set of int’s. Relevant parts of Set are shown below. The integer count holds the number of elements in the Set. The array elements holds the elements themselves. The class Set also has public methods addElement, equals, isIn, and toString. They are defined as in the lectures, and you can use them if you need to. class Set   {     private int count;     private int...
Create “New Class…” named Book to store the details of a book Declare 3 fields for...
Create “New Class…” named Book to store the details of a book Declare 3 fields for the details of the book: field named author of type String field named title of type String field named callNumber of type String Add overloaded constructors with the following headers and make sure each constructor has only 1 statement in the body that makes an internal method call to setBookDetails: public Book(String author, String title, String callNumber) public Book(String author, String title) HINT: Initialize...
This is a Discussion Board Question for Pharmacology Class. The book is Pharmacology Principles and Applications,...
This is a Discussion Board Question for Pharmacology Class. The book is Pharmacology Principles and Applications, 3rd Edition, by Eugenia Fulcher, Robert Fulcher, and Kathy Debeansky-Soto. Please explain how hormones secreted by anterior and posterior pituitary glands affect diseases and their treatment?
Question #3: What is the purpose of absorbing the Pt serum with Reiter organisms first prior...
Question #3: What is the purpose of absorbing the Pt serum with Reiter organisms first prior to testing? Question #4: What specimen is used to test for neurosyphilis?
Question 3: A freshman class consists of 6 students, 3 of which are girls. The class...
Question 3: A freshman class consists of 6 students, 3 of which are girls. The class needs to select a committee of 2 to represent them in the student senate. (1) Write the sample space of this experiment. (2) Calculate the probability of a committee of two boys. (3) Calculate the probability of one boy and one girl.
Weber discussed the 3 Ps of Social Class- Property, Prestige and Power. Define these and how...
Weber discussed the 3 Ps of Social Class- Property, Prestige and Power. Define these and how they are related to life outcomes and determinants of social class. Provide an example which illustrates the 3 Ps.
Inflation (show all work) (10 Marks) Name the two measurements of inflation discussed in class               ...
Inflation (show all work) Name the two measurements of inflation discussed in class                1)                2) Using 2012 as the base year (=100) calculate the inflation rate for 2013 Year Slices of Pizza Price per Slice Cans of Pepsi Price per Can 2012 40 10 10 20 2013 60 12 20 24 What does currency depreciation mean? Who is the only legal issuer of bank notes and coins in Canada? A responsible government believes that the inflation rate is...
The name of the course Physics of Measurements Question 3 a) what is the Rejection of...
The name of the course Physics of Measurements Question 3 a) what is the Rejection of Data ? b) What is the Weighted Averages and how is it calculated ?
Consider the data from Ms. Lloyd PE class for the 10 students in the course. Push...
Consider the data from Ms. Lloyd PE class for the 10 students in the course. Push up Sit up 13 18 10 15 10 20 23 40 20 30 28 35 27 32 40 50 42 50 15 25 Use the data for the two variables to create the scatterplot and draw the line. Then, find the linear regression equation. Discuss the topic about regression covered the slope, intercept, and the best point on the line that demonstrates that your...
Qu 3. In class, we discussed two measures for theory of mind: the Sally/Ann task, and...
Qu 3. In class, we discussed two measures for theory of mind: the Sally/Ann task, and the mountain task. Choose one of these two measures, and describe: (a) the procedure used to carry out the task (b) the possible outcomes (i.e. the possible responses the child might make), and how those outcomes are interpreted don't copy from the internet
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT