Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
37 views2 pages

DAA Tutorial: Function Growth & Complexity

ding ding ding
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)
37 views2 pages

DAA Tutorial: Function Growth & Complexity

ding ding ding
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

School of Computer Science Engineering and Technology

Course- B. Tech Type- Core Course


Code- CSET206 Course Name-DAA
Year- 2024 Semester- Even
Date-13-01-2023 Batch- 4th Sem

Tutorial: 01
Objective 1: Comparing two functions
Objective 2: Counting the loop execution
Tut No. Name CO 1 CO 2 CO 3
1. Tutorial:01 √

1. Which kind of growth (Constant, Linear, Logarithmic, Polynomial,


Exponential) best characterizes each of these functions:
8
𝑛1.4 , 50, 𝑛, 2𝑛5 , 8𝑛 , 109𝑛109 , 1000, ( )𝑛
9
𝑺𝒐𝒍𝒖𝒕𝒊𝒐𝒏:
𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡: 50, 1000
𝐿𝑖𝑛𝑒𝑎𝑟: n
𝑃𝑜𝑙𝑦𝑛𝑜𝑚𝑖𝑎𝑙: n, 𝑛1.4 , 2𝑛5 , 109𝑛109
8
𝐸𝑥𝑝𝑜𝑛𝑒𝑛𝑡𝑖𝑎𝑙: ( )𝑛 , 8𝑛
9

2. One of the two software packages, A or B, should be chosen to process


data collections, containing each up to 109 records. Average processing
time of the package A is TA(n) = 0.001n milliseconds and the average
processing time of the package B is TB(n) = 500√ n milliseconds. Which
algorithm has better performance.

𝑺𝒐𝒍𝒖𝒕𝒊𝒐𝒏:
𝑇𝐴(𝑛) = 0.001𝑛 𝑚𝑠
𝑇𝐵(𝑛) = 500√ n ms
𝑇𝑖𝑚𝑒 𝑡𝑜 𝑝𝑟𝑜𝑐𝑒𝑠𝑠 109 𝑟𝑒𝑐𝑜𝑟𝑑𝑠 𝑏𝑦 𝑠𝑜𝑓𝑡𝑤𝑎𝑟𝑒 𝑝𝑎𝑐𝑘𝑎𝑔𝑒 𝐴 𝑖𝑠
TA(109 ) = .001 ∗ 109 = 106 𝑚𝑠
𝑇𝑖𝑚𝑒 𝑡𝑜 𝑝𝑟𝑜𝑐𝑒𝑠𝑠 109 𝑟𝑒𝑐𝑜𝑟𝑑𝑠 𝑏𝑦 𝑠𝑜𝑓𝑡𝑤𝑎𝑟𝑒 𝑝𝑎𝑐𝑘𝑎𝑔𝑒 𝐵 𝑖𝑠
104.5
𝑇𝐵(109 ) = 500√ 109 = 103 ∗ = 107.5 /2= 5*106.5 ms
2
𝑇ℎ𝑒 𝐴𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚 𝑨 ℎ𝑎𝑠 𝑏𝑒𝑡𝑡𝑒𝑟 𝑝𝑒𝑟𝑓𝑜𝑟𝑚𝑎𝑛𝑐𝑒 𝑎𝑠 𝑐𝑜𝑚𝑝𝑎𝑟𝑒 𝑡𝑜 𝑎𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚 𝐵

3. Arrange the following function in increasing order of their growth


a. 𝑛𝑙𝑜𝑔𝑛 , 1010 , √𝑙𝑜𝑔𝑛, 𝑛, 𝑛√𝑛 , 𝑛𝑛
b. 2𝑛 , 𝑛, 90, 𝑙𝑜𝑔𝑙𝑜𝑔𝑛, √𝑙𝑜𝑔𝑛, 𝑛𝑙𝑜𝑔𝑛, 𝑛!, 𝑛𝑛

𝑺𝒐𝒍𝒖𝒕𝒊𝒐𝒏:
𝑎. 1010 < √𝑙𝑜𝑔𝑛 < 𝑛 < 𝑛𝑙𝑜𝑔𝑛 < 𝑛√𝑛 < 𝑛𝑛
𝑏. 90 < 𝑙𝑜𝑔𝑙𝑜𝑔𝑛 < √𝑙𝑜𝑔𝑛 < 𝑛 < 𝑛𝑙𝑜𝑔𝑛 < 2𝑛 < 𝑛! < 𝑛𝑛

4. Count the loop execution and find the time complexity of following
programs

a. for(i = n-500; i <= n+500; i++)


for(j =1; j <= n; j = j*2)
k = k + 1;

Cost = 𝐎(𝐥𝐨𝐠 𝟐 𝒏)

b. for(i =1; i <= n; i++)


for(j =1; j <= n; j++)
for(k=1; k<=n; k++)
k = k + 1;

Cost = 𝑶(𝒏𝟑 )

c. for(i =1; i <= n; i++)


for(j =1; j <= n; j = j*2)
for(k=1; k<=n; k = k +2)
k = k + 1;

Cost = 𝑶(𝒏𝟐 𝐥𝐨𝐠 𝟐 𝒏)

d. for(i =1; i <= 100; i++)


for(j =1; j*j<= n; j++)
for(k=1; k<=n; k= k*2)
k = k + 1;
Cost = 𝑶(√𝒏 𝐥𝐨𝐠 𝟐 𝒏)

You might also like