Compare commits

..

No commits in common. "f5c973dfe7bc4d8ecf4c4691076064647db17741" and "98d51273d9a4eda44f6757cf123f2441613f09d1" have entirely different histories.

5 changed files with 0 additions and 134 deletions

View File

@ -1,32 +0,0 @@
#include <stdio.h>
main()
{
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
else if (c == ' ' || c == '\t')
++nwhite;
else if (c == '\n')
{
++nwhite;
printf("digits = ");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n", nwhite, nother);
}
else
++nother;
printf("digits = ");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n", nwhite, nother);
}

View File

@ -1,8 +0,0 @@
Important concepts
Big O is a way to categorize your algorithms time or memory requirements based on input.
- Growth is with respect to the input
- Constants are dropped
- Worst case is usually the way we measure

View File

@ -1,17 +0,0 @@
array [0][]
a + width * offset
contigious memory
```
int a[3];
[ jakdf ] [ adsfa ] [ vdsfv ]
a[1] = 4;
[ jakdf ] [ 4 ] [ vdsfv ]
```
O(1) operations, do not grow by input, we know all the positions and variables, so we just multiply

View File

@ -1,33 +0,0 @@
#include <stdio.h>
#define SIZE 55
// Search complexity is O(n)
// bc growths in respect to input, if array is 999
// in the worst case the search will take 999 iterations over the loop
// if array is 4, the worst case will take 4 loops
int linear_search(int array[], int size, int value)
{
for (int i = 0; i < size; ++i)
if (array[i] == value)
return 1;
return 0;
}
int main()
{
int array[SIZE];
for (int i = 0; i < SIZE; ++i)
array[i] = 0;
array[3] = 45;
int value = 45;
int is_found = linear_search(array, SIZE, value);
printf("1 if found: %d\n", is_found);
is_found = linear_search(array, SIZE, 99);
printf("1 if found: %d\n", is_found);
}

View File

@ -1,44 +0,0 @@
#include "stdio.h"
#define SIZE 4096
int binary_search(int array[], int size, int offset, int value)
{
int pivot = size / 2;
int current_value = array[offset + pivot];
printf("At %d\n", offset + pivot);
if (current_value == value)
{
return 1;
}
if (pivot > 0)
{
if (current_value > value)
return binary_search(array, pivot, offset, value);
else
return binary_search(array, pivot, offset + pivot, value);
}
return 0;
}
int main()
{
int array[SIZE];
for (int i = 0; i < SIZE; ++i)
array[i] = i;
printf("1 if found: %d\n", binary_search(array, SIZE, 0, 5243));
printf("1 if found: %d\n", binary_search(array, SIZE, 0, 1));
printf("1 if found: %d\n", binary_search(array, SIZE, 0, 1044));
// for (int i = 0; i < SIZE; ++i)
// if (!binary_search(array, SIZE, 0, i))
// printf("YOU FUCKED UP!!! at index %d\n", i);
printf("1 if found: %d\n", binary_search(array, SIZE, 0, SIZE));
array[14] = 13;
printf("1 if found: %d\n", binary_search(array, SIZE, 0, 14));
}