Yes.
First, do you understand theta notation? Do you understand it well enough to tell me, using theta notation, how long this algorithm takes to run?
for i = 1 to n
for j = 1 to i
sum = sum + 1
I'll assume yes.
So, when adding two seven-digit numbers together, e.g.
abcdefg
+ hijklmn
How many times do you add two one-digit numbers? (It depends on how many times you have to carry, but there's an upper limit and a lower limit.)
So, my question for you is, and this is possibly a hard question, but one you need to be good at answering in order to be good at thinking about hard problems: What, precisely, do you not understand?
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
Well, I know that. Why can't you solve this problem? Where in the solution process do you go, I don't know how to do this? You can't just draw a blank. That's not how problems get solved. Do you understand what the problem's asking you to do? Yes? No?
If yes, then do you know what big theta notation means? Yes? No?
If yes, then do you know how to calculate the minimum and maximum possible number of addition operations when adding two numbers? Yes? No?
If yes, then can you express those bounds using theta notation? Yes? No? (Here, "No" might mean that it's just impossible.)
Which part can't you do? That's the part you need to identify.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
Well, what are the bounds? If the numbers have length n, then the number of addition operations you have to make is between n and 2n-1, right?
So, to find theta notation for this growth, we try to find some function, f(n), where a*f(n) < number-of-addition-operations < b*f(n), where a and b are positive numbers.
That function would be f(n) = n, with a = 0.5, and b = 2. (Or you could let a = 0.9, b = 999, if you wanted.) Anyway, looking at large enough values of n, we know that the number of addition operations is greater than 0.5*n, and less than 2*n. This means that Theta(n) would describe the number of addition operations, where n is the length of the two numbers.
For multiplication, you undergo a similar procedure.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177