+ 5

How do you determine the efficiency of an algorithm?

Which is more efficient: storing and iterating over a relatively large array, or just iterating over a giant range of numbers? I'm trying to understand the best algorithm for a program that finds prime numbers.

23rd Feb 2017, 4:35 PM
Shauna Lynn Skoubye Salter
Shauna Lynn Skoubye Salter - avatar
6 Answers
+ 11
I agree Vaibhav Dwivedi, "DRY" coding: Don't Repeat Yourself.
24th Feb 2017, 9:22 PM
Thomas A. Beaudry
Thomas A. Beaudry - avatar
+ 5
Well, there's a bit of mathematical theory to know beforehand. Have a look at this! https://en.wikipedia.org/wiki/Big_O_notation
23rd Feb 2017, 4:56 PM
Marco Bimbati
Marco Bimbati - avatar
+ 5
Everytime we develop or write a code in any language, Our first priorities are that the code we develop must reduce time of execution and goal should be accomplished in less lines of code. Hence, I think it also implies on algorithm that it would be called efficient when it takes less time to execute and is covered in less lines of code.
24th Feb 2017, 4:14 PM
Vaibhav Dwivedi
Vaibhav Dwivedi - avatar
+ 4
there are some simple ideas without too much theory: even numbers are no primes ...2 is one if you look for primes up to x, you only have to look up to sqrt(x) for divisors
25th Feb 2017, 8:47 AM
Oma Falk
Oma Falk - avatar
+ 1
efficiency of an algorithm depends on time and space used if the more lines are there then memory used is more ,efficiency is less u could use time complexity in program by which time efficiency is found out
4th Mar 2017, 4:58 PM
kiran kumar
kiran kumar - avatar
using space and time complexity
26th Feb 2017, 2:51 AM
kumar Saurav
kumar Saurav - avatar