Nested for loop, Data Structure & Algorithms

nested for loop

for (i = 0; i < n; i + +) {

for (j = 0; j < m; j + +) {

sequence of statements

}

}

Here, we observe that, the outer loop executes n times. Every time the outer loop executes, the inner loop executes m times. Consequently of this, statements in the inner loop execute a total of n * m times. Thus, the time complexity is O(n * m). If we modify the conditional variables, where the condition of the inner loop is j < n instead of j < m (i.e., the inner loop also executes n times), then the total complexity for the nested loop is O(n2).

Posted Date: 4/4/2013 5:56:17 AM | Location : United States







Related Discussions:- Nested for loop, Assignment Help, Ask Question on Nested for loop, Get Answer, Expert's Help, Nested for loop Discussions

Write discussion on Nested for loop
Your posts are moderated
Related Questions
What values are automatically assigned to those array elements which are not explicitly initialized? Garbage values are automatically assigned to those array elements that

implement multiple stack in single dimensionl array.write algorithms for various stack operation for them

Define null values.  In some cases a particular entity might not have an applicable value for an attribute or if we do not know the value of an attribute for a particular entit

how we can convert a graph into tree

In the present scenario of global warming, the computer hard ware and software are also contributing for the increase in the temperature in the environment and contributing for the

Define Dynamic Programming  Dynamic  programming  is  a  method  for  solving  problems  with  overlapping  problems.  Typically, these sub problems arise from a recurrence rel

Prove that uniform cost search and breadth- first search with constant steps are optimal when used with the Graph-Search algorithm (see Figure). Show a state space with varying ste

How many nodes in a tree have no ancestors 1 node in atree have no ancestors.

Q. Define a method for keeping two stacks within a single linear array S in such a way that neither stack overflows until entire array is used and a whole stack is never shifted to

differentiate between indexing and hashing in file organization