You are on page 1of 25

Details:

Course No: CSE 2202


Course Title: Sessional based On CSE 2201
Date of Experiment:
Date of Submission:
Module No: 04

Submitted To:

RIZOAN TOUFIQ
ASSISTANT PROFESSOR
Department of Computer Science & Engineering
Rajshahi University of Engineering & Technology

Submitted By:

Name: Fahim Ahmed


Roll: 1903178
Section: C
Page |1

No Items Page

1 K-th Smallest index : 2


(selection)
Machine Configuration
2 Completion of Table-1 3
3 Plotting Bar Graph 4
4 Plotting Line Graph 5
5 Time complexity and Analysis 6-7
6 Matrix Multiplication: 8
Machine Configuration
7 Completion of Table-2 9
8 Plotting Graph 10
9 Plotting Bar Graph 11
10 Time complexity and Analysis 12-14
Page |2

K-th Smallest index (Selection):



Machine Configuration:
Machine used for this lab experiment
Page |3

Table -1:
Select 1 Select 1 Select 2 Select 2

No of Data Average Worst Case Average Worst Case


Case Case
10000 1971 1189 2348 2560

20000 2587 3812 4598 4088

30000 4017 4982 4901 4345

40000 7819 9157 5901 5169

*NB: time given in microseconds.









Page |4

Plotting Graph:

Bar Graph:

Comparison Graph
10000

9000

8000

7000

6000

5000

4000

3000

2000

1000

0
10000 20000 30000 40000

Select 1 (Avg) Select 1 (Wc) Select 2 (Avg) Select 2 (Wc)















Page |5

Line Graph:

Comparison Graph
10000

9000

8000

7000

6000

5000

4000

3000

2000

1000

0
10000 20000 30000 40000

Select 1 (Avg) Select 1 (Wc) Select 2 (Avg) Select 2 (Wc)
















Page |6

Time Complexity and Analysis:



Select 1:
Suppose, TAvgk (n) be the average time for finding , the kth-smallest element
in array a from index 1.. to n. (i.e.: a [1: n]). Then,

TAvgk (n) and R (n) is defined as:



TAvg (n) is the average computing time of Select1. Where it can be shown
that , TAvg ≤ R(n). Similarly, , TAvg (n)= O(n).

For space needed by Select1 is O(1).













Page |7

Select 2:
Obtaining the recurrence relation, we have: 




Where c1 is a suitable constant (integer). Additional space is needed for
the recursion stack call.

So we get,

T(n) ≤ cn/5 + c(7n/10 + 6) + O(n)


≤ cn/5 + c + 7cn/10 + 6c + O(n)
≤ 9cn/10 + 7c + O(n)
≤ c n,

Resulting, T(n) = 0(n)


Analysis:
Given the time complexity, we see that both the algorithms have an average
case complexity O(n). But select1 has a worst-case complexity of O(n2 ). So,
select 2 performs the task to reduce the complexity of the worst case to O(n).
For better performance, the pivot point was taken randomly for the average
time complexity





Page |8


Matrix Multiplication:

Machine Configuration:
Machine used for this lab experiment













Page |9

Table -2:
Required Time
 

Dimension Divide and Conquer Strassen Multiplication


Algorithm Algorithm
5x5 103451 7015

10x10 143463 10045

20x20 249098 210018


*NB: time given in microseconds.




















P a g e | 10

Plotting Graph:

Bar Graph:

Comparison Graph
300000

250000

200000

150000

100000

50000

0
2x2 10x10 20x20

Divide and Conquer Algorithm Strassen Multiplication Algo















P a g e | 11

Line Graph:


Comparison Graph

300000

250000

200000

150000

100000

50000

0 Divide and Conquer Algorithm Strassen Multiplication Algo


2x2 10x10 20x20 
















P a g e | 12

Time Complexity and Analysis:



Divide & Conquer Approach:

Given the matrix A and B, and resultant matrix C, we see that both are
partitioned into four square sub-matrices, each sub-matrix having dimensions
n/2 * n/2. Then the product AB can be computed by using the given formula
(below) for the product of 2 × 2 matrices:



In order to compute AB using above equation, we need to perform eight
multiplications of n/2 x n/2 matrices and four additions of n/2 x n/2 matrices.
Since two n/2 x n/2 matrices may be added in time cn 2 for some constant c,
the overall computing time,

T(n) of the resulting divide-and-conquer algorithm is given by the recurrence:

Giving us the complexity of O(n3)


P a g e | 13

Strassen’s Approach:

Strassen provided the method below to solve this which requires little but less
time than previous method.



Giving us the recurrence relation for T(n):
Where a and b are the constants ,



From the formula we get: 



P a g e | 14


Analysis:

3
Both of the algorithm is of O(n ). But Strassen requires less operation time
than as usual divide and conqueror method. Which is O(n2.81) or O(nlog27)
























P a g e | 15






























P a g e | 16






























P a g e | 17






























P a g e | 18

























Table -1:

Required Time
 

No of Data Brute-force method Max/Min


P a g e | 19

1000 14 6

2500 23 17

5000 27 29

7500 31 51

10000 56 61

12500 59 79

15000 61 94

17500 76 106

20000 85 122

*NB: time given in microseconds.


Plotting Graph:
P a g e | 20
P a g e | 21
P a g e | 22
P a g e | 23
P a g e | 24

You might also like