Two recursive calls in a Merge Sort function confusion

前端 未结 9 1658
情书的邮戳
情书的邮戳 2021-02-19 13:37

I have been out of touch with Algorithms for a while and have start revising my concepts these days. To my surprise the last i remember of my recursions skill was that i was goo

9条回答
  •  半阙折子戏
    2021-02-19 13:50

    The indentation in the following corresponds to the recursion:

    mergesort(0, 7)
        middle=3
        "Before the 1st Call"
        mergesort(0, 3)
            middle=1
            "Before the 1st Call"
            mergesort(0, 1)
                middle=0
                "Before the 1st Call"
                mergesort(0, 0)
                    (0 < 0) is false so return
            "After the 1st Call"
            mergesort(1, 1)
                (1 < 1) is false so return
            "After the 2nd Call"
    
            etc ...
    

提交回复
热议问题