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
In this unit, we learned the data structure arrays from the application point of view and representation point of view. Two applications that are representation of a sparse matrix


Q. By making use of stacks, write an algorithm to determine whether the infix expression has balanced parenthesis or not.

Sorting Algorithm A sorting algorithm is an algorithm which puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Eff

The controversy of RISC versus CISC never ends. Suppose that you represent an advocate for the RISC approach; write at least a one-page critic of the CISC approach showing its disa

A full binary tree with 2n+1 nodes have n non-leaf nodes

Djikstra's algorithm (named after it is discovered by Dutch computer scientist E.W. Dijkstra) resolves the problem of finding the shortest path through a point in a graph (the sour

Q. The degree of a node is defined as the number of children it has. Shear show that in any binary tree, the total number of leaves is one more than the number of nodes of degree 2

A queue is a, FIFO (First In First Out) list.

Implement algorithm to solve 5-1 fifth order equation given.