Tutorial by Examples

The following function finds the maximal element in an array: int find_max(const int *array, size_t len) { int max = INT_MIN; for (size_t i = 0; i < len; i++) { if (max < array[i]) { max = array[i]; } } return max; } The input size is the...
The following function checks if an array has any duplicates by taking each element, then iterating over the whole array to see if the element is there _Bool contains_duplicates(const int *array, size_t len) { for (int i = 0; i < len - 1; i++) { for (int j = 0; j < len; j++) { ...
Introduction Consider the following problem: L is a sorted list containing n signed integers (n being big enough), for example [-5, -2, -1, 0, 1, 2, 4] (here, n has a value of 7). If L is known to contain the integer 0, how can you find the index of 0 ? Naïve approach The first thing that comes ...
Let's say we have a problem of size n. Now for each step of our algorithm(which we need write), our original problem becomes half of its previous size(n/2). So at each step, our problem becomes half. StepProblem1n/22n/43n/84n/16 When the problem space is reduced(i.e solved completely), it cannot ...

Page 1 of 1