+ 2

Is there a code that is more optimize than this?

I did the code in C Language about n Choose r and it takes a long time when doing with 8C4. And what is the Big-O Notation of this code? Thank you in advance. https://code.sololearn.com/cIT8JkyOdZ3i/?ref=app

15th Nov 2018, 12:47 PM
Supakorn Nilsuwan
Supakorn Nilsuwan - avatar
3 odpowiedzi
+ 4
You have a tiny bug: line 17 should be "for(int i=num; i<=n; i++){". Other than that, your code seems quite fine to me! It finds and prints each combination exactly once. So I think the time complexity should be O((nCr) * r), which is obviously the best one can expect. What made you think it takes a long time?
16th Nov 2018, 3:16 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
I must have written that in a state of sleepy deliriousness. I guess running the code would have helped. I'll... just quietly delete that :D
16th Nov 2018, 10:41 PM
Schindlabua
Schindlabua - avatar
0
Schindlabua I knew that but I'm afraid that it would take more time using nCr recursive.
17th Nov 2018, 3:22 AM
Supakorn Nilsuwan
Supakorn Nilsuwan - avatar