Skip to content

Instantly share code, notes, and snippets.

@ZacharyThompson
Created July 18, 2023 02:55
Show Gist options
  • Save ZacharyThompson/4cc6edf190b6655762450035ad607f97 to your computer and use it in GitHub Desktop.
Save ZacharyThompson/4cc6edf190b6655762450035ad607f97 to your computer and use it in GitHub Desktop.
// 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