Tuesday 1 April 2014

Week 11 - Sorting and Efficiency

Through the past weeks of class the main topic of discussion is sorting and efficiency. Sorting is the process of placing elements in a list into a certain order. Before taking a look at bigger sorting algorithms and concepts it is important to understand the basic necessities. Firstly, you have to be able to compare two different pieces of information and secondly to exchange that piece of information. All the most popular sorts that we have learned implement this in a way (bubble sort, insertion sort, etc.). The idea of sorting was at first glance mostly a review, therefore the topic where not to out of reach for me to grasp. I understand the basics of sorting and also the many different methods of sorting that can we used. I see where how sorting is important to computer science as many different people have thought of many different ways of sorting. Also I can understand that sorting is an important function in computer science (e.x sorting databases based on specific labels)

Another topic covered in the past few weeks has been Big O notation. Big O notation describes the limiting behaviour of a function. For sorting purposes this describes the best case runtime of sorting function based on input size n. We tested this in the Lab in week 10. We had to run each sorting algorithm on a list of items and see how the runtime changed with different factors (sorting, random). What we learned from this lab that certain sorting functions are better based on these factors. Another important fact about sorting is that merge sort and quick sort at O(nlog(n)) is the fastest runtime of a sorting algorithm. This is compared to other sorting algorithms at O(n^2), O(n), etc. After looking at each algorithm I begin to get an appreciation for what it takes to make an efficient algorithm. What I found hard about Big O notation is that it is hard to understand how runtimes are derived from the function. I will have to read more in depth into how every algorithm works so that I can get a better understanding of how they all work and how their runtimes compare and why they are a certain time.

Saturday 1 March 2014

Week 7: Recursion

Through the last  few weeks the main topic of study was recursion. The literal definition of recursion is "defining something in terms of itself", possibly multiple times to achieve your objective. In code this would mean that a function would call itself again and again until some condition is met (the final goal/solution). A real life example of recursion is when someone could say "everyone has a Mother". You can constantly say that about one person and the person who is the Mother. So in programming terms a recursive function must constantly go deeper and deeper in to itself.

Going in to the topic of recursion I was not comfortable with the idea of it. But after listening to lectures and doing my own research I able to grasp the basics of how it worked and what it was used for. Recursion is used to solve problems that are depended on smaller instances of the same problem. This is like dividing a problem into a sub problem of itself. Even though I understood the main idea of recursion, when it came to tracing solutions for examples during class and tests I was confused. I was able to overcome this problem when I learned how to divide each instance of a recursive function separately based on a parameter and thus be able to trace the values output by the function.

I am able to see the possibility of using recursion in programming. After using it in the Tower of Anne Hoy I was amazed with the possibility and applications of recursion. How it was able to solve a problem without a DEFINITE solution, by this I mean how the solution to how many cheeses' there were in the problem the recursive function was able to solve the problem for how to complete the game. I am excited on future possibilities and programs that would possibly become more complicated and will be able to do more with recursion.

Tuesday 21 January 2014

Week 3: Object-oriented Programming

One of the main topics throughout the first few weeks of classes has been object-oriented programming and how it differs from procedural programming. Firstly OOP programming paradigm (a fundamental style of programming) uses objects to represent concepts. The main focus is using classes as objects which contain both data and have a function. These classes correspond to an object in the real world and have functions that operate like they would in the real world. Furthermore, each object instance has attributes. Attributes are names contained in namespaces that can be saved and accessed. The idea of OOP at first was very clear to me. The idea of it worked was very straight forward and logical. The example of the class "Point" made it even more clear. It having different methods and attributes as if that point where to be drawn on a graph in real life. It has attributes (x and y coordinates) and you can do calculations using this point (distance from origin) using methods. OOP is one of the most interesting things I've learned so far. It makes me think of all the possibilities of future programming and how OOP can be used to create better more interesting programs.

Another topic throughout the first few weeks was the idea of advanced data types (ADT's). The concept of stacks is a collection of of data which can be manipulated by removing and adding. Stacks are specialized where you only have access to the most recent added item. When items are added to a stack they are put at the top of a stack and also can only be removed from the top so that there is no increase in runtime of the program based on how many items are in the list. The idea of stacks at first to me was slightly confusing. I didn't really understand what it was and how it was meant to be used. After looking over it again, researching online and mainly in lab I began to get a deeper understanding of stacks.

Another important topic covered is recursion. Basically recursion is a function that calls itself. At first I thought it was simple until I looked through examples. The process on how it actually worked was the most confusing part for me and I still don't feel 100% about it. From examples I could understand that recursion is used to make a complicated task simpler by using the same function multiple times to break down a problem. That is what I can gather right now from recursion, I plan to go over the programs and examples done in class so that I can begin to get a larger understanding in more detail of how recursion works.