DSA-Assignments

Log | Files | Refs | README

commit d62ad0cdb7ba40dd000c99f7144421b152f93e4f
parent 5bdd04f44568b818464d8f809ddec48c20bfe1fd
Author: TranLili <tranlili96@gmail.com>
Date:   Wed, 29 Nov 2023 15:18:47 +0100

Add if statement so the recursive expression ends.

Diffstat:
MProblem4/Problem4.cpp | 3+++
1 file changed, 3 insertions(+), 0 deletions(-)

diff --git a/Problem4/Problem4.cpp b/Problem4/Problem4.cpp @@ -16,6 +16,9 @@ using namespace std; // T(1) = 1 // Recursive function to calculate T(n) int T(int n) { + if (n == 1) + return 1; + int result = T(n - 1) + T(ceil(n / 2.0)) + n; return result;