MA/CSSE 473 Day 21 In 201310, Day 21 was the exam.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Greedy Algorithms
Advertisements

CSC 421: Algorithm Design & Analysis
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
Tutorial 6 of CSCI2110 Bipartite Matching Tutor: Zhou Hong ( 周宏 )
Chapter 5 Decrease and Conquer. Homework 7 hw7 (due 3/17) hw7 (due 3/17) –page 127 question 5 –page 132 questions 5 and 6 –page 137 questions 5 and 6.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
Chapter 5: Decrease and Conquer
Design & Analysis of Algorithms CS315
Discrete Structure Li Tak Sing( 李德成 ) Lectures
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Hamming Codes 11/17/04. History In the late 1940’s Richard Hamming recognized that the further evolution of computers required greater reliability, in.
MA/CSSE 473 Day 22 Gray Code More Decrease and Conquer Algorithms No class Day 22 in because of Abby's broken arm.
- ABHRA DASGUPTA Solving Adhoc and Math related problems.
MA/CSSE 473 Day 28 Hashing review B-tree overview Dynamic Programming.
MA/CSSE 473 Day 03 Asymptotics A Closer Look at Arithmetic With another student, try to write a precise, formal definition of “t(n) is in O(g(n))”
MA/CSSE 473 Day 20 Josephus problem Transform and conquer examples.
CS 312: Algorithm Analysis Lecture #3: Algorithms for Modular Arithmetic, Modular Exponentiation This work is licensed under a Creative Commons Attribution-Share.
MA/CSSE 473 Day 13 Permutation Generation. MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation.
A few leftover Decrease-and-conquer Algorithms
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
MA/CSSE 473 Day 23 Transform and Conquer. MA/CSSE 473 Day 23 Scores on HW 7 were very high (class average was 93%). Good job! (Score was not included.
1 Decrease-and-Conquer 1. Reduce problem instance to smaller instance of the same problem 2. Solve smaller instance 3. Extend solution of smaller instance.
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
Combinatorial Algorithms Reference Text: Kreher and Stinson.
RAIK 283: Data Structures & Algorithms
Theory of Algorithms: Brute Force. Outline Examples Brute-Force String Matching Closest-Pair Convex-Hull Exhaustive Search brute-force strengths and weaknesses.
Chapter 5 Decrease-and-Conquer Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
MA/CSSE 473 Day 14 Permutations wrap-up Subset generation (Horner’s method)
MA/CSSE 473 Day 18 Permutations by lexicographic order number.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
MA/CSSE 473 Day 19 Exam Prep. MA/CSSE 473 Day 19 If you want additional practice problems for Tuesday's exam: –The "not to turn in" problems from various.
MA/CSSE 473 Day 23 Student questions Space-time tradeoffs Hash tables review String search algorithms intro.
MA/CSSE 473 Day 20 Questions before exam More decrease and Conquer.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Week 8 - Wednesday.  What did we talk about last time?  Level order traversal  BST delete  2-3 trees.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 7.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
MA/CSSE 473 Day 19 Subset Generation. MA/CSSE 473 Day 19 HW 7 due today Exam 1 Thursday There will be significant time for your questions in tomorrow's.
MA/CSSE 473 Day 16 Combinatorial Object Generation Permutations.
ELEC692 VLSI Signal Processing Architecture Lecture 12 Numerical Strength Reduction.
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
MA/CSSE 473 Day 14 Strassen's Algorithm: Matrix Multiplication Decrease and Conquer DFS.
Week 8 - Monday.  What did we talk about last time?  Properties of functions  One-to-one  Onto  Inverses  Cardinality.
MAT 2720 Discrete Mathematics Section 8.1 Introduction
MA/CSSE 473 Day 11 Knuth interview Amortization (growable Array) Brute Force Examples.
Introduction to Algorithms: Brute-Force Algorithms.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
MA/CSSE 473 Day 20 Finish Josephus
Some more Decrease-and-conquer Algorithms
Decrease-and-Conquer
MA/CSSE 473 Day 19 Sleepsort Finish Nim Josephus problem
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
Chapter 5 Decrease-and-Conquer
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis
CSC 421: Algorithm Design & Analysis
Decrease-and-Conquer
Chapter 5 Decrease-and-Conquer
Decrease-and-Conquer
Decrease-and-Conquer
Decrease-and-Conquer
Chapter 5 Decrease-and-Conquer
CSE 2010: Algorithms and Data Structures Algorithms
CSC 421: Algorithm Design & Analysis
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
CSC 421: Algorithm Design & Analysis
Presentation transcript:

MA/CSSE 473 Day 21 In , Day 21 was the exam

MA/CSSE 473 Day 21 HW 8 is due Friday. HW 9 is due Tuesday. Its "late day" period will extend until Friday at noon. Don't forget the Convex Hull implementation problem. It is due 24 days after I assigned it (October 21), and 10 of those days have already passed. HW 10 due Tuesday, Oct 19 HW 11 Due Friday, Oct 22. Student Questions Exam discussion Subset Generation More Decrease and Conquer algorithms

Exam 1 Discussion Exam was a little bit long. –No one turned it in more than 2 minutes early –My remedy: I used 85 as the max score in the ANGEL gradebook –So your score is taken as a percentage of 85. –For example, 70 points counts as 82.35% Grader has not finished grading HW 7. If HW7 grading is finished by tomorrow, midterm grades will be based on HW1-7 + Trominoes, Exam1, and ICQs.

My grade scale approach Give many challenging and interesting problems, and adjust the grading scale accordingly:

Rose Grading Philosophy From hulman.edu/academicpolicies/#grades : hulman.edu/academicpolicies/#grades –Thorough competence to do excellent work in the field is required for the grades of "B" and "B+" which will not be given for mere compliance with the minimum essential standards of the course.

Exam 1, problem 4a

Exam 1, problem 4b-d

Exam 1, problem 5a

Exam 1, problem 5b

Exam 1, problem 6

Exam 1, problem 8 Partial credit: : 2 points if you said n5 or n7. Interesting note: This is the only problem that I re-used, unchanged, from the Fall 2008 Exam 1 that I ed to everyone out on Monday. Surprisingly, of all the problems on the exam, the one you got to see beforehand is the one whose overall percentage score was lowest.

Questions on any other problems?

BACK TO GENERATION OF COMBINATORIAL OBJECTS Subsets of a set

Generate All Subsets of a Set Sample Application: –Solve the knapsack problem –In the brute force approach, we try all subsets If A is a set, the set of all subsets is called the power set of A, and often denoted 2 A If A is finite, then Thus we know how many subsets we need to generate.

Generate all Subsets of {a 0, …, a n-1 } Decrease by one: Generate S n-1, the collection of the 2 n-1 subsets of {a 0, …, a n-2 } Then S n = S n-1  { s  {a n-1 } : s  S n-1 } You'll do details of this in the homework. Another approach: –Each subset of {a 0, …, a n-1 } corresponds to a bit string of length n, where the i th bit is 1 iff a i is in the subset

Another approach: Each subset of {a 0, …, a n-1 } corresponds to an bit string of length n, where the i th bit is 1 if and only if a i is in the subset def allSubsets(s): n = len(s) subsets=[] for i in range(2**n): subset = [] current = i for j in range (n): if current % 2 == 1: subset += [s[j]] current /= 2 subsets += [subset] return subsets Output: [[], [0],[1], [0, 1], [2], [0, 2], [1, 2], [0, 1, 2]]

Gray Code Named for Frank Gray An ordering of the 2 n n-bit binary codes such that any two consecutive codes differ in only one bit Example: 000, 010, 011, 001, 101, 111, 110, 100 Note also that only one bit changes between the last code and the first code. A Gray code can be represented by its transition sequence: which bit changes each time In above example: 1, 0, 1, 2, 1, 0, 1 In terms of subsets, the transition sequence tells which element to add or remove from one subset to get the next subset Q1

Generating a Transition Sequence Binary Reflected (Gray) Code T 1 = 0 T n+1 = T n, n, T n reversed What are T 2, T 3, T 4 Show that Tn is always a palindrome and that T n+1 = T n, n, T n Q2-3 Q2 should say, "Show the transition sequence for …"

Iteratively Generating Gray Code We add a parity bit, p. Set all bits (including p) to 0. Q4 * Based on Knuth, Volume 4, Fascicle 2, page 6.

Quote of the Day There are 10^11 stars in the galaxy. That used to be a huge number. But it's only a hundred billion. It's less than the national deficit! We used to call them astronomical numbers. Now we should call them economical numbers. - Richard FeynmanRichard Feynman

OTHER DECREASE-AND-CONQUER ALGORITHMS Decrease by a constant factor Decrease by a variable amount

Decrease by a Constant Factor Examples that we have already seen: –Binary Search –Exponentiation (ordinary and modular) by repeated squaring –Multiplication à la Russe (The Dasgupta book that I followed for the first part of the course called it "European" instead of "Russian") Example Then strike out any rows whose first number is even, and add up the remaining numbers in the second column.

Fake Coin Problem We have n coins All but one have the same weight One is lighter We have a balance scale with two pans. All it will tell us is whether the two sides have equal weight, or which side is heavier What is the minimum number of weighings that will guarantee that we find the fake coin? Decrease by factor of two.

Decrease by a variable amount Search in a Binary Search Tree Interpolation Search –See Levitin, pp –Also Weiss, Section 5.6.3

Median finding Find the k th element of an (unordered) list of n elements Start with quicksort's partition method Best case analysis

One Pile Nim There is a pile of n chips. Two players take turns by removing from the pile at least 1 and at most m chips. (The number of chips taken can vary from move to move.) The winner is the player that takes the last chip. Who wins the game – the player moving first or second, if both players make the best moves possible? It’s a good idea to analyze this and similar games “backwards”, i.e., starting with n = 0, 1, 2, …

Graph of One-Pile Nim with m = 4 Vertex numbers indicate n, the number of chips in the pile. The losing position for the player to move are circled. Only winning moves from a winning position are shown (in bold). Generalization: The player moving first wins iff n is not a multiple of 5 (more generally, m+1); –The winning move is to take n mod 5 (n mod (m+1)) chips on every move.

Josephus problem - background Flavius Josephus was a Jewish general and historian who lived and wrote in the 1 st century AD Much of what we know about 1 st century life in Israel (and the beginning of Christianity) before and after the Roman destruction of the Jewish temple in 70 AD comes from his writings The "Josephus problem" is based on an odd suicide pact that he describes –He and his men stood in a circle and counted off –Every other person (or every third person, accounts vary) was killed –The last person was supposed to kill himself –He must have been the next-to-last person! –When it got down to two people, he persuaded the other person that they should surrender instead

Josephus Problem n people, numbered 1-n, are in a circle Count starts with 1 Every 2 nd person is eliminated The last person left, J(n), is the winner Examples: n=8, n=7 J(1) = 1 Solution if n is even Solution if n is odd Use it to find J(2) … J(8) Clever solution: cyclic bit shift left