2016-10-23 2 views
1

ここでは、配列の右または左の円を動かす再帰的プログラムの私の擬似コードです。私は複雑さを理解しようとしています(これはn、配列Aのサイズ、または左右どちらかに戻ることができるので2^nかもしれません)。"OR"を持つreturn文はどのような種類の再帰呼び出しですか?

私はまた、これが最後のreturn文にORを持つため、これに関する情報を見つけることができないので、どのような再帰があるか把握しようとしています。

Boolean rightWing (int circle, Array A, List<int> checkerList) 

Integer lastPlace equals A.length - 1 

If circle equals lastPlace then // base case for recursion 
    Return true 

If circle < 0 then 
    Return false 

If circle > lastPlace then 
    Return false 

// impossible case 
If checkerList contains (circle) returns True then 
    Return false 

checkerList.add(circle) // add the circle to the list for the checker if it's an impossible case 

Integer moveRight equals circle + A[circle] 
Integer moveLeft equals circle - A[circle] 

Return rightWing (moveRight, A, checkerList) or rightWing(moveLeft, A, checkerList) 
+0

「種類の再帰」を定義します。あなたが何を求めているのか不明です。 – EJP

答えて

0

は、私はあなたのアルゴリズムが正しいですが、あなたは私はあなたが一度あなたの配列の各要素をチェックし、N =はsizeof(A)と(n)のOようになると思う言ったことが正しいですから、よく分かりません。

あなたが探している反論的な呼び出しの種類は、テール再帰的または非テール再帰的です。 What is tail recursion?

関連する問題