General Information

General Information
18:31

Hello everyone! Welcome to Paris, I hope you'll have a fantastic term here.

Lectures
  • Tuesday 17:45-19:00, 19:15-20:00
  • Thursday 17:45-19:00, 19:15-20:00
  • Lectures and recitations will be combined
Room
406
Resources
Email
nguyen.khoi@nyu.edu
Office hour
Wednesday 5:00pm (online)
Evaluation
  • Homework: 50%
  • Midterm: 25%
  • Final: 25%
Useful documents

Syllabus
18:31

Chapter 1: Foundations

Reference: (Cormen et al., 2022, Chapters 1, 2, 3, 4)

  • First examples
  • Run-time analysis
  • -notation
  • Divide and conquer

Chapter 2: Sorting and Order Statistics

Reference: (Cormen et al., 2022, Chapters 7, 8, 9)

  • Comparison sorts
  • Counting Sort, Radix sort
  • Median and order statistics

Chapter 3: Advanced Design and Analysis Techniques

Reference: (Cormen et al., 2022, Chapters 14, 15, 16)

  • Dynamic Programming: RodCutting, Longest Common Subsequence, Knapsack
  • Greedy: Interval scheduling, Huffman Code

Chapter 4: Graph Algorithms

Reference: (Cormen et al., 2022, Chapters 22, 23, 24, 25)

  • Graph: basics
  • Classical algorithms: Kruskal, Prim, Dijkstra, Floyd-Warshall, etc.
  • P vs NP, NP completeness

Notes about code
18:31

  • Programming language: Python 3
  • Recommended setup: Visual Studio Code + Jupyter extension

Question (Why Python?)

  • Free/Open Source
  • Easy to read and learn
  • Ubiquitous, can even run on your browser

During lectures, you'll be able to edit and run code cells directly from the browser (kind of like in Jupyter). When editing the code, you can press Shift+Enter to run it or click the icon on the left.

Loading

Go to Chapter 1.

5 Sept 2023
18:31

  • Insertion sort is the algorithm you use when you play cards

    • Correctness (invariant: cards in the left-hand are sorted)
    • Runtime: (best case) or (average and worst case)
    • Space complexity: (in place)
  • Asymptotic notation:
  • Sorting is an important operation in compsci (e.g. median, search)
  • Click here

Homework (due Tuesday 12 September)

Send me a Jupyter file by email (nguyen.khoi@nyu.edu) with the following exercises solved.

  • 2-2. Bubble sort (Cormen et al., 2022, p. 46): use Python instead of pseudo-code
  • 2-3. Horner (Cormen et al., 2022, p. 47): use Python instead of pseudo-code
  • Leetcode problem

7 Sept 2023
18:31

  • Divide and conquer: recursively divide the problem until it becomes trivial, and combine the solutions of the subproblems to solve the original problem.
  • Merge sort: divide-and-conquer sorting algorithm which runs in Merge sort example
  • Bold prediction of the day: my website is going to work today on at least one computer.
  • Click here

Homework (due Tuesday 12 September)

Send me a Jupyter file by email (nguyen.khoi@nyu.edu) with the following exercises solved.

  • 2-2. Bubble sort (Cormen et al., 2022, p. 46): use Python instead of pseudo-code
  • 2-3. Horner (Cormen et al., 2022, p. 47): use Python instead of pseudo-code
  • Leetcode problem

12 Sept 2023
18:31

  1. Quicksort: divide-and-conquer algorithm that puts one number in the correct position (the pivot) and recursively calls itself on both lists that this pivot determines.
  2. Quicksort's runtime depends a lot on the choice of pivot. While the average case is , the worst case is
  3. Karatsuba's algorithm is a divide-and-conquer algorithm in which the combining step uses three multiplications instead of four. We will go over it again today.
  4. Continue

Homework due next Monday

  • Implement Gauss and Karatsuba's algorithm in Python so that given two arrays of integers, it results a the digits of the product of the two numbers associated with the arrays.
    karatsuba([1, 3], [1, 2]) # returns [1, 5, 6]
  • Using a plotting library such as matplotlib, plot the time both algorithms take as a function of n random digits. Roughly when is your Karatsuba implementation faster?
  • Use your Karatsuba implementation and a divide-and-conquer approach to write an algorithm that computes the th power of a number. You may not use
    power([1, 3, 4, 2], 2) # return 1342**2

14 Sept 2023
18:31

  1. Comparison sorts are algorithms that can be modelled by decision trees which only use comparisons.
  2. The running time of a comparison sorting algorithm is at best
  3. We now move on to the less ambitious plan to order integers. Can we reach ? This is still an open problem.
  4. Counting sort is an algorithm which uses a tally to recreate the list. Its complexity is
  5. Continue

Homework due Tuesday

  • Implement Gauss and Karatsuba's algorithm in Python so that given two arrays of integers, it results a the digits of the product of the two numbers associated with the arrays.
    karatsuba([1, 3], [1, 2]) # returns [1, 5, 6]
  • Using a plotting library such as matplotlib, plot the time both algorithms take as a function of n random digits. Roughly when is your Karatsuba implementation faster?
  • Use your Karatsuba implementation and a divide-and-conquer approach to write an algorithm that computes the th power of a number. You may not use
    power([1, 3, 4, 2], 2) # return 1342**2

19 Sept 2023
18:31

  • Radix sort: stable counting sort on last, then penultimate, etc.
  • Running time:
  • Why is stability important in sorting?

26 Sept 2023
18:31

Dynamic programming

  • Break down problem into overlapping subproblems
  • Subproblems are often created via substrings or subarrays (often prefixes/suffixes)
  • Recursion and memoization to reduce to smaller problems (top-down) and ultimately to base cases
  • Notion of order (bottom-up)
  • Running time: number of subproblems non-recursive work

Homework

  • Homework 1 and 2 due today
  • Homework 3 on dynamic programming due next monday

7 November 2023
18:31