Category: C

Depth First and Breadth First Traversal

Depth first traversal of a Graph could be used to traverse a directed or un-directed graph and thus creating a spanning tree. Depth first traversal...

Linked representation of Graphs in C

There are many in-inadequacies in using the Adjacency Matrix representation of Graphs. Once such inadequacy is the difficulty in adding or deleting nodes while data...

Representing Graphs and Networks in C

A Graph is a data structure that consists of a set of nodes interconnected by directed or un-directed arcs. For a DIRECTED Graph, the ordered pair of nodes...

Merge and Radix Sorts

Merge Sort Merge Sort is a process of combining more than one sorted files into a single sorted file. The procedure is to divide a...

Insertion Sort and its implementation in C

Insertion Sort is a simple implementation of the general straight selection sort. A simple routine for insertion sort can be written as below – void insertionsort(int...

Binary Tree Sort in C

Binary Tree Sort uses a Binary search tree. The various steps involved in such a sort would be – Construct a binary tree with the given...

Selection Sort

A Selection sorting technique uses a general algorithm which uses an ascending or descending priority queue. The idea would be to pre-process input array X[i] into...

Bubble Sort in C

Lets explain Bubble sort by illustrating tow specific examples involving steps where smaller numbers bubbles to first and when larger numbers bubbles to last. Number...

Efficiency and Order of a Sorting Program

Efficiency Considerations The following are the efficiency considerations while planning for a sorting program / algorithm – Time required to code the program and the...

Efficiency of Recursion

In general cases, a non-recursive program runs more efficiently than a recursive program since a recursive program requires more execution time to enter and exit...

Recursion in C

Recursion Recursion and Iteration are two different concepts of achieving a result by a number of repeated operations. Iteration involves use of for, while and...

Doubly Linked Lists

Doubly Linked lists eliminates below drawbacks of circular lists – not able to traverse backward not able to delete and node given only points to...

Dynamic Circular Linked Lists in C

Circular lists eliminates same drawbacks of linear lists. In as circular list it is assumed that items are inserted at the front and the list...

Dynamic Linked Lists as Queues in C

When Dynamic Linked Lists are represented as Queues, the first node represents front of queue given by q.front and last node represents the rear of...

Implementing Dynamic Linked Lists in C

List is a type of dynamic data structure which rectifies certain drawbacks of Stacks and Queues. Lists generally uses the concept of pointers which points...

Queues and its implementation in C

A Queue is a First In First Out (FIFO) which is an ordered collection of items which are deleted at the front end and inserted...

Game Trees

Game Tree is one of the applications of Binary Trees. For example the one implemented for the Tic-Tac-Toe Game. X | X | X O...

Traversing a Binary Tree in C

There are generally 3 traversal strategies for Binary Trees – INORDER, PREORDER and POSTORDER. For eg:, the inorder, preorder and postorder traversal of an expression tree...

C program for Hailstones series

Hailstones is a sequence of numbers that could be generated from any positive number by performing a specific operation on it until it reaches 1....

for loops in C

The ‘for’  loop is another important looping structure which could replace ‘while’  and ‘do .. while’ loops. It has a special feature that the initialization,...

C program to implement Russian Peasant

Here is a C program that I wrote years back to implement Russian Peasant method of an interesting multiplication technique – main(){ int a, b,...

While Loop in C

Like do-while loop, While loop is the most commonly used looping construct to repeat a process or calculation for a set or collection of inputs...

Do – While Loops in C

Looping constructs is an important programming language technique to repeat a process or calculation for a set or collection of inputs or storage based on...

C Program to check for leap year

Here is a C program to check for leap year – main () { int year; printf("Please enter any year as 4 digits>> "); scanf("%d",...

Making decision in C program

Decision making is an important aspect of programming language that enables the programmer to arrive at a conclusion based on certain data processing, comparisons and conditional...

Declaring variables in C language

C programming language allows to define and classify data so we can use it appropriately in various parts of the program in the correct form...

C Programming Language

C language developed at Bell lab by Dennis Ritchie on UNIX environment. UNIX was later rewritten in C. An earlier version of C is BCPL...

Recursive C program for Binary search

Below is an example Recursive C program to perform Binary – int binsearch(int low, int high, in a, X){ int mid; if(low > high){ return(-1);...

Bubble sort in C

Simple bubble sort in C – for (i=0; i<n-1; i++){ for(j=i+1; j<n; j++){ if(x[j] < x[i]){ temp = x[j]; x[j] = x[i]; x[i] = temp;...

File Operation in C

Below is a simple C program to perform file operation – include <stdlib.h> main() { FILE * file_source char * file_name = (char*) malloc (sizeof...