Saturday, 28 February 2015

Week 7- Summary of Abstract Data Types

There are 4 ADT's I have learned so far. I learned 2 of them in CSC108 and the other 2 in CSC148. The ADT's I learned so far are lists, stacks, queues and dictionaries.
1. Lists are sequences of items and they can be added, removed, modified, and accessed by position. Lists are mutable. This means that you can modify a list. You can access a list by putting its index in brackets. Empty list is shown as '[]'. You can add a object to a list by using 'append' method which is pre-defined. Len operation helps you to find the length of a list.
2. Stacks are specialized lists where we only have access to most recently added item. They have methods such as pop and push. Pop removes and returns the last item on a stack and push adds an item to the last index of the stack. They also have indexes such as lists.
3.Queues are also specialized lists where we have access to most recently added item and the first item. They have methods such as enqueue and dequeue. The first item gets in and the first item gets out. Enqueue adds the first item to a list and dequeue removes the first item that you put in a queue.
4.Dictionaries are mutable and another container types that can store python objects. Empty dictionary is represented as "{}". Dictionaries have keys and values. You can access the keys and values by a for loop. The general form a dictionary is "{key: value}". You can have one key and multiples values but you can't have multiple keys. Keys have to be immutable.

Friday, 13 February 2015

CSC148H1S - My summary of Object-Oriented programming concepts

Since the beginning of the semester, we are talking about classes which are object-oriented programs. If you want to create a class in python, you just need to write class and the name of the class and if you want to inherit that in the paranthesis you just need to put the superclass. Every class has to have an __init__ method which gets called every time you create a class. Also the first parameter of every class should be self. Self refers to the specific object created from that class. If a function is within a class we call it a method.

Friday, 6 February 2015

Impressions of tracing recursion from Week 4

We mostly did tracing recursive function exercises in week 4. "Recursion in computer science is a method where the solution of a problem depends on solutions to smaller instances of the same problem"(Wikipedia). Tracing means that when given a body of a function you have to show the steps the function will go through and the output it will produce. I really liked tracing recursion after doing some exercises I totally understood it. Writing a recursive function is harder than tracing because in tracing they give you the code and in writing you have to think and write it. It requires more time to write. There was a tracing recursion question in term test, I think I did it right.