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.