Algorithms!

Algorithms!

A fancier word for $h!t you're already doing

Today's Tour

  • Definition of an algorithm
  • Ways to design an algorithm
  • Example designing an algorithm
  • MVP

Algorithm- what is it?

  • A set of instructions to accomplish a task

Algorithm- what is it?

  • A set of instructions to accomplish a task

That's it.

Algorithm- what is it?

  • A set of instructions to accomplish a task

That's it.

Sorry to disappoint- no nuclear physics here, folks. 

Examples of Algorithms

  • A recipe
  • Instructions on how to drive somewhere
  • How to get ready in the morning
  • An approach to dealing with fights
  • Instructions for the baby sitter
  • IKEA $^!*%# instructions

 

All these are just a set of instructions to accomplish a specific task. 

Algorithm Design

  1. Define the rules of the problem
  2. Determine any constraints
  3. Explore the problem and discover techniques or patterns that might be useful
  4. Generate a simple plan that should solve the problem
  5. Turn that plan into steps- put your pseudocode skills to use!

Algorithm Design Examples

Reverse a string.

 

Define the problem:

1. Take in a string

2. Return a string

3. Returned string must be the reversed order of the original string

Algorithm Design Examples

Reverse a string.

 

Constraints:

1. Are we allowed to use native JS functions?

2. Are we allowed to change it from a string into an array?

Algorithm Design Examples

Reverse a string.

 

Exploring Patterns/Techniques:

1. Does JS have a native method that does this?

2. Can we try swapping items?

3. Could we just iterate through the string backwards?

4. What if we turned the string into an array of characters?

Algorithm Design Examples

Reverse a string.

 

Simple plan:

1. Get input into a form we can iterate through backwards

2. iterate through it backwards

3. add each character to reversedString variable

4. return reversedString

Algorithm Design Examples

Reverse a string.

 

Pseudocode

1. split the string into an array

2. iterate through that array backwards

3. push each item into a reversedArray

4. join reversedArray

5. return reversedArray

MVP- Minimum Viable Product

  • Get something out the door that works to the smallest possible degree.
  • Rapidly iterate from there. 

MVP

What does this mean for you?
 

Make the most basic possible version first. 

Don't worry about edge cases. 

Don't worry about handling everything. 

Just get something out the door that is one step closer to what you're trying to accomplish. 

MVP

If you're asked to put two dozen things on a board at specific positions:

 

Start by putting a single thing on the board. 

Then put two dozen things anywhere on the board. 

Then worry about how to position them all. 

MVP

This makes your job much easier. 

 

You don't need to solve the whole thing at once, just one tiny next portion of it. 

MVP

Celebrate each step along the way.

 

Each one gets you a little bit closer to what you're trying to accomplish. 

MVP

MVP lets you write code that isn't great. It's not your goal to write amazing code the first time through it! 

 

In fact, if you write amazing code on your first try, you're probably doing it wrong and spending way too much time on that first attempt. 

 

Leave yourself notes when you're writing crappy code. //TODO: this is inefficient. We can stop checking values if XYZ condition is false. 

MVP- iterate rapidly

Once you've got a super basic version up and working, make rapid changes to improve it from there. 

Today's Exercises

These exercises are a review from last week and are not necessarily tied to today's lecture material 

https://github.com/TelegraphPrep/week2

Algorithms!

By Preston Parry

Algorithms!

  • 1,905