Data
Data
In simple language, Data Structures are structures programmed to store ordered data, so that various
operations can be performed on it easily. It represents the knowledge of data to be organized in
memory. It should be designed and implemented in such a way that it reduces the complexity and
increases the efficiency.
The data structures can also be classified on the basis of the following characteristics:
Characterstic Description
In Linear data structures,the data items are arranged in a linear sequence.
Linear
Example: Array
In Non-Linear data structures,the data items are not in sequence. Example:
Non-Linear
Tree, Graph
In homogeneous data structures,all the elements are of same type. Example:
Homogeneous
Array
Non- In Non-Homogeneous data structure, the elements may or may not be of the
Homogeneous same type. Example: Structures
Static data structures are those whose sizes and structures associated memory
Static
locations are fixed, at compile time. Example: Array
Dynamic structures are those which expands or shrinks depending upon the
Dynamic program need and its execution. Also, their associated memory locations
changes. Example: Linked List created using pointers
What is an Algorithm ?
An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain
predefined task. Algorithm is not the complete code or program, it is just the core logic(solution)
of a problem, which can be expressed either as an informal high level description as pseudocode
or using a flowchart.
An algorithm is said to be efficient and fast, if it takes less time to execute and consumes less
memory space. The performance of an algorithm is measured on the basis of following
properties :
1. Time Complexity
2. Space Complexity
Sorting is nothing but arranging the data in ascending or descending order. The term sorting came into
picture, as humans realised the importance of searching quickly.Sorting arranges data in a sequence
which makes searching easier.
There are many different techniques available for sorting, differentiated by their efficiency and
space requirements. Following are some sorting techniques which we will be covering in next
few tutorials.
1. Bubble Sort
2. Insertion Sort
3. Selection Sort
4. Quick Sort
5. Merge Sort
6. Heap Sort
Linear Search
Linear search is a very basic and simple search algorithm. In Linear search, we search an element
or value in a given array by traversing the array from the starting, till the desired element or
value is found.
It compares the element to be searched with all the elements present in the array and when the
element is matched successfully, it returns the index of the element in the array, else it return -1.
Linear Search is applied on unsorted or unordered lists, when there are fewer elements in a list.
Arrays
An array is a collection of similar data elements. These data elements have the same data type.
The elements of the array are stored in consecutive memory locations and are referenced by an
index (also known as the subscript).
Arrays are generally used when we want to store large amount of similar type of data. But they
have the following limitations:
Σ Arrays are of fixed size.
Σ Data elements are stored in contiguous memory locations which may not be always available.
Σ Insertion and deletion of elements can be problematic because of shifting of elements from
their positions.
A linked list
does not store its elements in consecutive memory locations and the user can add any number
of elements to it. However, unlike an array, a linked list does not allow random access of data.
Elements in a linked list can be accessed only in a sequential manner.
A linked list, in simple terms, is a linear collection of data elements. These data elements are
called nodes. Linked list is a data structure which in turn can be used to implement other data
. structures. Thus, it acts as a building block to implement data structures such as stacks, queues,
and their variations.
Since
in a linked list, every node contains a pointer to another node which is of the same type, it is also
called a self-referential data type.
let us briefly discuss the basic concept behind it. The computer maintains a list of
all free memory cells. This list of available space is called the free pool
We have seen that every linked list has a pointer variable START which stores the address of the
first node of the list. Likewise, for the free pool (which is a linked list of all free memory cells),
we have a pointer variable AVAIL which stores the address of the first free space.
their address to the free pool, so that these cells can be reused by other programs. This process
is called garbage collection.
In a circular linked list, the last node contains a pointer to the first node of the list. We can have
a circular singly linked list as well as a circular doubly linked list. While traversing a circular
linked list, we can begin at any node and traverse the list in any direction, forward or backward,
until we reach the same node where we started. Thus, a circular linked list has no beginning and
no ending. Figure 6.26 shows a circular linked list.
doubly linked list or a two-way linked list is a more complex type of linked list which contains
a pointer to the next as well as the previous node in the sequence. Therefore, it consists of three
parts—data, a pointer to the next node, and a pointer to the previous node
Unlike C++ and Java, C doesn’t support generics. How to create a linked list in C that can be used for any
data type? In C, we can use void pointer and function pointer to implement the same functionality. The
great thing about void pointer is it can be used to point to any data type. Also, size of all types of
pointers is always is same, so we can always allocate a linked list node. Function pointer is needed
process actual content stored at address pointed by void pointer.
stack is a linear data structure which uses the same principle, i.e., the elements in a stack are
added and removed only from one end, which is called the
TOP. Hence, a stack is called a LIFO (Last-In-First-Out) data
structure, as the element that was inserted last is the first one to
be taken out.
Reversing a list
Σ Parentheses checker
Σ Conversion of an infix expression into a postfix expression
Σ Evaluation of a postfix expression
Σ Conversion of an infix expression into a prefix expression
Σ Evaluation of a prefix expression
Σ Recursion
Σ Tower of Hanoi
A deque (pronounced as ‘deck’ or ‘dequeue’) is a list in which the elements can be inserted or
deleted at either end. It is also known as a head-tail linked list because elements can be added to
or removed from either the front (head) or the back (tail) end.
However, no element can be added and deleted from the middle. In the computer’s memory, a
deque is implemented using either a circular array or a circular doubly linked list. In a deque, two
pointers are maintained, LEFT and RIGHT, which point to either end of the deque.