Skip to main content

CSC 151.01, Class 39: Trees

Overview

  • Preliminaries (long, sorry)
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Lab

News / Etc.

  • It’s Wednesday. New partners!
  • Answer key for exam 2 forthcoming.
  • Think about taking CSC 161 next semester. It’s an awesome course. You get to play with robots. You get to learn a more well-known language. Many students say it’s less work than CSC 151. You don’t have to deal with me. (Disclaimer.)
  • Apologies.

Rotating reminders

  • Sam review session, 9:00 a.m., Thursday. here.
  • Mentor-led review sessions, 7:00 and 8:00 p.m., Thursday, commons.

Upcoming Work

Quiz Topics

  • Vectors - odds of a vector recursion question are high
  • Pairs and pair structures - odds of a “draw this” are high (or turn drawing into code)
  • Random numbers - odds of a “what’s wrong with this” are medium
  • Geometric art - odds of a “draw this” are unknown

Exam 3

  • New model for submitting prologue: Email.
  • Should be a bit less time consuming than the last exam.
  • We get one day to fix bugs before you start getting credit for them.

Extra credit (Academic/Artistic)

  • Tech Night Study Break, tonight, 8 p.m., Faulconer gallery.
  • Spark Tank Pitch Contest, Thursday, 11am-1pm, Harris
  • CS Extras, Thursday, 4:15 pm, Ursula Wolz on High School Coding Conference
  • Screening of Between Earth and Sky: Climate Change on the Last Frontier, Thursday at 5pm at the Strand.
  • Jonathan Katz: Donald Trump, Hilary Clinton, and the Politics of Presidential Masculinity, Thursday, 7:00 p.m., Harris Cinema.
  • Music Faculty Recital, Thursday, 7:30 p.m., Sebring-Lewis.
  • James McBride and the Good Lord Bird Band, Thursday, 8pm, Herrick
  • The Barber of Seville, Monday, 17 April 2017, 7:30 p.m., Herrick

Extra credit (Peer)

  • Submit to (or attend) the Art House Arts Fest on April 22nd. They want visual art, performance art, musical talent, crafting skills, culinary arts etc. If anyone is interested in participating they can email our Art House member.
  • After spending this entire weekend doing Improv at a conference, Ritalin Test Squad will be doing 24 Hour Improv the upcoming Friday. They will be performing in Loose Lounge from 6pm Friday to 6pm Saturday. There may be other improv troupes performing with them.
    • Get sleep! Do not attend for all 24 hours.
    • Yes, they perform even if there is no audience.
    • It’s improv, it will work out.
    • They perform to sleeping audiences, too. But be careful, they may improv VERY LOUDLY
  • Baseball vs. Knox Saturday at noon or 2:30 p.m.
  • Drag Show Saturday night.

Extra credit (Misc)

None right now.

Other good things to do

  • James McBride talk, Thursday, ??:?? p.m.
  • Pizza and Q&A with director of Between Earth and Sky, Thursday, 6:30 p.m.
  • Godspell, Thursday, Friday, Saturday at 7:30 p.m., Sunday at 2:00 p.m.
  • Kinetic Sculpture Competition, Saturday, 11:00 a.m., Bucksbaum Rotunda
  • Symphony, Friday, 7:30. Awesome cello playing with backing by other musicians.

Questions

Lab

  • node is like cons, except that there are two “cdrs”.
  • value is like car
  • left is one of the cdr operations
  • right is the other

Writeup is problem 4.

Hints on problem 3:

  1. Use direct recursion.

  2. Just as (sum null) is 0 and (+) is 0, (number-tree-sum empty) can also be 0.

Hints on problem 4:

  1. Use direct recursion, rather than tail recursion.

  2. Think about the way you’d find the largest element in a list, particularly the base case.

(define largest
  (lambda (lst)
    (if (null? (cdr lst))
        (car lst)
        (max (car lst) (largest (cdr lst))))))
  1. Try different trees. For example
> (tree-largest (node 4 empty empty))
> (tree-largest (node 4 (node 3) empty))
> (tree-largest (node 3 (node 4) empty))
> (tree-largest (node 4 empty (node 3)))
> (tree-largest (node 3 empty (node 4)))
> (tree-largest (node -5 empty empty))
  1. Think about the cases.
  • Empty tree: Error
  • Leaf:
  • No left subtree: …
  • No right subtree: …
  • Both subtrees: …

Writeup

Write up exercise 4 from the lab on binary trees.

Send your solution to csc151-01-grader@grinnell.edu.

Title your email CSC 151.01 Writeup for Class 39 (YOUR FULL NAMES).