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
4 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 B, 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: "B, D, C, B, A, B". Đồ thị có hai cạnh song song giữa A với đỉnh B, thêm cạnh B–C, cạnh B–D, cạnh C–D, tổng 5 cạnh và mọi đỉnh đều bậc chẵn. Chạy từ B, mỗi bước lấy đỉnh trên đỉnh ngăn xếp, chọn láng giềng đầu theo thứ tự chữ cái rồi xoá cạnh vừa dùng, nên thứ tự đẩy vào ngăn xếp đúng là "B, A, B, C, D, B": B sang A, A trở về B, B sang C, C sang D, D trở về B, lúc đó 5 cạnh đã hết. Sau đó các đỉnh lần lượt thành cô lập và bị lấy ra để nối vào mảng kết quả, vì vậy mảng Euler là dãy đẩy vào đọc ngược. Chính vì thế "B, A, B, C, D, B" là thứ tự vào ngăn xếp chứ không phải mảng mà thuật toán trả về. Dãy "B, A, B, D, C, B" chỉ xuất hiện nếu ở lần quay lại B thuật toán chọn D trước C, trái luật lấy láng giềng nhỏ nhất theo chữ cái. Dãy "B, A, B, D, C" liệt kê 5 đỉnh và không kết thúc ở B, mà một chu trình qua 5 cạnh phải gồm 6 đỉnh với đỉnh đầu trùng đỉnh cuối.
Cùng phần 5
What data structure is used for breadth first traversal of a graph?Có lời giảiCâu hỏiGiven a weighted graph below and you are using the Dijkstra algorithm to find the shortest path from the vertex A to the vertex F. What is the label of the vertex E when the shortest path from A to F is determined?Có lời giảiCâu hỏiGiven a graph below. What is the output of depth-first traversal from vertex B? (visit nodes in ABC order if there are some nodes having the same selection ability).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