- Be able to define the term pseudocode and algorithm
- Be able to use pseudocode to describe the flow of an algorithm’s implementation
First, spend 5 minutes writing an “algorithm” that explains how to tie your shoes. Try to be as explicit and specific as possible. Assume your reader is a human, but a very literal one.
- Begin with your feet in untied shoes.
- Take one lace in each hand.
- Cross laces.
- Wrap end of left lace under right lace.
- Pull ends of laces until they're tight against your shoe.
- Make a loop with one lace end, holding the end of the lace against the base.
- Wrap the end of the other lace around the base of the loop.
- Pull the middle of the second lace through the knot to make another loop.
- Pull the middles of both loops until laces are tight enough.
Now, pair up with your neighbor. The person whose name is alphabetically first will read their algorithm step-by-step to the person whose name is alphabetically last. The person whose name is alphabetically last will attempt to tie their shoes according only to the instructions from their partner.
You can repeat instructions if needed, but don’t add any instructions beyond what you had originally written down.
A programming algorithm is a computer procedure that is a lot like a recipe (called a procedure) and tells your computer precisely what steps to take to solve a problem or reach a goal. The ingredients are called inputs, while the results are called the outputs.
Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. Programming – what makes it hard? (Translating ideas into code? Or coming up with ideas?) An Iterative Process
- How will you know when the problem is solved? (Identify the big-picture goal)
- How do you want to use the software? (Identify the “interface”)
- What’s the (next-)most trivial possible case? (Identify the next small-picture goal)
- How do we achieve this goal? (Sketch an algorithm using pseudocode)
- Implement it (do programming)
- Is the whole problem (from step 1) solved? If not, return to 3.
Answer the questions from steps 1 through 4 for the following problem. When you get to steps 3 and 4, repeat them at least 3 times for increasing levels of complexity.
I have a text document and want to know “What are the three most common words in the text?”
- Search the document
- Find the three most common words
- Extract them from the text
- Place the words in the outputs
if match, delete I, you, etc Then run the above
I have a file with 100 numbers. I want to create two new files: one with all the odds and one with all the evens.
even_file << if.even? odd_file << if.odd?
I have a file with 100 latitude/longitude pairs. Find the point that’s closest to the north pole.