CSC373 Algorithm Design, Analysis & Complexity Nisarg Shah
CSC373 Algorithm Design, Analysis & Complexity Nisarg Shah
Algorithm Design,
Analysis & Complexity
Nisarg Shah
• Tutorials
➢ Every Mon 6-7pm
➢ Divided by birth month
➢ Jan-Jun: UC 244, Jul-Dec: UC 261
• Discussion Board
piazza.com/utoronto.ca/fall2019/csc373
• Citation
➢ For each question, must cite the peer (write the name) or
the online sources (provide links), if you obtained a
significant insight directly pertinent to the question
➢ Failing to do this is plagiarism!
• 20% > 0% !!
➢ NP-completeness, NP-hardness, …
rather than 𝑂 𝑛2
➢ Largest subsequence sum in 𝑂 𝑛
➢…
• Applications
➢ Voting theory
➢ Collaborative filtering
➢ Measuring the “sortedness” of an array
➢ Sensitivity analysis of Google's ranking function
➢ Rank aggregation for meta-searching on the Web
➢ Nonparametric statistics (e.g., Kendall's tau distance)
• Problem:
➢ Given 𝑛 points of the form (𝑥𝑖 , 𝑦𝑖 ) in the plane, find the
closest pair of points.
• Applications:
➢ Basic primitive in graphics and computer vision
➢ Geographic information systems, molecular modeling, air
traffic control
➢ Special case of nearest neighbor
• Brute force: Θ 𝑛2
• Sorting attempt in 2D
➢ Find closest points by x coordinate
➢ Find closest points by y coordinate
• Non-degeneracy assumption
➢ No two points have the same x or y coordinate
1+𝜖
1 2
1 1+𝜖
• Combine
➢ We can restrict our attention to points within 𝛿 of 𝐿 on
each side, where 𝛿 = best of the solutions in two halves
• Karatsuba’s observation:
➢ Divide each integer into two parts
𝑛 𝑛
o 𝑥 = 𝑥1 ∗ 10 Τ2 + 𝑥2 , 𝑦 = 𝑦1 ∗ 10 Τ2 + 𝑦2
𝑛
o 𝑥𝑦 = 𝑥1 𝑦1 ∗ 10𝑛 + 𝑥1 𝑦2 + 𝑥2 𝑦1 ∗ 10 Τ2 + (𝑥2 𝑦2 )
➢ Four 𝑛Τ2-digit multiplications can be replaced by three
o 𝑥1 𝑦2 + 𝑥2 𝑦1 = 𝑥1 + 𝑥2 𝑦1 + 𝑦2 − 𝑥1 𝑦1 − 𝑥2 𝑦2
➢ Running time
o 𝑇 𝑛 = 3 𝑇 𝑛Τ2 + 𝑂(𝑛) ⇒ 𝑇 𝑛 = 𝑂 𝑛log2 3
• Problem?
➢ If pivot is close to the min or the max, then we basically get
𝑇 𝑛 = 𝑇 𝑛 − 1 + 𝑂(𝑛), which is just 𝑛2
➢ Want to reduce 𝑛 − 1 to a fraction of 𝑛 (like 𝑛/2, 5𝑛/6, etc)
• Machine operations
➢ We’re only counting comparison or arithmetic operations
➢ So we’re ignoring issues like how real numbers will be
represented in closest pair problem
➢ When we get to P vs NP, representation will matter