How work recursion and draw recursion tree

一曲冷凌霜 提交于 2020-01-07 06:28:08

问题


 public static void allCombination(char[] S, int start, int r, String output) {
        int length = S.length;
        if (r == 1) {
            for (int i = start; i < length; i++) {

                System.out.println(output + S[i]);
            }
        } else {
            for (int k = start; k < length - r + 1; k++) {

                allCombination(S, k + 1, r - 1, output + S[k]);
            }
        }

Hey tied to run above code to make possible combination of a given String(I took it from internet).Can you tell me how this recursion work and how i draw recursion tree for that(I am new to programming).


回答1:


Just start at the top of the paper, draw a box for the first call. Then trace through the code looking for any call back to itself, draw a box for the new call(s) under the first one. Then go through each of the boxes at the second level and repeat the process.



来源:https://stackoverflow.com/questions/21496283/how-work-recursion-and-draw-recursion-tree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!