Suppose the graph G = (V,E) satisfies the conditions for the existence of an Eulerian cycle. The following is an algorithm for finding Euler cycle from the vertex X using stack: declare a stack S of characters (a vertex is labeled by a character) declare an empty array E (which will contain Euler cycle) push the vertex X to S
5 phương ánCó giải thích
while(S is not empty){ch = top element of the stack S if ch is isolated then remove it from the stack and put it to E
elseselect the first vertex Y (by alphabet order), which is adjacent to ch,push Y to S and remove the edge (ch,Y) from the graph
}the last array E obtained is an Euler cycle of the graph Suppose a multigraph G is given below (view picture). Which of the followings is the Euler cycle from the vertex A, created by above algorithm?
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "A, B, D, C, B, A". Đồ thị có hai cạnh song song A–B cùng các cạnh đơn B–C, B–D, C–D, mọi đỉnh bậc chẵn. Chạy thuật toán từ A: đẩy B và bỏ một cạnh A–B; tại B các đỉnh kề là A, C, D nên theo thứ tự chữ cái chọn A, đẩy A và bỏ cạnh A–B còn lại; A lúc này cô lập nên lấy ra, ghi A vào mảng kết quả; đỉnh ngăn xếp lại là B, chọn C, bỏ B–C; tại C chọn D, bỏ C–D; tại D chọn B, bỏ D–B; giờ mọi đỉnh đã cô lập nên lần lượt lấy ra B, D, C, B, A. Mảng kết quả theo đúng thứ tự lấy ra là A, B, D, C, B, A. "A, B, C, D, B, A" là chu trình thu được nếu tại B ta chọn C thay vì A, trái với quy tắc chọn đỉnh kề đầu theo thứ tự chữ cái. "A, B, C, B, A" chỉ đi bốn cạnh và bỏ sót hai cạnh nối với D. "A, B, A, B, D, C, A" kết thúc bằng cạnh C–A, mà ô A–C trong ma trận kề bằng 0 nên cạnh đó không tồn tại. "A, B, C, D, A" cũng cần cạnh D–A không có trong đồ thị.
Cùng phần 5
Suppose the graph G = (V,E) satisfies the conditions for the existence of an Eulerian cycle. The following is an algorithm for finding Euler cycle from the vertex X using stack:
declare a stack S of characters (a vertex is labeled by a character)
declare an empty array E (which will contain Euler cycle)
push the vertex X to S
while(S is not empty)
{ch = top element of the stack S
if ch is isolated then remove it from the stack and put it to E
else
select the first vertex Y (by alphabet order), which is adjacent
to ch,push Y to S and remove the edge (ch,Y) from the graph
}
the last array E obtained is an Euler cycle of the graph
Suppose a multigraph G is given below (view picture). Which of the followings is the Euler cycle from the vertex B, created by above algorithm?Có lời giảiCâu hỏiGiven the graph G = (V,E) and X is a vertex of G. Suppose there exists at least one Hamilton Cycle for the graph. The following is a backtracking algorithm for finding the first Hamilton cycle from the vertex X:
declare an empty array H (which will contain Hamilton cycle)
(1) Put the vertex X to H
(2) Check if H is a Hamilton cycle then stop, else go to (3)
(3) Consider the last vertex Y in H, if there is/are vertex(es) adjacent to Y, select the first adjacent vertex Z (by alphabet order) and put it to H. If there no adjacent vertex, remove Y from H and denote it as a bad selection (so you do not select it in the same way again).
Go to (2).
Suppose a G is given below (view picture). Which of the followings is the Hamilton cycle from the vertex A, created by above algorithm?Có lời giảiCâu hỏiWhat data structure is used for breadth first traversal of a graph?Có lời giảiCâu hỏiCả 48 câu của chủ đề48 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây