18CSC162J DSA Unit1
18CSC162J DSA Unit1
Dr. K.Vijaya
Associate Professor
Department of CSE
SRMIST/KTR
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
5 Utilize algorithms to find shortest data search in graphs for real-time application
development
6 Utilize the different types of data structures and its operations for real-time
programming applications
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
3 Construct stack and queue data structures and evaluate its operations
4 Create tree data structures and evaluate its types and operations
5 Create graph data structure, evaluate its operations, implement algorithms to identify
shortest path
6 Construct the different data structures and evaluate their types and operations
SRM
INSTITUTE OF SCIENCE ANDTECHNOLOGY,
CHENNAI.
INTRODUCTION TO DATA
STRUCTURES
UN I T 1
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
TOPICS TO BE COVERED (THEORY)
Session Topics
1 Introduction to Data Structure
2 ADT and operations
3 Specifications of Algorithms, recursion and performance analysis
4 Style of programming, refining code and Complexity (Space and Time)
5 Mathematical notations and functions
6 Asymptotic notations – Big O, Omega and Theta
7 Data Structure : Types – Linear and Non Linear
8 1D and 2D Array using Pointers – Initialize and access
9 Structures and Array of Structures
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
Session Topics
1 Recursive functions
2 Towers of Hanoi
3 Array implementation using pointers - Insertion
4 Array implementation using pointers- Deletion
5 Structures using pointers
6 Array of structures using Pointers
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
ELAB SESSIONS
1. SEARCHING
2. SORTING
3. ARRAYS
4. LINKED LIST
5. STACK
6. QUEUE
7. TREE1
8. TREE2
9. GRAPH
10. HASHING
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
LEARNING RESOURCES
PROBLEM SOLVING
• Process
Creative Thinking (Generate)
• Defining the Problem Critical Thinking (Judge)
• Designing the Solution
• Implementing
• Testing
• Documenting and Maintaining
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
CREATIVE VS CRITICAL
PROPERTIES
• Maintainability Ease with which it could be modified – fix bugs, security holes, adapt to new environment
• Efficiency/Performance
System resources that are consumed: Processor time, Memory Space, Disks, Network bandwidth
SRM
The data structures deal with the study of how the data is
organized in the memory, how efficiently it can be
INSTITUTE
retrieved OF SCIENCE
and manipulated and theAND TECHNOLOGY,
possible ways in which
CHENNAI.
different data items are logically related”.
DEFINITIONS
Field TERMINOLOGIES
Name Register No Branch Batch
• Field (Attribute):
Name Register No Branch Batch
Anjali RA201106 CSE 2011
Record
• Record (Structure)
Name Register No Branch Batch
Student Anjali RA201106 CSE 2011
• Data set (Entity) Alamu RA201007 CE 2010
Student • Data base
Courses
(Entity
Registered
set) Malathi RA201009 CE 2010 Courses
Name Register No Branch Batch Register No Sem Course code Code Name
Anjali RA201106 CSE 2011 RA201007 5 CE501 CE501 Foundation Engg.
Alamu RA201007 CE 2010 RA201007 5 CE502 CE502 Reinforced concrete
Malathi RA201009 CE 2010 RA201009 5 CE501 CS501 DBMS
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
Data Structures
Basic type
Stack
Queue
ADT AND OPERATIONS
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
Data declaration packaged with the operations that are meaningful for the data type.
OPERATIONS
• Create • Insert
• Select • Delete
• Update • Search
• Destroy • Traversing
• Sorting
• Merging
SPECIFICATIONS OF
ALGORITHMS, RECURSION AND
PERFORMANCE ANALYSIS
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
ALGORITHM
Pictorial Small
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
SPECIFICATION - CRITERIA
RECURSION
RECURSION - RULES
• Base Case
• Making Progress
• Design Rule: Assume all recursive calls work
• Compound interest rule: Never duplicate work by solving the
same instance of a problem in separate recursive calls.
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
PERFORMANCE ANALYSIS
}
STYLE OF PROGRAMMING, REFINING
CODE AND COMPLEXITY
STYLE OF PROGRAMMING
STYLE OF PROGRAMMING
BEST PRACTICES
CODING STANDARDS
SELF LEARNING
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
REFINING CODE
Execute Rapidly
Fewer I/O
SRM
CODEOFREFINEMENT
INSTITUTE SCIENCE AND TECHNOLOGY,
CHENNAI.
• Constant Folding:
• Compile time evaluation of constant expression
H/w performance improvement
• Scalars and Arrays that are constant need to be specified as const
• Conversion of explicit data flow Parameter passing instead of global declaration
COMPLEXITY
• M: Algorithm
• N: Size of Data Count of number of key operations
• Measures of efficiency: Time and Space
• Complexity : f(n) Memory needed by the algorithm
Common (10)
Natural (e ) ln x
Binary (2) log x
ASYMPTOTIC NOTATIONS – BIG O,
OMEGA AND THETA
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
BIG O NOTATION
Upper bound
OMEGA NOTATION
Lower bound
Example: f(n)=5n+1
f(n)= !(1)
f(n)= !(n)
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
THETA NOTATION
Lower and Upper bound
"1 $ % ≤ |( % | ≤ "2 $ %
for all n ≥ n0
( % =+ $ % and ( % =, $ %
-./0123: ( % = 18% + 9
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
ASYMPTOTIC NOTATIONS
Describe the behaviour of a function f(n) when n is very large.
f(n) = O(g(n))
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
ASYMPTOTIC NOTATIONS
If n≥ 1 then n2≤n3
ASYMPTOTIC NOTATIONS
• f(n)=an2 + bn + c
n0=?
c1=?
c2=?
c1=a/4
c2=7a/4
% (
n0= 2*max( , )
& &
DATA STRUCTURE : TYPES – LINEAR
AND NON LINEAR
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
LINEAR
Array (List)
Stack
Linked List
Queue
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
NON LINEAR
Tree
Graph
General Directed
Binary
Undirected
1D AND 2D ARRAY USING POINTERS –
INITIALIZE AND ACCESS
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
HUNGARIAN NOTATION
POINTER ARRAYS
POINTER ARRAYS
POINTER ARRAYS
POINTER ARRAYS
DECLARATION
DECLARATION
INITIALIZATION
struct Student
{
int regNo;
char name[25];
int english, science, maths;
};
struct Student stud;
scanf(“%d %s %d %d %d”,&stud.regNo, stud.name, &stud.english,&stud.science, &stud.maths);
printf("Register number = %d\n",stud.Regno); //Accessing member Regno
printf("Name %s",stud.name); //Accessing member name
stud.english= stud.english +10; //Updating member english
stud.science++; //Updating member science
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
NESTED STRUCTURE
ARRAY OF STRUCTURES
struct Student
{
int regNo;
char name[25];
int english, science, maths;
};
struct Student stud[10];
scanf(“%d%s%d%d%d”,&stud[1].regNo,stud[1].name,&stud[1].english,&stud[1].science,&stud[1].maths);
printf("Register number = %d\n",stud[1].Regno); //Accessing member Regno
printf("Name %s",stud[1].name); //Accessing member name
stud.[1]english= stud[0].english +10; //Updating member english
stud[1].science++; //Updating member science
ARRAY OF STRUCTURES SRM – DYNAMIC
INSTITUTEALLOCATION
OF SCIENCE AND TECHNOLOGY,
struct Student CHENNAI.
{
int regNo;
char name[25];
int english, science, maths;
};
struct Student *stud;
scanf(“%d”, &n);
for(i=0;i<n;i++)
scanf(“%d %s %d %d %d”,&stud[i]->regNo, stud[i]->name, &stud[i]->english, &stud[i]->science,
&stud[i]->maths);
printf(“Register number Name English Science Maths\n”);
for(i=0; i<n; i++)
{
printf("%d\t%s\t%d\t%d\t%d\n", stud[i]->regNo, stud[i]->name, &stud[i]->english, &stud[i]->science,
&stud[i]->maths);
}
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
STRUCTURE WITH SELF REFERENCE
POINTER
struct node { stud2.regNo=100660;
int regNo; stud2.name=“Pushpi”;
char name[20]; stud2.link=NULL;
struct node* link; stud1.link=&stud2;
};
struct node stud1, stud2;
1000 102660 Nivi NULL
stud1.regNo=102660;
stud1.name=“Nivi”;
stud1.link=NULL; 7000 100660 Pushpi NULL
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
STRUCTURE WITH SELF REFERENCE
POINTER
struct node { stud2.regNo=100660;
int regNo; stud2.name=“Pushpi”;
char name[20]; stud2.link=NULL;
struct node* link; stud1.link=&stud2;
};
struct node stud1, stud2;
1000 102660 Nivi 7000
stud1.regNo=102660;
stud1.name=“Nivi”;
stud1.link=NULL; 7000 100660 Pushpi NULL
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
STRUCTURE WITH SELF REFERENCE
POINTER
struct node { stud2.regNo=100660;
int regNo; stud2.name=“Pushpi”;
char name[20]; stud2.link=NULL;
struct node* link; stud1.link=&stud2;
};
struct node stud1, stud2;
1000 102660 Nivi 7000
stud1.regNo=102660;
stud1.name=“Nivi”;
stud1.link=NULL; 7000 100660 Pushpi NULL
SRM
INSTITUTE OF SCIENCE AND TECHNOLOGY,
CHENNAI.
https://www.youtube.com/watch?v=Q_1M2JaijjQ
https://www.youtube.com/watch?v=dwApFR-MpLk