+ 2

Alternative for nested loop

Do you know a solution to replace nested loop to reach O(n) time complexity. here's the problem: for(i=0; i<10; i++) { for(j=0; j<10-i; j++) { Console.WriteLine(i.ToString() + " " + j.ToString()); } } and would you please give me the sample of solution code?

3rd Jan 2017, 11:46 AM
Irpan
Irpan - avatar
2 ответов
+ 2
yes we can use nested for loop, but will reduce performance.
3rd Jan 2017, 11:08 PM
Irpan
Irpan - avatar
0
I think it depends on what you want to do with them, because, lets say you want to store numbers in a bidimensional array, you can use nested loops to reach every single position in the array, that is the easy and short way to do it.
3rd Jan 2017, 1:52 PM
Janier Almarza
Janier Almarza - avatar