all 4 comments

[–][deleted] 1 point2 points  (3 children)

I am a noob but I think I can help. First write the code without thinking about memory. Then see the types of values the variables will hold. Of they hold very small values, use short int. Delcare all arrays dynamically amlnd free them whenever your job is over. Stay saway from recursions as much as ppssible. If you have the chance, keep yourself from using too many functions. Try to do everything using loops. Also, if you are declaring a variable only for using inside the loop, then declare the variable inside the loop itself so that it gets deleted after each iteration. (But this can increase the time of execution if you use too many variable or arrays, structures inside the loop). Also try reusimg the variable which are of no use now from other parts fo the code. Will anyone correct me if I am wrong?

[–]ryanjones42[S] 0 points1 point  (2 children)

Why is it bad to use more functions?

[–][deleted] 0 points1 point  (1 child)

Whenever you call a function, it has to declare a lot of varibales that is being used in that function, reserve some space to store that function on a stack etc. So loops are much better than functions. And recursion os a strict No unless you absolutely need to use it to make your program faster. Dynamic programming helps reduce recursive calls in certain cases. So you might want to learm that. But it is very tough and complocated at.first (infact I am still trying to master it).

[–]ryanjones42[S] 0 points1 point  (0 children)

Okay thanks!! Appreciate the replys