java recursive method 一問

fundamental operation 係指algorithm 嘅中心

咁recursive method嘅fundamental operation 係咪指 method自己本身?

還是method入面嘅工作?


好亂。。。。。

舉個例:

check(string a){


//  base case
if()

    return true

else if ()

     return false

//  recursive case

if ()

    return check(a.substring(1))

else

     return check(a.substring(2))


}

咁到底substring係core 定 check 依條method係

A Method can call another methods but it can also call itself. When a method calls itself, it'll be named recursive method.
A Recursive usually, has the two specifications:
Recursive method calls itself so many times until being satisfied.
Recursive method has parameter(s) and calls itself with new parameter values.

TOP

A Method can call another methods but it can also call itself. When a method calls itself, it'll be  ...
7h1r733n 發表於 2015-11-17 23:37


    thx for reply , bro

but i am not asking about the definition of recursive method......

TOP

樓主有無一啲 reference 睇睇你個 "fundamental operation" 既 definition 响邊度黎?

我讀咁多年書淨係記得加減乘除係 fundamental operations

TOP

揾到呢個 SO thread

應該係 algorithm 既 thoery study,但睇黎唔係一個 hard definition 黎過喎。

以小弟淺見,對於你個 `check()` 黎講佢個 algorithm 係自己個 method body。 但係個 method body 除左 recursive calls, `substring()` 之外仲有 flow control,呢三樣野係唔可以獨立拆出黎睇,一定要一齊用先成立到呢條 algorithm。所以當你講 fundamental operation 我會覺得係指 `check()` 成個 method body,亦可以話係 `check()` 本身,而唔係淨係 `substring()`。

TOP

揾到。

應該係 algorithm 既 thoery study,但睇黎唔係一個 hard definition 黎過喎。

以小弟淺見,對於 ...
justlazy 發表於 2015-11-18 16:26


   係呀,就係algorithm

TOP

揾到。

應該係 algorithm 既 thoery study,但睇黎唔係一個 hard definition 黎過喎。

以小弟淺見,對於 ...
justlazy 發表於 2015-11-18 16:26


    咁如果所有if statement都有 comparison,可唔可以話comparison就係fundamental operations?

例如if (a==b && b==c)

TOP

回覆 7# brotherofninth

我覺得唔可以。

因為 if statement 只係 flow control 既一種形式,唔係 operation。

如果一個 method 裹面只有 flow control 而無其他野,咁果個 method 其實乜 operations 都無做到,又點會有 fundamental operations?

TOP

回覆  brotherofninth

我覺得唔可以。

因為 if statement 只係 flow control 既一種形式,唔係 operatio ...
justlazy 發表於 2015-11-18 20:59


    可唔可以pm份code俾師兄,分析一下fundamental operation係邊

TOP

post 出黎大家一齊研究下? pm 我都無所謂

TOP