Thursday, 9 April 2015

CSC148 - Entry 10 (Final)

Entry no. 10, Week 12: 

Topics

1. Final thoughts 

Into these last weeks, we're approaching the end of this term. For the majority of this course the material wasn't hard for me to handle. Things like object oriented programming, recursion, etc... are things that I've learned in the past, but this course provided a steady introduction to it. I think that the labs were relatively quick and easy to complete with a teammate, but the assignments added more challenge. I think the biggest hurdle in this course was the TA-Strike. I know I didn't talk about it as much, but it brought upon a slower learning experience with the absence of attending and doing weekly labs and interaction with the TA's to a large majority of the student body. With this being my final entry, Thank you for reading my course blog!!!

- DChau

Tuesday, 31 March 2015

CSC148 - Entry 9

Entry no. 9, Week 11:

Topics

1. Revisiting an old post.

Another short blog entry (Sorry, not much to write anymore).

I looked at my 2nd entry and some subsequent posts, and can definitely say that the pacing of the lectures and overall difficulty of the material grew from then. Even though I've encountered the material thus far, applying in the ways that we did was a nice experience. Regarding the beginning of the course, I'm an odd example as I was less impacted by the scaling into Assignment #1 than one of my collegues. I agree that Danny is an excellent professor, as well as the labs being a good basis for encountering new code, but the assignment wasn't too hard for me to manage solo.

Thursday, 26 March 2015

CSC148 - Entry 8

Entry no. 8, Week 10:

Topics

1. Thoughts on Week 9

This weeks topic is Week 8; Term Test #2

Short blog entry because this was a very uneventful week

Term Test #2 was this week, and it covered topics from Weeks 5-8. The material on it included Trees, Methods of Traversal, Recursion on Binary Trees and Iteration on Linked Lists. I felt like I did pretty well on this test by because this material isn't too new to me. Compared to the last Term Test, it required more knowledge of programming but was still at a level where the average undergraduate would do well if they completed their labs. That being said, thanks to the strike the past few tutorials were cancelled along with the absence of our TA's. As much as not having to go to tutorials is nice, I am concerned for some of the other undergrads in this course who are in need of a TA.

Tuesday, 17 March 2015

CSC148 - Entry 7

Entry no. 7, Week 9:

Topics

1. Impression on Week 8

 

This weeks topic is Week 8; Linked Lists.

An easy way to describe a linked list is as a tree with an arity (branching factor) of 1 which means there is only 1 'child' for each node.
This also means that this linked list will be linear and traversing can be accomplished by iteration where one can loop through the list until the end or until an object is found.
Example of a linked list

Generally for a linked list a class is used to keep track of it's information, a Wrapper class. Typically, it stores the size, front and end of the linked list but can keep track of anything within the linked list. 

Example of a wrapper class 

With further implementation of __str__, __repr__, __eq__ and other methods, a linked list can be extremely useful.

Something to be weary of when using iteration on a linked list is mutation. If one isn't careful, objects inside the linked list may be changed or swapped with each other.

Monday, 9 March 2015

CSC148 - Entry 6

Entry no. 6, Week 8:

Topics

1. Impression on Week 7


This weeks topic is on Week 7; Binary Trees (BT), Traversal and Binary Search Trees(BST).

In my previous post I used a Binary Tree to help illustrate a use of Recursion.
For this entry, I'll be writing more in depth on BT's, Traversal and BST's.

The weeks material is something I've learned before, so it's nothing new. As a result I feel like I already have a firm grasp on it.

BT's are variations of Trees in the sense that they are limited to 2 predecessors, Left and Right. We call their predecessors children and can each represent another BT. An empty sub tree can be identified as a NoneType because it is in the set of everything.

Traversal is the ways that we visit each node in a BT. The three simple traversals are Pre-Order, In-Order and Post-Order, and will each go through the tree in different ways. These are recursive definitions that were defined in class.
  • Pre-Order:  
    • Visit the current node
    • Traverse the left sub tree Pre-Order
    • Traverse the right sub tree Pre-Order
  • In-Order:  
    • Traverse the left sub tree In-Order
    • Visit the current node
    • Traverse the right sub tree In-Order
  • Post-Order:
    • Traverse the left sub tree Post-Order
    • Traverse the right sub tree Post-Order
    • Visit the current node
BST's are BT's that store comparable values and separate their left sub tree with data that values less than itself and a right tree with data that values greater than itself. We assume that if a value is added to a BST that already contains that value, it is not added.

