Neon32
- 68
- 1
It would be much appreciated if you could show me how to do recursive tracing for this method.
Last edited:
The discussion revolves around tracing a recursive method in Java, with participants exploring the concept of recursion, sharing their experiences with tracing, and clarifying misunderstandings about the method's structure. The scope includes technical explanations and conceptual clarifications related to programming and recursion.
Participants express differing views on what constitutes recursion in the method, and there is no consensus on the best approach to trace the method. The discussion remains unresolved regarding the clarity of the recursive nature of the method and the effectiveness of different tracing strategies.
Participants note limitations in their understanding of the method's behavior, particularly in relation to the differences between programming languages and the specific implementation details of the method.
Readers interested in programming, particularly those studying recursion in Java or comparing it with other languages like Visual Basic, may find this discussion relevant.
BvU said:What's recursive in this method ?
Did you try typing it in and see what it does ?
Is this homework ?
I see. Maybe I misunderstand 'recursive' : I then expect a call to 'mystery' inside the method.Neon32 said:1) mystery(n-1) is recursive
BvU said:Did you try typing it in and see what it does ?
BvU said:All I've left is question 2![]()
----- 6 ----------
(6 + ((4 + ((2 + ( 0
+ 1)
)
+ 3)
)
+ 5)
)
--------------------------
Sub mist(n As Integer)
If n / 2 = 0 Then
Debug.Print n
ElseIf n Mod 2 = 0 Then
Debug.Print "(" & n & " + ";
mist n - 1
Debug.Print ")"
Else
Debug.Print "(";
mist n - 1
Debug.Print " + " & n & ")"
End If
End Sub
Sub test()
Dim n As Integer
again:
n = CInt(InputBox("Give n "))
Debug.Print " "
Debug.Print " ----- " & n & " ---------- "
If n < 0 Then Exit Sub
Call mist(n)
Debug.Print " -------------------------- "
GoTo again
End Sub
No. The mystery() function is recursive because it calls itself.Neon32 said:1) mystery(n-1) is recursive
BvU didn't ask about tracing the function; he asked if you had tried typing it in and running it. Seeing what the function produces might be helpful in understanding what it does.Neon32 said:Yes I've tried to trace it and all I got was (6 + ((4 + ((2 + . I don't understand how to continue it.
----- 6 ----------
(6 + ((4 + ((2 + 1 ) + 3)) + 5))
--------------------------
Thank you :).BvU said:Didn't know that; was just trying to help. My systematic method has always been trial and error-- especially the latter.
Good luck with your exam !