


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Design AND ANALYSIS LAB PROGRAM
Typology: Lab Reports
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Algorithm Lab Exp No 1 : Tower of Hanoi
def toh(n,x,y,z): create an function name if n>=1: move(x,z) call the function move in ordered to solve the function else: toh(n-1,x,z,y) move(x,z) toh(n-1,y,x,z) def move(x,y): print(“Move the top n disk from “, x,” tower x to tower y”, y) n=int(input(“Enter the number of disk”)) toh(n,”X”,”Y”,”Z”)
n = 3 # Number of disks source = 'A' temp = 'B' destination = 'C' stack = [(n, source, temp, destination)] while stack: n, source, temp, destination = stack.pop() if n == 1: print(f"Move disk 1 from {source} to {destination}") else: stack.append((n-1, temp, source, destination)) stack.append((1, source, temp, destination)) stack.append((n-1, source, destination, temp))
Palindrome for string Reverse Palindrome for prime number