Created
July 18, 2023 02:55
-
-
Save ZacharyThompson/4cc6edf190b6655762450035ad607f97 to your computer and use it in GitHub Desktop.
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
// Zachary Thompson | |
// Idea from "The Algorithm Design Manual" by Skiena page 179 | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
#define N 100000000 | |
int main() { | |
int *arr = malloc(sizeof(int) * N); | |
memset(arr, 0, sizeof(int) * N); | |
srand(time(NULL)); | |
for (int i = 0; i < N; i++) { | |
int index = rand() % N; | |
arr[index]++; | |
} | |
int count = 0; | |
printf("n=%d\n", N); | |
printf("\e[4mk\tBuckets w/ k Items\e[24m\n"); | |
for (int k = 0; k < 15; k++) { | |
for (int i = 0; i < N; i++) { | |
if (arr[i] == k) { | |
count++; | |
} | |
} | |
printf("%d\t%d\n", k, count); | |
count = 0; | |
} | |
free(arr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment