Optimization: The for loop inside the isPrime function doesn't need to iterate over even numbers, as all prime numbers (except 2) are odd.
@the_daily_improvement15 күн бұрын
I am not really good at programming but i don't think this solution will optimize thee problem. Nice try by the way.
@thecodinglion15 күн бұрын
Nice try. But it is still not optimized
@E.N772 күн бұрын
Dude ... He was not giving a course on how to optimize the code ... He just give an example for us to understand the problem solving .... And by the way ... That's not optimization you basically add another problem to solve Instead : you can make the loop go through the half of the round (number) 🤝
@FoXcodeZ2 күн бұрын
@@E.N77 He literally asked for that type of comment at 3:00, so you misunderstood my point. Rejecting unnecessary elements is part of optimization, aligning with Donald Knuth's statement: "Premature optimization is the root of all evil".
@christiantld6 күн бұрын
Optimizing the function isPrime: - if num is 2 return true - if is even return false (all primes are odd) - we don't need to iterate over all numbers, just to square root of given number Optimizing the function printPrimesInRange: I'm not sure if it is a real optimization but i thought about using recursion over the elements of the array