CS-401
DATA STRUCTURE OF ALGORITHM
(Sir: Malik Shehzad)
Data:
Unprocessed (information). In data structure data is captured from different sources
organized for later use.
How can you organize data / manipulate it.
Organize it.
Sort it
Types of Data
Basic and abstract
Basic
o Numeric
o Integer
o Real Number
o Character
Abstract
o Developed from basic data types
o Used in place of basic data types to handle large amount of data
o It is for ease of use
o Array/ list/strings
Types of Abstract
o Linear
The type in which data is stored in sequence and is used in a sequence.
o Non-Linear
The type in which data is neither stored nor used in sequence.
Algorithm:
The process of solving a problem e.g.
1. Start
2. Take two no.
3. Add these no.
4. Show sum
5. End
Stack:
A type of linear data structure used to store data or delete data from one end. It has two
functions;
Push: It is used to enter data into the stack.
Pop: It is used to delete data from the stack.
Pointer:
It is used to store and address or represent a value at that address. A pointer used in stack is TOP.
Top = (Most recent value )
Top = -1 is empty.
Top = top (full) is full.
Basic Principle
The basic principle of stack is LIFO (last in first out).
Linked List
A type of linear data structure:
Singular Link list
Double Link list
Circle Link list
Singular Link List
In a single linked list, the address of the first node is always stored in a reference node known as
"front" (Sometimes it is also known as "head"). Always next part (reference part) of the last node
must be NULL.
Node
Data Address
The pointer used for link list is a variable which has the address of the starting node. It is name is
start. It is used to represent the status of a node.
If start = null than status of the node is empty
The address of the first node is given to the pointer while the address of the second node is given
to the first node and so on.
Double Link List
A Doubly Linked List is represented using the Linear Arrays in memory where each memory
address stores 3 parts: Data Value, Memory address of next Element and Memory Address of the
previous Element.
Previous Address
Data
Address Next
Circular Link List
The circular linked list is a linked list where all nodes are connected to form a circle. In a circular
linked list, the first node and the last node are connected to each other which forms a circle.
Basic functions of linked list
Insert first
Insert last
Insert specific
Additional functions circular linked list are:
Delete first
Delete last
Delete specific
Also in CLL only insert specific is used.
Structure
Structure is a collection of variables of different data types under a single name. It is similar to
a class in that, both holds a collection of data of different data types.
Queue
A linear data structure that is open from both ends to perform. (FIFO)
FIFO (Basic Principle)
Function:
o En-queue
o De-queue
Pointer used:
o Rear
o Front
“Like top to check the state of queue”.
To enter a value we start from tail.
To delete a value we start from head.
Types of Queue
Input restricted queue
Output restricted queue
Circular queue
Double ended
(Can only be implement through double linked list)
Priority queue
Basic Operations of Queue
En-queue to add items / values
De-queue to remove / delete
Peek or front which item is available at front.
Rear which item is available at rear.
Is full if value of “front and rear” is same queue is full.
Is empty if value of “front and rear” is same queue is empty.
Tree Data structure
It has non-linear behavior is a hierarchical structure used to represent and organized data in a
way that is easy to use and navigate.
Types of Trees
Binary tree
Ternary tree
Full/ Partial binary tree
Binary Search tree
AVL binary tree
B-Tree
Binary Tree
If a root node has only two leaves nodes it is a binary. It has different levels. Complexity of
binary tree = 2n
Ternary Tree
If a root has three branches / leaves node then it is called ternary tree.
Basic Operation of Tree
Create
Insert
Search
Traversal
o In-order
o Pre-order
o Post-order
Tree Traversal
Depth first
Breath first