Personally I actually find linked lists kind of confusing. On the second midterm test, there was one question where a class was given, but it wasn't clear whether it was a class of a linked list, or a class of linked nodes, and I think I lost some marks on that question because of that.
When we are dealing with linked list and linked nodes, we really have to think hard about it first, because it has many cases, where it might be the first one of the list or the last one of the list. I found out that when writing a function of linked list, it usually involves a base case, a case where the node is the first one in the list (linkedlist.front), a case where the node is somewhere in the middle of the linked list, and a case where the node is the last one in the list (linkedlist.end). And one important thing while writting about linked lists is that you have to change the attribute -size of the linked list when ever you add or delete a node from the list, sometimes I just forget that. I also found when we call linkednode.next, or linkednode.next.next sometimes confusing, and I really have to stop for a sec to think about it which node is it, but it really got better as I practice more and more on this.
Wednesday, 6 April 2016
Week 10
This week we learned about recursive delete on Binary Search Tree, it's another delete method followed by the iterative delete. And then we talked about efficiency of algorithms. There are two basic points in the efficiency of a method, they are memory (space taken) and time (how long does it take to run the program. There are many types of efficiencies, such as "n", "log n", "n!" and so on.
Comparing to iterative functions, recursive functions tend to take more time and more memory. But recursive functions can be turned into iteratively function, which might take longer to write and less understandable.
Comparing to iterative functions, recursive functions tend to take more time and more memory. But recursive functions can be turned into iteratively function, which might take longer to write and less understandable.
Tuesday, 5 April 2016
Week 9
In addition to last week's Binary Tree, this week we learned about Binary Search Trees (BST), which is very similar to a Binary Tree. The main difference between a normal Binary Tree and a Binary Search Tree is that, a Binary Search Tree is "balanced". The data in a Binary Search Tree are comparable, values in the left subtree are less than the node value, and values in the right subtree are more than the node value. Therefore, searching for a value on a Binary Search Tree will take much less time than searching for a value on a Binary Tree.
Week 8
This week we learned about Binary Trees. Binary tree is like a real tree, it has a root, and have children which are like the leaves on a tree. The binary tree node class has attributes value (which is the value of the current node), left children, and right children. I found the tree classes very useful in real everyday life.
The recursive functions work on the binary trees really well. There are three different ways to visit a tree. The first one is inorder, where you visit the left subtree inorder first, then visit the node itself, then visit the right subtree inorder. When visiting the left and right subtree inorder, it involves recursion, which we call the function on the left/right child of the node recursively. The second way is preorder, where you visit the node itself first, then the left subtree preorder, and then the right subtree preorder. Lasly, postorder, where you visit the left subtree postorder, then the right subtree postorder, and then the node itself.
The recursive functions work on the binary trees really well. There are three different ways to visit a tree. The first one is inorder, where you visit the left subtree inorder first, then visit the node itself, then visit the right subtree inorder. When visiting the left and right subtree inorder, it involves recursion, which we call the function on the left/right child of the node recursively. The second way is preorder, where you visit the node itself first, then the left subtree preorder, and then the right subtree preorder. Lasly, postorder, where you visit the left subtree postorder, then the right subtree postorder, and then the node itself.
Sunday, 13 March 2016
Week 7
During the last weeks, we
learned about recursion.
Recursion is a recursive
method or class which calls the method itself inside the method. Take trees for
example, if we want to get the total value of all nodes, we have to go through
each node. In order to do this, we need to start from the root, and all the
value of the current node to the total count, and if the current node have
children, we call the method again on its children, and so on. This method will
go on and on until it went through all the nodes, and we will get an accurate
total value of all the values inside the tree.
When we use recursion in our
methods, we usually use it alone with “while” or “for” loops, because recursion
is a continuous idea. Recursion is usually used on object which its solutions
is based on similar smaller objects. I think that recursion is a very important
idea in computer science, and mastering it will help me a lot in future
computer science studies.
Sunday, 28 February 2016
Week 6
This week we learned more about linked list. Linked list is a class with subclass linked nodes. The attributes of linked list are head, tail, and length, where head is the first node in the linked list, tail is the last node in the linked list, and length is the number of nodes in the linked list. The subclass linked node represents a node in the linked list, linked nodes have attributes: value and next, where value is the value of the current node, and next is the next node after the current node.
Linked lists have methods that add a node in the middle of the list somewhere, or a method that takes out a node from the list somewhere.
Linked lists have methods that add a node in the middle of the list somewhere, or a method that takes out a node from the list somewhere.
Week 5
There was a test this week, unfortunately during the test, the fire alarm went off, so the students had to stop writing the test and wait outside. Once we got back into the testing location, we couldn't continue writing the test. I was a bit disappointed because I studied for the test and according to the questions I did before the alarm went off, the test wasn't that hard. Hopefully the professors will vote for a solution that is fair to us and the rest of the class who took the test.
Week 4
After last week's inheritance, and subclass, we learned about abstract data type - stack and container, unit test, balanced parentheses and linked list.
Stacks and containers are just abstract data types that can store values and new items are added on top of the stack, and you can only remove items from the top of the stack. Also there's a method which tells me whether the stack is empty or not.
I personally find unit test to be the most challenging part of this week's materials. Apparently unit test is a framework that setup test cases, and run them independently. An example of unit test can be used on balancing parentheses. The solution to this unit test is that we create an empty list, which if see a "(", add to s. If see a ")" remove from s, and if at the end the list is empty, then it's true.
The next part of this weeks lecture is linked list. It is like a list, but the nodes inside the list are linked with the previous and the next node. Linked lists have a head and tail, which are the first and last node in the linked list. and each node have a node linked to node.next.
Stacks and containers are just abstract data types that can store values and new items are added on top of the stack, and you can only remove items from the top of the stack. Also there's a method which tells me whether the stack is empty or not.
I personally find unit test to be the most challenging part of this week's materials. Apparently unit test is a framework that setup test cases, and run them independently. An example of unit test can be used on balancing parentheses. The solution to this unit test is that we create an empty list, which if see a "(", add to s. If see a ")" remove from s, and if at the end the list is empty, then it's true.
The next part of this weeks lecture is linked list. It is like a list, but the nodes inside the list are linked with the previous and the next node. Linked lists have a head and tail, which are the first and last node in the linked list. and each node have a node linked to node.next.
Wednesday, 10 February 2016
Week 3 - First impressions of the course.
It has been 3 weeks into the course, I found this course pretty fun. Unlike csc108 this course is teaching me more about how to design a programs using the codes I learned in csc108.
So far I have learned about designing classes, and abstract data types(ADT). At the beginning I found classes pretty confusing, because I didn't know why classes are needed, why can't we just use methods without a class? But after going over the slides and reading the example codes available on the course website, I found out that classes are for things with same properties and operations. Like squares for example, all the squares have a centre, and a side length. I can make a class with side length and centre as its properties, and every time I want to initialize a square, I can just initialize the class with the proper properties. This makes the codes very organized and clear to see.
In addition, I like the tutorial questions a lot, I get a sense of accomplishment when I complete the problems and see them run without any errors, I think I'm starting to like coding. :)
Subscribe to:
Comments (Atom)