Tuesday, 8 October 2013

Object-Oriented Programming & Recursion

This week Task:

As well as your regular entries in your SLOG, this week I'd like you
to write two short paragraphs: one on Object-Oriented Programming, and
one on Recursion.
Each paragraph should state, in your own words, what the concept is
and why it is useful (or not) for computer scientists.



 Object-Oriented Programming:

 Object-Oriented Programming is like we can come up with concepts("objects, instances of classes"), also have approaches attributes to it, which is known as methods.  Languages like C++, Java are example of objext-oriented programming language. This programming paradigm makes programming more flexible and extendable as well as make people enable to simply design something and use it.


Recursion:


Recursion is like a method that repeatedly call itself.
For example, fibonacci sequences( 0, 1, 1, 2, 3, 5, 8, 13, 21, 34...), we have maths definition:


fibonacci from wikipedia 
we can write in python like,
def fib(n):
   if n == 1:
      return 1
   elif n == 0:   
      return 0            
   else:                      
      return fib(n-1) + fib(n-2)
so we have 
fib(0) = 0
fib(1) = 1
fib(2) = fib(1) + fib(0) = 1
fib(3) = fib(2) + fib(1) = 2
...
This approach is very convenient in programming, as it makes it possible to 
'define an infinite set of objects by a finite statement' because of repetitions. 





No comments:

Post a Comment