Thursday, 3 March 2016

Week 7 SLog

Recursion

Recursion is not something I look back at with fond memories. I'll try and summarize my understanding of recursion so far:

Recursion is when you create a function and you call on it within your return statement.
Recursion can be thought as jumping into oneself as deep as you can then working your way out.


Recursive Functions have 3 general parts:
The Base:
This is the simplest part of the function and requires no recursion at all. This is the point where you want your function to stop

The Work:
What is meant to be done at each step of the function

The Recursive Call:
Calling on the function within the function.

In class we went over this example:

def sum_list(L):
    if isinstance(L, list):
        return sum([sum_list(x) for x in L])
    else:
        return L


When this function is called it will try to go into the list as deep as it can then solve for that level and work its way out. ie
  >>> sum_list(17)
    17
    >>> sum_list([1, [2, 3, [4]], 5])
    15
Another great example is the fibonacci sequence. its like 5! is the same as 5*4*3*2*1.
Understanding recursion so far is pretty difficult but I'm sure by next week I'll be a pro.

Thursday, 25 February 2016

Week 6 SLog

AHHHHH!! We have are test this week and I'm super nervous!!
We just got introduced to recursion and at first glance is the most confusing thing I've ever seen.
To be quite honest not having a lot of programming experience and the combination of recursion has real distracted me. 

Thursday, 11 February 2016

Week 5 SLog


This week we learned about linked lists, another Abstract Data Type .
A Linked list is a data structure where nodes are linked together. Each of these nodes holds data and has a reference to at least it's tail/next.  Each node has a reference to its next but not its previous one. So trying to find out what is before that node would be impossible unless we introduce something called a doubly linked list. In a doubly linked list a node has a reference to its head/front and tail/back so it would be easy to iterate through a linked list no matter where you were.
Image result for doubly linked list

Another interesting point that was brought up was how do you know which head is the actual head of a linked list where the nodes are linked into a circle.
Image result for circular linked list

The answer is there is no way because you would just be linked into a continuous circle.

The way you would do this is create a class node and a class linked list that takes in nodes as a container and have each node an attribute to its head if its singly linked and if its doubly linked an extra attribute linking to its tail.

This was after writing the midterm. I think the midterm was fair, even though if we were given 10 more minutes it would've helped a lot.



Thursday, 4 February 2016

Week 4 SLog Post

This week we learned about creating classes, Queues and Stacks.

 We can create any class we like with Object Oriented programming languages like Python. Using python you can use things like lists to create Abstract Data Types like Queues and Stacks.




Image result for queue
The concept was fairly simple and not hard to grasp.
A queue is an ADT or container that is first in first out.
A queue is like a line at the grocery store.
The first person in line at the register will be the first person who is serviced and out the door.








We also learned about Stacks where a stack is an ADT or container that is first in last out.
A Stack is like a pile of papers.
If you are given a stack of papers one at a time and lay them on a table one on top of the other.
The first page that was put in if you choose to look at each paper from top to bottom will be the last one marked and the last person to get their work back.



Monday, 25 January 2016

Week 3 SLOG Post

So far in CSC148 I have learned to build classes in the python programming class as well as a lot of other things that I will touch on a little later in this post.

Having taken CSC108 2 years ago it is a bit difficult to amalgamate my my knowledge from then to the new information that I am learning in this class and that can be frustrating at times. The challenge is something I look forward to as I want to become well versed in programming in python.


I have however acquired a lot of new knowledge and have provided a small summary of the things I have learned and found interesting since the beginning of the school semester. 

Python is an Objected Oriented language and this means the language is modelled around objects rather than actions and logic.


Image result for oopYou can override extend and inherit methods from parents/subclasses.

Generally when implementing classes:
You start by defining the special methods: __init__, __eq__, and
__str__ .Then  you define and create the methods unique to the class. Then create your doctests.




Data Abstraction (Encapsulation and Hiding):
When you create a protected variable it cannot be used outside of the class definition and the the variable is preceded by a single underscore i.e. _var
when you create a private variable it cannot accessed other than within its class.

You can access these variable by creating public getter and setter methods that give you access  to the variable as well as the option to change the variable.