Sie sind auf Seite 1von 29

CSCE 310: Brute Force Algorithms

August 26, 2016


Ryan Patrick

Figure : xkcd #287

Outline
Brute Force Algorithms
Closest Pair
Convex Hull
Travelling Salesperson Problem (TSP)
Knapsack Problem
P, N P, and N P-hard
Searching
Depth-First Search
Breadth-First Search

Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
Searching
Depth-First
Breadth-First

29

Outline
Brute Force Algorithms
Closest Pair
Convex Hull
Travelling Salesperson Problem (TSP)
Knapsack Problem
P, N P, and N P-hard
Searching
Depth-First Search
Breadth-First Search

Brute Force
Patrick
3

Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
Searching
Depth-First
Breadth-First

29

Brute Force Algorithms


Brute Force
Patrick
4

Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

Drawn from Problem Statement

P, N P, and
N P-hard

Simplistic

Searching
Depth-First
Breadth-First

Sometimes Useful

29

Brute Force Algorithm


Example: Parsing a JSON File in MATLAB
Brute Force
Patrick
5

Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

Track 3D Position and Orientation of Marker

P, N P, and
N P-hard

Place Markers on Both Wrists, Both Elbows, and Head

Searching
Depth-First
Breadth-First

Measure New Values Every 10 milliseconds


Track During 5-Minute Interaction

29

Closest Pair Problem


Brute Force
Patrick
Brute Force
6

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

n Points

Searching

d Dimensions

Depth-First
Breadth-First

29

Closest Pair Problem


Example: Organizing a Tennis Tournament at UNL
Brute Force
Patrick
Brute Force
7

24, 593 students

Closest Pair
Convex Hull
TSP
Knapsack

How many dimensions?

P, N P, and
N P-hard

Years Experience?

Searching
Depth-First
Breadth-First

Serve Speed?
Serve Accuracy?
More?

29

Closest Pair Problem


Realistic Example: Pattern Recognition
Brute Force
Patrick
Brute Force
8

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

n Features

Searching

Feature Described by Feature Vector of Dimension d

Depth-First
Breadth-First

29

Closest Pair Problem


Realistic Example: Pattern Recognition: Efficient Subwindow Search [LBH08]
Brute Force
Patrick
Brute Force
9

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
Searching
Depth-First
Breadth-First

29

Closest Pair Problem


Speed Up
Brute Force
Patrick
Brute Force
10

q
Can We Speed Up (x1 y1 )2 + (x2 y2 )2 + + (xd yd )2 ?

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

Yes

Searching

How much does (x1 y1 )2 + (x2 y2 )2 + + (xd yd )2 improve things?

Depth-First
Breadth-First

Constant Factor

Still n2

29

Convex Hull
Brute Force
Patrick
Brute Force
11

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

Collection of Points

Searching

Tightest Boundary Around Outside of Points

Depth-First
Breadth-First

29

Convex Hull
Complexity
Brute Force
Patrick
Brute Force
12

n
k

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

Searching

What is the value of k?

Depth-First
Breadth-First

29

Travelling Salesperson Problem (TSP)


Brute Force
Patrick
Brute Force

13

Closest Pair
Convex Hull
TSP
Knapsack

1. Start in City 1 (of n)

P, N P, and
N P-hard

2. Pass through n 1 Other Cities Once (and Only Once)

Searching
Depth-First
Breadth-First

3. Finish in City 1
Path Called a Hamiltonian Path

29

TSP
Example
Brute Force
Patrick
Brute Force

14

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
Searching
Depth-First
Breadth-First

29

TSP
Question: What is the complexity of a Brute Force approach to the Travelling Salesperson
Problem?
Brute Force
Patrick
Brute Force

15

A. O (n)

P, N P, and
N P-hard

B. O (2n)

C. O n2
D. O

Closest Pair
Convex Hull
TSP
Knapsack

Searching
Depth-First
Breadth-First

(2n )

E. O (n!)

29

Knapsack Problem
Brute Force
Patrick
Brute Force

16

Closest Pair
Convex Hull
TSP
Knapsack

