TAILIEUCHUNG - Algorithms and Data Structures in C part 7

The Tower of Hanoi problem is illustrated in Figure . The problem is to move n discs (in this case, three) from the first peg, A, to the third peg, C. The middle peg, B, may be used to store discs during the transfer. | Previous Table of Contents Next Copyright CRC Press LLC Algorithms and Data Structures in C by Alan Parker CRC Press CRC Press LLC ISBN 0849371716 Pub Date 08 01 93 Previous Table of Contents Next Tower of Hanoi The Tower of Hanoi problem is illustrated in Figure . The problem is to move n discs in this case three from the first peg A to the third peg C. The middle peg B may be used to store discs during the transfer. The discs have to be moved under the following condition at no time may a disc on a peg have a wider disc above it on the same peg. As long as the condition is met all three pegs may be used to complete the transfer. For example the problem may be solved for the case of three by the following move sequence where the ordered pair x y indicates to take a disk from peg x and place it on pegy. Figure Tower of Hanoi Problem The problem admits a nice recursive solution. The problem is solved in terms of n by noting that to move n discs from A to C one can move n - 1 discs from A to B move the remaining disc from A to C and then move the n - 1 discs from B to C. This results in the relation for the number of steps S n required for size n as with the boundary conditions Eq. admits a solution of the form and matching the boundary conditions in Eq. one obtains A growing field of interest is the visualization of algorithms. For instance one might want to animate the solution to the Tower of Hanoi problem. Each disc move results in a new picture in the animation. If one is to incorporate the pictures into a document then a suitable language for its representation is This format is supported by almost all word processors and as a result is encountered frequently. A program to create the PostScript description of the Tower of Hanoi is shown in Code List The program creates an encapsulated postscript file shown in Code List . The word processor used to generate this book took the output of the program in Code List and .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.