Richard Anderson Lecture 14 Inversions, Multiplication, FFT

Slides:



Advertisements
Similar presentations
Dr. Deshi Ye Divide-and-conquer Dr. Deshi Ye
Advertisements

Fast Fourier Transform Lecture 6 Spoken Language Processing Prof. Andrew Rosenberg.
CSE 421 Algorithms Richard Anderson Lecture 12 Recurrences.
CSE 421 Algorithms Richard Anderson Lecture 15 Fast Fourier Transform.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fast Fourier Transform Jean Baptiste Joseph Fourier ( ) These lecture.
CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer.
Lecture 33 CSE 331 Nov 17, Online office hours Alex will host the office hours.
CSE 421 Algorithms Richard Anderson Lecture 11 Recurrences.
Analysis of Recursive Algorithms October 29, 2014
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 12.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
5.6 Convolution and FFT. 2 Fast Fourier Transform: Applications Applications. n Optics, acoustics, quantum physics, telecommunications, control systems,
Karatsuba’s Algorithm for Integer Multiplication
Applied Symbolic Computation1 Applied Symbolic Computation (CS 300) Karatsuba’s Algorithm for Integer Multiplication Jeremy R. Johnson.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
The Fast Fourier Transform and Applications to Multiplication
1 Fast Polynomial and Integer Multiplication Jeremy R. Johnson.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 11.
May 9, 2001Applied Symbolic Computation1 Applied Symbolic Computation (CS 680/480) Lecture 6: Multiplication, Interpolation, and the Chinese Remainder.
Advanced Algorithms Analysis and Design
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Introduction to Algorithms
Chapter 2 Divide-and-Conquer algorithms
Chapter 2 Divide-and-Conquer algorithms
Lecture 16 Fast Fourier Transform
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Polynomial + Fast Fourier Transform
Chapter 4 Divide-and-Conquer
Applied Symbolic Computation
September 4, 1997 Applied Symbolic Computation (CS 300) Fast Polynomial and Integer Multiplication Jeremy R. Johnson.
Richard Anderson Lecture 14 Divide and Conquer
Polynomials and the FFT(UNIT-3)
Applied Symbolic Computation
September 4, 1997 Applied Symbolic Computation (CS 300) Fast Polynomial and Integer Multiplication Jeremy R. Johnson.
Punya Biswas Lecture 15 Closest Pair, Multiplication
The Fast Fourier Transform
Advanced Algorithms Analysis and Design
Lecture 30 CSE 331 Nov 11, 2016.
Applied Symbolic Computation
Topic: Divide and Conquer
Richard Anderson Lecture 11 Recurrences
Richard Anderson Lecture 13 Divide and Conquer
September 4, 1997 Applied Symbolic Computation (CS 567) Fast Polynomial and Integer Multiplication Jeremy R. Johnson.
Applied Symbolic Computation
Lecture 32 CSE 331 Nov 14, 2011.
Lecture 29 CSE 331 Nov 8, 2017.
Applied Symbolic Computation
Dynamic Programming Shortest Paths with Negative Weights Yin Tat Lee
Lecture 30 CSE 331 Nov 10, 2017.
Transform and Conquer Transform and Conquer Transform and Conquer.
Lecture 31 CSE 331 Nov 14, 2012.
Merge and Count Merge and count step.
Merge and Count Merge and count step.
Merge and Count Merge and count step.
Transform and Conquer Transform and Conquer Transform and Conquer.
Lecture 30 CSE 331 Nov 12, 2012.
The Fast Fourier Transform
Lecture 15, Winter 2019 Closest Pair, Multiplication
Richard Anderson Lecture 14 Divide and Conquer
Lecture 31 CSE 331 Nov 11, 2011.
Lecture 30 CSE 331 Nov 9, 2011.
Applied Symbolic Computation
Richard Anderson Lecture 14, Winter 2019 Divide and Conquer
Richard Anderson Lecture 14 Divide and Conquer
Lecture 15 Closest Pair, Multiplication
Richard Anderson Lecture 12, Winter 2019 Recurrences
Fast Polynomial and Integer Multiplication
Richard Anderson Lecture 12 Recurrences
Richard Anderson Lecture 13 Divide and Conquer
Presentation transcript:

Richard Anderson Lecture 14 Inversions, Multiplication, FFT CSE 421 Algorithms Richard Anderson Lecture 14 Inversions, Multiplication, FFT

Divide and Conquer Algorithms Mergesort, Quicksort Strassen’s Algorithm Closest Pair Algorithm (2d) Inversion counting Integer Multiplication (Karatsuba’s Algorithm) FFT Polynomial Multiplication Convolution

