Skip to content

Instantly share code, notes, and snippets.

@rogerwschmidt
Forked from Shurlow/searching.md
Last active October 25, 2018 18:05
Show Gist options
  • Save rogerwschmidt/80f21dce900a27fff4b6b0312c5451aa to your computer and use it in GitHub Desktop.
Save rogerwschmidt/80f21dce900a27fff4b6b0312c5451aa to your computer and use it in GitHub Desktop.
Searching & Sorting Lesson Notes

Searching

Objectives

  • Write pseudocode for linear search
  • Write pseudocode for binary search
  • Translate algorithm pseudocode to working code

Guiding Questions

  • Take a minute to look over these examples of pseudocode for a selectEvenNumbers function. Which one do you prefer? Why?

    Style 1:
    function selectEvenNumbers takes 1 parameter, numbers (array of integers)
    
    create evenNumbers variable and set to an empty array
    
    for each num in numbers array
      check if num is even
        add num to evenNumers array
    
    return evenNumbers
    
    Style 2:
    Function selectEvenNumbers
      Input: numbers -> array integers
      Output: array of integers
    
    set evenNumbers -> []
    
    for i = 0 to i = numbers.length
      if (numbers[i] % 2 === 0)
        push numbers[i] onto evenNumbers
    
    return evenNumbers
    
Linear Search

Given an array of integers, numbers, and a value val, a linearSearch() function should return the index of val in numbers. If val does not exist in numbers, return -1.

  • Write Pseudo code

Your answer...

  • Write Code

Your answer...

Binary Search
  • How does binary search work in your own words. What condition needs to be met to use binary search on an array?

    Your answer...

  • Write pseudocode for Binary Search. Start by forking this: https://repl.it/@rogerschmidt/BinarySearch

    Your answer...

  • Translate your pseudocode from above to working code.

    Your answer...

Resources

Sorting

Objectives

  • Write pseudocode for Selection Sort
  • Write working code for Selection Sort
  • Write pseudocode for Merge Sort
  • Write working code for Merge Sort

Guiding Questions

  • Write pseudocode for Selection Sort.

    Your answer...

  • Translate pseudocode into working code for Selection Sort.

    Your answer...

  • Write pseudocode for Merge Sort. Start from this example: https://repl.it/@rogerschmidt/MergeSort

    Your answer...

  • Translate pseudocode into working code for Merge Sort.

    Your answer...

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment