SlideShare a Scribd company logo
1
Data Structures and Applications (21CS32)
2
Syllabus
Module 1: Introduction to Data structures, Arrays, Structures
Module 2: Stacks and Queues
Module 3: Linked Lists
Module 4: Trees
Module 5: Graphs and Hasing
3
Course Objectives
• Explain the fundamentals of data structures and their applications essential
for implementing solutions to problems.
• Illustrate linear representation of data structures: Stack, Queues, Lists,
Trees and Graphs.
• Design and Develop Solutions to problems using Arrays, Structures, Stack,
Queues, Linked Lists.
• Explore usage of Trees and Graph for application development.
• Apply the Hashing techniques in mapping key value pairs.
4
Course Outcomes
• Understand fundamentals of data structures and their applications
essential for programming/problem solving
• Apply Linear Data Structures such as Stack, Queues and Recursion in
solving problems.
• Apply Linear Data Structures such as Linked Lists in solving problems.
• Apply Non-Linear Data Structures such as Trees to model and solve the
real-world problem.
• Apply Non-Linear Data Structures such as Graphs model and solve the
real-world problem and Make use of Hashing techniques and resolve
collisions during mapping of key value pairs.
Module 1
Introduction to Data structures, Arrays,
Structures
5
6
Introduction: Data Structures, Classifications (Primitive & Non-Primitive), Data
structure operations (Traversing, inserting, deleting, searching, and sorting).
Review of Arrays
Structures: Array of structures, Self-Referential Structures.
Dynamic Memory Allocation Functions, Representation of Linear Arrays in
Memory, dynamically allocated arrays and Multidimensional Arrays.
Demonstration of representation of Polynomials and Sparse Matrices with arrays.
Module 1
1.1
Introduction
7
8
• Data structure is 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.
• Data structure affects the design of both structural & functional aspects of
a program.
Program=Algorithm + Data Structure
Introduction
9
• Data structure is 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.
• Data structure affects the design of both structural & functional aspects of
a program.
Program=Algorithm + Data Structure
Introduction
10
• Data structures includes:
 Defining operations that Performed can be on data.
 Representing data in the memory.
 Determining amount of memory required to store and amount of time
needed to process data.
Introduction
11
• The computers are electronic data Processing machines. In order to we
need to know
 How to represent data in computer?
 How to access them?
 What are steps to be performed to get the needed output.
Need of Data Structures
12
Classification of Data Structures
13
1. Traversing: To access each data item exactly once so that it can be
processed.
2. Searching: To find out the location of the data item if it exists in the
given collection
3. Inserting: To add a new data item in the given collection of data items.
4. Deleting: To delete an existing data item from the given collection of data
items.
5. Sorting: To arrange the data items in some order i.e. in ascending or
descending order
6. Merging: To combine the data items of two sorted files into single file in
Data Structure Operations
1.2
Review of Arrays
14
15
• Array is a data structure that can store a fixed-size sequential collection of
elements of the same type.
• An array holds several values of the same kind.
• Accessing the elements in an array is very fast. It may not be possible to
add more values than defined at the start, without copying all values into a
new array.
• An array is stored so that the position of each element can be computed
from its index.
Review of Arrays
16
#include <stdio.h>
int main ()
{
int arr[10]; /* n is an array of 10 integers */
int i,j;
/* initialize elements of array n to 0 */
for(i=0;i<10;i++)
arr[i] =i+100; /* set element at location i to i + 100 */
/* output each array element's value */
for (j=0;j<10;j++)
printf("Element[%d] = %dn", j, arr[j] );
}
Declaration assignment, and accessing arrays
17
#include <stdio.h>
int main() {
int arr[10], pos, value, i, n;
printf("Enter number of elements in array: ");
scanf("%d", &n);
printf("Enter %d elements: ", n);
for(i=0;i<n;i++)
scanf("%d", &arr[i]);
printf("Enter the location where you wish to insert an element: ");
scanf("%d",&pos);
printf("Enter the value to insert: ");
scanf("%d",&value);
Declaration assignment, and accessing arrays
18
for (i=n-1;i>=pos-1;i--)
arr[i+1] = arr[i];
arr[pos-1] = value;
printf("Resultant array : ");
for (i=0;i<=n;i++)
printf("%dt", arr[i]);
}
Declaration assignment, and accessing arrays
19
#include <stdio.h>
int main()
{
int arr[10], pos, i, n;
printf("Enter number of elements in array: ");
scanf("%d",&n);
printf("Enter %d elements: ", n);
for(i=0;i<n;i++)
scanf("%d", &arr[i]);
printf("Enter the location where you wish to delete an element: ");
scanf("%d", &pos);
To delete an element in the middle of an array
20
if (pos>= n+1)
printf("Deletion not possible.n");
else
{
for (i=pos-1;i<n-1;i++)
arr[i] = arr[i+1];
}
printf("Resultant array: ");
for (i=0;i<n-1;i++)
printf("%dt", arr[i]);
return 0;
}
To delete an element in the middle of an array
21
#include <stdio.h>
int main()
{
int arr[10], search, i, n;
printf("Enter the number of elements in array: ");
scanf("%d",&n);
printf("Enter %d integer(s): ", n);
for(i=0;i<n;i++)
scanf("%d", &arr[i]);
printf("Enter a number to search: ");
scanf("%d",&search);
Search an element using Linear Search (Sequential Search)
22
for(i=0;i<n;i++)
{
if (arr[i] == search) /* If required element is found */
{
printf("%d is present at location %d.n", search, i+1);
break;
}
}
if(i==n)
printf("%d isn't present in the array.n", search);
return 0;
}
Search an element using Linear Search (Sequential Search)
23
• Binary Search is a searching algorithm used in a sorted array by repeatedly dividing the
search interval in half.
• Binary search is used to find the position of a key in a sorted array.
• The following describes the binary search algorithm:
 We compare the key with the value in the middle of the array.
 If the key match found, we return its position, which is the index of the middle element
of the array.
 If the key is less than the value of the middle element of the array, we repeat the
above step on the sub-array on the left. If the key is greater than the value of the
middle element of the array, we repeat the above step on the sub-array on the right.
 If the sub-array to be searched has zero item, it means the key cannot be found.
Search an element using Binary Search
24
#include <stdio.h>
int main()
{
int i, low, high, mid, n, key, arr[10];
printf("Enter number of elements: ");
scanf("%d",&n);
printf("Enter %d integers in ascending order: ", n);
for(i = 0; i < n; i++)
scanf("%d",&arr[i]);
printf("Enter Search Key: ");
scanf("%d", &key);
low = 0;
high = n - 1;
Search an element using Binary Search
25
while (low <= high) {
mid = (low+high)/2;
if(arr[mid] == key) {
printf("%d found at location %dn", key, mid+1);
break;
}
else if(arr[mid] < key)
low = mid + 1;
else
high = mid - 1;
}
if(low > high)
printf("%d Not found! in the Array", key); }
Search an element using Binary Search
26
• First Iteration (Compare and Swap)
 Starting from the first index, compare the first and the second elements.
 If the first element is greater than the second element, they are swapped.
 Now, compare the second and the third elements. Swap them if they are not in order.
 The above process goes on until the last element.
To sort an element using Bubble Sort
• Remaining Iteration
 The same process goes on for the remaining iterations.
 After each iteration, the largest element among the unsorted elements is placed at the
