You are on page 1of 8

DATA STRUCTURES

The logical and mathematical model of a particular organization of data is called


data structure.

DS

NON PRIMITIVE
PRIMITIVE
PRIMITIVE

LINEAR NON
LINEAR

ARRAYS TREE

STRUCTURE GRAPH

LIST

STACKS

QUEUES

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.
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


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


R

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

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 50

B=0 40 B=-1 60

()

70
B=0

Graph:

A+B ::: INFIX

+AB ::: PREFIX

AB+ ::: POSTFIX

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”.

Each element is called “node of the tree”


ROOT
A

PREDEESSOR

RIGHT SUB TREE


LEFT SUB TREE B C
SIBBLINGS
S

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

You might also like