Bubble Sort - O(N²) Concept Bubble sort works by repeatedly compairng adjcaent elements and swapping them if they're in wrong order. For ascending order, each pass moves the largest unsorted element to its correct position at the end of the array. Implementation void bubble_sort(int* arr, int size)...
Constants and Macros Define a constant representing seconds in a year: #define SECONDS_IN_YEAR (365UL * 24 * 60 * 60) Standard minimum value macro: #define MIN_VALUE(x,y) (((x) < (y)) ? (x) : (y)) Preprocessor Directives The #error directive halts compilation and displays custom error messages. I...
Bubble Sort Bubble Sort is a simple comparison-based algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. void bubble_sort(int *arr, int size) { for (int i = 0; i &...
The Sieve of Eratosthenes To efficiently determine primes within a range, the Sieve of Eratosthenes is a classic algorithm. The process involves creating an array where each index represents a number. Initially, all entries are marked as potential primes (1). We then iterate starting from 2; if a n...
Differences Between inline, static inline, and extern inline inline Functions Function calls involve stack operations for parameter passing and return address management. Frequent calls to small functions can lead to significant stack memory consumption. The inline keyword addresses this by suggesti...
Sleep A simple utility to pause execution for a specified number of seconds. #include "kernel/types.h" #include "user/user.h" int main(int argument_count, char *argument_values[]) { if (argument_count < 2) { fprintf(2, "Usage: sleep <seconds>\n"); exit(1); } in...
Sliding window algorithms efficiently solve substring and subarray problems with linear time complexity. This technique uses two pointers to define a window that expands and contracts based on conditions. A basic sliding window structure in C: #include <stdio.h> #include <string.h> void...
What is C? C is a general-purpose computer programming language widely used in low-level development. The design goals of C were to provide a language that could be compiled in a straightforward manner, handle low-level memory, produce a small amount of machine code, and run without requiring any ru...