Merge Sort in C – Algorithm, Program, and Complexity

Merge sort in C is a classic divide-and-conquer sorting algorithm that guarantees O(n log n) time in all cases. It splits an array into halves, recursively sorts each half, then merges the sorted halves back together. Unlike bubble sort or insertion sort, merge sort never degrades to O(n²) — making it the preferred choice when …

Insert an Element into an Array in C – At Position and Sorted

Inserting an element into an array means placing a new value at a specific position while shifting existing elements to make room. Because C arrays are fixed in size, you need to allocate enough space upfront and track the current number of elements separately. This guide shows two practical approaches: inserting at a given index …

C Program: Array Summation Using Pointers

This program reads N integers into a dynamically allocated array and computes their sum using pointer arithmetic instead of array subscript notation. Understanding the equivalence between *(a + i) and a[i] is fundamental to C — both produce identical machine code. The program also demonstrates malloc() and free() for runtime-sized arrays. The original post used …

C Program to find the average of largest two of the given numbers in the array.

This program reads N integers and finds the two largest values without sorting the array, then computes their average. The key technique: maintain two variables — first (the largest seen so far) and second (the second-largest). Scan each new element and update these two variables in one pass. Time complexity: O(n). Space: O(1) — no …

C Program To Demonstrate Linear search

Linear search (also called sequential search) is the simplest searching algorithm: start at the first element, compare each element to the key, and stop when you find a match or exhaust the array. It makes no assumption about the data being sorted. It runs in O(n) time and O(1) space — no extra memory needed …

C Program to Find Sum and Average of an Array

C Program to Find Sum and Average of an Array This program reads N integers (positive, negative, and zero) into an array and computes three values: the sum of negatives, the sum of positives, and the average of all elements. Algorithm Read N (array size) from the user. Read N integers into the array one …