Computational thinking in programming
Last updated on 2024-03-12 | Edit this page
Decomposition is crucial in any kind of problem breakdown, but especially so in programming. The computer must be told precisely what to do, and in what order, so problems must be broken down into discrete parts and each section coded appropriately.
Suppose we want to find the ten words most commonly used in a text. How might we go about that?
Linear code
While there are many different ways to do this task, this is one way, where all the commands are run in a linear sequence, e.g.,
First we save the file in .txt
format to eliminate all
the “smart” formatting created by programs like Word (as they would
otherwise introduce a messy bunch of extraneous characters). Then we
progressively eliminate everything from the text that is not a word,
i.e. punctuation.
Converting all the words to lower case means we end up with a single
version of each word - not two. This is important because, to a
computer, Word
(starting with an upper case letter) does
not equal word
(starting with a lower case letter) - it
treats them as two separate entities.
By replacing spaces with new line
characters, each word
will end up on its own line, which makes them easy to sort
alphabetically and then count.
Each part of the sequence would need to be individually programmed. Fortunately, programmers can adapt code that others have already used to do similar tasks, such as code to identify letter, number or word frequency. Once you are coding, this is where the computational thinking skill of pattern recognition comes in - identifying similar code that can be used for or adapted to the specific problem you want to solve.