Week 3
This week we learn about running time.
Running time is to measure the number of steps the program executes and input size. And above all, we have a worst case called Big-O notation, which called an asymptotic upper bound.
This lab week is about to find running time in provided examples.
For instance:
ALGORITHM m01 is
Operation : simple loop
Input : an integer, n
Output :
SET rounds to 0
SET sum to 0
WHILE rounds is less than n
increment sum by 1
increment rounds by 1
ENDWHILE
RETURN sum
From above we know that SET rounds to 0; SET sum to 0; is constant, so we make that called constant 'c' and for while function we have to put 1st degree of variable, so we make it called variable 'x'. Then, we have to look conditions in while function that said 'round is less than n', so we can know that it should take n steps to make out of while loop and when is pass the condition, it'll re-loop again till not match the conditions. So, we could make it running time in a worst case be O(n).
Running time is to measure the number of steps the program executes and input size. And above all, we have a worst case called Big-O notation, which called an asymptotic upper bound.
This lab week is about to find running time in provided examples.
For instance:
ALGORITHM m01 is
Operation : simple loop
Input : an integer, n
Output :
SET rounds to 0
SET sum to 0
WHILE rounds is less than n
increment sum by 1
increment rounds by 1
ENDWHILE
RETURN sum
From above we know that SET rounds to 0; SET sum to 0; is constant, so we make that called constant 'c' and for while function we have to put 1st degree of variable, so we make it called variable 'x'. Then, we have to look conditions in while function that said 'round is less than n', so we can know that it should take n steps to make out of while loop and when is pass the condition, it'll re-loop again till not match the conditions. So, we could make it running time in a worst case be O(n).
ความคิดเห็น
แสดงความคิดเห็น