5 comment
This commit is contained in:
parent
fb847aa4bd
commit
fe9e21048f
|
@ -1,6 +1,19 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// complexity is O(sqrt(N))
|
||||||
|
// well we need ot find an exact moment,
|
||||||
|
// let's say "height" at which our crystal
|
||||||
|
// balls break, for that we only have 2 balls,
|
||||||
|
// so we can't do binary search, since the range
|
||||||
|
// is tooooo huge, therefore we run a linear
|
||||||
|
// growth bigger than N, but small enough to find where
|
||||||
|
// the first ball breaks, then we take the interval
|
||||||
|
// between: [the previous non-break] and [where it broken]
|
||||||
|
// and run a normal linear search
|
||||||
|
// therefore we run sqrt(n) + sqrt(n) times
|
||||||
|
// so it's O(sqrt(N)
|
||||||
|
|
||||||
#define SIZE 999
|
#define SIZE 999
|
||||||
|
|
||||||
int two_crystal_balls_search(int array[], int size, int value)
|
int two_crystal_balls_search(int array[], int size, int value)
|
||||||
|
|
Loading…
Reference in New Issue