SlideShare a Scribd company logo
Data Structure and Algorithms by Sabeen Memon03.pptx
Data Structure and Algorithm
Lec 1
Introduction to data structure
 What is a Data Structure?
 Purpose of Data Structure
 Classification of Data Structure
 Operations of Data Structure
 What is algorithm
 Properties of Algorithm
What is Data Structure
 Organized collection of data in particular format called data structure.
Data structure is a technique or method of study how the data is
implemented to each other logically or mathematically.
Purpose of Data Structure
 The main aim of data structure is to increase the efficiency of program and
decrease the storage requirement.
What is Algorithm
 The step-by-step description of any programin general language is called
algorithm.
Or
Algorithm is a sequence of clear instructions used to solve a problem in such a
way that it can be implemented as a program in computer.
Algorithm to add two numbers
 1 start, begin
 2 input two numbers a nd b
3 sum of a and b
 4 display output of addition
 5 exit
Classification of Data Structure
 Linear (Data elements stored in sequence)
Array(Static)
Linked List(Dynamic)
Stack(Dynamic)
Queue(Dynamic)
 Non Linear(Data elements stored in hierarchical manner)
Graph
Tree
Classification of Data Structure
 We can classify Data Structures into two categories:
1. Primitive Data Structure
2. Non-Primitive Data Structure
The following figure shows the different classifications of Data Structures.
Primitive Data Structures
 1. Primitive Data Structures are the data structures consisting of the numbers
and the characters that come in-built into programs.
2. These data structures can be manipulated or operated directly by
machine-level instructions.
3. Basic data types like Integer, Float, Character, and Boolean come under the
Primitive Data Structures.
4. These data types are also called Simple data types, as they contain
characters that can't be divided further
Non primitive data structures
 1. Non-Primitive Data Structures are those data structures derived from
Primitive Data Structures.
2. These data structures can't be manipulated or operated directly by
machine-level instructions.
3. The focus of these data structures is on forming a set of data elements that
is either homogeneous (same data type) or heterogeneous (different data
types).
4. Based on the structure and arrangement of data, we can divide these data
structures into two sub-categories –
1. Linear Data Structures
2. Non-Linear Data Structures
Difference between Primitive and non-
Primitive
Linear Data Structures
 A data structure that preserves a linear connection among its data elements is
known as a Linear Data Structure. The arrangement of the data is done
linearly, Based on memory allocation, the Linear Data Structures are further
classified into two types:
Static Data Structures:
 1. The data structures having a fixed size are known as Static Data Structures.
The memory for these data structures is allocated at the compiler time, and
their size cannot be changed by the user after being compiled; however, the
data stored in them can be altered. The Array is the best example of the
Static Data Structure as they have a fixed size, and its data can be modified
later.
Dynamic Data Structures:
 2. The data structures having a dynamic size are known as Dynamic Data
Structures. The memory of these data structures is allocated at the run time,
and their size varies during the run time of the code. Moreover, the user can
change the size as well as the data elements stored in these data structures
at the run time of the code.
Linked Lists, Stacks, and Queues are common examples of dynamic data
structures
Operations Performed in DS
 Searching
 Sorting
 Insertion
 Deletion
 Updation
 Traversing
 Merging
Array
 An Array is a list of elements where each element has a unique place in the list.
The data elements of the array share the same variable name; however, each
carries a different index number called a subscript. We can access any data
element from the list with the help of its location in the list. Thus, the key
feature of the arrays to understand is that the data is stored in contiguous
memory locations, making it possible for the users to traverse through the data
elements of the array using their respective indexes.
Def
Array
 Contiguous areaof memoryconsisting of equal-size elementsindexedby contiguous integers.
 1 2 3 4 5 6 7
Array
What’s Special About Arrays?
Constant-time access
1 2 3 4 5 6
7
What is special about array
Constant-time access array_addr
 1 2 3 4
5 6 7
This is a variable or symbol representing the starting memory address of
the array in a system's memory.
Constant-time access
 array_addr + elem_size × ()
 The base address (starting memory location of the array).
The size of each element in bytes.
Represents the index (i) of the element you want to access.
Example
 #include <iostream>
 using namespace std;
 int main() {
 int arr[] = {10, 20, 30, 40, 50}; // Define an array
 int *array_addr = arr; // Store the base address of the array
 int index = 2; // Index of the element we want to access
 int elem_size = sizeof(int); // Size of each element (typically 4 bytes)
 // Calculating the memory address manually (for explanation purposes)
 int *element_address = array_addr + index; // Correct way in C++ (automatically handles size)
 cout << "Base address of the array: " << array_addr << endl;
 cout << "Memory address of index " << index << ": " << element_address << endl;
 cout << "Value at index " << index << ": " << *(array_addr + index) << endl; // Accessing the value
 return 0;
 }
Array
 Arrays can be classified into different types:
a. One-Dimensional Array: An Array with only one row of data elements is
known as a One-Dimensional Array. It is stored in ascending storage location.
b. Two-Dimensional Array: An Array consisting of multiple rows and columns of
data elements is called a Two-Dimensional Array. It is also known as a Matrix.
c. Multidimensional Array: We can define Multidimensional Array as an Array of
Arrays. Multidimensional Arrays are not bounded to two indices or two
dimensions as they can include as many indices are per the need.
Example 1D
 #include <iostream>
 using namespace std;
 int main() {
 // Declare and initialize an array of 5 integers
 int numbers[5] = {10, 20, 30, 40, 50};
 // Print the elements of the array using a loop
 cout << "Array elements are: ";
 for (int i = 0; i < 5; i++) {
 cout << numbers[i] << " "; // Access elements using index
 }
 return 0;
 }
2. Linked Lists
 A Linked List is another example of a linear data structure used to store a
collection of data elements dynamically. Data elements in this data structure
are represented by the Nodes, connected using links or pointers. Each node
contains two fields, the information field consists of the actual data, and the
pointer field consists of the address of the subsequent nodes in the list. The
pointer of the last node of the linked list consists of a null pointer, as it points
to nothing. Unlike the Arrays, the user can dynamically adjust the size of a
Linked List as per the requirements.
Linked List
Linked List
 Linked Lists can be classified into different types:
a. Singly Linked List: A Singly Linked List is the most common type of Linked List. Each node has
data and a pointer field containing an address to the next node.
b. Doubly Linked List: A Doubly Linked List consists of an information field and two pointer
fields. The information field contains the data. The first pointer field contains an address of the
previous node, whereas another pointer field contains a reference to the next node. Thus, we
can go in both directions (backward as well as forward).
c. Circular Linked List: The Circular Linked List is similar to the Singly Linked List. The only key
difference is that the last node contains the address of the first node, forming a circular loop in
the Circular Linked List.
Singly linked list
 A singly linked list is a fundamental data structure, it consists
of nodes where each node contains a data field and a reference to the
next node in the linked list. The next of the last node is null, indicating the
end of the list. Linked Lists support efficient insertion and deletion
operations.
 Data link
 1
 2
 3
 4
 5
 6
 7
R 4
S null
A 7
G 1
S 3
Data Structure and Algorithms by Sabeen Memon03.pptx
example
 // Definition of a Node in a singly linked list
 struct Node {

 // Data part of the node
 int data;
 // Pointer to the next node in the list
 Node* next;
 // Constructor to initialize the node with data
 Node(int data)
 {
 this->data = data;
 this->next = nullptr;
 }
 };
In this example, the Node class contains an integer data field (data) to store the information and a pointer to another Node (next) to
establish the link to the next node in the list.
Operations on Singly Linked List
• Traversal
• Searching
• Length
• Insertion:
• Insert at the beginning
• Insert at the end
• Insert at a specific position
• Deletion:
• Delete from the beginning
• Delete from the end
• Delete a specific node
Traversal of Singly Linked List
 Traversal involves visiting each node in the linked list and performing
some operation on the data. A simple traversal function would print or
process the data of each node.
 Step-by-step approach:
• Initialize a pointer current to the head of the list.
• Use a while loop to iterate through the list until the current pointer reaches
NULL.
• Inside the loop, print the data of the current node and move the current
pointer to the next node.
example
 // C++ Function to traverse and print the elements of the linked
 // list
 void traverseLinkedList(Node* head)
 {
 // Start from the head of the linked list
 Node* current = head;
 // Traverse the linked list until reaching the end
 // (nullptr)
 while (current != nullptr) {

 // Print the data of the current node
 cout << current->data << " ";
 // Move to the next node
 current = current->next;
 }
 cout << std::endl;
 }
Searching in Singly Linked List
 Searching in a Singly Linked List refers to the process of looking for a
specific element or value within the elements of the linked list.
 Step-by-step approach:
1. Traverse the Linked List starting from the head.
2. Check if the current node's data matches the target value.
2. If a match is found, return true.
3. Otherwise, Move to the next node and repeat steps 2.
4. If the end of the list is reached without finding a match, return false.
example
 // Function to search for a value in the Linked List
 bool searchLinkedList(struct Node* head, int target)
 {
 // Traverse the Linked List
 while (head != nullptr) {
 // Check if the current node's
 // data matches the target value
 if (head->data == target) {
 return true; // Value found
 }
 // Move to the next node
 head = head->next;
 }
 return false; // Value not found
 }
How to insert an item at the beginning
of Singly Linked List
 Step1:Begin
 Step2:if Fr =NULL then print “Overflow”
step 3:zinput new item “X”
step4:new fr
step5:fr link[new]
 Step6:Data [new] item
step7:link[new] st
step8:st new
step9:exit
Data Structure and Algorithms by Sabeen Memon03.pptx
Doubly Linked List
 A doubly linked list is a more complex data structure than a singly linked
list, but it offers several advantages. The main advantage of a doubly
linked list is that it allows for efficient traversal of the list in both directions.
This is because each node in the list contains a pointer to the previous
node and a pointer to the next node. This allows for quick and easy
insertion and deletion of nodes from the list, as well as efficient traversal
of the list in both directions.
Example
Representation of Doubly Linked List in Data
Structure
 In a data structure, a doubly linked list is represented using nodes that
have three fields:
1. Data
2. A pointer to the next node (next)
3. A pointer to the previous node (prev)
Example
 struct Node {
 // To store the Value or data.
 int data;
 // Pointer to point the Previous Element
 Node* prev;
 // Pointer to point the Next Element
 Node* next;

 // Constructor
 Node(int d) {
 data = d;
 prev = next = nullptr;
 }
 };
Doubly Linked List
 Each node in a Doubly Linked List contains the data it holds, a pointer to
the next node in the list, and a pointer to the previous node in the list. By
linking these nodes together through the next and prev pointers, we can
traverse the list in both directions (forward and backward), which is a key
feature of a Doubly Linked List.
Operations on Doubly Linked List
• Traversal in Doubly Linked List
• Searching in Doubly Linked List
• Finding Length of Doubly Linked List
• Insertion in Doubly Linked List:
• Insertion at the beginning of Doubly Linked List
• Insertion at the end of the Doubly Linked List
• Insertion at a specific position in Doubly Linked List
• Deletion in Doubly Linked List:
• Deletion of a node at the beginning of Doubly Linked List
• Deletion of a node at the end of Doubly Linked List
• Deletion of a node at a specific position in Doubly Linked List
 Let's go through each of the operations mentioned above, one by one.
 Traversal in Doubly Linked List
 To Traverse the doubly list, we can use the following steps:
 a. Forward Traversal:
• Initialize a pointer to the head of the linked list.
• While the pointer is not null:
• Visit the data at the current node.
• Move the pointer to the next node.
 b. Backward Traversal:
• Initialize a pointer to the tail of the linked list.
• While the pointer is not null:
• Visit the data at the current node.
• Move the pointer to the previous node.
How to insert a new item at the
beginning of doubly linked list
Step1: Begin
Step2: if fr=Null then print “overflow”
Step3: input new item X
Step4: set newfr
fr<-next[fr]
Step5:Data [new]<-item
Step6:next[new]<- first
step7:previous[new]<- null
Step 8:previous[first]<- new
step 9:first<- new
Step 10:exit
Data Structure and Algorithms by Sabeen Memon03.pptx
Ad

More Related Content

Similar to Data Structure and Algorithms by Sabeen Memon03.pptx (20)

Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...
Tutort Academy
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
SulabhPawaia
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
raji175286
 
CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111
kannanmeenu602
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
Jazz Jinia Bhowmik
 
UNITIII LDS.pdf
UNITIII LDS.pdfUNITIII LDS.pdf
UNITIII LDS.pdf
meenamadhuvandhi2
 
Data structure (basics)
Data structure (basics)Data structure (basics)
Data structure (basics)
ShrushtiGole
 
Data Structures-UNIT Four_Linked_List.pptx
Data Structures-UNIT Four_Linked_List.pptxData Structures-UNIT Four_Linked_List.pptx
Data Structures-UNIT Four_Linked_List.pptx
shilpar780389
 
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
Malikireddy Bramhananda Reddy
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Axmedcarb
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
priyanshukumar97908
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptx
Mumtaz
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)
Madishetty Prathibha
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
DataStructurePpt-01.pptxEngineering data structure notes
DataStructurePpt-01.pptxEngineering data structure notesDataStructurePpt-01.pptxEngineering data structure notes
DataStructurePpt-01.pptxEngineering data structure notes
limev72215
 
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
 
DataStructurePpt.pptx
DataStructurePpt.pptxDataStructurePpt.pptx
DataStructurePpt.pptx
DCABCA
 
DataStructureccvdgddfffdesddsssdssPpt.pptx
DataStructureccvdgddfffdesddsssdssPpt.pptxDataStructureccvdgddfffdesddsssdssPpt.pptx
DataStructureccvdgddfffdesddsssdssPpt.pptx
bgmi52926
 
M v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notesM v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notes
Malikireddy Bramhananda Reddy
 
Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...
Tutort Academy
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
SulabhPawaia
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
raji175286
 
CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111CS8391-DATA STRUCTURE.pdf1111111111111111
CS8391-DATA STRUCTURE.pdf1111111111111111
kannanmeenu602
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
Jazz Jinia Bhowmik
 
Data structure (basics)
Data structure (basics)Data structure (basics)
Data structure (basics)
ShrushtiGole
 
Data Structures-UNIT Four_Linked_List.pptx
Data Structures-UNIT Four_Linked_List.pptxData Structures-UNIT Four_Linked_List.pptx
Data Structures-UNIT Four_Linked_List.pptx
shilpar780389
 
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
Malikireddy Bramhananda Reddy
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Axmedcarb
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
priyanshukumar97908
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptx
Mumtaz
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)
Madishetty Prathibha
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
DataStructurePpt-01.pptxEngineering data structure notes
DataStructurePpt-01.pptxEngineering data structure notesDataStructurePpt-01.pptxEngineering data structure notes
DataStructurePpt-01.pptxEngineering data structure notes
limev72215
 
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
 
DataStructurePpt.pptx
DataStructurePpt.pptxDataStructurePpt.pptx
DataStructurePpt.pptx
DCABCA
 
DataStructureccvdgddfffdesddsssdssPpt.pptx
DataStructureccvdgddfffdesddsssdssPpt.pptxDataStructureccvdgddfffdesddsssdssPpt.pptx
DataStructureccvdgddfffdesddsssdssPpt.pptx
bgmi52926
 

Recently uploaded (20)

Process Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challengesProcess Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challenges
Process mining Evangelist
 
problem solving.presentation slideshow bsc nursing
problem solving.presentation slideshow bsc nursingproblem solving.presentation slideshow bsc nursing
problem solving.presentation slideshow bsc nursing
vishnudathas123
 
vMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free DownloadvMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free Download
eyeskye547
 
Process Mining and Data Science in the Financial Industry
Process Mining and Data Science in the Financial IndustryProcess Mining and Data Science in the Financial Industry
Process Mining and Data Science in the Financial Industry
Process mining Evangelist
 
Collibra DQ Installation setup and debug
Collibra DQ Installation setup and debugCollibra DQ Installation setup and debug
Collibra DQ Installation setup and debug
karthikprince20
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf
2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf
2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf
OlhaTatokhina1
 
Modern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx AaModern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx Aa
MuhammadAwaisKamboh
 
50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd
emir73065
 
real illuminati Uganda agent 0782561496/0756664682
real illuminati Uganda agent 0782561496/0756664682real illuminati Uganda agent 0782561496/0756664682
real illuminati Uganda agent 0782561496/0756664682
way to join real illuminati Agent In Kampala Call/WhatsApp+256782561496/0756664682
 
RAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit FrameworkRAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit Framework
apanneer
 
Customer Segmentation using K-Means clustering
Customer Segmentation using K-Means clusteringCustomer Segmentation using K-Means clustering
Customer Segmentation using K-Means clustering
Ingrid Nyakerario
 
hersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distributionhersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distribution
hershtara1
 
chapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptxchapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptx
justinebandajbn
 
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
Taqyea
 
How to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process miningHow to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process mining
Process mining Evangelist
 
Decision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdfDecision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdf
Saikat Basu
 
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
disnakertransjabarda
 
Automation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success storyAutomation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success story
Process mining Evangelist
 
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
muhammed84essa
 
Process Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challengesProcess Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challenges
Process mining Evangelist
 
problem solving.presentation slideshow bsc nursing
problem solving.presentation slideshow bsc nursingproblem solving.presentation slideshow bsc nursing
problem solving.presentation slideshow bsc nursing
vishnudathas123
 
vMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free DownloadvMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free Download
eyeskye547
 
Process Mining and Data Science in the Financial Industry
Process Mining and Data Science in the Financial IndustryProcess Mining and Data Science in the Financial Industry
Process Mining and Data Science in the Financial Industry
Process mining Evangelist
 
Collibra DQ Installation setup and debug
Collibra DQ Installation setup and debugCollibra DQ Installation setup and debug
Collibra DQ Installation setup and debug
karthikprince20
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf
2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf
2024-Media-Literacy-Index-Of-Ukrainians-ENG-SHORT.pdf
OlhaTatokhina1
 
Modern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx AaModern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx Aa
MuhammadAwaisKamboh
 
50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd
emir73065
 
RAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit FrameworkRAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit Framework
apanneer
 
Customer Segmentation using K-Means clustering
Customer Segmentation using K-Means clusteringCustomer Segmentation using K-Means clustering
Customer Segmentation using K-Means clustering
Ingrid Nyakerario
 
hersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distributionhersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distribution
hershtara1
 
chapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptxchapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptx
justinebandajbn
 
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
Taqyea
 
How to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process miningHow to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process mining
Process mining Evangelist
 
Decision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdfDecision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdf
Saikat Basu
 
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
disnakertransjabarda
 
Automation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success storyAutomation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success story
Process mining Evangelist
 
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
muhammed84essa
 
Ad

