This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
void bubbleSort(int* A, int length) { | |
// Guarantee of iterations to sort the array | |
for (int k = 0; k < length - 1; k++) { // Loop K | |
int flag = 0; | |
// Actual implementation | |
for (int i = 0; i < length - k - 1; i++) { // i < length - 2 | |
if (A[i] > A[i + 1]) { | |
// Swap positions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// Arreglo final | |
// Arreglo izquierdo | |
// Arreglo derecho | |
// tamaño del arreglo izquierdo | |
// tamaño del arreglo derecho | |
void Merge(int* A, int* L, int lefCount, int* R, int rightCount) { | |
int i, leftIndex, rightIndex; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
void insertionSort(int* A, int length) { | |
for (int i = 1; i < length; i++) { | |
int value = A[i]; | |
int hole = i; | |
// Regresion con hoyos hasta el más chico | |
while (hole > 0 && A[hole - 1] > value) { | |
A[hole] = A[hole -1]; | |
hole--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
void swap(int* a, int* b) { | |
int t = *a; | |
*a = *b; | |
*b = t; | |
} | |
int Partition(int* A, int start, int end) { | |
int pivotValue = A[end]; // VALOR de pivot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
using namespace std; | |
class BST { | |
public: | |
int value; | |
BST *left; | |
BST *right; | |
BST(int val); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int findFirstIndex(int* A, int n, int target, int position) { | |
int low, high; | |
low = 0; | |
high = n - 1; | |
int result = -1; | |
while (low <= high) { | |
int mid = low + (high - low) / 2; | |
if (target == A[mid]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.youtube.com/watch?v=4qjprDkJrjY&list=PL2_aWCzGMAwL3ldWlrii6YeLszojgH77j&index=6 | |
#include <iostream> | |
int ArrayCountRotation(int* A, int n) { | |
/** | |
// low <= high | |
// A[mid] menor a next y prev | |
// binary search | |
// binary search |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.youtube.com/watch?v=uufaK2uLnSI&list=PL2_aWCzGMAwL3ldWlrii6YeLszojgH77j&index=7 | |
#include <iostream> | |
int SearchRing(int* A, int n, int target) { | |
int low = 0; | |
int high = n - 1; | |
while (low <= high) { | |
int mid = low + (high - low)/2; | |
if (target == A[mid]) return mid; // Case 1: Found X |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.youtube.com/watch?v=wAyrtLAeWvI&list=PL2_aWCzGMAwLz3g66WrxFGSXvSsvyfzCO&index=7 | |
#include <iostream> | |
int fibDynamic(int n, int* A) { | |
//if (n <= 1) return n; // Toggle* | |
if (A[n] != -1) return A[n]; | |
A[n] = fibDynamic(n-1, A) + fibDynamic(n-2, A); | |
return A[n]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.youtube.com/watch?v=wAyrtLAeWvI&list=PL2_aWCzGMAwLz3g66WrxFGSXvSsvyfzCO&index=7 | |
#include <iostream> | |
// Big(Log N) //if (n <= 1) return n; // Toggle^1/2 * Toggle^1/2 | |
int expoIterativeBest(int x, int n) { | |
if (n == 0) return 1; | |
if (n % 2 == 0) { | |
int Y = expoIterativeBest(x, n - 1); | |
return Y * Y; | |
} |