Professional Documents
Culture Documents
DS
NON PRIMITIVE
PRIMITIVE
PRIMITIVE
LINEAR NON
LINEAR
ARRAYS TREE
STRUCTURE GRAPH
LIST
STACKS
QUEUES
Array:
Stack:
Follows LIFO
Elements are removed from a stack (pop) in the reverse order of that in which
they were inserted into the stack (push).
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.
It is a collection of data elements called nodes, where each node is divided into
three parts
T1 T2
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
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 50
B=0 40 B=-1 60
()
70
B=0
Graph:
Precedence order:
1. Exponential
2. Multiplication
3. Divison
4. Addition
5. Substraction
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 2 nd
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 2 nd block & take the 2 nd 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
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”.
PREDEESSOR
D F
E
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. LEVEL
MAX.
A 0
1
1
2
B C
3
D E F G 2
4 I K M O
H J L N 3
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
B C
E F G