2014年3月30日星期日

csc148 SLOG9: Sorting and Efficiency

    I don’t have many things to talk about. Efficiency is important for a successful program. 

    It seemed that operations like assigning values to variables take a lot of time. For example, insert sort 2 in the 10th lab was faster than insert sort 1 because instead of swapping (involves assigning) values, it returned the index of the right spot to insert and only assign value to that index. 

    I was surprised by the speed of the build-in sort. I did understand why merge sort is always fast but I the build-in sort is still way faster than it. I learnt it at the end of the lab. TA showed us how the build-in sort divides the list into many pieces and merge them in the end. It was so fast because dividing and merging lists take linear time but sorting requires more. 

    I am still a bit unclear about the two versions of bubble sort. From the description, it looked like the second one should be faster, since it would stop when not necessary. But in our test, the first one is faster. I will try to figure that out.

2014年3月23日星期日

csc148 SLOG8

    This week was still hard for me. Different from assignment 1, I finished assignment 2 part 2 1 day ahead of the deadline. I felt relieved.

    Assignment 2 tortured me a lot. I doubted my answer often, since it certainly was not the most efficient way to solve the problem. For example, when generating the regex permutations, I could have limited the dots and the bars inside the parenthesis but I failed to. Then the codes I wrote took minutes to run on some input. Besides, it was hard to choose whether to merge different cases together or seperate them. Combining different cases can avoid duplicating codes, but it could make codes longer than separating the cases and it made the codes unclear.

    I also had to deal with the style problem. A line that looks wonderful had to be modified due to the length. I wrote an if statement in one line and because of the last word fell to the next line, I had to rewrite this if statement in four lines, including an else case who took 2 lines. I was a little amazed by the length the code had. I doubted whether or not it would work with a shorter length.


    But anyway I handed it in after learning that I didn't have to pay too much attention on efficiency for now. I sometimes blame computers why they are so stupid that they never understand my mind. But that is why I am learning computer science. And I love computers.

csc148 SLOG6&7

    Sorry I was too busy that I almost have forgotten my SLOGs. These few weeks were tough for me. Exams and assignments were filling up my time. This SLOG is built up from my memory.

    I was not doing well in labs. That was expected for me. I have to admit I missed a few classes that made things even worse. So assignment 2 and exercise 3 that have just passed taught me a lot. Practices do bring improvements. I knew the class has moved on to binary trees. I remember I first saw it in the lab. I got terribly confused. But I did manage to make it clear for me in the labs by asking. I finished the tasks after the labs.

    I was still on the way to catch up with the class by end of last week. It is not too far away now.

2014年3月2日星期日

csc148 SLOG5: Recursion

Still, I am not doing good in recursion. For most of the time, I can understand the question well and represent the operations in English or math, but I don’t know how to translate them into Python. For example, I failed to write the best recursion in assignment one to operate the cheeses in the smallest steps.

Recursion itself is not something hard to understand. It is like a function that has only one kind of base operation, and the rest are guiding the function itself to the base operation. So simple cases are fine for me. It is just a choice whether the function should do the base operation or keep on entering itself to choose again with some simple indirect edit. But when facing complicated ones or when recursion is just part of the program, I feel struggling. 

I have done many practices on deciding base cases. It looks good. Now I should start to practice translating, those small edits before the function reenter itself. 

2014年2月17日星期一

csc148 SLOG4

We learnt about binary trees this week. I was somehow familiar with it since I was also learning it in class csc240. It is always a good news to have different classes linked together. Though, I was sometimes confused by the expression. Also, I was still having trouble finding the base cases for recursion functions. 

Assignment was hard for me and exams was filling my week. I had to accept some scarifies. I was unable to find out the best way for the recursion, but at least I finished the three files. Besides, I had great trouble when running GUI files. I was also experiencing the problem like ‘cheese does not have attribution highlight’. I spent hours on it and finally fixed it. Actually my original TOAHModel.py used a different cheese-location storing method. It worked well when I ran it in Python Shell, but not when complementing with GUI. I should have read the hand out carefully. That wasted me a lot of time.

I wasn’t so worried about the lab. My partner and I did well in it. We finished the tasks before class was over. 

2014年2月9日星期日

csc148 SLOG3

    I am now beginning to understand recursion functions. Actually I am doing quite well in this week’s lab. I finished all the tasks in the lab and thought of the optional ones. All I need to improve now is to practice finding the base case for recursion functions. In the lab for example, I did manage to get the code work, and it contains itself as a recursion function, but the base case wasn't separated and instead is aligned with the recursion lines.

    Besides, I am getting used to put adjacent lines into one. For example,
                if x > 1:
                    return True
                else:
                    return False
can be squeezed into one line :
                return True if x>1 else False
That saves a lot of space and is just as easy to read as the longer one.

    
    The problem for me this week is probably understanding assignment 1. And now I am having a hard time with it. I admit I feel a little delighted when seeing the sentence saying that this assignment is challenging. Deadline is approaching. 

2014年2月2日星期日

csc148 SLOG2

    I think I am in the right class. When I was taking csc108 last semester, I thought that coding was easy. Now I find that it isn’t in csc148. Actually it was very challenging. There were always new methods and words popping up in my mind (for example, method isinstance). Sometimes old things got replaced by fresh ones. I should have pointed it out in last week’s SLOG. For example, a new way to represent type contract in docstring is to add a colon after the input variable, and simply write the type contract there. (def something(variable:type)->type). For another, a loop can be written in a single line (//ToDo for x in f(x)). But these are the reasons I am studying.

    We learned more about recursion this week. I remembered the turtle best since it drew something on the screen. Recursion does save time and cut down lengths in programming. Though, it was hard for me to understand a recursion code at a glance.

    Just like last week, I got lost when doing the tutorial task. I almost went crazy when writing the test file. I didn’t finish the lab, but I completed it in my dorm. That drove me crazy again. All that stuck me were those tiny little bugs, like spelling errors or missing a bracket. A very simple mistake could kill my program. I wanted to say it was just because of carelessness. Nonetheless, I knew I wasn’t comprehending the material well. I have to practice more. Also, reviewing is necessary. Sometimes I have to search the previous slides and examples for some knowledge learned. I forget things.