Brute force “Obvious” solution Enumerate all possibilities

Slides:



Advertisements
Similar presentations
Minimum Spanning Network: Brute Force Solution
Advertisements

Chapter 11 Counting Methods © 2008 Pearson Addison-Wesley. All rights reserved.
Section 10-3 Using Permutations and Combinations.
THE NATURE OF COUNTING Copyright © Cengage Learning. All rights reserved. 12.
Permutations & Combinations: Selected Exercises. Copyright © Peter Cappello2 Preliminaries Denote the # of arrangements of some k elements of a set of.
Introduction to Algorithms: Brute-Force Algorithms.
Copyright © 2012 Pearson Education, Inc. Publishing as Addison Wesley CHAPTER 8: Sequences, Series, and Combinatorics 8.1 Sequences and Series 8.2 Arithmetic.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
EXAMPLE 1 Count permutations
Discrete Optimization
Problem Solving: Brute Force Approaches
Permutations and Combinations
Integer Programming An integer linear program (ILP) is defined exactly as a linear program except that values of variables in a feasible solution have.
Data Structures Lab Algorithm Animation.
BackTracking CS255.
Arithmetic Sequences January 26, 2017.
Analysis of Algorithms
Divide-and-Conquer 6/30/2018 9:16 AM
Copyright © Cengage Learning. All rights reserved.
Permutations and Combinations
Backtracking And Branch And Bound
Solve Systems of Linear Equations by Elimination
Backtracking And Branch And Bound
CC 215 Data Structures Graph Searching
Types of Algorithms.
5.2 Mixed Integer Linear Programming
Building Java Programs
Problem Solving: Brute Force Approaches
Solving Systems Using Elimination
Chapter 10: Algorithm Design Techniques
Analysis and design of algorithm
ITEC 2620M Introduction to Data Structures
Types of Algorithms.
Exercise: fourAB Write a method fourAB that prints out all strings of length 4 composed only of a’s and b’s Example Output aaaa baaa aaab baab aaba baba.
Brute Force Approaches
Breadth-First Searches
Divide-and-Conquer 7 2  9 4   2   4   7
MURI Kickoff Meeting Randolph L. Moses November, 2008
Road Map - Quarter CS Concepts Data Structures Java Language
CSE 373 Data Structures Lecture 16
Divide and Conquer Algorithms Part I
Counting Discrete Mathematics.
Recall Brute Force as a Problem Solving Technique
Insertion Sort Demo Sorting problem:
Pruning 24-Feb-19.
Solving Systems of Three Linear Equations in Three Variables
Quicksort.
Constraint satisfaction problems
National Taiwan University
Divide-and-Conquer 7 2  9 4   2   4   7
Road Map - Quarter CS Concepts Data Structures Java Language
Backtracking and Branch-and-Bound
CSC 172 DATA STRUCTURES.
Types of Algorithms.
Recursive backtracking
Backtracking And Branch And Bound
Exercise: Dice rolls Write a method diceRoll that accepts an integer parameter representing a number of 6-sided dice to roll, and output all possible arrangements.
Introduction to Algorithms
5.2 Mixed Integer Linear Programming
Recursive backtracking
David Kauchak cs161 Summer 2009
Divide-and-Conquer 7 2  9 4   2   4   7
Analysis and design of algorithm
The Division Rule Theorem: Suppose a set A has n elements and is partitioned by the collection {A1, A2, ..., Ap}, where each partition set has m elements.
Non-Linear data structures
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Constraint satisfaction problems
Quicksort.
Integer Programming (IP)
5.2 Mixed Integer Linear Programming
Presentation transcript:

Brute force “Obvious” solution Enumerate all possibilities Reliable way to score 30-50%

Depth-first search Recursively enumerate all possibilities Takes n^m time, where n is the depth and m is the branching factor Backtracking can speed this up

permutations/combinations Permutations: possible orderings of the elements of a set For each element, generate the permutations for the remaining elements and prepend that element Combinations: ways of selecting subsets of size K For each element from 1 to N-K-1, recursively generate combinations of size K-1 for elements after that one {1, 2, 3} {1, 3, 2} {2, 1, 3} {2, 3, 1} {3, 1, 2} {3, 2, 1} {1, 2, 3} {1, 2} {1, 3} {2, 3}

Generating all subsets Solution 1: Use bits of integer as flags for membership Increment x & (1<<n) is non-zero if (n+1)th bit is set Solution 2: Depth-first search 000 001 010 011 100 101 110 111

Problem example 1 - aliens Brute force: O(n) Brute force marks: 40 Linear search

Problem example 2 - sails “In test cases worth a total of 25 points, the total number of ways to arrange the sails will be at most 1000000” Generate all combinations for each mast Other suboptimal solutions may be easier

Problem example 3 - flood Walls flooded on one side only collapse in 1 hour Determine which walls will not collapse Brute force: O(W.H) Brute force marks: 40 0-1 BFS