0% found this document useful (0 votes)
70 views

Lab 5

This document describes Lab Assignment 5 for the course COMP 301 Analysis of Algorithms taught in Fall 2019. The assignment involves implementing algorithms for matrix multiplication in Java. Students are asked to implement a standard iterative matrix multiplication algorithm and a recursive divide-and-conquer algorithm. For each algorithm, students must verify the method works correctly on sample matrices, run it on randomly generated 16x16 and 64x64 matrices and report the runtime, and compare the scaling of runtime between the smaller and larger examples. Students should submit their Java code and solution document with their name and surname as the file name.

Uploaded by

Hatice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Lab 5

This document describes Lab Assignment 5 for the course COMP 301 Analysis of Algorithms taught in Fall 2019. The assignment involves implementing algorithms for matrix multiplication in Java. Students are asked to implement a standard iterative matrix multiplication algorithm and a recursive divide-and-conquer algorithm. For each algorithm, students must verify the method works correctly on sample matrices, run it on randomly generated 16x16 and 64x64 matrices and report the runtime, and compare the scaling of runtime between the smaller and larger examples. Students should submit their Java code and solution document with their name and surname as the file name.

Uploaded by

Hatice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

COMP

301 Analysis of Algorithms, Fall 2019


Instructor: Zafer Aydın
Lab Assignment 5

Introduction

In this lab you will implement algorithms for matrix multiplication. Submit your
answers to the questions below in a text file (e.g. Word document). Name your file in
name_surname.docx format. Submit your solution document and Java codes as a
folder in name_surname format to TA through a USB flash disk.

You can use the code templates in matrix.java in this lab.

Problem Statement
Given two matrices 𝐴 and 𝐵 each with size 𝑛 × 𝑛 compute 𝐶 = 𝐴. 𝐵, which is the product
of 𝐴 and 𝐵.

Assignment

1. (a) Implement the standard matrix multplication algorithm given below in Java. You
can use 2D arrays to represent matrices. You can define array 𝐶 outside of your method
and pass it as input to that method. You can use the code template in matrix.java.


1 3 6 8
(b) Verify that your method works correctly for 𝐴 = ( -, 𝐵 = ( -, where 𝐶 should
7 5 4 2
18 14
be = ( -.
62 66

(c) Randomly generate 𝐴 and 𝐵 such that their sizes are 16 by 16 and elements are
random integers from 0 to 99. Compue 𝐶 = 𝐴. 𝐵 using the method you implemented in
part (a). Report the time it takes to compute 𝐶.

COMP 301 Analysis of Algorithms, Fall 2019
Instructor: Zafer Aydın
Lab Assignment 5

(d) Repeat part (c) this time for arrays of size 64 by 64. Report the time it takes to
compute 𝐶 = 𝐴. 𝐵. How much did the time increase as compared to part (c)?

2. (a) Implement the recursive version of matrix multiplication algorithm given below
that uses the divide and conquer strategy. You can define array 𝐶 outside of your
method and pass it as input to that method. Use indexing to partitioning the matrices
into four sub-blocks instead of defining new arrays each time. You can use the code
template in matrix.java.



1 3 6 8
(b) Verify that your method works correctly for 𝐴 = ( -, 𝐵 = ( -, where 𝐶 should
7 5 4 2
18 14
be = ( -.
62 66
(c) Use the same random matrix as in question 1(c) and compute 𝐶 = 𝐴. 𝐵 using the
method implemented in question 2(a). Report the time it takes to compute 𝐶.

(d) Repeat part (c) this time for arrays of size 64 by 64. Report the time it takes to
compute 𝐶 = 𝐴. 𝐵. How much did the time increase as compared to part (c)?

You might also like