Lecture 6: Recursion and Dictionaries

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

Recursion

process of repeating items in a self-similar way

2
New cards

What is Recursion (Algorithmically/Abstractly)

a way to design solutions to problems by divide-and-conquer or decrease-and-conquer; reduce a problem to simpler versions of the same problem

3
New cards

What is Recursion (semantically)

a programming technique where a function calls itself

4
New cards

How to make sure not to have infinite recursion in programming

  • must have 1 or more base cases that are easy to solve

  • must solve the same problem on some other input with the goal of simplifying the larger problem input

5
New cards

Recap of Iterative Algorithms

  • looping constructs (while and for loops) lead to iterative algorithms

  • can capture computation in a set of state variables that update on each iteration through loop

6
New cards
<p>Iteration vs Recursion</p>

Iteration vs Recursion

  • Recursion may be simpler, more intuitive

  • Recursion may be more efficient from Programmer POV

  • Recursion may not be efficient from Computer POV

7
New cards

Mathematical Induction

To prove a statement indexed on integers is true for all values of n if can prove it’s true when n is smallest value and then prove that if it’s true for an arbitrary value of n, one can show that it must be true for n+1

8
New cards

Divide and Conquer Algorithm

Solve a hard problem by breaking it into a set of sub-problems such that sub-problems are easier to solve than the original and solutions of the sub-problems can be combined to solve the original.

9
New cards

Python Dictionary

Mutable compound data type that stores pairs (keys and values) of data

10
New cards

Dictionary lookup

similar to indexing a list; looks up the key then returns the value associated with the key; if key isn’t found, gets an error

11
New cards

Dict[new key] = new value

add an entry to dictionary

12
New cards

“Key” in dictionary

test if key in dictionary (either returns a True or False value)

13
New cards

del(Dict[Key])

delete an entry in dictionary

14
New cards

Dict.keys()

gets an iterable that acts like a tuple of keys (no guaranteed order)

<p>gets an iterable that acts like a tuple of keys (no guaranteed order)</p>
15
New cards

Dict.values()

gets an iterable that acts like a tuple of values (no guaranteed order)

<p>gets an iterable that acts like a tuple of values (no guaranteed order)</p>
16
New cards

Dictionary values

any type (immutable and mutable); can be duplicates, lists, and even other dictionaries

17
New cards

Dictionary Keys

must be unique; immutable/hashable type (int, float(challenging), string, tuple, bool)

18
New cards

list vs dict

knowt flashcard image