Computational Thinking, Problem-Solving, and Programming
Computer science is sometimes defined as the study of algorithms and their efficient implementation in a computer. The focus now is their role in problem solving, strategies for developing the, techniques for following and testing them. Because algorithms operate on data, we examine ways to structure data so that it can be more efficiently processed.
General principles[edit | edit source]
Thinking procedurally[edit | edit source]
Generally speaking, all problems begin with an idea. Finding the connection between this information and the solution lies at the heart of problem solving. To do this, the following strategies can be utilised.
When given a problem or task verbally, one typically asks questions until what is needed is known fully and clear. Generally, when, why, and where are asked until the task is completely specified. If the instructions are written, one might put question marks in the margin; underline a word, a group of words, or a sentence; or in some other way indicate the parts of the task that are not clear. Perhaps the questions might be answered in a later paragraph, or one might have to discuss them with the person giving the task. If the task is one that it self-set, this sort of questioning might not be verbal, but instead takes place on the subconscious level.
- In this case, some typical questions that one should consider are:
- What should I know about the problem?
- What does the solution look like?
- What sort of special cases exist?
- How will I recognise that I have found the solution?
Look for Familiar Things[edit | edit source]
Don't reinvent the wheel. Exploit the similarities between previous problems solved. This is a form of pattern recognition.
Divide and Conquer[edit | edit source]
Algorithms[edit | edit source]
Computer Problem-Solving Process[edit | edit source]
Summary of Methodology[edit | edit source]
Testing the Algorithm[edit | edit source]
We constantly break up a large problem into smaller units that we can handle. The task of cleaning the house or apartment may seem overwhelming. The task composed of cleaning the living room, the dining room, the kitchen, the bedrooms, and the bathroom seems more manageable. This principle is especially relevant to computing.
Do not reinvent the wheel. If a solution exists, use it. If you have solved the same or a similar problem before, just repeat the successful solution. We usually do not consciously think, "I have seen this before, and I know what to do" - we just do it. Humans are good at recognising similar situations. We do not have to learn how to go to the store and buy milk, then to buy eggs, then to buy candy. We know that going to the store is always the same and only what we buy is different.
Recognising familiar situations is particularly useful in computing. In computing, you see certain problems again and again in different guises. A good programmer sees a task, or perhaps part of a task (a subtask), that has been solved before and plugs in the solution. For example, finding daily high and low temperatures in a list of temperatures is exactly the same problem as finding the highest and lowest grades in a list of test scores. You want to the largest and smallest values in a set of numbers.
Thinking logically[edit | edit source]
Thinking ahead[edit | edit source]
Thinking concurrently[edit | edit source]
Concurrent processing allows for faster computation, as multiple tasks are run simultaneously. However, concurrent processing is a lot more difficult to program.
Thinking abstractly[edit | edit source]
Connecting computational thinking and program design[edit | edit source]
Searching algorithms[edit | edit source]
Sequential search[edit | edit source]
There are numerous algorithms that exist in the realm of computer science, however, sorting and searching are two of the most important types.
Sequential, or linear, search is the simplest search algorithm; it is a special case of brute-force search. Its worst case cost is proportional to the number of elements in the list; and so is its expected cost, if all list elements are equally likely to be searched for. Therefore, if the list has more than a few elements, other methods (such as binary search or hashing) will be faster, but they also impose additional requirements.
This relies upon the linear array being sorted into order. Assume we want to find X.
- Start at the middle element.
- Is X greater than or equal to that element?
- If yes, remove all lower than that from the population.
- Move to the middle of the new population and repeat.
Note the 'middle' is always the larger element when you have an even set.
Assuming we are sorting a list of numbers from lowest to highest.
- Starting from the left, compare that number X to the one on its right Y.
- Ix X>Y then swap X and Y around.
- Repeat through the entire list.
- Repeat whole process until nothing needs to switch on a full pass through.
The simplest way to sort from low to high.
- Go through entire population and find the lowest.
- Shift the lowest to the farthest left.
- Ignore the sorted element(s), go through the remainder of the population in the same manner.