In programming drilling, I am still in the process of groking insertion sort. Insertion sort can be thought as a combination of two operations. 1) find the place to insert. 2) shift. In fact these two operations are more general patterns which in actual programming that appears most. These two basic operations is not entirely trivial. Or else there won't be tricks just to improve one single aspect. e.g. Binary insertion sort is trying to improve how you find the place to insert. Using tricks like memmove and linked-list means you shift faster.
I still don't think I grok insertion sort. Shell and library sort are the two ideas I want to drill it. They are deep concept. That might mean I need to set it aside and call it Read 4 in future.
I also read Sedgewick's survey paper on Shell sort. It's interesting to read and the fun part is that I think I understand the argument. This is likely because my background of having read "Elementary Number Theory". (It's a great self-learning book by the way.) I guess I will some time to drill on it until I grok.
This is my self-study page for the book, "Introduction to Algorithm", or commonly known as CLRS. This is also my diary page of how I struggle and grow in the programming world. I hope this blog can help amateurs or professionals, to improve their skills in programming, learning and living. As of Sep 12, 2011, I finished the "exercise read" of Chapter 2 (20110518) and 3 (20110608) and half of Chapter 4.
Shortcut for chapter specific information
Chapter4
(62)
chapter3
(41)
Chapter2
(22)
chapter6
(10)
chapter12
(9)
chapter15
(8)
chapter13
(7)
chapter7
(7)
Chapter10
(5)
chapter5
(5)
Appendix A
(4)
chapter8
(4)
Chapter19
(3)
Chapter22
(3)
Chapter34
(3)
Chapter35
(3)
chapter11
(3)
chapter16
(3)
chapter18
(3)
Appendix C
(2)
Chapter21
(2)
Chapter25
(2)
Chapter26
(2)
Chapter27
(2)
Chapter28
(2)
Chapter29
(2)
Chapter9
(2)
chapter14
(2)
chapter20
(2)
chapter23
(2)
chapter24
(2)
chapter30
(2)
chapter31
(2)
chapter32
(2)
Appendix D
(1)
Chapter1
(1)
Chapter33
(1)
chapter17
(1)
Showing posts with label insert sort. Show all posts
Showing posts with label insert sort. Show all posts
Saturday, May 21, 2011
Wednesday, April 27, 2011
Debugged Insertion sort 47
What happened? Turns out I used
"> =" instead of ">=".
The whole thing dies.
The perfect one-liner game is not for everyone......
"> =" instead of ">=".
The whole thing dies.
The perfect one-liner game is not for everyone......
Insertion sort 45 -47 (perl one-liner)
Ah, it got me. 45 and 46 both failed first time. Debugging one-liner needs to make sure bracket matches mentally. (It's difficult.) I even found that I can't debug insertion sort 47. Since the machine is suddenly halt.
Bummer for the day, I guess this is skill. You got to fail sometime to refine it.
Bummer for the day, I guess this is skill. You got to fail sometime to refine it.
Tuesday, April 26, 2011
Insertion sort 43 (perl one-liner)
:) Quite epic.
perl -lane '{push @A,$_}END{for($j=1;$j<$#A+1;$j++){$k=$A[$j];$i=$j-1;while($i>=0&&$A[$i]>$k){$A[$i+1]=$A[$i];$i--}$A[$i+1]=$k;} printf("%s\n",join(" ",@A))}'
33_P
perl -lane '{push @A,$_}END{for($j=1;$j<$#A+1;$j++){$k=$A[$j];$i=$j-1;while($i>=0&&$A[$i]>$k){$A[$i+1]=$A[$i];$i--}$A[$i+1]=$k;} printf("%s\n",join(" ",@A))}'
33_P
Sunday, April 24, 2011
Friday, April 22, 2011
33rd writing of insertion sort (C)
Nailed it. Feel more natural. It's better to time myself from now on.
33_P
33_P
Thursday, April 21, 2011
29th writing of insertion sort (perl)
Still got it wrong. Changed > to = in the second condition. Should spot-check every condition before interpretation.
Wednesday, April 20, 2011
21st time of insertion sort writing(C)
Get it right.
This makes you compare program writing as playing an Arcade shooting game. Equally difficult but equally understated.
33_P
This makes you compare program writing as playing an Arcade shooting game. Equally difficult but equally understated.
33_P
17-19th writings of insertion sort (C)
Had lunch, try again.
17th: missed i=j-1;
18th: when print, print i instead of A[i]. Wow 3rd time.
19th: get it right.
That's why not many people can treat programming as arcade. Even a simple game like insertion sort is not easy to play.
33_P
17th: missed i=j-1;
18th: when print, print i instead of A[i]. Wow 3rd time.
19th: get it right.
That's why not many people can treat programming as arcade. Even a simple game like insertion sort is not easy to play.
33_P
17th writing of insertion sort (C)
Get it right the first time.
Of course, all these writings are all start from scratch. It's like you retype a command.
Another discovery: these kinds of practice doesn't take time at all. Why not?
Of course, all these writings are all start from scratch. It's like you retype a command.
Another discovery: these kinds of practice doesn't take time at all. Why not?
Subscribe to:
Posts (Atom)