”¹µµ½·ƒ·...

Click here to load reader

download ”¹µµ½·ƒ· ³±†®¼±„‚

of 50

  • date post

    20-Mar-2016
  • Category

    Documents

  • view

    48
  • download

    0

Embed Size (px)

description

Διερεύνηση γραφήματος. Διερεύνηση γραφήματος. Ένας αλγόριθμος διερεύνησης γραφήματος επισκέπτεται τους κόμβους του γραφήματος με μια καθορισμένη στρατηγική, π.χ. κατά εύρος ή κατά βάθος. - PowerPoint PPT Presentation

Transcript of ”¹µµ½·ƒ·...

PowerPoint Presentation

, .. . (breadth-first search) : FIFO . v v .

bca

aebdfgaeefefcdbhh

bca

aebdfgaeefefcdbhh .

FIFO Q .

bca

aebdfgaeefefcdbhh Q :

bca

aebdfgaeefefcdbhh Q : (Q,a) : a

bca

aebdfgaeefefcdbhh Q :(Q,a) : a

1

bca

aebdfgaeefefcdbhh Q :

(Q) : Q 1

bca

aebdfgaeefefcdbhh Q : a1

bca

aebdfgaeefefcdbhh Q :(Q,b)

12

bca

aebdfgaeefefcdbhh Q :(Q,c)

12

3

bca

aebdfgaeefefcdbhh Q :(Q,f)

12

34

bca

aebdfgaeefefcdbhh Q :

12

34

(Q)

bca

aebdfgaeefefcdbhh Q :12

34

b

bca

aebdfgaeefefcdbhh Q :12

34

o a Q

bca

aebdfgaeefefcdbhh Q :12

34

o c Q

bca

aebdfgaeefefcdbhh Q :12

34

5(Q,d)

bca

aebdfgaeefefcdbhh Q :12

34

5

(Q)

bca

aebdfgaeefefcdbhh Q :1234

5

c

bca

aebdfgaeefefcdbhh Q :1234

5

o a Q

bca

aebdfgaeefefcdbhh Q :1234

5

o b Q

bca

aebdfgaeefefcdbhh Q :1234

5

(Q)

bca

aebdfgaeefefcdbhh Q :12345

f

bca

aebdfgaeefefcdbhh Q :12345

o a Q

bca

aebdfgaeefefcdbhh Q :12345

6(Q,e)

25

bca

aebdfgaeefefcdbhh Q :12345

6(Q,h)

7

26

bca

aebdfgaeefefcdbhh Q :12345

6

7

(Q)27

bca

aebdfgaeefefcdbhh Q :123456

7

d28

bca

aebdfgaeefefcdbhh Q :123456

7

o b Q 29

bca

aebdfgaeefefcdbhh Q :123456

7

o e Q 30

bca

aebdfgaeefefcdbhh Q :123456

7

(Q)31

bca

aebdfgaeefefcdbhh Q :1234567

e32

bca

aebdfgaeefefcdbhh Q :1234567

o d Q 33

bca

aebdfgaeefefcdbhh Q :1234567

o f Q 34

bca

aebdfgaeefefcdbhh Q :1234567

8(Q,g)

35

bca

aebdfgaeefefcdbhh Q :1234567

8o h Q

36

bca

aebdfgaeefefcdbhh Q :1234567

8

(Q)37

bca

aebdfgaeefefcdbhh Q :12345678

h38

bca

aebdfgaeefefcdbhh Q :12345678

o e Q 39

bca

aebdfgaeefefcdbhh Q :12345678

o f Q 40

bca

aebdfgaeefefcdbhh Q :12345678

(Q)41

bca

aebdfgaeefefcdbhh Q :12345678 g42

bca

aebdfgaeefefcdbhh Q :12345678o e Q 43

bca

aebdfgaeefefcdbhh Q :12345678 . 44

a :

12345678 . x a x a x

12345678

1091211

1413 .

46 .

12345678

1091211

1413

:

(offline) , (adjacency lists)TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAclass AdjacencyLists {static class Node { int v; Node next;Node(int v, Node t){ this.v = v; next = t; } }

public static void main(String[] args) {int N = Integer.parseInt(args[0]);int M = Integer.parseInt(args[1]);Node adj[] = new Node[V];for (int i = 0; i < N; i++) adj[i] = null;for (In.init(); !In.empty();) {int i = In.getInt(), j = In.getInt(); adj[j] = new Node(i, adj[j]);adj[i] = new Node(j, adj[i]);}}} 1234523413512413524adj void BFS(int s) // s {Queue Q = new Queue();marked[s] = true;Q.put(s);while (!Q.isEmpty()){k = Q.get(); for (Node t = adj[k]; t != null; t = t.next)if (!marked[t.v]) {marked[t.v] = true;parent[t.v] = k;Q.put(t.v);}}}} . ( .)

void BFS(int s) // s {Queue Q = new Queue();marked[s] = true;Q.put(s);while (!Q.isEmpty()){k = Q.get(); for (Node t = adj[k]; t != null; t = t.next)if (!marked[t.v]) {marked[t.v] = true;parent[t.v] = k;Q.put(t.v);}}}} . ( .)