Last week we talked about stack and queue and a little more about recursion. Stack and queue are containers of data. We can add elements to the end of the stack and delete the element in the end. On the contrary, we can add elements to the start of the queue and delete the element in the end. It just likes the model of lineup at a coffee shop or vending machine.
Queue and stack can be complicated, such as [1,[2,3],[[4,5,6],7]].
It is easy for us to get lost when we trace it. And the method which we use to deal with queue and stack is recursion.
When it comes to trace recursion. To be honest, I don't like it because it can be complicated. For example, I got lost when I traced the list on last week's lab.
(find the max one of [4 ,5, [6,7,[3,9,0], 6],10]). I asked my TA in help center and I figured out some efficient way to trace: The key thing to trace a recursion is to apply your function step by step. We can't (and not possible) to figure out the final outcome all at once.
(find the max one of [4 ,5, [6,7,[3,9,0], 6],10]). I asked my TA in help center and I figured out some efficient way to trace: The key thing to trace a recursion is to apply your function step by step. We can't (and not possible) to figure out the final outcome all at once.
This week we talked about Tree. A tree is a container of data with children.
We can put value in a node and edges connect node with nodes.
One of the most important thing which we need to keep in mind is that a tree both has value and many children and children have their own values.
After 6 weeks of studying, we have learned a lot about Object-Oriented Programming. We have learnt how to write a class, how to write a subclass and inherit methods from super class.In this week's slog I want to make a summary of concepts of OOP.
First, some concepts of OOP:
1.objects .it is the basic unit of OOP. Objects can be a function, can be a list of integer.
2.class. Class is a container of methods and data.
3.Subclass. Class can inherit some methods from super class and share some properties.
4.inheritance. subclass can inherit methods from super class.
SO what is oop?
In my mind, oop is a programming style
which focuses on objects and their properties rather than actions. For example,
in week three we wrote a class “employee” .Then “employee” was our object then we
considered what we need to do with this object in our program. We wanted to record the money which was paid to employees and record the total amount of money which we paid. So we added
several methods into the class, such as “record pay”, “total pay”. Then we
found that we need more information to complete methods. So we wrote subclasses :“hourly
employee”and "weekly employee".
In a word, oop is programming language model,
and we write classes to achieve our goals.
Then, what is the benefits of OOP?
The first thing which comes to my mind is inheritance.
As I mentioned above, we wrote subclass and let them inherit methods from super
class. It is possible to define lots of subclasses which share some properties
of the super class. It is quite efficient.
In a word, OOP is a useful programming
method to improve efficiency, and I guess we will continue learning about it through
the term.
