Top Banner
ALGORITHM
49
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intersection Study - Algorithm(Search)

ALGORITHM

Page 2: Intersection Study - Algorithm(Search)

ALGORITHMSEARCH

Page 3: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH INTRO

What is Search?

Page 4: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH INTRO

1 3 4 6 7 8 10 13 14

When Dataset is Sorted

Page 5: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH INTRO

Binary Search

Page 6: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH INTRO

Dataset not Sorted

4 3 8 6 7 13 10 14 9

Page 7: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH INTRO

Search Process can Produce additional Data

4 3 8

6

7 13 10 14 9

1 11

3

Page 8: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH INTRO

State space Tree

Page 9: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH INTRO

Three Things to Decide

STATE STRUCTURE

SEARCH ORDER

ENDCONDITION

Page 10: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

DEPTHFIRST

SEARCH

Page 11: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

Page 12: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

STATE STRUCTURE

x y

Page 13: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

SEARCHORDER

DFS

Page 14: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

ENDCONDITION

(X,Y) = E

Page 15: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

S

Page 16: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

S

1,2

Page 17: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

S

1,2

2,2

Page 18: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

S

1,2

2,2

3,2

Page 19: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

S

1,2

2,2

3,2

3,3

Page 20: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

3,3

3,4

Page 21: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

3,3

3,4

3,5

Page 22: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out?

3,3

3,4

3,5

4,5

Page 23: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out? YES

3,3

3,4

3,5

4,5

E

Page 24: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

S

E

Is there way out? YES

S

1,2

2,2

3,2

3,3

2,1

Page 25: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

Simple DFS prototype logic

function start

EndCondition

child function call

child function call

Return

Page 26: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

function start

EndCondition

Child function call

child function call

Return (x,y)==E or found

process(x+1,y)

process(x,y+1)

process(x-1,y)

process(x,y-1)

Simple DFS prototype logic

Page 27: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

Simple DFS prototype logic

loop start(Every possible start Node)

function

loop end condition

Search Complete

Page 28: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH DFS

Simple DFS prototype code

Page 29: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

BREADTHFIRST

SEARCH

Page 30: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

S

E

How many Shortest Path to End?

Page 31: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

S

E

How many Shortest Path to End?

STATE STRUCTURE

x ystep

Page 32: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

S

E

SEARCHORDER

BFS

How many Shortest Path to End?

Page 33: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

S

E

ENDCONDITION

(X,Y) = E

How many Shortest Path to End?

Page 34: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

S

E

How many Shortest Path to End?

S

1,1,2

Page 35: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End?

S

1,1,2 1,2,1

S

E

Page 36: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End?

S

1,1,2 1,2,1

S

E

2,2,2

Page 37: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End?

S

1,1,2 1,2,1

S

E

2,2,2 2,2,2

Page 38: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End?

S

1,1,2 1,2,1

S

E

2,2,2 2,2,2

2,3,2 2,3,2

Page 39: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End?

S

1,1,2 1,2,1

S

E

2,2,2 2,2,2

3,3,2 3,3,2

4,4,2 4,3,3 4,4,2 4,3,3

Page 40: Intersection Study - Algorithm(Search)

ALGORYTHM

SEARCH BFS

How many Shortest Path to End?

S

E

4,4,2 4,3,3

5,5,25,4,3 4,4,35,3,45,4,1

Page 41: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End?

S

E

4,4,2 4,3,3

5,5,25,4,3 5,4,35,3,45,4,1

6,4,3

Page 42: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End?

S

E

4,4,2 4,3,3

5,5,25,4,3 5,4,35,3,45,4,1

6,4,3

7,3,57,4,5

Page 43: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

How many Shortest Path to End? 8, 2

S

E

4,4,2 4,3,3

5,5,25,4,3 5,4,35,3,45,4,1

6,4,3

7,3,57,4,5

8,E 8,1,5

Page 44: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

Simple BFS prototype logic

loop start

EndCondition

Enqueue Start Node

Search Complete

Dequeue

Process

Page 45: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

Simple BFS prototype logic

loop start

EndCondition

Enqueue Start Node

Queue process end

Dequeue

Process

queue is Empty & found

1 2 3 4 5

Process

Page 46: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

Simple BFS prototype logic

process start

Enqueuecondition

enqueue

Enqueue loop start

Make new node

process end

Page 47: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

Simple BFS prototype logic

process start

Enqueuecondition

enqueue

Enqueue loop start

Make new node

process end

1 2 3 4 5

Process

Visited? End of map?

n1 n2 n3 n4

n2 n4

n2n4

Page 48: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

Simple BFS prototype logic

loop start(Every possible start Node)

Queue Process

loop end condition

Search Complete

Page 49: Intersection Study - Algorithm(Search)

ALGORITHM

SEARCH BFS

queue for BFS(left), BFS prototype code(right)