Assigment 1

You might also like

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

Assignment 1

Time Complexity ‫اﺣﻣد اﺑراھﯾم ﻋﻠﻰ ﻋﺑد اﻟﺳﻼم‬


G1

Due Data: the same day in next week from publishing the assignment

Hint:
1. In cout code each print after << sign takes one step
cout<<"your name is: " << name<<endl;

2. Any built-in function either give you how much steps it takes or compute it as one step
sum = sum + rand () // rand () is 4 steps then total steps = 6

3. int main () or any function names are not computed

4. return 0; is not computed in the algorithm so don’t forget that.

How you upload your answer?! (IMPORTANT)


1. Make pdf file with the following instructions
2. Write your name and your group number (ex: - 1CS, 2IS…) in the first page of the file
3. For each question write in detail for what number of steps for each line of code
4. At the end of the question answer write the total number of steps of that question
Questions
Compute the number of steps of the following questions that compiler would use it to run

Question 1:

0 step
1 step
1 step

2*counter+2 step
3*counter step

5 steps

0 step
total = 1 + 1 + 2*counter + 2 + 3* counter + 5 = 5*counter + 9

Question 2:

0 step
1 step

1 step

2n+2 step

n(2n+2) step

n(3n) step

Note : n2 = n square

Total = 2 + 2n+2 + n(2n+2) + n(3n) = 5n2 + 4n + 4

Question 3:
1. Main() function: (start from here)

0 step

0 step

2 steps

8 steps

2 steps
14 steps

total = 26 steps

2. GetUserData() function

1 step
1 step
1 step
1 step
1 step
1 step
1 step
total = 8 steps
1 step
3. displayUserData() function

2 steps
3 steps

3 steps
3 steps
3 steps total = 14 steps

You might also like