+ 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
3 Answers
+ 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?
+ 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
0
Schindlabua I knew that but I'm afraid that it would take more time using nCr recursive.