Some of tips are related to Java as to my main language, but they may be useful while programming in different languages as well.
- Create working algorithm first, then optimize it.
- Don't use buffer variable for exchanging values between variables. Many languages allow to do that avoiding the usage of buffer variable. Integer values can be exchanged in any language:
a = a + b
b = a - b
a = a - b
- If you are accessing to the characters in the string more than once, it is much better to convert string to char array and work with it.
- If you are solving the task based on array, think if sorting of this array helps you. Language build-in methods of array sorting are optimized enough to rely on them.
- But don't concatenate already sorted arrays one by one with post-sorting! This definitely increases execution time a lot.
- Multiplication and division operations can be replaced with byte-shifting, but second ones work faster.
to be continued...
Comments
Post a Comment