- #1
mohamed el teir
- 88
- 1
Moved from a technical forum, so homework template missing.
Assume the following set of instructions:
1. i = 0
2. if i < n, goto line 6
3. if A [ i ] = = x, goto line 7
4. i++
5. goto line 2
6. return false
7. return true
Assume that line i take Ci time, where Ci is a constant. The worst case total time of running this block of code can be calculated as: C1 + (n+1)C2 + nC3 + nC4 + nC5 + C6 = (C2 + C3 + C4 + C5)n + (C1 + C2 + C6) = An + B, where A = C2 + C3 + C4 + C5 and B = C1 + C2 + C6 are both constants.
is this right ?
1. i = 0
2. if i < n, goto line 6
3. if A [ i ] = = x, goto line 7
4. i++
5. goto line 2
6. return false
7. return true
Assume that line i take Ci time, where Ci is a constant. The worst case total time of running this block of code can be calculated as: C1 + (n+1)C2 + nC3 + nC4 + nC5 + C6 = (C2 + C3 + C4 + C5)n + (C1 + C2 + C6) = An + B, where A = C2 + C3 + C4 + C5 and B = C1 + C2 + C6 are both constants.
is this right ?
Last edited by a moderator: