Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Implementation of Floyd's Cycle Detection algorithm. More...
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
Functions | |
uint32_t | duplicateNumber (const uint32_t *in_arr, size_t n) |
for assert | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
Implementation of Floyd's Cycle Detection algorithm.
Given an array of integers containing n + 1
integers, where each integer is in the range [1, n] inclusive. If there is only one duplicate number in the input array, this algorithm returns the duplicate number in O(1) space and the time complexity is less than O(n^2) without modifying the original array, otherwise, it returns -1.
uint32_t duplicateNumber | ( | const uint32_t * | in_arr, |
size_t | n | ||
) |
for assert
for uint32_t for IO operations
The main function implements the search algorithm
T | type of array |
in_arr | the input array |
n | size of the array |
< variable tortoise is used for the longer jumps in the array
< variable hare is used for shorter jumps in the array
int main | ( | void | ) |
|
static |
Self-test implementations.