Wednesday, 30 March 2016

Slog Views: Lets Reflect

        It has been 3 months since I began blogging and today, unlike my other slog entries I am going to take this time to revisit an earlier slog and reflect. My most recent slog 'The Puzzle Solver' has already 6 views. In the 'The Puzzle Solver' entry I discussed about the computer science assignment I submitted last week and how I approached it. Writing that entry allowed me to express how I was thinking and how I managed to complete this challenging project. I think its important as a computer scientist to explain to others how and why you tackled a problem. Its also important to include why your solution was a good idea. Based on my views (6) I am somewhat impressed. I would have never expected such attention and because of that I am truly grateful. I appreciate those that take there time in reading my slog. The last time I checked the views for 'The Puzzle Solver' was 3. Therefore, I am proud to say that my views are increasing. I also made sure not to include my own page views in the page view count on the statistics  page. It wouldn't be fair to say that I had many views when most of them are me. Because of this increase in views, I believe people are becoming more interested with computer science and hope to see what I learn in this class. I also think its because the assignment was interesting and exciting. In addition to this, I also have a total of 83 views for the past three months of blogging. I really hope that you readers are beneficiating from my weekly posts and learn something new. 

Wednesday, 23 March 2016

The Puzzle Solver

        I recently submitted Assignment 2. As I previously stated, in this particular assignment we were asked to implement some classes so that we could solve four puzzles: Sudoku, Peg Solitaire, MN Puzzle and Word Ladder. Similarly to assignment 1 the professor provided a starter code and it was my responsibility to complete it.There were many methods that needed to be implemented such as extentions, is_solved , fail_fast and many more.

        To tackle this assignment, I first had to understand the rules and purpose of each game. Once I built enough confidence, I thought: How could my program solve these puzzles? The only solution that crossed my mind was if the program explored all of the different possible game moves from a given board. From those possible game moves, the program would then explore the possible moves of these and so on. With this idea, a tree needed to be built. The children for a 'current board' would be all the possible moves that the computer could make from that current board. This would continue until the answer is found. The methods depth search and breadth search especially helped in this area. These searches simply use recursion to search for the solution in the tree. It was very important for me to implement extensions and is_solved correctly for each puzzle. The searches use these methods to access and return the solution in the tree. Method extensions returns a list of children of a given puzzle and is_solved simply returns whether a current board is solved.

      Personally, I enjoyed this assignment much better than the first. This is because it dealt with puzzles which I personally enjoy and was less confusing. I was able to see the connections between all methods immediately in the starter code and hence made it much easier to complete.

Wednesday, 16 March 2016

Test # 2

      I had my computer science test this week. The test was not extremely difficult and it asked questions that I was expecting. The test consists of recursion, binary trees, regular tress and linked lists. I studied very hard on linked lists, recursion and regular tress but binary trees, I could have studied more. Despite this, I feel that I performed alright on the exam and am eager to see my mark. In addition, the computer science assignment is due next week. In the assignment we are asked to create a program that solves four puzzles: Sudoku, peg solitaire, word ladder and MN puzzle. This assignment sounds really cool and I am pretty excited to start. I will have a more deeper discussion on how I will tackle this assignment in my next slog. As of lecture material we haven't learned anything new since I have mentioned, the test is this week.  

Thursday, 10 March 2016

It Just Got More Complicated: Trees, Linked Lists and Recursion

Previously, I have been introduced to recursion and learnt about linked lists. During this week, we talked about trees and how they can be created in python by using linked lists. The tree can then be accessed and tweaked with methods that use recursion. This topic is very challenging for me. I understand and have done many examples on linked lists, but recursion is something that I need to work on. As we go through more challenging and complicated functions that require recursion, I become confused and overwhelmed. For instance, the quiz I had today was asking to implement a function that counted the number of nodes in a tree. I am confident that I implemented the base case correctly, but when it came to the recursive step it became difficult. I became even more frustrated afterwards while I was walking home. This is mainly because I suddenly knew the answer and realized my foolish mistake near the end of my code. To prevent this, I am going to do many examples tomorrow and test them thoroughly. Sometimes when I am asked about a confusing topic I forget to look over my work and I just hand it in. That cost me today. I also know that my midterm for csc148 is next week and I will ensure that I don't repeat this mistake. As I previously mentioned I will do many examples and practice! Practicing is the only way I can do better and develop the skills that I need to become a good programmer.

Thursday, 3 March 2016

Recursion


    This week I learned about recursion. Recursion is a technique that allows a function to call itself and can be a pretty powerful and useful tool.  For example, you can use recursion when finding the factorial of a number, as shown in the following:

Fact(n)
if n==1:
    return 1
else:
    return n x Fact(n-1)

     In this example, the Fact function is calling itself and calculating the factorial of n by breaking down the task to two steps.
     Recursion takes a task and breaks it into smaller pieces that are more manageable. I find this technique very interesting and am excited to do more practice on recursive functions. With such a powerful tool I think that it is important to use such a technique wisely. Currently I am still wondering which cases recursion should be used and when it should be dismissed. The reason I ask is because recursion is very elegant but can sometimes be inefficient. For instance, recursive sequences store lots of data and take time. I believe that as a computer scientist it is crucial for one to understand when such a powerful tool is needed and when it is unnecessary. It is important to develop these skills so that you can write a simple yet efficient program. Hopefully I can have these questions answered when I ask my T.A and professor this week.