Data Structure Module 1 Notes For Calicut University Sem 3 2024
Data Structure Module 1 Notes For Calicut University Sem 3 2024
Data structure is the representation of the logical relationship existing between individual elements
of data.
In other words, a data structure is a way of organizing all data items that considers not only the
elements stored but also their relationship to each other.
Introduction
Data structure effects the design of both structural and functional aspect of a program.
i.e., algorithm is a set of instructions written to Carrie out certain tasks and the data structure is the
way of organizing the data with their logical relationship retained.
To develop a program of an algorithm, we should select an appropriate data structure for that
algorithm.
Data structures are normally divided into 2 broad categories: Primitive data structures and non-
primitive data structures.
There are basic data structures and they are directly operated up on by the machine instructions.
Integers, floating point numbers, character constants, string constants, pointers, etc. fall in this
category
The non primitive data structures emphasize on the structuring of a group of homogenies (same
type) or heterogenous data items.
List, stack, queue, tree, graph, are examples of non-primitive data structures.
The design of an efficient data structure must take operations to be performed on the data structure.
The most commonly used operation on data structures is broadly categorized into the following
types:
Create
Selection
Updating
Searching
Sorting
Merging
Destroy or delete
A primitive data structure is generally a basic structure that is usually built into the language, such as
indigen, or a float
A non-primitive data structure is built out of primitive data structures linked together in meaningful
ways.
Such as a linked list, binary search trees, AVL trees, graph, etc.
array
It means an array can contain 1 type of data only, either all integers, or float point, number of all
characters.
Where, int specifies the datatype or type or elements array stores. “array” is the name of array and
the number specified inside the square bracket is the number elements an array can store (the
length of an array).
The individual element of an array can be accessed by specifying the name of the array, followed by
index or subscript inside the square brackets.
The first element of an array has index 0 and the last element of the array have index 9. Represented
by array [0], array [9] respectively.
The number of elements that can be stored in an array (in the consecutive memory locations) is
given by (upper bond – lower bond) + 1
List
An element of list must contain 2 fields: 1 for storing data and other for storing the address of next
element.
Stack
Like arrays, but it has special feature that deletion and insertion of elements can be done only from
one end called the top of stack (TOS).
Due to this property, it is also called as last in first out (lifo) type of data structure.
Insertion of element into stack is called push and deletion of element from stack is called pop.
The stack can be implemented in 2 ways: using arrays (static implementation), using pointer
(dynamic implementation)
Queue
Queue are the first in first out (fifo) type of data structures.
In a queue new elements are added to the queue from one end called rear-end and the elements are
always removed from another end called the front-end
The queue can be implemented by 2 methods: using arrays (static implementation), using pointer
(dynamic implementation).
Trees
Tree is a non-Lenier type of data structure. In which, data items are arranged or stored in a sorted
sequence
In trees there is a special data item at the top of hierarchy call the root of the tree
The remaining data items are partitioned into number of mutually exclusive subject, each of which is
itself, a tree which is called the subtree
Graph
A graph is a mathematical non-Lenier data structure capable of representing many kind of physical
structure.
Definition
An edge connects a pair of vertices and many have wait such as length, cost and another measuring
instrument for recording to the graph.
Vertices on the graph are shown as point or circles and edges are drawn as arcs or line segments.
Types of graph
Directed graph
Undirected graph
Simple graph
Waited graph
Connected graph
Non-connected graph
Complexity of algorithm
To analyze an algorithm for calculating the amount of resources (time and storage) needed to
execute.
The complexity of an algorithm is a measure of time and or space required by the algorithm for an
input of a given size n
There are 2 types of complexity in which efficiency of an algorithm is measured: Space complexity
and time complexity
Space complexity
Space complexity is the amount of computer memory required during the program execution.
It depends on fixed part (input is of array, structure, etc.), variable part (input like linked list, stack,
queue, etc.)
Time complexity
Time complexity of an algorithm is the running time of the program as a function of input.
best case – minimum number of steps, minimum number of time, and minimum number of storage.
Verst case – maximum number of steps, maximum number of time, and maximum number of
storage.
Average case – optimum number of steps, optimum number of time, and optimum number of
storage.