After sleeping for nearly 12 hours, another sleepless night passed. I decide to write this post because this post reminds something about my weakness when dealing with algorithm problems. Maybe my low IQ is which I should blame to. But I love my parents, this is not their fault. So I think I should try to confront the shadow side. At least I have plenty of time to prove how poor my mind is, and before that I shall not give up my weakness.
Enough for dirty words. Here’s the problem, I put it to the gist.
How to abstract reality problems to sort problems, and how to take advantage of sort to find out things that interest us?
The code above, I want to use observer design pattern ( compare_event ). Yes that’s the part to emphasise that we always want to search things interest us, if not, why we search things? So that is the pattern of human beings, and I always decouple things when I find a point that fit normal brains.
Here is the steps that I always follow to create a solution:
- Understand them, feel them, and try to measure them. We always have a way to quantify things, though most people die here or find a really bad way to measure things.
- So we have convert states to numbers in the first step. We can use the numbers to compare two things.
- If I want to search something, I always search things while sort them. You always do the two things together, think about it when you are paring the socks from your washing machine. Even school child does it without thinking.
- I interpolate tasks while each comparison. Searching itself is also a task. Each task can access the current comparison result and process state.
- Choose a sort algorithm which fit the situation best
- Launch the whole process.