Muchos estudiantes se confunden al comprender el concepto de complejidad del tiempo, pero en este artículo lo explicaremos con un ejemplo muy simple.
P. Imagina un salón de clases de 100 estudiantes en el que le das tu bolígrafo a una persona. Tienes que encontrar ese bolígrafo sin saber a quién se lo diste.
C++
#include <iostream> using namespace std; int main() { cout << "Hello World"; return 0; } // This code is contributed by vikash36905.
C
#include <stdio.h> int main() { printf("Hello World"); return 0; }
Java
import java.io.*; class GFG { public static void main(String[] args) { System.out.print("Hello World"); } } // This code is contributed by vikash36905.
C++
#include <iostream> using namespace std; int main() { int i, n = 8; for (i = 1; i <= n; i++) { cout << "Hello World !!!\n"; } return 0; } // This code is contributed by vikash36905.
C
#include <stdio.h> void main() { int i, n = 8; for (i = 1; i <= n; i++) { printf("Hello World !!!\n"); } }
Java
class GFG { public static void main(String[] args) { int i, n = 8; for (i = 1; i <= n; i++) { System.out.printf("Hello World !!!\n"); } } } // This code is contributed by Rajput-Ji
C#
using System; public class GFG { public static void Main(String[] args) { int i, n = 8; for (i = 1; i <= n; i++) { Console.Write("Hello World !!!\n"); } } } // This code contributed by Rajput-Ji
Javascript
<script> var i, n = 8; for (i = 1; i <= n; i++) { document.write("Hello World !!!<br/>"); } // This code is contributed by Rajput-Ji </script>
C++
#include <iostream> using namespace std; int main() { int i, n = 8; for (i = 1; i <= n; i=i*2) { cout << "Hello World !!!\n"; } return 0; } // This code is contributed by Suruchi Kumari
C
#include <stdio.h> void main() { int i, n = 8; for (i = 1; i <= n; i=i*2) { printf("Hello World !!!\n"); } } // This code is contributed by Suruchi Kumari
Java
class GFG { public static void main(String[] args) { int i, n = 8; for (i = 1; i <= n; i=i*2) { System.out.printf("Hello World !!!\n"); } } } // This code is contributed by Suruchi Kumari
C++
#include <iostream> #include <cmath> using namespace std; int main() { int i, n = 8; for (i = 2; i <= n; i=pow(i,2)) { cout << "Hello World !!!\n"; } return 0; } // This code is contributed by Suruchi Kumari
C
#include <stdio.h> #include <math.h> void main() { int i, n = 8; for (i = 2; i <= n; i=pow(i,2)) { printf("Hello World !!!\n"); } } // This code is contributed by Suruchi Kumari
Java
import java.lang.Math; class GFG { public static void main(String args[]){ int i, n = 8; for (i = 2; i <= n; i=(int)Math.pow(i,2)) { System.out.println("Hello World !!!"); } } }
C
Pseudocode : Sum(a, b) { return a + b }
C
Pseudocode : list_Sum(A, n) // A->array and // n->number of elements in array { sum = 0 for i = 0 to n-1 sum = sum + A[i] return sum }
C
Pseudocode : list_Sum(A, n) { total =0 // cost=1 no of times=1 for i=0 to n-1 // cost=2 no of times=n+1 (+1 for the end false condition) sum = sum + A[i] // cost=2 no of times=n return sum // cost=1 no of times=1 }
Publicación traducida automáticamente
Artículo escrito por Dhawal Arora y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA