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.
Subscribe to:
Comments (Atom)