Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Towers of Hanoi matlab ( non recursive) I want someone to help me writing the Non recursive Algorithms code for Towers of Hanoi in matlab

Towers of Hanoi matlab ( non recursive)

I want someone to help me writing the Non recursive Algorithms code for Towers of Hanoi in matlab syntax

Here is the code using recursive function if that helps

image text in transcribed

function Towers of Hanoi (n, initial pea, final pea,temp peg If n=-1 S1 S2 S3 S4 message = [S1, S2,S3, S4 ]; disp (message); - , Move one disk from , ; = num2str(initial-peg); to'i num2str (final-peg); = else % move n-1 disk from peg 1 to peg 2 and use peg 3 as a temporarily % holding peg. Towers_of_Hanoi ( n-1, initial_peg, temp_peg, final_peg) % move the last disk from peg 1 to peg 3. Towers_of_Hanoi ( 1, initial_peg, final_peg ,temp_peg) % move the n-1 disk from peg 2 to peg 3 using peg 1 as the temporarily % holding peg. Towers_of_Hanoi (n-1, temp_peg, final_peg, initial_peg) end end % To get the instruction for 3 disks type Towe rs of Hanoi (3,1,3,2) in your % command window

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

explain the concept of strategy formulation

Answered: 1 week ago

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

Explain strong and weak atoms with examples.

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago