SlideShare a Scribd company logo
1 of 29
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

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

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
 
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
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
DSA - Array.pptx
DSA - Array.pptxDSA - Array.pptx
DSA - Array.pptx
 
Chapter Two.pdf
Chapter Two.pdfChapter Two.pdf
Chapter Two.pdf
 

Recently uploaded

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

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