Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 27: Trees and Logs

Class 27: Trees and Logs

cs1120: Introduction to Computing
Explorations in Language, Logic, and Machine
University of Virginia, Spring 2016

http://xplorecs.org/class27

Class 27:
The Search Problem
Complexity of FindMatch
Introducing Trees

David Evans

April 04, 2016
Tweet

More Decks by David Evans

Other Decks in Programming

Transcript

  1. Class 27: Trees and Logs Introduction to Computing: Explorations in

    Language, Logic, and Machines cs1120 Spring 2016 David Evans University of Virginia
  2. Course Update 10 people have now passed the Blue Belt

    Level 7 qualified to (re-)take Blue Belt exam If you are stuck, not making progress, or unsure what you should be doing, make sure to check in with me today or at office hours tomorrow.
  3. FindMatch Problem Inputs: lst, a list of N elements of

    type T, ftest, a test function T → Bool Output:
  4. FindMatch Problem Inputs: lst, a list of N elements of

    type T, ftest, a test function T → Bool Output: an element, e, of lst such that ftest(e) is True, or None if no such element exists What is the complexity of the FindMatch problem?
  5. FindMatch Complexity Inputs: lst, a list of N elements of

    type T, ftest, a test function T → Bool Output: an element, e, of lst such that ftest(e) is True, or None if no such element exists Complexity: Running time is in ϴ(N) - We know an algorithm, find_match, with running time in ϴ(N) - We know no asymptotically faster solution exists since it is necessary to look at all elements for a possible match.
  6. FindMatch Complexity Inputs: lst, a list of N elements of

    type T, ftest, a test function T → Bool Output: an element, e, of lst such that ftest(e) is True, or None if no such element exists Complexity: Running time is in ϴ(N) - We know an algorithm, find_match, with running time in ϴ(N) - We know no asymptotically faster solution exists since it is necessary to look at all elements for a possible match. How can we do better?
  7. Doing Better: Adding Restrictions 1. Input must be organized according

    to some comparison function. 2. The matching function must be restricted in a way that enables one comparison to eliminate a fraction of the input.
  8. Charge • Next class: implementing Trees, searching in a binary

    tree, faster searching If you are stuck, not making progress, or unsure what you should be doing, make sure to check in with me today or at office hours tomorrow.