+ 8
Josephus problem: optimization [SOLVED]
I tried to optimize a code using linked list instead of array list, but in practice I get similar time results. When running on PC with 100,000 people, the optimized code gets the best result (time is reduced by half) but I think it isn't a worthwhile improvement. Both codes in C language: https://code.sololearn.com/cgS0wbo5AMHy/?ref=app https://code.sololearn.com/c3kIyIfq76Yz/?ref=app What do you think? I would like to see your own proposals. EDIT: Finally I found the most efficient solution: using bit operations. I also found another recursive solution. None of them can show the process. Both codes: https://code.sololearn.com/ciPaV7L6Tdku/?ref=app https://code.sololearn.com/ckOmOHcUwiGP/?ref=app Thank you all!
3 Answers
+ 12
you may find this one interesting:
https://en.m.wikipedia.org/wiki/Josephus_problem
0
can you teach me doing this
0
was curious and did some searching so and it probably shouldn't matter but putting the code that "kills" inline instead of as a function call could maybe affect performance but not in a nontrivial way and it looks like their is a strong chance the compiler does it for you anyway. just a random idea and probably not worth the time though