BST's are useful because they cut down the search time to Big-O(log2(n)) where n represents the amount of data stored within the tree. Using the properties of a BST, we can eliminate an entire half of the BST and check the other half for the value. However, if a BST is not balanced (ie. all the data is stored within the either only the right or only the left sub trees) the search time grows to Big-O(n).

Sunday, 1 March 2015

CSC148 - Entry 5

Entry no. 5, Week 7: 

Topics

1. Summary of Recursion


This weeks topic is on Recursion.

In general, recursion is an extremely powerful technique where a function calls itself on a smaller instance of the problem to simplify the initial problem. For coding, recursion is beneficial but has certain drawbacks. Recursion allows us to create algorithms that traverse trees easier. On the other hand, a weakness about recursion is that it takes up lots of memory in stacks and is slower to compute for larger sets of problems.

Let's take a look at some sample code from a lecture exercise

Getting started on coding evaluate, we must first define a base case. The base case is a case simple enough that it requires no recursion. In this example, when the node is a leaf (ie. no children) it returns the float value inside. 
Eg.
if b.left == None and b.right == None: #No children
    return b.data

Moving on to the recurse part of evaluate the recursive case when the node is an interior node (ie. has two children) will be looked at, we can use the built-in python eval method to evaluate a string that involves arithmetic.

Using this binary tree as an example, we would have to call evaluate on the left and right children, and append their values as strings to the current data in the interior node ('+') then call eval on that resulting string.




The body of the function would look something like this.
Eg. 
if b.left == None and b.right == None: #No children, base case
    return b.data
else: #Has children, recursive case
    return eval(str(evaluate(b.left)) + b.data + str(evaluate(b.right)))

Since the recursive and base case both returns a float, the type contract is satisfied. When the method is called on a larger binary tree, it will traverse the tree in such a way that the values from smaller binary trees will be returned and then calculated. Thus since this tree works for smaller cases of binary trees, it will work when called for any binary tree provided that it is not too big for the stacks to handle.

Recursion is an important aspect of computer science because it makes solves problems by breaking them down into sub-problems, like what we did above.

Saturday, 14 February 2015

CSC148 - Entry 4

Entry no. 4, Week 6:

Topics

1. Summary of Object-Oriented Programming concepts


This week, the topic is about object-oriented programming which is something that I am already very familiar with. Since this is a very broad topic, I will be talking about Instances, Abstract classes and Inheritance. The examples will be in Python3.

First, let's define a class. A class is a representation of an object. They are given names and are composed of attributes and operations (methods) that can be used by several Instances of the same class.

Instances are objects and are occurrences of specific classes. They use the methods that are defined within the class, and also have unique variables that store information. (disclaimer: that does not mean that there can only exist unique variables, but that there are also exist variables which can be accessed throughout all instances of a class.) Instances of classes are frequently used in programming and play a large role in creating interfaces.

For example, we can create a class Student that manages the information and actions of a student. We can give that Student a name and attributes by creating an instance of Student, we can tell the student to enroll in courses and we can take a look at their grades.

Abstract classes are classes that aren't meant to be used. Within these abstract classes, there exist properties and methods as well. Even though these are defined, they represent the framework for subsequent classes. That is, they are meant to be used in subclasses that will extend the functionality of the abstract class. The way that these subclasses extend functionality is called Inheritance.

Suppose we had a class called Vehicle which is a thing used for transporting people or goods. This is an example of an Abstract class because there are many vehicles, but they are all different in their own respects. Subsequent classes may include Cars, Boats, Planes...etc but they are all derived from the same Abstract class Vehicle. 

In one of my previous post's I briefly talked about Inheritance which mentioned method Over-riding, Extending, and Inheriting. Over-riding is a process where an entire method is re-written to fulfill the needs of the current class. In abstract classes, methods that were not fully defined would be over-written and defined in the sub-class. Extending is a process where a sub-class would use a methods from the super-class in the definition of the current method or define a completely new method that is semi-related to the super-class. Inheriting is taking a method that is already defined in the super-class and using it in the sub-class, such that it does not need to be defined in the sub-class.

Still using the Vehicle class, suppose we made a subclass Bus. We would over-ride the __str__ method because the string representation for the two would be completely different. We could also extend the Bus by using the __init__ method from Vehicle, but by adding fare and totalFare attributes, and adding methods passengerOn and passengerOff. The bus would inherit the method move, since Vehicles Buses both move.

