6.100L | Fall 2022 | Undergraduate

Introduction to CS and Programming using Python

Lecture 23: Complexity Classes Examples

Topics: String and List Examples, Analyzing Complexity, Search: indirection, linear search, bisection search

Lecture Notes

Lecture 23: Complexity Classes Examples

Lecture 23 Code

Readings

Ch 12.1

Finger Exercise Lecture 23

Question 1: Choose the worst case asymptotic order of growth (upper and lower bound) for the following function. Assume n = a.

def running_product(a):
    """ a is an int """
    product = 1
    for i in range(5,a+5):
        product *= i
        if product == a:
            return True
    return False

Question 2: Choose the worst case asymptotic order of growth (upper and lower bound) for the following function. Assume n = len(L).

def tricky_f(L, L2):
    """ L and L2 are lists of equal length """
    inL = False
    for e1 in L:
        if e1 in L2:
            inL = True
    inL2 = False
    for e2 in L2:
        if e2 in L:
            inL2 = True
    return inL and inL2

Question 3: Choose the worst-case asymptotic order of growth (upper and lower bound) for the following function.

def sum_f(n):
    """ n > 0 """
    answer = 0
    while n > 0:
        answer += n%10
        n = int(n/10)
    return answer

6.100L Finger Exercises Lecture 23 Solutions

Recitation 10

Recitations were smaller sections that reviewed the previous lectures. Files contain recitation notes and worked examples in code.

Recitation 10 Notes and Code

Course Info

Instructor
As Taught In
Fall 2022
Learning Resource Types
Lecture Videos
Lecture Notes
Problem Sets
Programming Assignments with Examples
Readings
Recitation Notes