Which of the following represents the Towers of Hanoi?
A. Function Numeric unKnown(Numeric num)
// Call function recursively until reaching 0 or 1
If num == 0 Or num == 1 Then
Return num
Else
Return unKnown(num - 2) + unKnown(num - 1)
End If
End Function
B. Function Numeric unKnown(Numeric num)
// Base case returns 1
If (num == 1) Then
Return 1
Else
Return (num * num) + unKnown(num - 1)
End If
End Function
C. Function Numeric unKnown(Numeric num)
// Declare variables
Declare Numeric fact = 1
Declare Numeric index // loop index
// Loop
For index = num to 1 Step -1
fact = fact * index
End For
Return fact
End Function
D. Module unKnown(Integer n, sourcePeg, targetPeg, sparePeg)
If (n > 0) Then
moveDiscs(n - 1, sourcePeg, sparePeg, targetPeg)
// Move disc from sourcePeg to targetPeg
moveDiscs(n - 1, sparePeg, targetPeg, sourcePeg)
End If
End Module
Answer: D
You might also like to view...
Adobe Flash is an example of a pop-up that can be added to Internet Explorer 11
Indicate whether the statement is true or false
What is the default mask mode and how does it affect masks?
What will be an ideal response?