Sunday, 8 February 2015

CSC148 - Entry 3

Entry no. 3, Week 5:

Topics

1. Impressions on Recursion, and Tracing Recursion (from Week 4)


Recursion isn't too foreign to myself and some others in this course as we have encountered it before. On my part, I haven't done recursion for a while (2 years give or take a few months) so it was something that I had to get the hang of again. The practice and lab for recursion was straightforward and simple enough for me to get my gears going again. For those who don't have a great grasp of or don't know much about recursion, it is a series of repeated applications of a procedure or definition that re-evaluates until certain criteria are met.

For example of what recursion can look like, below is part of an exercise from a lecture.



At a quick glance, this code accomplishes very much with very little amounts of code. That is, it can sum any size list of ints (nested lists importantly) with 4 lines of code without comments.

What's really key is writing about the criteria needed for the call to start recursion. In this case, if the input L is a list then it calls itself again (that is, it calls sum_list(x) for each element in L) within a List-Comprehension that is later summed. Another key part is that this function returns the input L if the input is not a list. These two parts together will eventually forge and sum a list of Depth-1 thanks to repeated calls on sum_list and List-Comprehension.

Monday, 2 February 2015

CSC148 - Entry 2

Entry no. 2, Week 4: First week impressions

Topics

1. My impression of the first few weeks


Going into the course, the pacing of the lectures felt a tiny bit slow to me, but that much was to be expected with the amount of new-comers from CSC108. Even though the lectures were slow, there were a few interesting concepts that I hadn't come across yet. 

A really useful concept was List-Comprehension, where new lists can be created based on other lists. 
For example in Python it looks a little bit like this.

>>> L = [1, 2, 3, 4].
>>> S = [ x ** x for x in L]
>>> S
[1, 4, 9, 16]

In addition to basic mathematical operators, well-defined functions or methods can be called on the elements inside as well.

>>> from math import sqrt

>>> L = [1, 4, 9, 16]
>>> S = [sqrt(x) for x in L]
>>> S
[1.0, 2.0, 3.0, 4.0]

Another thing that caught my eye was that Python didn't really have a "private" feature like other languages do. A single underscore ('_') on instance variables and methods coupled with the use of property(<fget>, <fset>, <fdel>, <doc>) acts as a way to redirect the access of information from the general public.

Other things we tackled over the first three weeks were Inheritance and ADT's, both of which are less new to me than the above topics. Below is a short run-down of what they are.

Inheritance is the idea of an Initial class (Super Class) giving its properties and methods to Subsequent classes (Sub Classes) where the Sub Classes are free to change (Over-ride), add to (Extend) or simply take (Inherit) from the Super Class.

ADT's  (Abstract Data Types) are ways of storing information. So far, we looked at Stacks, which is LastInFirstOut (LIFO) type of data type. With a stack, users can push in objects, pop the top-most one out, or just peek at it without popping it out.

Thursday, 22 January 2015

CSC148 - Entry 1

Entry no. 1, Week 3: Clear Communication

For the next couple of weeks I'll be keeping a course blog which will be updated weekly with content that pertains to a university course, CSC 148 - Introduction to Computer Science.

 

Topics

1. Why geeks should write

 

Why should we write?

For this first entry, I was given an assignment to write about "why geeks should write"... To be honest my writing skills are lacking but I'll try my best. Well here goes!!!

What's so important about writing anyways?

A: Darn, I wish i had a way of doing x efficiently and quickly!
B: Well I can write some (shifty) code to do x.... Uhhh, Here it is! Awesome_Code_That_Is_Vague_But_Does_x_Efficiently_and_well.py 
A: ... Cool, but what does it do? Are you sure that it does what I want it to do?
B: Yeah it does... how do I explain what y line does again...?
C: Try this! Does_X_Like_This.py
A: Ahah! Now I see. Can I use you're code to develop z?
Even though B's code works, B should have explained his code clearly, now he is seen as untrustworthy... And that's not good!


We often take 'Simple' things such as applications and software for granted each day. The reason that we can use these things so often is because developers work together in a way such others can use their code with ease to create even more 'Simple' things. These developers ( 'geeks' ) who express their knowledge in writing and communicate their ideas to the world are important to advancing the current level of technology. If every programmer was like person B, then nothing would ever get done. But If they were like person C, then world hunger would be solved!

(Note: World hunger does not actually get solved, but it's a nice thought nonetheless)