Download presentation
Presentation is loading. Please wait.
Published byAlvin Allison Modified over 9 years ago
1
Algorithms Design CSCI 3110 Nov.23, 2015
2
Overview Divide and Conquer : closest pair problem Backtracking : N-Queens problem Dynamic Programming : Fibonacci Sequence Binomial Coeffient Matrix Chain Multiplication problem. Change-Making problem
3
Divide and Conquer : closest pair problem How do we find the closest pair in the strip area ? δ = min(dL, dR) Naïve Solution #1 // Points are all in the strip for( i = 0; i < numPointsInStrip; i++ ) for( j = i + 1; j < numPointsInStrip;j++) if( dist(pi, pj) < δ ) δ = dist(pi, pj);
4
Divide and Conquer : closest pair problem Naïve Solution #2 // Points are all in the strip for( i = 0; i < numPointsInStrip; i++ ) for( j = i + 1; j < numPointsInStrip;j++) if( pi and pj’s y-coordinates differ by more than δ ) break; // Go to next pi. else if( dist(pi, pj) < δ ) δ = dist(pi, pj);
5
N-Queen Problem Naïve brute force Count the number of nodes in state space tree 1 + n + n 2 + n 3 + n 4 + …= O(N^N) Backtracking (optional lab)
6
Fibonacci Sequence Simple recursive: O(2^n) -> Bad Dynamic Programming: O(n) -> Good
7
Dynamic Programming How do you calculate Binomial Coeffient C(n,k) = ? C(12,5) = ? What if you forgot the formula of C(n,k) = n!/(k!(n-k)!) Can you derive C(12,5) from a recursive relation and base cases ?
8
Math background (a+b)^0= (a+b)^1= (a+b)^2= (a+b)^3= (a+b)^4= (a+b)^5= Base cases : Recursive relation:
9
Binomial Coeffient Excel
10
Matrix Chain Multiplication problem Background Naïve brute force ->4^n DP-> Excel
11
Change-Making problem Excel
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.