Container has Weight Capacity

P, N P, and
N P-hard

Items have Weight and Value

Searching
Depth-First
Breadth-First

Maximize Total Value for Given Weight Capacity

29

Figure : xkcd #287

Outline
Brute Force Algorithms
Closest Pair
Convex Hull
Travelling Salesperson Problem (TSP)
Knapsack Problem
P, N P, and N P-hard
Searching
Depth-First Search
Breadth-First Search

Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack
18

P, N P, and
N P-hard
Searching
Depth-First
Breadth-First

29

P, N P, and N P-hard [Sud06]


Brute Force
Patrick
Brute Force

P: Problems Solved Deterministically in Polynomial Time

Closest Pair
Convex Hull
TSP
Knapsack
19

N P: Problems Solved Non-Deterministically in Polynomial Time

P, N P, and
N P-hard
Searching

Solution Verifiable in Polynomial Time

Depth-First
Breadth-First

N P-hard: Problems with No Known Deterministic Solution in Polynomial


Time

29

Outline
Brute Force Algorithms
Closest Pair
Convex Hull
Travelling Salesperson Problem (TSP)
Knapsack Problem
P, N P, and N P-hard
Searching
Depth-First Search
Breadth-First Search

Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
20

Searching
Depth-First
Breadth-First

29

Depth-First Search
Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

1. Start at a (Parent) Node


2. Explore Children of Child1 (Grandchildren of Parent Node) Before Child2

Searching
21

3. Repeat

29

Depth-First
Breadth-First

Depth-First Search
Brute Force
Patrick

Brute Force

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

10

Searching
22

11

12

5 4 2 8 6 7 10 9 11 12
29

Depth-First
Breadth-First

Breadth-First Search
Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

1. Start at a (Parent) Node

P, N P, and
N P-hard

2. Explore All Children Before Grandchild1,1

Searching

3. Repeat

23

29

Depth-First
Breadth-First

Breadth-First Search
Brute Force
Patrick

Brute Force

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

10

Searching
24

11

12

5 4 8 2 6 10 7 9 11 12
29

Depth-First
Breadth-First

Depth-First Search
In Graphs
Brute Force

d f s P a t h (A , B , [ A | R e s t O f P a t h ] ) :
e d g e (A , Next ) ,
n o n r e p e a t i n g P a t h ( Next , B , [ A ] , R e s t O f P a t h ) .

Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

n o n r e p e a t i n g P a t h (B , B , , [ B ] ) .
nonrepeatingPath ( Current , B, V i s i t e d , [ Current | RestOfPath ]):
e d g e ( C u r r e n t , Next ) ,
n o t ( member ( Next , V i s i t e d ) ) ,
n o n r e p e a t i n g P a t h ( Next , B , [ C u r r e n t | V i s i t e d ] , R e s t O f P a t h ) .

P, N P, and
N P-hard
Searching
25

29

Depth-First
Breadth-First

Examples of Breadth & Depth-First Searches


Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard

Breadth-First Search
U.S. Presidency

Depth-First Search
British Monarchy

Searching
26

29

Depth-First
Breadth-First

Examples of Breadth & Depth-First Searches


Britians New Node
Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
Searching
27

29

Depth-First
Breadth-First

External References I
Brute Force
Patrick
Brute Force

[LBH08] Christoph H. Lampert, M.B. Blaschko, and T. Hofmann.


Beyond sliding windows: Object localization by efficient subwindow
search.
In Computer Vision and Pattern Recognition, 2008. CVPR 2008. IEEE
Conference on, pages 18, June 2008.

Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
Searching
28

[Sud06] T.A. Sudkamp.


Languages And Machines: An Introduction To The Theory Of
Computer Science.
Pearson international edition. Addison-Wesley Longman, Incorporated,
2006.

29

Depth-First
Breadth-First

Any Questions?
Brute Force
Patrick
Brute Force
Closest Pair
Convex Hull
TSP
Knapsack

P, N P, and
N P-hard
Searching
29

29

Depth-First
Breadth-First

Das könnte Ihnen auch gefallen