210 likes | 224 Views
Explore algorithm complexity, topological orders, integer arithmetic, subset problems, LCS, cuts, Baseball elimination, and more in this educational resource. Test and enhance your algorithm skills!
E N D
Algorithms Classroom Activities Richard Anderson University of Washington IUCEE: Algorithm Activities
What does it mean for an algorithm to be efficient? IUCEE: Algorithm Activities
Polynomial vs. Exponential Complexity • Suppose you have an algorithm which takes n! steps on a problem of size n • If the algorithm takes one second for a problem of size 10, estimate the run time for the following problems sizes: 12 14 16 18 20 10: 1 second 12: 2 minutes 14: 6 hours 16: 2 months 18: 50 years 20: 20K years IUCEE: Algorithm Activities
Find a topological order for the following graph H E I A D G J C F K B L IUCEE: Algorithm Activities
How many processors are needed for this example? IUCEE: Algorithm Activities
Prove that you cannot schedule this set of intervals with two processors IUCEE: Algorithm Activities
Who was Dijkstra? • What were his major contributions? IUCEE: Algorithm Activities
Solve by unrollingT(n) = n + 5T(n/2) Answer: nlog(5/2) IUCEE: Algorithm Activities
Classify the following recurrences(Increasing, Decreasing, Balanced) • T(n) = n + 5T(n/8) • T(n) = n + 9T(n/8) • T(n) = n2 + 4T(n/2) • T(n) = n3 + 7T(n/2) • T(n) = n1/2 + 3T(n/4) IUCEE: Algorithm Activities
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: IUCEE: Algorithm Activities
Subset Sum Problem • Let w1,…,wn = {6, 8, 9, 11, 13, 16, 18, 24} • Find a subset that has as large a sum as possible, without exceeding 50 IUCEE: Algorithm Activities
Knapsack Grid Opt[ j, K] = max(Opt[ j – 1, K], Opt[ j – 1, K – wj] + vj) Weights {2, 4, 7, 10} Values: {3, 5, 9, 16} IUCEE: Algorithm Activities
Determine the LCS of the following strings BARTHOLEMEWSIMPSON KRUSTYTHECLOWN IUCEE: Algorithm Activities
How good is this algorithm? • Is it feasible to compute the LCS of two strings of length 100,000 on a standard desktop PC? Why or why not. IUCEE: Algorithm Activities
Find two augmenting paths 2/5 2/2 0/1 2/4 3/4 3/4 3/3 3/3 1/3 1/3 s t 3/3 3/3 2/2 1/3 3/3 1/3 2/2 1/3 IUCEE: Algorithm Activities
Find a minimum value cut 6 6 5 8 10 3 6 2 t s 7 4 5 3 8 5 4 IUCEE: Algorithm Activities
Enumerate all finite s,t cuts and show their capacities s 2 2 -2 1 2 -2 1 1 2 1 t IUCEE: Algorithm Activities
Baseball elimination • Can the Dinosaurs win the league? • Remaining games: • AB, AC, AD, AD, AD, BC, BC, BC, BD, CD A team wins the league if it has strictly more wins than any other team at the end of the season A team ties for first place if no team has more wins, and there is some other team with the same number of wins IUCEE: Algorithm Activities
Circuit SAT Satisfying assignment x1 = T, x2 = F, x3 = F x4 = T, x5 = T AND OR OR Find a satisfying assignment AND AND AND AND NOT OR NOT OR AND OR AND NOT AND NOT OR NOT AND x3 x4 x5 x1 x2 IUCEE: Algorithm Activities
Complement of a Graph • Defn: G’=(V,E’) is the complement of G=(V,E) if (u,v) is in E’ iff (u,v) is not in E 1 2 1 2 3 5 3 5 4 4 6 6 7 7 Construct the complement IUCEE: Algorithm Activities
Minimum cost tour highlighted Traveling Salesman Problem • Given a complete graph with edge weights, determine the shortest tour that includes all of the vertices (visit each vertex exactly once, and get back to the starting point) 3 7 7 2 2 5 4 1 1 4 IUCEE: Algorithm Activities Find the minimum cost tour