-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculoComplejidad.java
69 lines (63 loc) · 1.38 KB
/
CalculoComplejidad.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package es.upm.dit.adsw.g23.clases.tema02;
/**
* Código usado en la clase del 17 de febrero
*/
public class CalculoComplejidad {
public static boolean buscar1(int k, int[] numeros) {
boolean encontrado = false;
for(int i=0; i< numeros.length; i++) {
if (numeros[i] == k) {
encontrado = true;
}
}
return encontrado;
}
public static boolean buscar2(int k, int[] numeros) {
for(int i=0; i< numeros.length; i++) {
if (numeros[i] == k) {
return true;
}
}
return false;
}
public static int repetidos1(int[] numeros) {
int repetidos = 0;
for(int i=0; i< numeros.length; i++) {
for (int j=0; j< numeros.length; j++) {
if (i == j) {
continue;
}
if(numeros[i] == numeros[j]) {
repetidos += 1;
}
}
}
return repetidos / 2;
}
public static int repetidos2(int[] numeros) {
int repetidos = 0;
for(int i=0; i< numeros.length; i++) {
for (int j=0; j < i; j++) {
if(numeros[i] == numeros[j]) {
repetidos += 1;
}
}
}
return repetidos;
}
public static int repetidos3(int[] numeros) {
return repetidos3(numeros, 0);
}
public static int repetidos3(int[] numeros, int pos) {
if(numeros.length < 2) {
return 0;
}
int repetidos = 0;
for (int i=pos + 1; i < numeros.length; i++) {
if(numeros[pos] == numeros[i]) {
repetidos += 1;
}
}
return repetidos + repetidos3(numeros, pos + 1);
}
}