Data Structure and Algorithms by Sabeen Memon03.pptx

  • 2. Data Structure and Algorithm Lec 1
  • 3. Introduction to data structure  What is a Data Structure?  Purpose of Data Structure  Classification of Data Structure  Operations of Data Structure  What is algorithm  Properties of Algorithm
  • 4. What is Data Structure  Organized collection of data in particular format called data structure. Data structure is a technique or method of study how the data is implemented to each other logically or mathematically.
  • 5. Purpose of Data Structure  The main aim of data structure is to increase the efficiency of program and decrease the storage requirement.
  • 6. What is Algorithm  The step-by-step description of any programin general language is called algorithm. Or Algorithm is a sequence of clear instructions used to solve a problem in such a way that it can be implemented as a program in computer.
  • 7. Algorithm to add two numbers  1 start, begin  2 input two numbers a nd b 3 sum of a and b  4 display output of addition  5 exit
  • 8. Classification of Data Structure  Linear (Data elements stored in sequence) Array(Static) Linked List(Dynamic) Stack(Dynamic) Queue(Dynamic)  Non Linear(Data elements stored in hierarchical manner) Graph Tree
  • 9. Classification of Data Structure  We can classify Data Structures into two categories: 1. Primitive Data Structure 2. Non-Primitive Data Structure The following figure shows the different classifications of Data Structures.
  • 10. Primitive Data Structures  1. Primitive Data Structures are the data structures consisting of the numbers and the characters that come in-built into programs. 2. These data structures can be manipulated or operated directly by machine-level instructions. 3. Basic data types like Integer, Float, Character, and Boolean come under the Primitive Data Structures. 4. These data types are also called Simple data types, as they contain characters that can't be divided further
  • 11. Non primitive data structures  1. Non-Primitive Data Structures are those data structures derived from Primitive Data Structures. 2. These data structures can't be manipulated or operated directly by machine-level instructions. 3. The focus of these data structures is on forming a set of data elements that is either homogeneous (same data type) or heterogeneous (different data types). 4. Based on the structure and arrangement of data, we can divide these data structures into two sub-categories – 1. Linear Data Structures 2. Non-Linear Data Structures
  • 12. Difference between Primitive and non- Primitive
  • 13. Linear Data Structures  A data structure that preserves a linear connection among its data elements is known as a Linear Data Structure. The arrangement of the data is done linearly, Based on memory allocation, the Linear Data Structures are further classified into two types:
  • 14. Static Data Structures:  1. The data structures having a fixed size are known as Static Data Structures. The memory for these data structures is allocated at the compiler time, and their size cannot be changed by the user after being compiled; however, the data stored in them can be altered. The Array is the best example of the Static Data Structure as they have a fixed size, and its data can be modified later.
  • 15. Dynamic Data Structures:  2. The data structures having a dynamic size are known as Dynamic Data Structures. The memory of these data structures is allocated at the run time, and their size varies during the run time of the code. Moreover, the user can change the size as well as the data elements stored in these data structures at the run time of the code. Linked Lists, Stacks, and Queues are common examples of dynamic data structures
  • 16. Operations Performed in DS  Searching  Sorting  Insertion  Deletion  Updation  Traversing  Merging
  • 17. Array  An Array is a list of elements where each element has a unique place in the list. The data elements of the array share the same variable name; however, each carries a different index number called a subscript. We can access any data element from the list with the help of its location in the list. Thus, the key feature of the arrays to understand is that the data is stored in contiguous memory locations, making it possible for the users to traverse through the data elements of the array using their respective indexes.
  • 18. Def Array  Contiguous areaof memoryconsisting of equal-size elementsindexedby contiguous integers.  1 2 3 4 5 6 7
  • 19. Array
  • 20. What’s Special About Arrays? Constant-time access 1 2 3 4 5 6 7
  • 21. What is special about array Constant-time access array_addr  1 2 3 4 5 6 7 This is a variable or symbol representing the starting memory address of the array in a system's memory.
  • 22. Constant-time access  array_addr + elem_size × ()  The base address (starting memory location of the array). The size of each element in bytes. Represents the index (i) of the element you want to access.
  • 23. Example  #include <iostream>  using namespace std;  int main() {  int arr[] = {10, 20, 30, 40, 50}; // Define an array  int *array_addr = arr; // Store the base address of the array  int index = 2; // Index of the element we want to access  int elem_size = sizeof(int); // Size of each element (typically 4 bytes)  // Calculating the memory address manually (for explanation purposes)  int *element_address = array_addr + index; // Correct way in C++ (automatically handles size)  cout << "Base address of the array: " << array_addr << endl;  cout << "Memory address of index " << index << ": " << element_address << endl;  cout << "Value at index " << index << ": " << *(array_addr + index) << endl; // Accessing the value  return 0;  }
  • 24. Array  Arrays can be classified into different types: a. One-Dimensional Array: An Array with only one row of data elements is known as a One-Dimensional Array. It is stored in ascending storage location. b. Two-Dimensional Array: An Array consisting of multiple rows and columns of data elements is called a Two-Dimensional Array. It is also known as a Matrix. c. Multidimensional Array: We can define Multidimensional Array as an Array of Arrays. Multidimensional Arrays are not bounded to two indices or two dimensions as they can include as many indices are per the need.
  • 25. Example 1D  #include <iostream>  using namespace std;  int main() {  // Declare and initialize an array of 5 integers  int numbers[5] = {10, 20, 30, 40, 50};  // Print the elements of the array using a loop  cout << "Array elements are: ";  for (int i = 0; i < 5; i++) {  cout << numbers[i] << " "; // Access elements using index  }  return 0;  }
  • 26. 2. Linked Lists  A Linked List is another example of a linear data structure used to store a collection of data elements dynamically. Data elements in this data structure are represented by the Nodes, connected using links or pointers. Each node contains two fields, the information field consists of the actual data, and the pointer field consists of the address of the subsequent nodes in the list. The pointer of the last node of the linked list consists of a null pointer, as it points to nothing. Unlike the Arrays, the user can dynamically adjust the size of a Linked List as per the requirements.
  • 28. Linked List  Linked Lists can be classified into different types: a. Singly Linked List: A Singly Linked List is the most common type of Linked List. Each node has data and a pointer field containing an address to the next node. b. Doubly Linked List: A Doubly Linked List consists of an information field and two pointer fields. The information field contains the data. The first pointer field contains an address of the previous node, whereas another pointer field contains a reference to the next node. Thus, we can go in both directions (backward as well as forward). c. Circular Linked List: The Circular Linked List is similar to the Singly Linked List. The only key difference is that the last node contains the address of the first node, forming a circular loop in the Circular Linked List.
  • 29. Singly linked list  A singly linked list is a fundamental data structure, it consists of nodes where each node contains a data field and a reference to the next node in the linked list. The next of the last node is null, indicating the end of the list. Linked Lists support efficient insertion and deletion operations.
  • 30.  Data link  1  2  3  4  5  6  7 R 4 S null A 7 G 1 S 3
  • 32. example  // Definition of a Node in a singly linked list  struct Node {   // Data part of the node  int data;  // Pointer to the next node in the list  Node* next;  // Constructor to initialize the node with data  Node(int data)  {  this->data = data;  this->next = nullptr;  }  }; In this example, the Node class contains an integer data field (data) to store the information and a pointer to another Node (next) to establish the link to the next node in the list.
  • 33. Operations on Singly Linked List • Traversal • Searching • Length • Insertion: • Insert at the beginning • Insert at the end • Insert at a specific position • Deletion: • Delete from the beginning • Delete from the end • Delete a specific node
  • 34. Traversal of Singly Linked List  Traversal involves visiting each node in the linked list and performing some operation on the data. A simple traversal function would print or process the data of each node.  Step-by-step approach: • Initialize a pointer current to the head of the list. • Use a while loop to iterate through the list until the current pointer reaches NULL. • Inside the loop, print the data of the current node and move the current pointer to the next node.
  • 35. example  // C++ Function to traverse and print the elements of the linked  // list  void traverseLinkedList(Node* head)  {  // Start from the head of the linked list  Node* current = head;  // Traverse the linked list until reaching the end  // (nullptr)  while (current != nullptr) {   // Print the data of the current node  cout << current->data << " ";  // Move to the next node  current = current->next;  }  cout << std::endl;  }
  • 36. Searching in Singly Linked List  Searching in a Singly Linked List refers to the process of looking for a specific element or value within the elements of the linked list.  Step-by-step approach: 1. Traverse the Linked List starting from the head. 2. Check if the current node's data matches the target value. 2. If a match is found, return true. 3. Otherwise, Move to the next node and repeat steps 2. 4. If the end of the list is reached without finding a match, return false.
  • 37. example  // Function to search for a value in the Linked List  bool searchLinkedList(struct Node* head, int target)  {  // Traverse the Linked List  while (head != nullptr) {  // Check if the current node's  // data matches the target value  if (head->data == target) {  return true; // Value found  }  // Move to the next node  head = head->next;  }  return false; // Value not found  }
  • 38. How to insert an item at the beginning of Singly Linked List  Step1:Begin  Step2:if Fr =NULL then print “Overflow” step 3:zinput new item “X” step4:new fr step5:fr link[new]  Step6:Data [new] item step7:link[new] st step8:st new step9:exit
  • 40. Doubly Linked List  A doubly linked list is a more complex data structure than a singly linked list, but it offers several advantages. The main advantage of a doubly linked list is that it allows for efficient traversal of the list in both directions. This is because each node in the list contains a pointer to the previous node and a pointer to the next node. This allows for quick and easy insertion and deletion of nodes from the list, as well as efficient traversal of the list in both directions.
  • 42. Representation of Doubly Linked List in Data Structure  In a data structure, a doubly linked list is represented using nodes that have three fields: 1. Data 2. A pointer to the next node (next) 3. A pointer to the previous node (prev)
  • 43. Example  struct Node {  // To store the Value or data.  int data;  // Pointer to point the Previous Element  Node* prev;  // Pointer to point the Next Element  Node* next;   // Constructor  Node(int d) {  data = d;  prev = next = nullptr;  }  };
  • 44. Doubly Linked List  Each node in a Doubly Linked List contains the data it holds, a pointer to the next node in the list, and a pointer to the previous node in the list. By linking these nodes together through the next and prev pointers, we can traverse the list in both directions (forward and backward), which is a key feature of a Doubly Linked List.
  • 45. Operations on Doubly Linked List • Traversal in Doubly Linked List • Searching in Doubly Linked List • Finding Length of Doubly Linked List
  • 46. • Insertion in Doubly Linked List: • Insertion at the beginning of Doubly Linked List • Insertion at the end of the Doubly Linked List • Insertion at a specific position in Doubly Linked List • Deletion in Doubly Linked List: • Deletion of a node at the beginning of Doubly Linked List • Deletion of a node at the end of Doubly Linked List • Deletion of a node at a specific position in Doubly Linked List  Let's go through each of the operations mentioned above, one by one.
  • 47.  Traversal in Doubly Linked List  To Traverse the doubly list, we can use the following steps:  a. Forward Traversal: • Initialize a pointer to the head of the linked list. • While the pointer is not null: • Visit the data at the current node. • Move the pointer to the next node.  b. Backward Traversal: • Initialize a pointer to the tail of the linked list. • While the pointer is not null: • Visit the data at the current node. • Move the pointer to the previous node.
  • 48. How to insert a new item at the beginning of doubly linked list Step1: Begin Step2: if fr=Null then print “overflow” Step3: input new item X Step4: set newfr fr<-next[fr] Step5:Data [new]<-item Step6:next[new]<- first step7:previous[new]<- null Step 8:previous[first]<- new step 9:first<- new Step 10:exit