end.
• In each iteration, the comparison takes place up to the last unsorted element.
• The array is sorted when all the unsorted elements are placed at their correct positions.
27
#include <stdio.h>
int main()
{
int i, j, n, arr[10];
printf("Enter number of elements: ");
scanf("%d",&n);
printf("Enter %d integers : ", n);
for(i = 0; i < n; i++)
scanf("%d",&arr[i]);
printf("Array Elements before Sorting : ");
for(i=0;i<n;i++)
printf("%dt",arr[i]);
To sort an element using Bubble Sort
28
for(i=0;i<n-1;i++) {
for (j=0;j<n-i-1;j++) {
if (arr[j] > arr[j+1]){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
printf("nArray Elements After Sorting : ");
for(i=0;i<n;i++)
printf("%dt",arr[i]);
}
To sort an element using Bubble Sort
29
for(i=0;i<n-1;i++) {
for (j=0;j<n-i-1;j++) {
if (arr[j] > arr[j+1]){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
printf("nArray Elements After Sorting : ");
for(i=0;i<n;i++)
printf("%dt",arr[i]);
}
To sort an element using Bubble Sort

More Related Content

Similar to 21CS32 DS Module 1 PPT.pptx

CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
saneshgamerz
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
infanciaj
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
montazur420
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
Prof. Dr. K. Adisesha
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
mexiuro901
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
swathirajstar
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
JohnStuart83
 
Unit iv(dsc++)
Unit iv(dsc++)Unit iv(dsc++)
Unit iv(dsc++)
Durga Devi
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
DwijBaxi
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
Abdul salam
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 
PPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structuresPPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structures
midtushar
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
researchgrad82
 
PPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting TechniquesPPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting Techniques
Vaibhav Parjane
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
maamir farooq
 
UNIT IV -Data Structures.pdf
UNIT IV -Data Structures.pdfUNIT IV -Data Structures.pdf
UNIT IV -Data Structures.pdf
KPRevathiAsstprofITD
 

Similar to 21CS32 DS Module 1 PPT.pptx (20)

CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
 
9 Arrays
9 Arrays9 Arrays
9 Arrays
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Unit iv(dsc++)
Unit iv(dsc++)Unit iv(dsc++)
Unit iv(dsc++)
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
PPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structuresPPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structures
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
PPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting TechniquesPPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting Techniques
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
UNIT IV -Data Structures.pdf
UNIT IV -Data Structures.pdfUNIT IV -Data Structures.pdf
UNIT IV -Data Structures.pdf
 

Recently uploaded

AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 

21CS32 DS Module 1 PPT.pptx

  • 1. 1 Data Structures and Applications (21CS32)
  • 2. 2 Syllabus Module 1: Introduction to Data structures, Arrays, Structures Module 2: Stacks and Queues Module 3: Linked Lists Module 4: Trees Module 5: Graphs and Hasing
  • 3. 3 Course Objectives • Explain the fundamentals of data structures and their applications essential for implementing solutions to problems. • Illustrate linear representation of data structures: Stack, Queues, Lists, Trees and Graphs. • Design and Develop Solutions to problems using Arrays, Structures, Stack, Queues, Linked Lists. • Explore usage of Trees and Graph for application development. • Apply the Hashing techniques in mapping key value pairs.
  • 4. 4 Course Outcomes • Understand fundamentals of data structures and their applications essential for programming/problem solving • Apply Linear Data Structures such as Stack, Queues and Recursion in solving problems. • Apply Linear Data Structures such as Linked Lists in solving problems. • Apply Non-Linear Data Structures such as Trees to model and solve the real-world problem. • Apply Non-Linear Data Structures such as Graphs model and solve the real-world problem and Make use of Hashing techniques and resolve collisions during mapping of key value pairs.
  • 5. Module 1 Introduction to Data structures, Arrays, Structures 5
  • 6. 6 Introduction: Data Structures, Classifications (Primitive & Non-Primitive), Data structure operations (Traversing, inserting, deleting, searching, and sorting). Review of Arrays Structures: Array of structures, Self-Referential Structures. Dynamic Memory Allocation Functions, Representation of Linear Arrays in Memory, dynamically allocated arrays and Multidimensional Arrays. Demonstration of representation of Polynomials and Sparse Matrices with arrays. Module 1
  • 8. 8 • Data structure is 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. • Data structure affects the design of both structural & functional aspects of a program. Program=Algorithm + Data Structure Introduction
  • 9. 9 • Data structure is 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. • Data structure affects the design of both structural & functional aspects of a program. Program=Algorithm + Data Structure Introduction
  • 10. 10 • Data structures includes:  Defining operations that Performed can be on data.  Representing data in the memory.  Determining amount of memory required to store and amount of time needed to process data. Introduction
  • 11. 11 • The computers are electronic data Processing machines. In order to we need to know  How to represent data in computer?  How to access them?  What are steps to be performed to get the needed output. Need of Data Structures
  • 13. 13 1. Traversing: To access each data item exactly once so that it can be processed. 2. Searching: To find out the location of the data item if it exists in the given collection 3. Inserting: To add a new data item in the given collection of data items. 4. Deleting: To delete an existing data item from the given collection of data items. 5. Sorting: To arrange the data items in some order i.e. in ascending or descending order 6. Merging: To combine the data items of two sorted files into single file in Data Structure Operations
  • 15. 15 • Array is a data structure that can store a fixed-size sequential collection of elements of the same type. • An array holds several values of the same kind. • Accessing the elements in an array is very fast. It may not be possible to add more values than defined at the start, without copying all values into a new array. • An array is stored so that the position of each element can be computed from its index. Review of Arrays
  • 16. 16 #include <stdio.h> int main () { int arr[10]; /* n is an array of 10 integers */ int i,j; /* initialize elements of array n to 0 */ for(i=0;i<10;i++) arr[i] =i+100; /* set element at location i to i + 100 */ /* output each array element's value */ for (j=0;j<10;j++) printf("Element[%d] = %dn", j, arr[j] ); } Declaration assignment, and accessing arrays
  • 17. 17 #include <stdio.h> int main() { int arr[10], pos, value, i, n; printf("Enter number of elements in array: "); scanf("%d", &n); printf("Enter %d elements: ", n); for(i=0;i<n;i++) scanf("%d", &arr[i]); printf("Enter the location where you wish to insert an element: "); scanf("%d",&pos); printf("Enter the value to insert: "); scanf("%d",&value); Declaration assignment, and accessing arrays
  • 18. 18 for (i=n-1;i>=pos-1;i--) arr[i+1] = arr[i]; arr[pos-1] = value; printf("Resultant array : "); for (i=0;i<=n;i++) printf("%dt", arr[i]); } Declaration assignment, and accessing arrays
  • 19. 19 #include <stdio.h> int main() { int arr[10], pos, i, n; printf("Enter number of elements in array: "); scanf("%d",&n); printf("Enter %d elements: ", n); for(i=0;i<n;i++) scanf("%d", &arr[i]); printf("Enter the location where you wish to delete an element: "); scanf("%d", &pos); To delete an element in the middle of an array
  • 20. 20 if (pos>= n+1) printf("Deletion not possible.n"); else { for (i=pos-1;i<n-1;i++) arr[i] = arr[i+1]; } printf("Resultant array: "); for (i=0;i<n-1;i++) printf("%dt", arr[i]); return 0; } To delete an element in the middle of an array
  • 21. 21 #include <stdio.h> int main() { int arr[10], search, i, n; printf("Enter the number of elements in array: "); scanf("%d",&n); printf("Enter %d integer(s): ", n); for(i=0;i<n;i++) scanf("%d", &arr[i]); printf("Enter a number to search: "); scanf("%d",&search); Search an element using Linear Search (Sequential Search)
  • 22. 22 for(i=0;i<n;i++) { if (arr[i] == search) /* If required element is found */ { printf("%d is present at location %d.n", search, i+1); break; } } if(i==n) printf("%d isn't present in the array.n", search); return 0; } Search an element using Linear Search (Sequential Search)
  • 23. 23 • Binary Search is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half. • Binary search is used to find the position of a key in a sorted array. • The following describes the binary search algorithm:  We compare the key with the value in the middle of the array.  If the key match found, we return its position, which is the index of the middle element of the array.  If the key is less than the value of the middle element of the array, we repeat the above step on the sub-array on the left. If the key is greater than the value of the middle element of the array, we repeat the above step on the sub-array on the right.  If the sub-array to be searched has zero item, it means the key cannot be found. Search an element using Binary Search
  • 24. 24 #include <stdio.h> int main() { int i, low, high, mid, n, key, arr[10]; printf("Enter number of elements: "); scanf("%d",&n); printf("Enter %d integers in ascending order: ", n); for(i = 0; i < n; i++) scanf("%d",&arr[i]); printf("Enter Search Key: "); scanf("%d", &key); low = 0; high = n - 1; Search an element using Binary Search
  • 25. 25 while (low <= high) { mid = (low+high)/2; if(arr[mid] == key) { printf("%d found at location %dn", key, mid+1); break; } else if(arr[mid] < key) low = mid + 1; else high = mid - 1; } if(low > high) printf("%d Not found! in the Array", key); } Search an element using Binary Search
  • 26. 26 • First Iteration (Compare and Swap)  Starting from the first index, compare the first and the second elements.  If the first element is greater than the second element, they are swapped.  Now, compare the second and the third elements. Swap them if they are not in order.  The above process goes on until the last element. To sort an element using Bubble Sort • Remaining Iteration  The same process goes on for the remaining iterations.  After each iteration, the largest element among the unsorted elements is placed at the end. • In each iteration, the comparison takes place up to the last unsorted element. • The array is sorted when all the unsorted elements are placed at their correct positions.
  • 27. 27 #include <stdio.h> int main() { int i, j, n, arr[10]; printf("Enter number of elements: "); scanf("%d",&n); printf("Enter %d integers : ", n); for(i = 0; i < n; i++) scanf("%d",&arr[i]); printf("Array Elements before Sorting : "); for(i=0;i<n;i++) printf("%dt",arr[i]); To sort an element using Bubble Sort
  • 28. 28 for(i=0;i<n-1;i++) { for (j=0;j<n-i-1;j++) { if (arr[j] > arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } printf("nArray Elements After Sorting : "); for(i=0;i<n;i++) printf("%dt",arr[i]); } To sort an element using Bubble Sort
  • 29. 29 for(i=0;i<n-1;i++) { for (j=0;j<n-i-1;j++) { if (arr[j] > arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } printf("nArray Elements After Sorting : "); for(i=0;i<n;i++) printf("%dt",arr[i]); } To sort an element using Bubble Sort