×

### Let's log you in.

or

Don't have a StudySoup account? Create one here!

×

or

## CS106B

by: clu2 Notetaker

33

0

3

# CS106B CS106A

clu2 Notetaker
Stanford

Get a free preview of these Notes, just enter your email below.

×
Unlock Preview

Notes from week 3
COURSE
Programming Abstractions
PROF.
Keith Schwartz
TYPE
Class Notes
PAGES
3
WORDS
CONCEPTS
Computer science recursion c++ programming abstractions Stanford
KARMA
25 ?

## Popular in ComputerScienence

This 3 page Class Notes was uploaded by clu2 Notetaker on Wednesday January 13, 2016. The Class Notes belongs to CS106A at Stanford University taught by Keith Schwartz in Winter 2015. Since its upload, it has received 33 views. For similar materials see Programming Abstractions in ComputerScienence at Stanford University.

×

## Reviews for CS106B

×

×

### What is Karma?

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 01/13/16
Thinking Recursion    Problem: Tower of Hanoi  ­ Can be written in 5 lines of code    Recursion:   Define an operation in terms of itself    Understanding a word:   ­Call understand word as many times to get the user to understand a definition  ­Break down more and more complicated words into simpler definitions    Powers:   ­Write a function that takes in base and an exponent and returns the result of base^exp    if() {  base case   } else {  recursive case  }    if(exponent==0) {  return base;  } else {  return base * someMethod(base, exp­1);  }    What’s the someMethod? power    What about negative case?  return 1.0/power(base, ­exponent);    The call Stack  Each previous call waits for the next call    Recursion    ­Fractals  ­Recursive definition  ­Recursive exploration and decision trees    Decision trees are recursive    Current state: has options 0 to N which will lead to a next state (also a decision tree with more  options)     Question: find a nine letter word that will be a word at every step after one letter is removed    Base case: empty string  Recursive: any word with some length    Pseudocode:   bool search(current state){  if(is solution(currentState)){  return true;  } else {  for(option: moves from currentState) {  nextState = takeOption(curr, option);  if(search(nextState)) {   return true;   }   }   return false;   }   }     Many problems can be seen as decision trees ­ art of decision trees    How to formulate a decision tree  1. How to represent current state?   2. How to calculate legal moves  3. How to general next states given move  4. How do you know if you should stop recursion     Generating permutations of abcd        Thinking Recursion    Problem: Tower of Hanoi  ­ Can be written in 5 lines of code    Recursion:   Define an operation in terms of itself    Understanding a word:   ­Call understand word as many times to get the user to understand a definition  ­Break down more and more complicated words into simpler definitions    Powers:   ­Write a function that takes in base and an exponent and returns the result of base^exp    if() {  base case   } else {  recursive case  }    if(exponent==0) {  return base;  } else {  return base * someMethod(base, exp­1);  }    What’s the someMethod? power    What about negative case?  return 1.0/power(base, ­exponent);    The call Stack  Each previous call waits for the next call

×

×

### BOOM! Enjoy Your Free Notes!

×

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

Jim McGreen Ohio University

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Amaris Trozzo George Washington University

#### "I made \$350 in just two days after posting my first study guide."

Steve Martinelli UC Los Angeles

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Parker Thompson 500 Startups

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!
×

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com