The document discusses different data structures and their properties. It defines data structures as the logical organization of data and describes several common primitive and non-primitive data structures including arrays, stacks, queues, linked lists, trees, graphs, and binary search trees. It provides examples of operations that can be performed on different data structures like insertion, deletion, searching, and sorting.
1. DATA STRUCTURES
The logical and mathematical model of a particular organization of data is called
data structure.
PRIMITIVE
Array:
Array is an ordered collection of items. It contains same data type.
Array is a static object i.e. no of item is fixed and is assigned by the
declaration of the array
Stack:
Stack is a ordered collection of items
It is a list of dynamic objects/ elements in which an element may be inserted
or deleted only at one end called top of the stack.
DS
PRIMITIVE NON PRIMITIVE
LINEAR NON
LINEAR
ARRAYS
STRUCTURE
LIST
STACKS
QUEUES
TREE
GRAPH
2. Elements are removed from a stack in the reverse order of that in which they are
inserted in the stack.
“Push”- to insert into the stack
“pop”- to delete an element from a stack.
Stacks are used to indicate the order of processing of data when certain steps of
the processing must be postponed until other conditions are fulfilled.
Follows LIFO
Elements are removed from a stack (pop) in the reverse order of that in which
they were inserted into the stack (push).
It may contain different data types
Integer to indicate the current stack top within the array.
Operations: push, pop.
Queue:
An ordered collection of items from which items may be deleted at one end
(front end) & items inserted at the other end (rear end).
It follows FIFO.
Priority Queue: priority queue is a data structure in which the intrinsic ordering
of the elements (numeric or alphabetic)
Linked list:
A linked list is a linear collection of data elements, called nodes, where the
linear order is given by pointers. Each node has two parts 1st part contain the
information of the element 2nd part contains the address of the next node in
the list.
double linked list:
It is a collection of data elements called nodes, where each node is divided into
three parts
i) An info field that contains the information stored in the node
3. ii) Left field that contain pointer to node on left side
iii) Right field that contain pointer to node on right side
Tree: It is used to represent data which has a hierarical relationship. It can
have any no. of children per node.
Binary tree: it can have max. 2 children per node.
LEFT SUCCESSOR RIGHT SUCCESSOR
A spanning tree is a tree associated with a network. All the nodes of the graph
appear on the tree once. A minimum spanning tree is a spanning tree organized
so that the total edge weight between nodes is minimized
Binary search tree:
The values in all nodes in the right subtree of a node are greater than the
node values.
AVL tree: An empty binary tree, is an AVL tree, a non empty binary T tree is a
AVL tree. If given, TL & TR to be the left & right subtrees of T & H(TL) &
H(TR) to be the height of the subtrees TL & TR respectively. TL & TR are AVL
trees &
| H(TL)- H(TR)| <=1 where { H(TL)- H(TR } is known as the balance factor. The
balance factor of a node can be either 0,1, or -1
B=-1
B=0 B=-1
50
40 60
()
70
R
T1 T2
5. Operations done:
1. Insertion
2. Deletion
3. Display/traversing
4. Searching
5. Sorting
Bubble sort:
Compare 2 adjacent elements, adjust by swapping & compare next 2 elements.
Insertion sort:
1st
element will be considered as a total array & the rest would be considered as a 2nd
array & the adjustment is made by swapping.
2nd
step: take 1st
2 elements as the 1st
array & rest as 2nd
array.
Continue till the 2nd
array becomes null.
Selection sort:
Take the smallest element & place it in the 1st
position.
Then start from the 2nd
block & take the 2nd
smallest element
In each pass we store 2 variables.
Binary search:
Last index will be in high. 1st
index will be in low.
Middle index will be stored in mid=(low + high)/2 for low<=high
Merge sort:
Last index will be in high. 1st
index will be in low.
Middle index will be stored in mid=(low + high)/2 for low<=high
Quick sort:
Mid= a[(high +low)/2] =p0
We will start checking from the left side & we will compare with p0 element.
Towers of Hanoi
6. A B C
Moving the blocks, from peg A to peg C, the condition is that only one block can be
moved at a time.
TREE:
It is used in networking.
Binary tree:
A set of elements that is either empty or is portioned into 3 disjoint subset.
The 1st
subset contains a single element called “root of the tree”.
Each element is called “node of the tree”
ROOT
LEFT SUB TREE
A
B C
RIGHT SUB TREE
D F
PREDEESSOR
SIBBLINGS
S
E
7. D,E,F – LEAVE NODE, because they don’t have successor.
Different type of binary tree:
1. Strictly binary tree:
A non leave node has non empty left & right sub tree.
A node can contain max. 2 child.
2. Complete binary tree:
Each node will contain maximum no. of child.
A
B C
D E F G
H I J K L
M N O
MAX.
1
2
3
4
LEVEL
0
1
2
3
8. 3. Almost binary tree:
All nodes are at its max. level except possibly the last level & all nodes at the last level
appear as far left as possible
A
B C
E F G