Monday, 26 November 2012

Deterministic and Non-deterministic FSAs

We learned about non-deterministic FSA's last week. I kind of missed the first half of the class so I didn't quite catch what the main difference between NDFSAs and DFSAs is. The lecture slides didn't really point out a specific answer to this either. So I had to ask everyone's best friend, Google.

http://cs.union.edu/~striegnk/courses/nlp-with-prolog/html/node4.html

I understand what is mentioned in the site and it actually relates to the example machine discussed during the lecture. So, according to my understanding, the main difference between the two types is that the NDFSAs can contain two paths for the same input from a single state hence the state being non deterministic?

We also have a3 due this friday! I need to start on it so i won't end up rushing through it on last minute. And hopefully, when i work through the assignment, I would get a better grasp on what the differences between   NDFSAs and DFSAs are.

Monday, 12 November 2012

The Master of all theorems : "The Master Theorem" ?

Clearly, the theorem was given the title for a reason. It was made to make everyone's lives just a little bit easier when finding time complexity of an algorithm without doing all the messy unwinding.. 
I studied it over and over, I knew how to use the Master Theorem, walked in to the write Test 2, saw Master Theorem question.... Perfection! ..or so it thought. What do I end up doing? Unwinding T(n) before applying the Masters Theorem!!!! >.< 
I should just slap my self over and over and over and over again.. and more. *Sigh*

I remembered to write what P(n) this time though! Life lessons I'll say.

So, to make up for my mistake,  Here goes..

The Masters Theorem: 

For T(n) =  aT( n/b ) + f(n) 

T(n)  =     Θ (nd)    if a < bd
         =     Θ (nd log n)    if a = bd
        =     Θ (nlogb a )      if a > bd


where a is the number of recursions, b is how many parts we divide n in to  and finally d is the largest degree of the polynomial f(n)

So, if i was given  lets say --- T(n) = T(⌈n/2⌉)+ T(⌊n/2⌋) +  1

If n was a power of 2,  we can simplify T(n) to be: T(n) = 2T(n/2) +  1

Now,  it's visible that a = 2, b = 2 and d = 0 since the largest degree of 1 is 0.
With this information, and the use of the Master Theorem, the complexity time of T(n) would be : 
Θ ( nlogb a )  since 2 > 20 

Finally,

T(n) = Θ( nlogb a )
T(n) = Θ( nlog2 2  )  =  Θ( n )

Phew! There, done. 

Saturday, 3 November 2012

Last Minute


So we had assignment 2 due yesterday, which I handed in on the last minute. I checked the time, it was 11.58pm. Woo! No pressure. No pressure at all.

So in a2, i understood question 1 after the TA explained how the question should be answered in 3 parts. And i am glad that we didn't have to show proof of how the fibonaaci sequence ended up with the golden ratio which was what i was really confused about. But in question 2, I didn't quite understand how to prove that the function is in Theta of lg(n). What i did was prove that two values, one larger than n, and one lower than n that are powers of 2 to be elements of the Order of lg(n) and Omega of lg(n) respectively using the closed form for T(n). Due to that reason and that fact that T(n) is a non-decreasing function, i reasoned that T(n) is an element of Theta of lg(n).
I don't know to what degree this proof is correct, but it kind of makes sense to me.

Something that I did not understand however was the significance of the Max and the floors and ceilings. Since T(n) is an increasing function, wouldn't the Max always be the ceiling of (n/2)? I did not quite know of how to address that in the assignment. So i'm really looking forward to seeing the answers to this assignment.