Module 18 · Algorithms and Problem Solving — topic 4 of 18
Pseudocode
Describing algorithms in structured plain language: common pseudocode keywords, indentation for structure, writing pseudocode before code, and translating it line by line into Python.
Learning objectives
- Write clear pseudocode for an algorithm
- Translate pseudocode into Python
- Use pseudocode to plan before coding
Definition
Pseudocode is an informal, language-independent description of an algorithm that uses structured English with programming-like keywords (IF, WHILE, FOR EACH, RETURN) and indentation, without worrying about exact syntax.
Introduction
Pseudocode is how programmers sketch algorithms on whiteboards: precise enough to implement, loose enough to write quickly.
Why it matters
Separating 'what are the steps?' from 'what is the syntax?' makes hard problems easier and lets you discuss algorithms with anyone.
Detailed explanation
Pseudocode has no strict rules, but common conventions use keywords such as SET, READ, PRINT, IF ... THEN ... ELSE, WHILE, FOR EACH, RETURN and END.
Indentation shows which steps belong inside a loop or decision, just like in Python.
Write at the level of ideas: 'find the largest value in the list' is fine if it's obvious; break it down further when it isn't.
Good pseudocode is precise about data and conditions — 'IF count is 0' rather than 'if there's nothing'.
Python's readable syntax makes translation very direct: FOR EACH becomes for, SET x TO 0 becomes x = 0.
Pseudocode is also useful as comments: write the steps as comments, then fill in code under each.
Exam boards and textbooks often define their own pseudocode style; the ideas are the same.
Check pseudocode by tracing it with a small example before writing any code.
Syntax
- Structured English with keywords.
- Indentation shows structure.
- Translate line by line.
Code examples
Pseudocode for a search
Translating to Python
5.0
More examples
Pseudocode as comments
enjoyable ''
Step-by-step explanation
- Each comment is one line of the original pseudocode.
- The Python under each comment implements that step directly.
- Tracing the empty sentence shows the loop never runs and the empty string is returned.
Expected output
Running “Pseudocode as comments” prints exactly:
Practical applications
- Whiteboard interviews and design discussions.
- Algorithm descriptions in textbooks and research papers.
Best practices
- Write pseudocode before tricky code.
- Be precise about conditions and data.
- Trace it with an example.
Common mistakes
Pseudocode that is really code
Avoid
Prefer
Pseudocode should express the idea, not a particular language's syntax.
Vague steps
Avoid
Prefer
Steps must be specific enough to implement.
Important notes
- Many algorithm books present algorithms only in pseudocode so readers can use any language.
Key takeaways
- Pseudocode describes algorithms in structured English.
- Indentation shows structure.
- It translates directly into Python.
Try it yourself
- 1Write pseudocode for FizzBuzz, then translate it to Python.
- 2Write pseudocode for counting vowels in a sentence and trace it with "Hello World".
Finished reading? Mark it complete to update your dashboard.
Suggested practice
16 questions cover the “Algorithms and Problem Solving” module. Answers and explanations are revealed after you submit.
- AdvancedWhat is printed?
- AdvancedWhat is the average time complexity of x in my_set?
- AdvancedA loop over a list checks item in other_list for each item. With both lists of length n, the complexity is…