PEDAC

A problem solving approach for solving [Programming] exercises.

Why?

  • code with intention (no hack and slash)
  • communicate more clearly
  • lower interview stress
  • help focus on one step at a time

understand the Problem

  • look closely at the information that's available
  • restate the explicit requirements
    • inout: string
    • output: boolean
    • return true if string is palindrome, false if not
    • what is a palindrome?
      • string reverse is string itself
      • is it case sensitive? yes
      • Tacocat != tacocat
  • fill in mental model
  • identify implicit requirements

create Examples

  • expand and clarify understanding
  • catch misunderstanding early on in the process
  • think through edge cases
    • "tacocat" is a palindrome
    • "spaghetticat" is not a palindrome
  • create user tests for yourself
    • isPalindrome('tacocat') // true
    • isPalindrome('spaghetticat') // false
    • isPalindrome('Tacocat') // false
    • isPalindrome('taco cat') // false
    • isPalindrome(' ') // true
    • isPalindrome('a') // true
    • isPalindrome('atta') // true

determine Data structures

  • example data structures: array, dictionary, tuple, heap, linked list, etc.
  • might take a long while or be really quick
  • brainstorm pros/cons
  • directly linked to next step
  • use what you're comfortable with
    • ok to reach for arrays because it fits most cases

write out Algorithm

  • write step by step procedure for solving a problem
  • use plain language
  • use an example
  1. split the string into an array of characters
  2. reverse the array
  3. join the array back into a string
  4. return true/false if the original string is equal to the reverse string

Code

  • code with intention
  • follow your algorithm
  • test as you go
  • mental model - start with what works and come back to refactor

To review