Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CS 3250: Discrete Structures –

November 7, 2023

Information Technology University Discrete Structures, Fall 2023 - Sections


01/02/03/04 Homework Assignment #3 (maximum 60 points)
HW Philosophy:
The objective of HW in this class is to expand on lecture topics and examine them in more detail and more depth. Keep in
mind this is not supposed to be an easy task. Expect HWs to take time, require thinking and challenge you. The TAs and
instructors are not here to provide you with an answer or tell you whether your answer is correct while you are working on
the HW. We are here to help you to think more critically and at a higher level than when you started this class.

Important Instructions:
You must hand-write your answers (or you will lose 50% on the exercise) on the printed version of this homework only
within the provided space against each question. You only need to upload the scanned copy of the homework as
a single pdf file. There is no need to submit the hard-copy. There is limited space provided for each question so be as con-
cise as possible - anything written outside the bounded boxes will not be graded. You are responsible for the clarity and
readability of your answers. You can use different colors if you want to markup your solution but avoid using red color.

Questions:
Post any questions to Google classroom/Slack or ask your instructor or TAs during office hours.

Due Date:
Your completed homework in PDF file with exactly five pages (excluding this title page) must be submitted to the google
classroom before 5:30 pm, on Friday Nov 17th.
1 Fun with Matices [16 points]
Skills: matrix multiplication, sequences, algorithm analysis
There are (4) parts to this exercise (A, B, C, D).
We know that the classical way of multiplying two n×n matrices requires n3 number multiplications. In this problem, we
will explore if there is a way to reduce the number of multiplications for certain types of matrices.
An n×n matrix is called upper triangular if aij = 0 whenever i > j. Consider an algorithm of the matrix product such that
computing the product of two upper triangular matrices, the algorithm ignores those products in the computation that are
automatically equal to zero, i.e., at least one of the numbers being multiplied is zero.

(For example the classical way of multiplying the following matrices requires 8 multiplications, however, our new suggested
method
[ only requires
] 4 multiplications.
[ ]
a11 a12 b b
A= and B = 11 12 ,
0 a22 0 b22
No. of multiplication operations for A×B = 1 (when multiplying 1st row with 1st column) + 2 (when multiplying 1st row
with 2nd column) + 0 (2nd row with 1st column) + 1 (2nd row with 2nd column) = 4)
   
a11 a12 a13 b11 b12 b13
A. Let A =  0 a22 a23  and B =  0 b22 b23 
0 0 a33 0 0 b33
Compute the number of multiplication operations required for computing A×B.

B. Compute the number of multiplication operations required for multiplying two 4×4 upper triangular matrices.
C. By using previous parts, compute the number of multiplication operations required for multiplying two n×n upper-
triangular matrices?

D. By using part C, compute the asymptotic run time complexity of the algorithm in Θ notation.
2 : Theta of Functions [14 points]
Skills: functions, algorithm analysis
There are (2) parts to this exercise (A and B).
Let all the functions in the following question be from Z+ to Z+ .

A. Show that if f1 (x) and f2 (x) are both Θ(g(x)), then f1 (x) + f2 (x) is Θ(g(x)).

B. If f1 (x) and f2 (x) are both Θ(g(x)), is (f1 (x)−f2 (x)) also Θ(g(x))?
Either prove it or disapprove it by giving a counter-example.
3 : Analysis of a Mystery Algorithm [14 points]
Skills: algorithm analysis
There are (2) parts to this exercise (A and B).
Consider the following algorithm that searches for the integer x in the list a1 , a2 , ..., an , where a1 < a2 < ··· < an

i := 1 {i is the left endpoint of the search interval}


j := n {j is the right endpoint of the search interval}
while i < j
m := (i + j)/2
if x > am then i := m + 1
else j := m
if x = ai then location := i
else location := 0
return location {location is the subscript i of the term ai equal to x, or 0 if x is not found}

A. Compute the time complexity of the above-mentioned algorithm

B. Describe how the no. of comparisons used in the algorithm changes when the size of the list doubles from n to 2n.
4 : A Recurring Problem [16 points]
Skills: algorithm analysis, closed form, recurrence relation
There are (4) parts to this exercise (A, B, C, D). Consider the code segment below for all parts of this question:
WHILE (n > 0)
n = n div 2 //assume x div y is a method that returns the floor of x/y, i.e., ⌊x/y⌋
END WHILE

A. Create a table to show the value of n after each iteration (i.e., after the div statement and before the “END WHILE”
statement). You may assume n has an initial value of 33. The table is started below for you. You may not need all
the lines provided.

Iteration # Value of n
0 (before the first iteration) n=33

Table 1: Fill up the values of n

B. Define a recurrence relation for a(n) that represents the code segment’s work in terms of div operations. You may use
the floor function in your expression.

C. Find a closed form formula for a(n). In other words, solve your recurrence from Part B.
D. Prove that your formula from Part C is Θ(log n). You should provide specific values for c and n0 .

You might also like