Topic 4 - Pseudocode
Topic 4 - Pseudocode
Programming
IB Computer Science
What We Will Cover
- Trace Tables
- Flow Charts
- IB Programming Problems
- Pseudocode Conventions
What We Will Not Cover
- Sorting Methods
- Searching Methods
- Gantt Charts
- Basic Programming Concepts (See ‘Intro to Python’ playlist)
Topic 4 Difficulties
- Pseudocode Guides mediocre
- No real curriculum
- Questions unclear
- Markschemes have slight differences in style
- No official textbook
What is Pseudocode?
- Pseudocode is any method that can be used to represent
programming concepts
- Used to plan algorithms
- Cannot be executed
- IB mandates that you use their own made up pseudocode language,
regardless of what programming language you know
- Heavily based on Java
- Older markschemes explicitly say that answers can be written in
Java
- Syntax and keywords must be memorized
Fundamental Programming Tasks for the IB Exam
- Iterate through an array
- Find the maximum and minimum in an array
- Calculate the sum and average of values in an array
- Search an array for certain values or ranges of values in an array
- Find the common elements between arrays
- All of the above, except with collections
- Transfer data between both data structures
- Understand and be able to use methods (functions)
- Be able to read and analyze problems (the most important)
- Solve problems with mod and div
- Validation
Arrays
- Fixed length
- Pre-initialized and pre-created in IB
- Length can be accessed using .length property
- Array locations contiguously located in memory
- Allows for empty data locations, not always efficient
Basic Array Tasks
- Iterate through an array
- Find the maximum and minimum in an array
- Calculate the sum and average of values in an array
- Search an array for certain values or ranges of values in an array
- Find the common elements between arrays
Collections
- No fixed length
- Items can be added dynamically
- Each location “points” to the next using a “pointer”
- Can only be traversed using collection methods
- Represents a type of object
Basic Collection Tasks
- Iterate through a collection
- Find the maximum and minimum in a collection
- Calculate the sum and average of values in a collection
- Search an array for certain values or ranges of values in a collection
- Find the common elements between collections
- Transfer data from arrays to collections
- Transfer data from collections to arrays
mod and div
- mod operator is used to figure out the remainder when two integers
are divided by each other
- mod is most often used to test for divisibility
- div operator can be viewed in two ways
- Rounding up the result when two numbers are divided by each other
- Finding out how many times one number “fits into” another
IB-style mod and div Question
Write a program that takes an input of up to 99 cents. Based on the amount of cents entered by the user, calculate the minimum
number of coins of the given types necessary to represent the amount. You can use 4 types of coins, but remember, you must
calculate the fewest number of coins possible:
- quarter - 25 cents
- dime - 10 cents
- nickel - 5 cents
- penny - 1 cent
For example, if the user enters 97 cents, your output should be “3 quarters, 2 dimes, 2 pennies” as this is the minimum
number of coins, with types, required to represent 97 cents.
Validation
- Makes sure user input fits certain parameters
- Uses a while loop
- “Traps” user in the loop until they enter a valid value
Methods
- Also referred to as “functions”
- You need to be able to write and call functions in pseudocode
- Typically methods are used to simplify an existing problem
- See slide 37 for a great example of a problem involving methods