Data Structures & Algorithms in C
Data Structures & Algorithms in C
Debapriya Mukherjee
What is Data Structure?
A data structure is a particular way of organising data in a computer so that it can be used effectively. The idea is
to reduce the space and time complexities of different tasks.
The choice of a good data structure makes it possible to perform a variety of critical operations effectively. An
efficient data structure also uses minimum memory space and execution time to process the structure. A data
structure is not only used for organising the data. It is also used for processing, retrieving, and storing data. There
are different basic and advanced types of data structures that are used in almost every program or software system
that has been developed. So we must have good knowledge of data structures.
Stack Operations:
push(): When this operation is performed, an
element is inserted into the stack.
pop(): When this operation is performed, an
element is removed from the top of the stack and
is returned.
top(): This operation will return the last inserted
element that is at the top without removing it.
size(): This operation will return the size of the
stack i.e. the total number of elements present in
the stack.
isEmpty(): This operation indicates whether the
stack is empty or not.
4. Queue:
Like Stack, Queue is a linear structure which follows a particular order in which
the operations are performed. The order is First In First Out (FIFO). In the queue,
items are inserted at one end and deleted from the other end. A good example of
the queue is any queue of consumers for a resource where the consumer that
came first is served first. The difference between stacks and queues is in
removing. In a stack we remove the item the most recently added; in a queue, we
remove the item the least recently added.
Queue Operations:
Enqueue(): Adds (or stores) an element to the end of
the queue..
Dequeue(): Removal of elements from the queue.
Peek() or front(): Acquires the data element available
at the front node of the queue without deleting it.
rear(): This operation returns the element at the rear
end without removing it.
isFull(): Validates if the queue is full.
isNull(): Checks if the queue is empty.
5. Binary Tree:
Unlike Arrays, Linked Lists, Stack and queues, which are linear data structures, trees are hierarchical data
structures. A binary tree is a tree data structure in which each node has at most two children, which are
referred to as the left child and the right child. It is implemented mainly using Links.
A Binary Tree is represented by a pointer to the topmost node in the tree. If the tree is empty, then the
value of root is NULL.
return 0;
}