Saturday, 28 March 2015

Revisit previous SLOG

I will revisit my SLOG of "Learning OO programming in a day", back when I was severely struggling with multiple elements of the course (as I had never taken a single CS course in my life and my prior knowledge was some rudimentary starts in PHP and MySQL back in September which was all procedural and did not use anything special)

Looking at this SLOG makes me realize how much my knowledge of computer science has grown. I remember writing this blog fondly thinking that OO programming was a incredibly powerful concept. Of course, it still is a very important paradigm of programming and is indeed very powerful, however after learning multiple concepts such as recursion, binary tree, and measuring the runtime complexity of algorithms, I've learnt that there are still many concepts that I have yet to learn and OO is nowhere near as "important" as I thought it was.

One of the main reasons is because of how applicable I have found the lecture material. It has been continually advancing my coding "etiquette" and constantly making connections to my current coding in PHP, AngularJS, and MySQL, especially in optimizations, and searching in the data structures of my database. Recursion is an incredibly simple yet powerful technique that can be modified so easily to drastically change its outcome (polynomial run time vs log or even constant).

Learning this course material has also had profound impacts that I never really expected out of it. For the most part, I drew a line between "coding" and "computer science" and thought it was mostly mathematics and had little to no application unless you were coding something INCREDIBLY complex that was nowhere near my ability. However, I completely disagree now, computing in general underlies a very certain fundamental "property" of the universe of a set that encompasses all the problems of the universe.

After noticing the little ways it is influencing my coding habits as well as my intellect (coding optimized functions and thinking about smarter data structures), it has also sharply increased my interest in computer science and algorithms in general. For example, in a recent hackathon, I was able to apply and learn A* and BFS algorithms to data searches (connecting multiple links to other multiple links). As well, I have become interested in hashing and its optimization towards databases:

https://www.youtube.com/watch?v=0M_kIqhwbFo&index=16&list=WL, 24:00 and onwards

Other impacts include my increased understanding in how MySQL works and being able to understand this has allowed me to flex the true strengths of MySQL support for multiple types of indexes.

Also, looking at my PHP code, I have completely changed to a MVC approach that still utilises OO programming, but in a largely different method. Understanding how OO works has helped me transition to this very quickly (something I never would've learnt without this course0. Furthermore, since PHP and most Web 3.0 sites use the MVC model to operate with Google's V8 Javascript Engine (which has full support for the very powerful AngularJS which also happens to be MVC), this knowledge has helped tremedously.

Often, the knowledge I learn in this course helps very minor things in my code, but eventually aggregate into a large change. Before the course I was convinced I could learn most coding knowledge by myself (which is why I am sadly currently enrolled in Commerce, but I WILL (if they accept me) be transferring out to comp sci, a choice this course helped solidify, when I posted this SLOG, I was still a bit unsure). However, after learning so much more than I ever could have imagined, I am glad to say I have found something I would love doing for a large portion of my life. A few other of my classmates also seem to share the same resolve:

http://mengziqiao.blogspot.ca/2015/02/i-have-learned-much-more-materials-than.html

This course has helped me in more ways than I'd ever imagined. I'm now interested in multiple computer science problems, such as the subset problem/knapsack problems, and would love to enter comp sci as my program.

Tuesday, 17 March 2015

SLOG Impression Week 8- 9

These past few weeks of CSC148 has been incredibly insightful and helpful and has multiple real-life applications beyond the classroom that I do encounter on a daily basis. These past 2 lesson we have learnt three simple and powerful data structures:

- Abstract Data Type, Tree
- Binary Search Tree
- LinkedList

Trees are a data type with a value and a set/list of children such that parent references the child, but the child does not have any data stored for its parent. These abstract data type trees are incredibly powerful for traversing, finding data, and also show the data structure that recursion operates in, such that one value depends on multiple branches of values that depend on other branches of values. A disorganized abstract tree such as:
Seems to have relatively little use, other than providing a data-integral structure for recursive operations. However, once we began learning about binary trees, a lot of things I've been doing have clicked. I work with MySQL and PHP on a daily basis and often have to worry about optimization (this includes partitioning literally millions of search rows, complicated JOINS, CASES, etc.) , and often need to deal with indexing data, BTREE, Fenwick trees, database engines, etc. I didn't really understand much, but I've always heard MySQL (which is renowned for its incredible speed) SELECT statement on BTREE indexed runs in log(n) time. It was not until we learnt about trees and BST that I made the connection from on why BTREE (Binary Tree) index runs in log(n) time almost immediately:



A BTRE, or BST, organizes data such that the left side of a node is always less than that node value and the right side is always more. While I'm not entirely sure how MySQL organizes its BTREE index, it makes sense behind how it works. By organizing data like this, we can continually eliminate half of the tree as we traverse it, thus running in log(n) time on average cases, explaining partially why MySQL SELECT statement is so fast:


This is extremely fast and efficient, 10,809 rows to search through for a u_id of 5963 and it was found in less than 0.03 seconds, and there isn't a considerable increase when you increase it to 100,000 rows either (which runs in roughly 0.04 to 0.05 seconds). BTREE search is much much faster than a linear search across an array. Another interesting data structure is the Fenwick tree:

http://en.wikipedia.org/wiki/Fenwick_tree

Which is a type of BTREE indexed data tree that is used to calculate very quickly a continually and cumulative increment of a sequence (useful for calculating likes on posts and for random-weighted select statements). The last data structure was for LinkedLists which actually finds a lot of use in comments on posts and other structures on websites:


LinkedLists allows for very quick insertion and deletion (as you just slice a reference out), but have slow indexing and random-access as well as other uses arrays may be used for.

With learning these applicable data structures beyond just the exam and term tests, I am quite excited to see what we will continue to learn and the next years of computer science.