Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6
Your code runs for values i = 3,4,5,6. f1(3), f1(4), f1(5), f1(6) gets called on each iteration. f1(3) = f1(2)+f2(1) = f1(1)+f2(0)+1 = 1+0+1 = 2 f1(4) = f1(3)+f2(2) = 2 + 2*f1(0)+1 = 2 + 2*0 + 1 = 3 ... it would be nice if you can handtrace the rest of the code. What should be the 'correct' output? Do you want it to output 20? I'm not too sure what the code is supposed to achieve in the first place.
24th Aug 2019, 5:17 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
TMS SHANU You can actually start another thread for that topic, but just as a summary: Stable sorting algorithms do not change the order/sequence of equal elements. E.g. if you use a stable sorting algorithm on {1, 3, 2, 3, 3, 4} to get {1, 2, 3, 3, 3, 4}, we can be sure that the sequence of the elements '3' are unchanged. If the sorting algorithm is unstable, the third 3 may be placed at the third slot instead of the fifth slot. The outcome of stable and unstable sorting, of course, looks the same. Some sorting algorithms move the entire set of elements into a new container as part of the algorithm. In place sorting means that the sorting process is done using same container (the original input array/list).
24th Aug 2019, 9:30 AM
Hatsy Rei
Hatsy Rei - avatar