Inversion Problem Let a1, . . . an be a permutation of 1 . . n (ai, aj) is an inversion if i < j and ai > aj Problem: given a permutation, count the number of inversions This can be done easily in O(n2) time Can we do better? 4, 6, 1, 7, 3, 2, 5

Counting Inversions Count inversions on lower half 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14 Count inversions on lower half Count inversions on upper half Count the inversions between the halves

Count the Inversions 4 2 3 1 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14 8 6 14 10 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14 19 43 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14

Problem – how do we count inversions between sub problems in O(n) time? Solution – Count inversions while merging 1 2 3 4 7 11 12 15 5 6 8 9 10 13 14 16 Standard merge algorithm – add to inversion count when an element is moved from the upper array to the solution

Use the merge algorithm to count inversions 1 4 11 12 2 3 7 15 5 8 9 16 6 10 13 14 Indicate the number of inversions for each element detected when merging

Inversions Counting inversions between two sorted lists O(1) per element to count inversions Algorithm summary Satisfies the “Standard recurrence” T(n) = 2 T(n/2) + cn x y z

Integer Arithmetic 9715480283945084383094856701043643845790217965702956767 + 1242431098234099057329075097179898430928779579277597977 Runtime for standard algorithm to add two n digit numbers: 2095067093034680994318596846868779409766717133476767930 X 5920175091777634709677679342929097012308956679993010921 Runtime for standard algorithm to multiply two n digit numbers:

Recursive Algorithm (First attempt) x = x1 2n/2 + x0 y = y1 2n/2 + y0 xy = (x1 2n/2 + x0) (y1 2n/2 + y0) = x1y1 2n + (x1y0 + x0y1)2n/2 + x0y0 Recurrence: Run time:

Simple algebra x = x1 2n/2 + x0 y = y1 2n/2 + y0 xy = x1y1 2n + (x1y0 + x0y1) 2n/2 + x0y0 p = (x1 + x0)(y1 + y0) = x1y1 + x1y0 + x0y1 + x0y0

Karatsuba’s Algorithm Multiply n-digit integers x and y Let x = x1 2n/2 + x0 and y = y1 2n/2 + y0 Recursively compute a = x1y1 b = x0y0 p = (x1 + x0)(y1 + y0) Return a2n + (p – a – b)2n/2 + b Recurrence: T(n) = 3T(n/2) + cn

FFT, Convolution and Polynomial Multiplication Preview FFT - O(n log n) algorithm Evaluate a polynomial of degree n at n points in O(n log n) time Computation of Convolution and Polynomial Multiplication (in O(n log n)) time

Complex Analysis Polar coordinates: reqi eqi = cos q + i sin q a is a nth root of unity if an = 1 Square roots of unity: +1, -1 Fourth roots of unity: +1, -1, i, -i Eighth roots of unity: +1, -1, i, -i, b + ib, b - ib, -b + ib, -b - ib where b = sqrt(2)

e2pki/n e2pi = 1 epi = -1 nth roots of unity: e2pki/n for k = 0 …n-1 Notation: wk,n = e2pki/n Interesting fact: 1 + wk,n + w2k,n + w3k,n + . . . + wn-1k,n = 0 for k != 0

Convolution a0, a1, a2, . . ., am-1 b0, b1, b2, . . ., bn-1 c0, c1, c2, . . .,cm+n-2 where ck = Si+j=kaibj

Applications of Convolution Polynomial Multiplication Signal processing Gaussian smoothing Sequence a1, a2, . . ., an Mask, w-k, w-(k-1), . . ., w-1, w0, w1, . . ., wk-1, wk Addition of random variables

FFT Overview Polynomial interpolation Given n+1 points (xi,yi), there is a unique polynomial P of degree at most n which satisfies P(xi) = yi

Polynomial Multiplication n-1 degree polynomials A(x) = a0 + a1x + a2x2 + … +an-1xn-1, B(x) = b0 + b1x + b2x2 + …+ bn-1xn-1 C(x) = A(x)B(x) C(x)=c0+c1x + c2x2 + … + c2n-2x2n-2 p1, p2, . . ., p2n A(p1), A(p2), . . ., A(p2n) B(p1), B(p2), . . ., B(p2n) C(p1), C(p2), . . ., C(p2n) C(pi) = A(pi)B(pi)

FFT Polynomial A(x) = a0 + a1x + . . . + an-1xn-1 Compute A(wj,n) for j = 0, . . ., n-1