title: Whiteboarding and Pseudocoding length: 120 tags: whiteboarding, interviews, pseudocoding module: 2 —

### Learning Goals

• Understand the relationship between problem-solving, programming, and algorithmic thinking
• Identify and implement different strategies for solving problems
• Identify common roadblocks to effective problem-solving

### Warm Up

• When you are presented with a problem, how do you solve it?
• In your journal, draw out the process of how you make toast. You must start with a clean sheet of paper and you are not allowed to write/use any words.

## Problem Solving

When you are presented with a problem… whether it is a complex mathematical problem or a broken printer, how do you solve it? Generally speaking, the first step in finding a solution to a problem is to be sure that you have clearly identified the problem itself. To solve problems, we can utilize the UPS strategy:

• Understand: Read the problem. Restate the problem by writing it down in your own words. What do you know? What do you not know?
• Plan: What problem strategy will you try? You might also draw a picture/representation of how you plan to approach the problem

#### Possible Problem Solving Strategies

Method Description Example
Trial and Error Continue trying different solutions until problem is solved Restarting phone, turning off WiFi, turning off bluetooth in order to determine why your phone is malfunctioning
Heuristic General problem-solving framework Working backwards, breaking a task into steps
Algorithm Step-by-step problem solving formula Instruction manual for installing new software on your computer

#### Journal/Reflection

Think about how you currently solve problems when you are programming. Has that changed since you were in Mod 1? What are some of the possible pros and cons of the methods listed above?

## Whiteboarding

In the context of building out programs, whiteboarding is a useful tool to ulitize in solving complex problems. If we rush into coding out the solution immediately, we completely skip over the `P`lanning part of the process… and its likely that we don’t fully `U`nderstand the problem at hand.

In the context of interviewing for a job, being able to whiteboard is important because it shows you can think through/discuss a problem without having to actually code it first - which can be a difficult skill to learn.

Things to remember

• Talk as you write
• Pay attention to the amount of space you have to write
• DON’T WIPE THE WHITEBOARD WITH YOUR HAND WHEN YOU ERASE THINGS
• High level vs low level
• Develop a shorthand for writing code:
``````if (foo === 'bar') {
this.changeFoo('baz')
} else if (foo === 'baz') {
this.changeFoo('bar');
} else {
this.changeFoo('caw caw');
}
``````

Could be written as shorthand:

``````foo = baz?
changeFoo(bar)
foo = bar?
changeFoo(baz)
else
changeFoo(caw caw)
``````

## Pseudocoding

Pseudocode is an artificial and informal language that helps programmers develop algorithms to solve problems. A key thing to remember is that psuedocode is not code. It is a way to force yourself to slow down and think about how to solve problems at a high-level, using natural language.

Pseudocode:

• gives you a fallback
• gives people 👀 the chance to intervene
• takes syntax errors out of the equation

### Basic Structure for Pseudocoding

Sequences: Sequences are the most straightforward part of structuring pseudocode. At the most basic level, a sequence is made up of commands or steps that must be followed. Any commands in a sequence are generally written as a list.

Here’s an IRL example of a sequence for feeding my dogs:

``````// Pick up dog bowls from the floor
// Bring bowls to pantry
// Open up big dog food bag
// Fill big bowl
// Open up small dog food bag
// Fill small bowl
// Call dogs by name
// Place both bowls on the floor
``````

Choices: Choices give us the option to take different paths based on certain conditions. You may find that you have just one path based on a condition, two paths, or multiple paths.

Here’s another IRL example of how I may choose a certain path (based on the weather) when dressing myself in the morning:

``````// Check the weather forecast
// If snow is expected, put on boots
// Otherwise, put on flip flops
``````

Iterations: Iterations allow us to repeat steps until a certain condition is met. They always begin with a choice. Here’s another IRL example of preheating my oven:

``````// While the oven is not 350 degrees, wait
``````

Which could also be written like this:

``````// Until the oven is 350 degrees, wait
``````

## PIA (Psuedocoding in action)

Task: Create your own `filter` function (on `Array.prototype`) to really understand/see how `filter` is working under the hood. You should implement a filter function that is like the `<Array>.filter()` in JavaScript.

``````[1,2,3,4].filter((num)=>{ return num > 3}) // Should return [4]
``````

#### Turn and Code:

In pairs, pull up and fork this codepen. You should be completing both phases for each individual test. Be sure that you are actively switching between being the driver and the navigator.

Phase I => (Understand and Plan) Break out the way that you would solve this problem in pseudocode. Remember, psuedocode is not code… but a way to work through the logic of the problem without worrying about syntax.

Person A: Driver
Person B: Navigator

Phase II => (Solve) Using your psuedocode as a guide (feeling free to make adjustments as necessary) to start to implement your solution in code.

Person B: Navigator
Person A: Driver

### Some possible pitfalls to problem solving

• Mental set - Persist in approaching a problem in a way that has worked in the past but is clearly not working now
• Anchoring bias - Tendency to focus on one particular piece of information when making decisions or problem-solving
• Availability bias - Decision is based upon either an available precedent or an example that may be faulty