Calculating
Running Time Of
Algorithm
BY: Adeel Rasheed
 For More Slides Visit:
 https://www.slideshare.net/adeel02
Pseudo Code
 For i  1 to n
 Do for j  1 to 2i
 Do k = j
 While(k ≥ 0)
 Do k = k – 1
While Loop
 Let I() Time Spend in while loop
 While(k ≥ 0)
 Do k = k – 1
I(j) = 𝑘=0
𝑗
1 = 𝑗 + 1
Middle For Loop
 Let M() be the time spend for for loop
 Its running time determined by I
 Do for j  1 to 2i
M(i) = 𝑗=1
2𝑖
𝐼(𝑗)
2
1
2
1
2 2
1 1
2
M(i) = ( )
M(i) = ( 1)
M(i) = 1
2 (2 1)
2
2
2 3
i
j
i
j
i i
j j
I j
j
j
i i
i
i i


 



 
 


 
Outer For Loop
 T(n) be the running time of entire algorithm.
 For i  1 to n
T(n) = 𝑖=1
𝑛
𝑀(𝑖)
2
1 1
2
1 1
3 2
3 2
3
T(n) = ( ) (2 3 )
2 3
2 3 ( 1)
2 3
6 2
4 15 11
6
( )
n n
i i
n n
i i
M i i i
i i
n n n n n
n n n
n
 
 
 
 
  
 
 

 
 
 
Calculate Running Time of Algorithm

Calculate Running Time of Algorithm

  • 1.
  • 2.
    BY: Adeel Rasheed For More Slides Visit:  https://www.slideshare.net/adeel02
  • 3.
    Pseudo Code  Fori  1 to n  Do for j  1 to 2i  Do k = j  While(k ≥ 0)  Do k = k – 1
  • 4.
    While Loop  LetI() Time Spend in while loop  While(k ≥ 0)  Do k = k – 1 I(j) = 𝑘=0 𝑗 1 = 𝑗 + 1
  • 5.
    Middle For Loop Let M() be the time spend for for loop  Its running time determined by I  Do for j  1 to 2i M(i) = 𝑗=1 2𝑖 𝐼(𝑗)
  • 6.
    2 1 2 1 2 2 1 1 2 M(i)= ( ) M(i) = ( 1) M(i) = 1 2 (2 1) 2 2 2 3 i j i j i i j j I j j j i i i i i               
  • 7.
    Outer For Loop T(n) be the running time of entire algorithm.  For i  1 to n T(n) = 𝑖=1 𝑛 𝑀(𝑖)
  • 8.
    2 1 1 2 1 1 32 3 2 3 T(n) = ( ) (2 3 ) 2 3 2 3 ( 1) 2 3 6 2 4 15 11 6 ( ) n n i i n n i i M i i i i i n n n n n n n n n                      