Tuesday 1 April 2014

Sorting And Efficiency

Last semester, I learned a decent amount about sorting and efficiency in CSC108. The main sorting algorithms I learned about were Bubble sort, insertion sort, and selection sort. Efficiency was touched upon, atlthough not as in depth as CSC148. I mostly learned about analyzing the best case and worst case. Best case is the least amount of steps possible the algorithm could perform while worst case is the most amount of steps possible the algorithm could perform. All of this depends on how the initial list is sorted. In CSC148, we learned about a couple of new sorting algorithms including merge sort and quick sort. From my understanding, merge sort splits lists approximately in half into smaller sublists. It then compares a pair of sublists and "merges" them into one sorted list. It does this by comparing the smallest value in each sublist, then putting the smaller value into the new merged list. From what I learned in class, the efficiency of this would be affected by how many times the list has to be split. Generally, no matter how a list of a certain size is sorted, the performance of this algorithm will generally be the same--unless the list is already sorted. Quick sort picks a pivot at random and sorts the values smaller than it to one side and values greater than it to the other side. Quick sort keeps doing this until the list is sorted.  I learned in class that depending on the pivot chosen for quick sort, the efficiency of it could be seriously affected(Example: If the pivot was the smallest value, it made it harder to sort). Danny solved this problem by making the pivot always random. Therefore from what I learned, if n amount of items are to be sorted by quick sort and merge sort, the performance of quick sort will vary more than that of merge sort. In terms of measuring algorithm performance, CSC148 introduced us to Big-Oh. Big-Oh measures the upper-bound of a function and is used as the symbol beside a certain run time of a function (Example: Linear run time is O(n) and quadratic run time is O(n^2).

Sunday 30 March 2014

CSC148 Week 10

A good portion of my week during week 10 of CSC148 was spent working on Assignment 2 Part 2. For my group, I was mostly working on the docstrings and the is_regex function. Although Danny explained in class a certain way to do an is_regex function, I didn't quite understand it. My partners and I worked on an alternate way of doing it without recursion and it worked from the results we saw, however this took a lot of time and effort compared to the amount of time we would've spent if we had figured the recursion out. Our algorithm was a for loop checking every character in the string, checking if the characters next to it were valid characters. Since there were so many possibilities, this took a lot of testing and the code turned out to be very long. Although the purpose of the function worked, I am a little disappointed since I wanted to make it work using recursion, but wasn't able to. It's already almost the end of the semester and I am really starting to get worried about my programming skills, especially with recursion and trees.

Sunday 23 March 2014

CSC148 Week 9

Week 9 of computer science focused on binary trees as well as other things. One thing that has been reintroduced was list searching from CSC108. My initial reaction to this was that it was going to be a pain again just like it was in CSC108. I had a lot of trouble with list searching in CSC108 at first but was eventually able to get it at the end. So knowing the pattern of how CSC148 has been going, the list searching this time around will be again harder to understand, especially in code form. It seemed so simple when it was being shown by Danny on the camera, which it is when we are thinking about it in terms of real life. However, on code it seems to me like it is much harder than thinking about it in real life. Running time analysis was also reintroduced this week which has got me even more worried. I must say I feel very overwhelmed going into the term test 2 coming up soon, and even more overwhelmed going into the exam next month although it is still far away.

CSC148 Week 8

Week 8 of CSC148 again focused on linked lists and going more into depth on linked lists. It was a pretty busy week since there was a lab like always but assignment 2 was also handed out to us.The lab consisted of adding methods to a LinkedList class, similar to the week before. I would still say that at this point that I still find this material very challenging to understand and keep up with. Last semester during CSC108, I already thought that a lot of the things we were doing were very challenging already. Now I'm here almost done CSC148 and I find that CSC108 was nothing compared to this and that this is at a whole different level. The hardest part for me right now is still understanding the recursion process in bigger problems. I always have to think more and sort of plan ahead before coding compared to before. However, I find that sometimes I understand what I am supposed to do but cannot put it into code which has been consistently been a problem for me when it comes to CSC148. There's also been more focus on helper functions on week 8 and although it wasn't that in depth, I understand its purpose. A challenge for me is applying this to my own code, instead of just following along in lecture where I seem to understand most of it. When I am alone, it's a whole different story.

Thursday 6 March 2014

CSC148 Week 7

Week 7 of CSC148 was a tough and stressful week for me because of the test on Wednesday of that week. Before I talk about the test though, I want to talk about the lecture on Monday and the lab on Tuesday. On Monday, we learned about LinkedLists and I found it interesting but at the same time confusing. Like many of the new concepts that I have learned this year, I found that it takes me a whole to understand it completely and LinkedList is no different.
On the lab, my regular partner wasn't there so I had to work on the lab by self. The instructions on the lab were very simple in my opinion but yet again, I ran into trouble when trying to code what I understood. The idea of implementing queue ADT using a linked list didn't seem difficult but it turned out to be harder than I expected. I wasn't able to implement some of the methods properly such as push. Although I had the steps right in my head, I wasn't able to translate all of it into code. The lab ended with me only passing half of the test cases.
I studied and prepared hard for the test in my opinion but I came out of the test not feeling so well. Even though I studied, I felt that a lot of my studying didn't help me so much, especially with trees. I think the most important thing I've learned on week 7 was that I shouldn't hold in questions that I might have. I felt like if I asked Professor or some other students more questions to clarify things I didn't understand, that I would have done better on the test, perhaps even if I studied less because some of my studying I feel went to waste because I was studying things I didn't quite understand completely. I want to make it a priority now to ask questions when I need help, not necessarily just to get better marks, but to gain knowledge and understanding of computer science, which as of right now is my major. Getting good marks but not understanding will hurt in the long run.

Friday 28 February 2014

Recursion

One of the new things that has been taught to us this semester is Recursion. The definition of the word "Recursion" is "the process of repeating items in a self similar way". In Computer Science, recursion mean "to define something within itself. A recursive function would be a function that calls itself in it's definition. This is somewhat similar to an iterative function definition that has a loop. Recursion is a powerful tool because functions can call themselves multiple times in order to achieve their objective or goal. However, in order for the recursive function to know when to stop calling itself, it must have a base case. Base Case is defined as "A branch of the conditional statement in a recursive function that does not give rise to further recursive calls." Without the base case, the recursive function will not stop calling itself and will eventually result in a recursion depth exceeded error. Base case could be somewhat compared to the condition in a while loop, because the base case will stop the recursive calls once its conditions are met, just like a while loop will stop when the condition of the while statement is fulfilled. Therefore, base cases are always included in the conditional structure of a Recursive Functions. Also included in the conditional structure of a recursive function is a general case. A general case specifies how to combine recursive subcalls.
After studying recursion for a couple of weeks now, I understand why it is a very useful and powerful tool to use in Computer Science. However, I am personally having a difficult time applying the idea or concept of it into my own coding. For example, If I see a problem where I believe recursion could be used, I sometimes don't know how to code the recursive function correctly, especially for more complex problems. Also, I also have found that tracing a recursive function to be a really big challenge. I remember at the beginning of CSC108, my professor said that Computer Science is one of the courses where the time it takes people to understand and be able to solve problems varies wildly, where in some cases a problem could take one person a short amount of time to solve, and another person a very long time to solve. I think I am one of those people that take a longer time to apply the concepts we have learned to programming. I believe it will come in time and through practice.
In conclusion, I personally believe Recursion is an important aspect to learn in Computer Science since it could be used in so many ways to solve small problems and big problems. Additionally, if coded right, it will save a programmer a lot of duplicate code, which contributes to the idea of "laziness" in Computer Science. I think I have made progress since first learning Recursion since I now understand its concept and purpose a lot more than I did before, now its just a matter of being able to apply it when I have to solve problems on my own.

Thursday 20 February 2014

CSC148 Week 6

Week 6 of CSC148 lectures was an interesting week for me. Week 6 introduced a new concept--at least to me--about how to think like a computer scientists, using the concept of a tree as an analogy to computer scientists. On the surface, this new concept to me seemed simple to understand, especially during lectures when Professor was going over it. However, upon doing the readings on it myself, I found that it was a little bit more complicated than I initially imagined. The analogy of the tree does make sense to me but applying it to code is a little bit confusing. A lot of times in this course, I have found that I have a hard time applying my understanding of concepts that I have learned in class to my own approach in programming. For example, while working on assignment 1, I somewhat understood what I had to do but I couldn't write it in code and needed my partner's help. I think that all of this is a learning experience for me and I hope I can use the reading week as a time to grasp and understand the course material better. As I prepare myself for the CSC148 midterm, I plan to review the labs that we have done and re-read the readings. I hope that by the time the test comes around that I will be prepared for it. For me, the biggest challenge is to be able to take my understandings of each specific problem and apply it into written code. In conclusion, week 6 was a useful week and I hope that by the time we return from reading week that I will have a much deeper understanding of the course material so far. The reading week will definitely be able to help me with that.