As the course comes to a close, the last few topics we are learning about are analysing function runtime and the beginning of learning how dictionary and hashing works. Analysing function runtime work is similar to the proof-based course CSC165, except there is no need to formally prove what it is. After we've determined what the runtime in respect to the length of the variable in question, we would classify them into the big Oh of a basic function like n, n squares, 1, nlog_2n and many more.
We have begun learning about dictionaries and why they are faster to find something in them compared to the more simpler list data type. It turns out dictionaries use a function known as hashing. Hashing is taking the the object and returning an integer value that seems to be chosen at random. Not all objects can be hashed however, mutable objects like lists are not hashable. This explains more as to why lists can't be made as keys for a dictionary. I'm interested in learning more about how dictionary works, because I've always wondered why they are more efficient in lookup compared to lists but never learned why.
Looking back on this course and recursion it seems as if I understand recursion and how it works and I feel better implementing it, but assignment 2 showed that it is indeed tricky but extremely useful and able to do what iteration could do in a lot less lines of code. I still don't know why however, python does not include linked lists by default. The only reason I can think of is that it isn't something easy for a beginner to understand. Nevertheless it is still extremely strong and I wonder why they aren't in by default.
CSC148 SLOG
Thursday, March 31, 2016
Monday, March 28, 2016
SLOG #8
We have begun analysing functions for their runtime and the most simple and easy to understand function to analyse are sort functions. Depending on the algorithms they use, the run time will vary from a quadratic time to an almost linear time, or nlogn, where n is the size, in this case, the length of the list we are sorting. An interesting sorting algorithm is quick sort, where the worst case is a list that is already almost or is sorted.
Friday, March 18, 2016
SLOG #7
This week was also on binary search trees and recursive functions on them. It turns out that writing out recursion functions for binary trees are not as similar as trees. Trees have the 'simple' children but binary trees have the right and left children. This means that there just extra scenarios to consider and extra lines of code to write to account for them. But this can also complicate thing as the delete function now has to decide which to make the new root for the deleted value in certain situations. It needs to make sure that it still keeps the properties of the binary search tree.
Sunday, March 13, 2016
SLOG #6
This week we learned more about trees, but specifically binary trees and even more specific, binary arithmetic trees. Binary trees are just trees with a branching factor of 2. There are many useful applications for these data types. One included organizing it in a certain way so it is simple to search for a specific value. Unfortunately the only types of data allowed in these binary trees for this purpose are those that have comparability. Arithmetic trees are trees that are designed to calculate math statements, with the leaves being numbers and everything else being the operations.
Thursday, March 3, 2016
SLOG #5
In these last 2 weeks we have been learning recursion. Recursion is the technique of repeating the same function over and over again until it is completed and then returns whatever it is supposed to return. The interesting thing about it is that it calls upon itself in the body of the function. The implementation of it consists of identifying the base case and then the recursive step. Usually there is one base case, which is easy to figure out. The hard part is the recursive step.
Sometimes this step can be straightforward, or really tricky. I found out when going through the lab exercise that it helps to keep the code for the recursive step as simple as possible and not to think too deep into it. The hardest part about this step is how to translate it from an idea in your head into code. I found that using print statements help a lot during the recursive process so I could easily figure out what was going wrong in the entire call.
Even though in the lab we went through what seemed to be really basic cases of recursion, it wasn't easy and I can't even imagine how much more complicated recursion can get as the cases and what exactly is required out of the function get more complicated.
Sometimes this step can be straightforward, or really tricky. I found out when going through the lab exercise that it helps to keep the code for the recursive step as simple as possible and not to think too deep into it. The hardest part about this step is how to translate it from an idea in your head into code. I found that using print statements help a lot during the recursive process so I could easily figure out what was going wrong in the entire call.
Even though in the lab we went through what seemed to be really basic cases of recursion, it wasn't easy and I can't even imagine how much more complicated recursion can get as the cases and what exactly is required out of the function get more complicated.
Monday, February 29, 2016
SLOG #4
This (last) week we learned about recursion. Recursion works by calling itself in the function. It makes more sense after going through a few examples such as determining the sum of a list with many lists in it. The steps to show recursion also work sort of like induction, where if it works for the first case, then it will work for the second, and so on. But there is no need to prove it unlike induction, it just works.
Saturday, February 13, 2016
SLOG #3
This week we had our midterm and our lecture was on implementing queues and stacks with the power of Linked Lists and the Container super class. The queue and stack class that was built before was based on list had a problem when they got extremely large and it would take up a lot of memory. So to fix this Linked Lists were used, however they did not solve everything. The Linked List that was used however, was only linked going forward, with the .next_ method. This meant it was easy to remove the front value and add a value to the back, but not the other way around. Each container based class was tested and each one had a linear computation time, except queue, which took the longest and had a quadratic computation time.
Subscribe to:
Posts (Atom)