Pruning 24-Feb-19.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms NP-Complete
Advertisements

18-Dec-14 Pruning. 2 Exponential growth How many leaves are there in a complete binary tree of depth N? This is easy to demonstrate: Count “going left”
BackTracking Algorithms
Types of Algorithms.
Games & Adversarial Search Chapter 5. Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent’s reply. Time.
Games & Adversarial Search
Sum of Subsets and Knapsack
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Heapsort. 2 Why study Heapsort? It is a well-known, traditional sorting algorithm you will be expected to know Heapsort is always O(n log n) Quicksort.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 21 Instructor: Paul Beame.
24-Jun-15 Pruning. 2 Exponential growth How many leaves are there in a complete binary tree of depth N? This is easy to demonstrate: Count “going left”
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
Ch 13 – Backtracking + Branch-and-Bound
Ref: Pfleeger96, Ch.31 NP-Complete Problems Reference: Pfleeger, Charles P., Security in Computing, 2nd Edition, Prentice Hall, 1996.
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 2 Adapted from slides of Yoonsuck.
Difficult Problems. Polynomial-time algorithms A polynomial-time algorithm is an algorithm whose running time is O(f(n)), where f(n) is a polynomial A.
Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
CSE332: Data Abstractions Lecture 24.5: Interlude on Intractability Dan Grossman Spring 2012.
Recursive Back Tracking & Dynamic Programming Lecture 7.
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
Costas Busch - LSU1 Time Complexity. Costas Busch - LSU2 Consider a deterministic Turing Machine which decides a language.
Analysis & Design of Algorithms (CSCE 321)
CSCE350 Algorithms and Data Structure Lecture 21 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
HW4: sites that look like transcription start sites Nucleotide histogram Background frequency Count matrix for translation start sites (-10 to 10) Frequency.
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Lecture 16  Last time Searching a Graphplan for a plan, and relaxed plan heuristics.
The NP class. NP-completeness
BackTracking CS255.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Recursive Objects (Part 4)
Analysis of Algorithms
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Time Complexity Costas Busch - LSU.
Binary Search Trees.
Problems with Linked List (as we’ve seen so far…)
Algorithms Furqan Majeed.
Introduction to Operations Research
Types of Algorithms.
Problem Solving: Brute Force Approaches
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Dr. David Matuszek Heapsort Dr. David Matuszek
Back Tracking.
Types of Algorithms.
Alpha-Beta Search.
Brute Force Approaches
Time Complexity We use a multitape Turing machine
Alpha-Beta Search.
Heapsort.
Alpha-Beta Search.
Analysis of Algorithms
Building Java Programs
Counting II: Recurring Problems And Correspondences
Backtracking and Branch-and-Bound
Types of Algorithms.
Alpha-Beta Search.
CPSC 121: Models of Computation
ECE 352 Digital System Fundamentals
Analysis of Algorithms
Heapsort.
Counting II: Recurring Problems And Correspondences
CPSC 121: Models of Computation
Heapsort.
Games & Adversarial Search
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Alpha-Beta Search.
CO 303 Algorithm Analysis and Design
Analysis of Algorithms
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

Pruning 24-Feb-19

Exponential growth How many leaves are there in a complete binary tree of depth N? depth = 0, count = 1 depth = 1, count = 2 depth = 3, count = 4 depth = 4, count = 8 depth = 5, count = 16 depth = N, count = 2N This is easy to demonstrate: Count “going left” as a 0 Count “going right” as a 1 Each leaf represents one of the 2N possible N-bit binary numbers This observation turns out to be very useful in certain kinds of problems

Pruning Suppose the binary tree represents a problem that we have to explore to find a solution (or goal node) If we can prune (decide we can ignore) a part of the tree, we save effort saves 15 saves 7 saves 3 The higher up in the tree we can prune, the more effort we can save The advantage is exponential

Sum of subsets Problem: Example: There are n positive integers, and a positive integer W Find a subset of the integers that sum to exactly W Example: The numbers are 2, 5, 7, 8, 13 Find a subset of numbers that sum to exactly 25 We can multiply each number by 1 if it is in the sum, 0 if it is not 2 5 7 8 13 0 0 0 0 0  0 0 0 0 0 1  13 0 0 0 1 0  8 0 0 0 1 1  21 0 0 1 0 1  20 0 0 1 1 0  15 0 0 1 1 1  28 0 1 0 0 0  5 0 1 0 0 1  18 0 1 0 1 0  13 0 1 0 1 1  26 0 1 1 0 0  12 0 1 1 0 1  25

Brute force We have a brute-force method for solving the sum of subsets problem For N numbers, count in binary from 0 to 2N For each 1, include the corresponding number; for each 0, exclude the corresponding number Stop if we get lucky This is clearly an exponential-time algorithm It seems like, with a little cleverness, we could do better It turns out that we can use pruning to do somewhat better But we are still left with an exponential-time algorithm

Binary tree representation Suppose our numbers are 3, 8, 9, 17, 26, 39, 43, 56 and our goal is 100 We can describe this as a binary tree search 3 (yes or no) 8 (yes or no) 9 (yes or no) 17 (yes or no) etc. As we search the binary tree, A node is promising if we might be able to get to a solution from it A node is nonpromising if we know we can’t get to a solution When we detect a nonpromising node, we can prune (ignore) the entire subtree rooted at that node How do we detect nonpromising nodes?

Detecting nonpromising nodes Suppose we work from left to right in the sequence 3 8 9 17 26 39 43 56 That is, we try things in the order 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 ... When we get to 0 0 0 0 0 0 1 0  43 we notice that even if we include all the remaining numbers (in this case, there is only one), we can’t get to 100 There is no need to try the 0 0 0 0 0 0 1 x numbers When we get to 1 1 1 1 1 1 0 0  101 we notice that we have overshot, hence no solution is possible with what we have so far We don’t need to try any of the 1 1 1 1 1 1 x x numbers

Still exponential Even with pruning, the sum of subsets typically requires exponential time However, in some cases, pruning can save significant amounts of time Consider trying to find a subset of {23, 29, 35, 41, 43, 46, 48, 51} that sums to 100 Here, pruning can save substantial effort Sometimes, common sense can be a big help Consider trying to find a subset of {16, 20, 28, 34, 44, 48} that sums to 75

Boolean satisfaction Suppose you have n boolean variables, a, b, c, ..., that occur in a logical expression such as (a or c or not f) and (not b or not d or a) and ... The problem is to assign true/false values to each of the boolean variables in such a way as to satisfy (make true) the logical expression The brute-force algorithm is the same as before (0 is false, 1 is true, try all n binary numbers) Again, you can do significant pruning, if you think about the problem Anything you do, you will still end up with a solution that is exponential in n

Intractable problems The technical term for a problem that takes exponential time is intractable Intractable problems can only be solved for small input sizes Faster computer speeds will not help much—exponential growth is fast Bottom line: Avoid these problems if at all possible!

The End