Monday, February 29, 2016

Week 7

This week I am going to discuss the Abstract Data Type.

Abstract Data Type, or ADT, refers to the data type defined only by its behavior and class of objects whose logical behavior is defined by a set of values and a set of operations. The STRUCTURE is usually meant to be inherited and is composed of no instances. The difference between abstract class and abstract data type is that the class does not provide definition for all of its methods and methods should be implemented in subclasses while the data type is merely a model of a certain kind of data structure.

Two popular examples of abstract data type are Stack and Queue, which respectively implies the rule of Last in First out (LIFO) and First in First out (FIFO). To clarify the ambiguity (which I initially had as I am an English learner), last in first out is like storing food in a draw; the ones you put in the last are the ones you eat first. On the other hand, First in first out is as trays in KFC restaurant because consumers take out the top ones, which are also the first ones that the employees inserted. Queue and Stack are two useful features that many class inherit. Each of them has a class list instantiation.

One good example of class that inherits Queue would be the dispatcher class in our first assignment. In the dispatcher class, the dispatcher needs to assign customs and drivers in order and the first come first serve rule is always obeyed. Without the Queue data structure, it would be hard to achieve such order. 

In short, Abstract Data Type is useful data structure that provides bases for many other classes and thus facilitates coding.   


Friday, February 26, 2016

Week 6

Back from reading week and ready to restart.

This week we discussed recursion, which is a fascinating topic as it enables solving complex questions. Although some function can be expressed without using recursion, the form of the recursion facilitates the speed of the function. The following example can be written in both recursive and non recursive 


def factorial(n):
    """    
    Recursive function computing the factorial of n 
    """
    return t
    if n == 0:  ###recursive 
        return 1    else:
        return n * factorial(n - 1)


During the week's tutorial, we practiced converting filtering and list comprehension to loops. I personally find that introducing filter, zip, reduce and map will be a good topic for a lab because they highly reduce the time students take to write codes.

Sunday, February 14, 2016

Week 5

This week we had our midterm exam. The test was not hard but long enough that I did not get to finish it. In addition, during the short lecture, we talked about the assignment one. I think I need to practice more for the later tests because my writing on code is not very fast. 

We discussed the general structure of the driver class and the things we need to pay attention.

For the tutorial, we had a challenging node class to work on. The concept was initially a bit frustrating for me because without drawing it on paper, it is hard to be visualized. However, as I struggled and got accustomed to the way of thinking, I can eventually finish any node class at fast pace; this is a breakthrough.

By the end of week 6, I aim to finish the driver class as I have full passion for it!

Wednesday, February 3, 2016

Week 4

At the end of last week, we discussed the use of abstract data type (ADT) and a particular 
Stack class as a popular case. This is a great way to visualize how the code should work the best way without telling how to implement codes. For the Stack class, for example, it creates a stack of items and use method of push, add, remove, pop to edit the list and use is_empty to check the emptiness. The stack class usually fulfills the conception of first in last out, or first in first out. This is a generally fascinating idea that I never encountered when I used Java.

During the tutorial, we practiced inheritance and I had a good idea about the parent and children classes.  


Moreover, we talked about balancing parentheses and we define a string with no parenthesis or with corresponding parentheses as balanced. To check the balance of parentheses, we can very well use the stack class we learnt last week. For instance, using this method


st=Stack
for c in s:
    if c not in '(){}[]':
      pass    
    elif c in '({[':
        st.add(c)
    elif not st.is_empty():
        c2=st.remove()
        if((c==')' and not c2=='(') or (c=='}' and not c2=='{') or\
                            (c==']' and not c2=='[')):
            return False    
    else:
        return False

At the second half of the week 4 class, we studied how the linked list works. Linked lists and 
the use of nodes are complements to other tracking methods because they conserve the 
memory for the current position and all node needs is a reference name and a simple value. 
In each Node class, we just give a prevnode, nextnode and the node value. For instance, 
if we create a n1=Node (1) and a n2=Node (2), by setting n2=n1.nextnode, we successfully 
connected the two nodes. 
The difficulty I have is that I write code way too slowly and it took my entire time to write the 
quiz. I need to practice more to get hands and brain speedy.
In short, the class this week taught a great deal of good stuff and I am looking forward into it.