2014年10月24日星期五

SLOG 6

                     This week is the week for us to learn the proof methods, and we finished the method proof by cases. And then professor introduced the concept of counting steps, which includes the worst case and the best case. Let us talk about proof by cases firstly.
      Sometimes we have to prove some claims that have conclusive antecedents. For example, if we now have a claim with an antecedent like this: | x - y | = e, we have to consider it by cases, for we know few ways to prove directly by absolute value. So we split | x - y | = e into two cases: 
x - y = e and | x - y | = -e. Then we prove in this structure:

Case 1: x - y = e
......
Case 2: x - y = -e
......

Then we have a lot of ways to figure out the claim, since we are familiar to the equation
 x - y = e and x - y = -e, and we know plenty of ways to do transformation on them.
  After that, we learned how to count steps. It is a tough part because we need to be careful or we will easily go on a wrong way. Counting the worst case is the most representative case of counting steps because it includes all the possibilities. Worst case is the situation that the algorithm has to run the largest times that it can run. For example, the worst case of the algorithm 
def LS(A, x): 
’’’
Return index i, x == A[i].
Otherwise, return -1 
’’’
i = 0                   
while i < len(A):         
if A[i] == x:         
    return i         
i = i + 1           
return -1              

  
 If it is in the worst case:
 It has to run once at step , twice at step , once at step , once at step , and once at step  if len(A) = 1.

It has to run once at step , three times at step , twice at step , twice at step , and once at step  if len(A) = 2.

It has to run once at step , four times at step , three times at step , three times at step , and once at step  if len(A) = 3.
......
So when len(A) = n, it has to run 1+( n + 1) + n + n +1 = 3n + 3 times.

   Next week we are supposed to enter a new world of logic. Although until now I have no idea about how that world is, I cannot be more excited on exploring it!

没有评论:

发表评论