data structure
data structure
Data Structure
2.Elementary item: Data items those can not be divided into sub items.
Ex:Age:17
Entity:An entity is something that has certain attributes or properties which assigned values.
Information:The information is also used for data with given attributes ,information means
meaningful data.
2.Searching:Finding location of a record with given key value or finding the location of all
records,which satisfy one or more conditions.
6.Merging;Combining the records in two different sorted files into a single sorted file.
Algorithm Notations
An alogorithm is a finite step-by step list of well-defined instruction for solving a particular
problem.the form for formal representation of an algorithm consists of two part
Generally three types of logic are used in algorithm that are as follow,
1)Sequence Logic
2)Selection Logic
3)Iteration Logic
Arrays
A linear array is a list of finite number n of homogeneous data elements . the elements of array are
referenced by index set consisting of n consecutive numbers.
Length=UB-LB+1
Here Array is linear array and address of first elements is denoted by base(Array) and called as base
address of Array.
Using base address computer calculates the address of any elements of Array by using formula.
LOC(Array[K])=Base(Array)+W(K-LB)
Let LA is a linear array with lower bound LB and upper bound UB.
LA
12 42 34 25
1 2 3 4
Steps:
1)Start
2)Initialize counter
Set K=LB
4)Visit element
5)Increment counter
K=K+1
6)Stop
Let LA is a linear array of size N,this algorithm will inset ITEM at the kth position of LA,where K<= N+1
Steps:
1)Start
2)Initialize counter
Set J=N
LA[J+1]=LA[J]
5)Decrement counter
J=J-1
6)Insert ITEM
LA[K}=ITEM
7)Reset N=N-1
8)Stop
1)Start
2)Set ITEM=LA[K]
3)Initialize counter
Set J=K
LA[J]=LA[J+1]
6)Increament counter
J=J+1
7)Reset N=N-1
8)Stop
Bubble Sorting
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent
elements if they are in the wrong order. This algorithm is not suitable for large data sets as its
average and worst-case time complexity are quite high.
We sort the array using multiple passes. After the first pass, the maximum element goes to
end (its correct position). Same way, after second pass, the second largest element goes to
second last position and so on.
In every pass, we process only those elements that have already not moved to correct
position. After k passes, the largest k elements must have been moved to the last k positions.
In a pass, we consider remaining elements and compare all adjacent and swap if larger
element is before a smaller element. If we keep doing this, we get the largest (among the
remaining elements) at its correct position.
Steps:
1)Start
5)Compare element
If (Data[PTR]>Data[PTR+1] then,
Set temp=Data[PTR]
Set Data[PTR]=Data[PTR+1]
Set Data[PTR+1]=Temp
6)Increment counter
PTR=PTR+1
8)Stop
Record
A record is collection of related data items. Each data item is termed as field. file is collection of
similar records. each data item may be a group item composed of sub item.
Ex
Linked List
It’s a linear collection of data elements called nodes .linear order is given by means of pointer.
Each node is divided into two parts,first part contains the information part of the elements and
second part contains the address of the next node in the list.
The left part represents the information part of node.the right part represents pointer field of
node.the arrow is drawn from this field to next node.pointer field of last node contain null
pointer.the address of first node in list called as start or name.we need only this address to trace the
linked list.
Tree
It is non linear data structure.it used to represents data containing hierarchical relationship between
elements.
Parent Node: The node which is an immediate predecessor of a node is called the parent
node of that node. {B} is the parent node of {D, E}.
Child Node: The node which is the immediate successor of a node is called the child node of
that node. Examples: {D, E} are the child nodes of {B}.
Root Node: The topmost node of a tree or the node which does not have any parent node is
called the root node. {A} is the root node of the tree. A non-empty tree must contain exactly
one root node and exactly one path from the root to all other nodes of the tree.
Leaf Node or External Node: The nodes which do not have any child nodes are called leaf
nodes. {I, J, K, F, G, H} are the leaf nodes of the tree.
Ancestor of a Node: Any predecessor nodes on the path of the root to that node are called
Ancestors of that node. {A,B} are the ancestor nodes of the node {E}
Sibling: Children of the same parent node are called siblings. {D,E} are called siblings.
Level of a node: The count of edges on the path from the root node to that node. The root
node has level 0.
Internal node: A node with at least one child is called Internal Node.
Neighbour of a Node: Parent or child nodes of that node are called neighbors of that node.
Binary Tree
2) T contains a distinguished node R,called root of T and the remaining node of T form an ordered
pair of disjoint binary tree T1 and T2
Representation binary tree in memory
1)Linked representation
2)sequential representation
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. This means that
the last element added to the stack is the first one to be removed. It can be visualized as a pile of
plates where you can only add or remove the top plate.
Operations on Stack:
Peek (or Top): Returns the top element of the stack without removing it.
Queues
Queue
A queue is a linear data structure that follows the First In, First Out (FIFO) principle. This means that
the first element added to the queue is the first one to be removed. It can be visualized as a line of
people waiting for a service, where the first person in line is the first to be served.
Operations on Queue:
Front (or Peek): Returns the front element of the queue without removing it.