After 2 weeks of the amazing winter break, I started my
second course for the computer language Python. Started from Week 1, the
professor and us discussed about the topic of Object Oriented Programming.
Python is an object-oriented computer language, which makes
creating and using classes much more easy. Class is a cool and
efficient prototype to organize a group of functions and
methods. I can utilize the class’s build-in methods and also write new
functions within the class. Also, a class can build upon/from another class,
called the superclass along with its subclasses. The characteristics of the
superclass would also transfer to its subclasses which are derived from it. I
like to use class in my codes, yet to keep track of the variables and methods
within it might be a bit of more work. In addition, the required variable
‘self’ is a cool way to organize my data.
Something new that I have
not encountered before, ADT – abstract data types. In the lecture, we learnt
one common ADT, the stack. A stack is a way of using collections; in 108 we
have learnt types of collections include dictionaries and lists. The basic
methods(behaviours) for a stack consists of these functions:
__init__:
Initialize a new stack
push:
Add a new item to the stack
pop:
Remove and return the last item that was added to the stack.
isEmpty:
Check whether the stack is empty
__init__:
Initialize a new stack
push:
Add a new item to the stack
pop:
Remove and return the last item that was added to the stack.
isEmpty:
Check whether the stack is empty
A
stack is a "last in, first out" structure, because it will always
first remove the last item that has been added to it. We have not really had a
practical lab/exercise that wanted us to use stack in, yet I think it was a
very interesting way of dealing with lists and dictionaries.
The lab the professor gave us was really interesting, because I have learnt something like a “brother” of stack – queue, where the first item added is the first item been removed (“first-in, first-out”). However, lists are not as efficient as stack by using queue. The runtime for stack is constant, yet queue is more likely to be linear; doing inserts or pops from index 0 of a list is slow since all the items on the other index will have to shift down by one.
The lab the professor gave us was really interesting, because I have learnt something like a “brother” of stack – queue, where the first item added is the first item been removed (“first-in, first-out”). However, lists are not as efficient as stack by using queue. The runtime for stack is constant, yet queue is more likely to be linear; doing inserts or pops from index 0 of a list is slow since all the items on the other index will have to shift down by one.
It was a really small thing that I will never notice and
it was fun to think of the reason why queue was inefficient. Discussing
question during labs was very good way of absorbing new knowledge for me; I
actually think more carefully, detailed and more rounded about the topics. Therefore,
I like to do labs in 148. My partner is a really smart and helpful person, I
can always gain something new that I have never noticed before :D.
No comments:
Post a Comment