CSC102-2 : DATA STRUCTURES (CIA Only)
Dr Sreeja C S
MISSION VISION CORE VALUES
CHRIST is a nurturing ground for an individual’s holistic development to Excellence and Service Faith in God | Moral Uprightness
make effective contribution to the society in a dynamic environment Love of Fellow Beings
Social Responsibility | Pursuit of Excellence
CHRIST
Deemed to be University
Excellence and Service
CHRIST
Deemed to be University
Excellence and Service
MISSION VISION CORE VALUES
CHRIST is a nurturing ground for an individual’s holistic development to Excellence and Service Faith in God | Moral Uprightness
make effective contribution to the society in a dynamic environment Love of Fellow Beings
Social Responsibility | Pursuit of Excellence
CHRIST
Deemed to be University
Unit-1:ARRAYS
Introduction to data structures Definition and Concept of
Data Structures - Abstract Data Type - Arrays :
Definition , terminology, one dimensional array, array
Operations - Searching : Linear Search - Iterative Binary
Search – Recursions - Recursive Binary Search.
Excellence and Service
CHRIST
Deemed to be University
What is Data?
Data is a collection of raw facts, figures, observations,
statistics or any discrete value.
Excellence and Service
CHRIST
Deemed to be University
What is information?
Excellence and Service
CHRIST
Deemed to be University
Data Structure
In computer science "Data Structure" is the way of data
arrangement in memory and applying some operations to
perform actions on the data.
A data structure is an effective technique to arrange data in a
computer. The goal is to simplify various chores regarding space
and time requirements.
Excellence and Service
CHRIST
Deemed to be University
Why are Data Structures Important?
1. It helps in improving data storing and organizing.
2. It aids in faster retrieval and manipulation of data.
3. It also facilitates the designing of algorithms for solving
complex problems.
4. It helps in data updating and maintaining tasks much more
straightforward.
5. It is the best solution for understanding the relationship
between data and the other elements.
Excellence and Service
CHRIST
Deemed to be University
Data structure
A data structure D is a triplet, that is, D = (D, F, A) where D is a set of
data object, F is a set of functions and A is a set of rules to implement the
functions.
Excellence and Service
CHRIST
Deemed to be University
Excellence and Service
CHRIST
Deemed to be University
Types of Data Structures
Primitive Data Structures
Primitive data types correspond to primitive data structures. The
primitive data structures that can store a single value are int, char,
float, double, and pointer.
Excellence and Service
CHRIST
Deemed to be University
Non- Primitive data Structures:
● Non-primitive data structures are those data structures which are
created using primitive data structures.
● Examples of non-primitive data structures is the processing of
complex numbers, linked lists, stacks, trees, and graphs Based on the
structure and arrangement of data, non-primitive data structures is
further classified into
1. Linear Data Structure
2. Non-linear Data Structure
Excellence and Service
CHRIST
Deemed to be University
Linear data structure:
• Data structure in which data elements are arranged sequentially or
linearly, where each element is attached to its previous and next
adjacent elements, is called a linear data structure.
Examples of linear data structures are array, stack, queue, linked list,
etc.
Excellence and Service
CHRIST
Deemed to be University
Linear data structure: Two Types
• Static data structure: Static data structure has a fixed memory size. It is easier to
access the elements in a static data structure.
An example of this data structure is an array.
• Dynamic data structure: In dynamic data structure, the size is not fixed. It can be
randomly updated during the runtime which may be considered efficient
concerning the memory (space) complexity of the code.
Examples of this data structure are queue, stack, etc.
Excellence and Service
CHRIST
Deemed to be University
Non-linear Data Structure:
● A data structure is said to be non-linear if the data are not arranged in
sequence or a linear.
● The insertion and deletion of data is not possible in linear fashion.
● This structure is mainly used to represent data containing a
hierarchical relationship between elements.
● Trees and graphs are the examples of non-linear data structure.
Excellence and Service
CHRIST
Deemed to be University
Excellence and Service
CHRIST
Deemed to be University
Classification of Data Structure
Excellence and Service
CHRIST
Deemed to be University
Linear Data structures
Excellence and Service
CHRIST
Deemed to be University
Non-Linear Data Structures
This data structure is the opposite of the linear one.
Here the data or the elements are arranged in many-
one, one-many, or many-many dimensions. It is not
single-dimension data like its counterpart. Some
examples of non-linear data structures are tables, trees,
and graphs.
Excellence and Service
CHRIST
Deemed to be University
Non Linear Data Structures
Excellence and Service
CHRIST
Deemed to be University
IMPLEMENTATION OF DATA STRUCTURES
● Phase1: Storage representation
● Phase2: Algorithmic notation of various operations of the classic data structure
Excellence and Service
CHRIST
Deemed to be University
Abstract Data Type/User Defined Data Type
● Data types specify the type of data structure.
● We can classify the data type into primitive data types like
integer, float, double, etc., or
● abstract data types like list, stack, queue, etc
Excellence and Service
CHRIST
Deemed to be University
Model for an Abstract Data Type
Excellence and Service
CHRIST
Deemed to be University
Arrays in Data Structure
● Arrays: The simplest type of data structure is a linear (or one
dimensional) array.
● It provides a systematic way of organizing and accessing a collection
of elements, where each element is identified by its index or position
within the array.
● Arrays work on an index system starting from 0 to (n-1), where n is
the size of the array.
Excellence and Service
CHRIST
Deemed to be University
Excellence and Service
CHRIST
Deemed to be University
Keywords:
● Size-length/dimension
● Index-Ai A[i]
● Type
● Base- is the address of the memory location
Excellence and Service
CHRIST
Deemed to be University
Range of Indices
● Lower Bound (L)
● Upper Bound (U)
Excellence and Service
CHRIST
Deemed to be University
What Are the Types of Arrays?
● One-Dimensional Arrays:
● Multi-Dimensional Arrays:
Excellence and Service
CHRIST
Deemed to be University
What is One dimensional Array in Data Structure?
Excellence and Service
CHRIST
Deemed to be University
How Do You Declare an Array?
● 1D Arrays: int arr[n];
● 2D Arrays: int arr[m][n];
Excellence and Service
CHRIST
Deemed to be University
How Do You Initialize an Array?
Different Methods:
1)int a[6] = {2, 3, 5, 7, 11, 13};
2)int arr[]= {2, 3, 5, 7, 11};
Excellence and Service
CHRIST
Deemed to be University
Method 3
int n;
scanf(“%d”,&n);
int arr[n];
for(int i=0;i<5;i++)
{
scanf(“%d”,&arr[i]);
}
Excellence and Service
CHRIST
Deemed to be University
Method 4:
int arr[5];
arr[0]=1;
arr[1]=2;
arr[2]=3;
arr[3]=4;
arr[4]=5;
Excellence and Service
CHRIST
Deemed to be University
How Can You Access Elements of Arrays in Data Structures?
Excellence and Service
CHRIST
Deemed to be University
The index at which you stored them
Excellence and Service
CHRIST
Deemed to be University
Code:
Excellence and Service
CHRIST
Deemed to be University
What Operations Can You Perform on an Array?
• Traversal code
• Insertion
• Deletion code
• Searching
• Sorting
Excellence and Service
CHRIST
Deemed to be University
Activity
Excellence and Service
CHRIST
Deemed to be University
Searching for an Element
Excellence and Service