SlideShare a Scribd company logo
DATA STRUCTURES AND ALGORITHM
1
01
1
1 0
2 1 0
3 .0
4 10
5 Q 1 0
6 01 0
7 3
8 01 0
1 0.
1 Qq.
2 qQq
3 1 A1z
Dr. Muhammad Idrees
2
Books to Follow
 D.S.Malik, “Data Structures using C++”
 D.Samanta, “Classic Data Structures”, Prentice Hall
 Tenenbaum, M.Augenstein, and Y. Langman, “Data
Structures using C and C++”, Prentice Hall.
3
Some General Comments
 Encouragement to ask questions during class
 Without your feedback, it is impossible for me to
know what you don’t know?
 There is no reason not to ask questions during class
 Of course, you could also send email.
 Encouragement to read course material prior to
class
 Kindly switch off your Mobile Phones during class
Introduction to Data Structure
4
A data structure is a particular way of storing and
organizing data in a computer so that it can be
used efficiently
Need for Data Structures
 Data structures organize data  more efficient
programs.
 More powerful computers  more complex
applications.
 More complex applications demand more
calculations.
Organizing Data
 Any organization for a collection of records that
can be searched, processed in any order, or
modified.
 The choice of data structure and algorithm can
make the difference between a program
running in a few seconds or many days.
7
What is Data Structure?
 Data structure is a representation of data and the
operations allowed on that data.
 A data structure is a way to store and organize
data in order to facilitate the access and
modifications.
 Data Structure is the method of representing of
logical relationships between individual data
elements related to the solution of a given problem.
8
Fundamental Data Structures
Hash Tables
Basic Data Structures
Linear Data Structures Non-Linear Data Structures
Linked Lists Stacks Queues Trees
Graphs
Arrays
array
Linked list
tree
queue
stack
10
Linear Data Structures
 A data structure is said to be linear if its elements
form a sequence or a linear list.
 Examples:
 Arrays
 Linked Lists
 Stacks
 Queues
11
Non-Linear Data Structures
 A data structure is said to be non-linear if its
elements does not form a sequence or a linear list.
 Examples:
 Trees
 Graphs
 Hash Tables
 Each element may be connected with two or more
other nodes or items in a non-linear arrangement.
12
Operations on Data Structures
 Traversal: Travel through the data structure
 Search: Traversal through the data structure for a
given element
 Insertion: Adding new elements to the data structure
 Deletion: Removing an element from the data
structure
 Sorting: Arranging the elements in some type of order
 Merging: Combining two similar data structures into
one
 Arrays
 Linked List
 Stacks
 Queues
Linear Data Structures
13
14
Arrays
 A sequence of n items of the same data type that are
stored contiguously in computer memory and made
accessible by specifying a value of the array’s index.
 Properties:
 fixed length (need preliminary reservation of memory)
 contiguous memory locations
 direct access
 Insert/delete
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]
1 2 3 4 5 6 7 8 9 10
Array a with 10 integer elements
15
Linked List
 A sequence of zero or more nodes each containing two kinds of
information: some data and one or more links called pointers to
other nodes of the linked list.
 Properties
 dynamic length
 arbitrary memory locations
 access by following links
 Insert/delete
 Types of Linked List
 Singly linked list (next pointer)
 Doubly linked list (next + previous pointers)
16
Stacks
 A stack is a data structure that uses last-in, first-out
(LIFO) ordering and allows reading and writing on the
top element only.
 Properties
 insertion/deletion can be done only at the top
 LIFO
 Two operations
 Push (insertion)
 Pop (removal)
17
Queues
 Collection with access only to the item that has been
present the longest
 Properties
 Insertion/enqueue from the rear (back) and deletion/
dequeue from the front.
 FIFO
 Two operations
 Enqueue
 Dequeue
20 30 10 60 57 29
Front Back
 Graphs
 Trees
 Hash Tables
Non-Linear Data Structures
18
19
Graphs
 Formal definition: A graph G = <V, E> is defined by a
pair of two sets: a finite set V of items called vertices and a
set E of vertex pairs called edges.
 Undirected and directed graphs (digraphs).
 Complete, dense, and sparse graphs
Undirected Graph Directed Graph
20
Trees
 A Tree is a way of representing the
hierarchical nature of a structure in a
graphical form.
 Properties of trees
 Root Node
 Child Node
 Parent Node
 Leaf Node
 Types
 Unordered Tree
 Binary Tree is an ordered tree data
structure in which each node has at most
two children.
Ordered Tree
Binary Tree
21
Hash Tables
 A hash table is a data structure that uses a hash
function to map identifying values, known as keys
(e.g., a person's name), to their associated values.
22
Summary
 A data structure is a particular way of storing and organizing
data in a computer so that it can be used efficiently.
 Linear Data Structures
 Arrays
 Linked List
 Stacks
 Queues
 Non Linear Data Structures
 Graphs
 Trees
 Hash Tables
Selecting a Data Structure
Select a data structure as follows:
1. Analyze the problem to determine the
resource constraints a solution must meet.
2. Determine the basic operations that must be
supported. Quantify the resource constraints
for each operation.
3. Select the data structure that best meets
these requirements.
Data Structure Philosophy
 Each data structure has costs and benefits.
 Rarely is one data structure better than another
in all situations.
 A data structure requires:
 space for each data item it stores,
 time to perform each basic operation,
 programming effort.
A precise rule (or set of rules) specifying
how to solve some problem.
Introduction to Algorithms
25
26
What is an Algorithm?
 An algorithm is a sequence of unambiguous
instructions for solving a problem, i.e., for obtaining a
required output for any legitimate input in a finite
amount of time.
 Properties
 Can be represented various forms
 Unambiguity/clearness
 Effectiveness
 Finiteness/termination
 Correctness
27
What is an Algorithm?
 Recipe, process, method, technique, procedure, routine,…
with the following requirements:
1. Finiteness
 terminates after a finite number of steps
2. Definiteness
 rigorously and unambiguously specified
3. Clearly specified input
 valid inputs are clearly specified
4. Clearly specified/expected output
 can be proved to produce the correct output given a valid input
5. Effectiveness
 steps are sufficiently simple and basic
28
Why Study Algorithms?
 Algorithms solve problems
 Good choice: more efficient programs
 Bad choice: poor programs performance
 Example:
 Problem: Find the largest element ‘k’ out of ‘N’ integers
 Easy algorithms: sort all integers, then list the first or last element
 Better algorithm: take first element then read through the list
 Different algorithms perform better on different inputs
 Input size also affect the performance.
29
Notion of Algorithm and Problem
“Computer”
Problem
Algorithm
Input Output
30
Representation of an Algorithms
 An algorithm may be represented in different
forms:
 A description using English/other languages
 A real computer program, e.g. C++ or java
 A pseudo-code, C-like program, program-language-
like program.
 Program = algorithms + data structures
31
Basic Issues Related to Algorithms
 How to design algorithms
 How to express algorithms
 Proving correctness
 Efficiency (or complexity) analysis
 Theoretical analysis
 Empirical analysis
 Optimality
32
Analysis of Algorithms
 How good is the algorithm?
 Correctness
 Time efficiency
 Space efficiency
33
Algorithm Efficiency
 There are often many algorithms for a given
problem. How do we choose the best?
 Goals of program design:
 Algorithm is to be easy to understand, code, debug
 Algorithm makes efficient use of computer’s resources
 How to measure the efficiency?
 Empirical comparison (run the program)
 Asymptotic algorithm analysis (without running the program)
 Factors affecting running time (size of the input)
34
Best, Worst and Average Cases
 Not all inputs of a given size take the same time.
 Each algorithm has three cases:
 Best case:
 Worst Case:
 Average Case:
35
Example: Best, Worst and Average Cases
 Sequential search for ‘k’ in an array of ‘n’ integers:
 Best case: ‘k’ is the first element of the array.
 Worst case: the search must visit every element once.
This happens when the value being searched for is
either the last element in the list, or is not in the list
 Average case: on average, assuming the value
searched for is in the list and each list element is
equally likely to be the value searched for, the search
visits only n/2 elements.
Ad

More Related Content

Similar to Data_structures_and_algorithm_Lec_1.pptx (20)

Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
DSA(Lec-1,2,3) For C++ Introduction for basics
DSA(Lec-1,2,3) For C++ Introduction for basicsDSA(Lec-1,2,3) For C++ Introduction for basics
DSA(Lec-1,2,3) For C++ Introduction for basics
x28tjyi81j
 
Data Structures unit I Introduction - data types
Data Structures unit I Introduction - data typesData Structures unit I Introduction - data types
Data Structures unit I Introduction - data types
AmirthaVarshini80
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
SajalFayyaz
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
1- Introduction.pptx.pdf
1- Introduction.pptx.pdf1- Introduction.pptx.pdf
1- Introduction.pptx.pdf
gm6523
 
Introduction of C++ Text book UNIT-1 .ppt
Introduction of C++ Text book UNIT-1 .pptIntroduction of C++ Text book UNIT-1 .ppt
Introduction of C++ Text book UNIT-1 .ppt
akulaaruna81
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
JohnStuart83
 
8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx
RavishankarBhaganaga
 
project on data structures and algorithm
project on data structures and algorithmproject on data structures and algorithm
project on data structures and algorithm
AnujKumar566766
 
Introduction to data structures and its types
Introduction to data structures and its typesIntroduction to data structures and its types
Introduction to data structures and its types
sonalishinge2015
 
EC2311 – Data Structures and C Programming
EC2311 – Data Structures and C ProgrammingEC2311 – Data Structures and C Programming
EC2311 – Data Structures and C Programming
Padma Priya
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
MuhammadTalhaAwan1
 
Chapter 1- IT.pptx
Chapter 1- IT.pptxChapter 1- IT.pptx
Chapter 1- IT.pptx
ssuserb78e291
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
Abdul salam
 
Algorithms and Data Structures~hmftj
Algorithms and Data Structures~hmftjAlgorithms and Data Structures~hmftj
Algorithms and Data Structures~hmftj
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
Lect 1-2 Zaheer Abbas
Lect 1-2 Zaheer AbbasLect 1-2 Zaheer Abbas
Lect 1-2 Zaheer Abbas
Information Technology Center
 
1introduction-191021211508Algorithms and data structures.pptx
1introduction-191021211508Algorithms and data structures.pptx1introduction-191021211508Algorithms and data structures.pptx
1introduction-191021211508Algorithms and data structures.pptx
smartashammari
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
DSA(Lec-1,2,3) For C++ Introduction for basics
DSA(Lec-1,2,3) For C++ Introduction for basicsDSA(Lec-1,2,3) For C++ Introduction for basics
DSA(Lec-1,2,3) For C++ Introduction for basics
x28tjyi81j
 
Data Structures unit I Introduction - data types
Data Structures unit I Introduction - data typesData Structures unit I Introduction - data types
Data Structures unit I Introduction - data types
AmirthaVarshini80
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
SajalFayyaz
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
1- Introduction.pptx.pdf
1- Introduction.pptx.pdf1- Introduction.pptx.pdf
1- Introduction.pptx.pdf
gm6523
 
Introduction of C++ Text book UNIT-1 .ppt
Introduction of C++ Text book UNIT-1 .pptIntroduction of C++ Text book UNIT-1 .ppt
Introduction of C++ Text book UNIT-1 .ppt
akulaaruna81
 
project on data structures and algorithm
project on data structures and algorithmproject on data structures and algorithm
project on data structures and algorithm
AnujKumar566766
 
Introduction to data structures and its types
Introduction to data structures and its typesIntroduction to data structures and its types
Introduction to data structures and its types
sonalishinge2015
 
EC2311 – Data Structures and C Programming
EC2311 – Data Structures and C ProgrammingEC2311 – Data Structures and C Programming
EC2311 – Data Structures and C Programming
Padma Priya
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
MuhammadTalhaAwan1
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
Abdul salam
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
1introduction-191021211508Algorithms and data structures.pptx
1introduction-191021211508Algorithms and data structures.pptx1introduction-191021211508Algorithms and data structures.pptx
1introduction-191021211508Algorithms and data structures.pptx
smartashammari
 

More from aamirali1061a (8)

impactoftechnologyone-phpappfjjjj02.pptx
impactoftechnologyone-phpappfjjjj02.pptximpactoftechnologyone-phpappfjjjj02.pptx
impactoftechnologyone-phpappfjjjj02.pptx
aamirali1061a
 
Ch8.Testing software enginnering 43.pptx
Ch8.Testing software enginnering 43.pptxCh8.Testing software enginnering 43.pptx
Ch8.Testing software enginnering 43.pptx
aamirali1061a
 
Presentation_The Israel-Palestine Conflict.pptx
Presentation_The Israel-Palestine Conflict.pptxPresentation_The Israel-Palestine Conflict.pptx
Presentation_The Israel-Palestine Conflict.pptx
aamirali1061a
 
Data_structures_and_algorithm_Lec_1.pptx
Data_structures_and_algorithm_Lec_1.pptxData_structures_and_algorithm_Lec_1.pptx
Data_structures_and_algorithm_Lec_1.pptx
aamirali1061a
 
1st lecture of DSA computer science 2024.ppt
1st lecture of DSA computer science 2024.ppt1st lecture of DSA computer science 2024.ppt
1st lecture of DSA computer science 2024.ppt
aamirali1061a
 
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.pptStack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
Lecture#2.pptx
Lecture#2.pptxLecture#2.pptx
Lecture#2.pptx
aamirali1061a
 
Lecture#3.pptx
Lecture#3.pptxLecture#3.pptx
Lecture#3.pptx
aamirali1061a
 
impactoftechnologyone-phpappfjjjj02.pptx
impactoftechnologyone-phpappfjjjj02.pptximpactoftechnologyone-phpappfjjjj02.pptx
impactoftechnologyone-phpappfjjjj02.pptx
aamirali1061a
 
Ch8.Testing software enginnering 43.pptx
Ch8.Testing software enginnering 43.pptxCh8.Testing software enginnering 43.pptx
Ch8.Testing software enginnering 43.pptx
aamirali1061a
 
Presentation_The Israel-Palestine Conflict.pptx
Presentation_The Israel-Palestine Conflict.pptxPresentation_The Israel-Palestine Conflict.pptx
Presentation_The Israel-Palestine Conflict.pptx
aamirali1061a
 
Data_structures_and_algorithm_Lec_1.pptx
Data_structures_and_algorithm_Lec_1.pptxData_structures_and_algorithm_Lec_1.pptx
Data_structures_and_algorithm_Lec_1.pptx
aamirali1061a
 
1st lecture of DSA computer science 2024.ppt
1st lecture of DSA computer science 2024.ppt1st lecture of DSA computer science 2024.ppt
1st lecture of DSA computer science 2024.ppt
aamirali1061a
 
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.pptStack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
Ad

Recently uploaded (20)

Brandon Flatley - A Skilled Musician
Brandon Flatley - A Skilled MusicianBrandon Flatley - A Skilled Musician
Brandon Flatley - A Skilled Musician
Brandon Flatley
 
Olga Baranets: AI Doesn’t Wait for Retros (UA)
Olga Baranets: AI Doesn’t Wait for Retros (UA)Olga Baranets: AI Doesn’t Wait for Retros (UA)
Olga Baranets: AI Doesn’t Wait for Retros (UA)
Lviv Startup Club
 
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
TheoRuby
 
Petslify Turns Pet Photos into Hug-Worthy Memories
Petslify Turns Pet Photos into Hug-Worthy MemoriesPetslify Turns Pet Photos into Hug-Worthy Memories
Petslify Turns Pet Photos into Hug-Worthy Memories
Petslify
 
TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...
TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...
TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...
Kirill Klip
 
Disinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key FindingsDisinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key Findings
MariumAbdulhussein
 
The Peter Cowley Entrepreneurship Event Master 30th.pdf
The Peter Cowley Entrepreneurship Event Master 30th.pdfThe Peter Cowley Entrepreneurship Event Master 30th.pdf
The Peter Cowley Entrepreneurship Event Master 30th.pdf
Richard Lucas
 
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand AwarenessAlec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler
 
Affinity.co Lifecycle Marketing Presentation
Affinity.co Lifecycle Marketing PresentationAffinity.co Lifecycle Marketing Presentation
Affinity.co Lifecycle Marketing Presentation
omiller199514
 
Introduction to MEDDPICC eLearning PDF.pdf
Introduction to MEDDPICC eLearning PDF.pdfIntroduction to MEDDPICC eLearning PDF.pdf
Introduction to MEDDPICC eLearning PDF.pdf
shonkoop
 
Kunal Bansal_ Building More Than Infrastructure in Chandigarh.pdf
Kunal Bansal_ Building More Than Infrastructure in Chandigarh.pdfKunal Bansal_ Building More Than Infrastructure in Chandigarh.pdf
Kunal Bansal_ Building More Than Infrastructure in Chandigarh.pdf
Kunal Bansal Chandigarh
 
Comments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdf
Comments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdfComments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdf
Comments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdf
Brij Consulting, LLC
 
Best Ever Platform To Buy Verified Wise Accounts In 2025.pdf
Best Ever Platform To Buy Verified Wise Accounts In 2025.pdfBest Ever Platform To Buy Verified Wise Accounts In 2025.pdf
Best Ever Platform To Buy Verified Wise Accounts In 2025.pdf
Topvasmm
 
Network Detection and Response (NDR): The Future of Intelligent Cybersecurity
Network Detection and Response (NDR): The Future of Intelligent CybersecurityNetwork Detection and Response (NDR): The Future of Intelligent Cybersecurity
Network Detection and Response (NDR): The Future of Intelligent Cybersecurity
GauriKale30
 
Jonathan Valetta: Leading with Purpose and Financial Knowledge
Jonathan Valetta: Leading with Purpose and Financial KnowledgeJonathan Valetta: Leading with Purpose and Financial Knowledge
Jonathan Valetta: Leading with Purpose and Financial Knowledge
Jonathan Valetta
 
Accounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdf
Accounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdfAccounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdf
Accounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdf
CA Suvidha Chaplot
 
The Five-Year Plan: A Clear Path to Family Business Succession
The Five-Year Plan: A Clear Path to Family Business SuccessionThe Five-Year Plan: A Clear Path to Family Business Succession
The Five-Year Plan: A Clear Path to Family Business Succession
Craig Toberman
 
EquariusAI analytics for business water risk
EquariusAI analytics for business water riskEquariusAI analytics for business water risk
EquariusAI analytics for business water risk
Peter Adriaens
 
TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...
TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...
TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...
Kirill Klip
 
Best 22 Platform To Purchase Verified Coinbase Account In This Year.pdf
Best 22 Platform To Purchase Verified Coinbase Account In This Year.pdfBest 22 Platform To Purchase Verified Coinbase Account In This Year.pdf
Best 22 Platform To Purchase Verified Coinbase Account In This Year.pdf
Topvasmm
 
Brandon Flatley - A Skilled Musician
Brandon Flatley - A Skilled MusicianBrandon Flatley - A Skilled Musician
Brandon Flatley - A Skilled Musician
Brandon Flatley
 
Olga Baranets: AI Doesn’t Wait for Retros (UA)
Olga Baranets: AI Doesn’t Wait for Retros (UA)Olga Baranets: AI Doesn’t Wait for Retros (UA)
Olga Baranets: AI Doesn’t Wait for Retros (UA)
Lviv Startup Club
 
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
TheoRuby
 
Petslify Turns Pet Photos into Hug-Worthy Memories
Petslify Turns Pet Photos into Hug-Worthy MemoriesPetslify Turns Pet Photos into Hug-Worthy Memories
Petslify Turns Pet Photos into Hug-Worthy Memories
Petslify
 
TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...
TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...
TNR Gold Investor Elevator Pitch - Building The Green Energy Metals Royalty a...
Kirill Klip
 
Disinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key FindingsDisinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key Findings
MariumAbdulhussein
 
The Peter Cowley Entrepreneurship Event Master 30th.pdf
The Peter Cowley Entrepreneurship Event Master 30th.pdfThe Peter Cowley Entrepreneurship Event Master 30th.pdf
The Peter Cowley Entrepreneurship Event Master 30th.pdf
Richard Lucas
 
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand AwarenessAlec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler
 
Affinity.co Lifecycle Marketing Presentation
Affinity.co Lifecycle Marketing PresentationAffinity.co Lifecycle Marketing Presentation
Affinity.co Lifecycle Marketing Presentation
omiller199514
 
Introduction to MEDDPICC eLearning PDF.pdf
Introduction to MEDDPICC eLearning PDF.pdfIntroduction to MEDDPICC eLearning PDF.pdf
Introduction to MEDDPICC eLearning PDF.pdf
shonkoop
 
Kunal Bansal_ Building More Than Infrastructure in Chandigarh.pdf
Kunal Bansal_ Building More Than Infrastructure in Chandigarh.pdfKunal Bansal_ Building More Than Infrastructure in Chandigarh.pdf
Kunal Bansal_ Building More Than Infrastructure in Chandigarh.pdf
Kunal Bansal Chandigarh
 
Comments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdf
Comments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdfComments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdf
Comments on Cloud Stream Part II Mobile Hub V1 Hub Agency.pdf
Brij Consulting, LLC
 
Best Ever Platform To Buy Verified Wise Accounts In 2025.pdf
Best Ever Platform To Buy Verified Wise Accounts In 2025.pdfBest Ever Platform To Buy Verified Wise Accounts In 2025.pdf
Best Ever Platform To Buy Verified Wise Accounts In 2025.pdf
Topvasmm
 
Network Detection and Response (NDR): The Future of Intelligent Cybersecurity
Network Detection and Response (NDR): The Future of Intelligent CybersecurityNetwork Detection and Response (NDR): The Future of Intelligent Cybersecurity
Network Detection and Response (NDR): The Future of Intelligent Cybersecurity
GauriKale30
 
Jonathan Valetta: Leading with Purpose and Financial Knowledge
Jonathan Valetta: Leading with Purpose and Financial KnowledgeJonathan Valetta: Leading with Purpose and Financial Knowledge
Jonathan Valetta: Leading with Purpose and Financial Knowledge
Jonathan Valetta
 
Accounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdf
Accounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdfAccounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdf
Accounting_Basics_Complete_Guide_By_CA_Suvidha_Chaplot (1).pdf
CA Suvidha Chaplot
 
The Five-Year Plan: A Clear Path to Family Business Succession
The Five-Year Plan: A Clear Path to Family Business SuccessionThe Five-Year Plan: A Clear Path to Family Business Succession
The Five-Year Plan: A Clear Path to Family Business Succession
Craig Toberman
 
EquariusAI analytics for business water risk
EquariusAI analytics for business water riskEquariusAI analytics for business water risk
EquariusAI analytics for business water risk
Peter Adriaens
 
TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...
TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...
TNR Gold Investor Summary - Building The Green Energy Metals Royalty and Gold...
Kirill Klip
 
Best 22 Platform To Purchase Verified Coinbase Account In This Year.pdf
Best 22 Platform To Purchase Verified Coinbase Account In This Year.pdfBest 22 Platform To Purchase Verified Coinbase Account In This Year.pdf
Best 22 Platform To Purchase Verified Coinbase Account In This Year.pdf
Topvasmm
 
Ad

Data_structures_and_algorithm_Lec_1.pptx

  • 1. DATA STRUCTURES AND ALGORITHM 1 01 1 1 0 2 1 0 3 .0 4 10 5 Q 1 0 6 01 0 7 3 8 01 0 1 0. 1 Qq. 2 qQq 3 1 A1z Dr. Muhammad Idrees
  • 2. 2 Books to Follow  D.S.Malik, “Data Structures using C++”  D.Samanta, “Classic Data Structures”, Prentice Hall  Tenenbaum, M.Augenstein, and Y. Langman, “Data Structures using C and C++”, Prentice Hall.
  • 3. 3 Some General Comments  Encouragement to ask questions during class  Without your feedback, it is impossible for me to know what you don’t know?  There is no reason not to ask questions during class  Of course, you could also send email.  Encouragement to read course material prior to class  Kindly switch off your Mobile Phones during class
  • 4. Introduction to Data Structure 4 A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently
  • 5. Need for Data Structures  Data structures organize data  more efficient programs.  More powerful computers  more complex applications.  More complex applications demand more calculations.
  • 6. Organizing Data  Any organization for a collection of records that can be searched, processed in any order, or modified.  The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days.
  • 7. 7 What is Data Structure?  Data structure is a representation of data and the operations allowed on that data.  A data structure is a way to store and organize data in order to facilitate the access and modifications.  Data Structure is the method of representing of logical relationships between individual data elements related to the solution of a given problem.
  • 8. 8 Fundamental Data Structures Hash Tables Basic Data Structures Linear Data Structures Non-Linear Data Structures Linked Lists Stacks Queues Trees Graphs Arrays
  • 10. 10 Linear Data Structures  A data structure is said to be linear if its elements form a sequence or a linear list.  Examples:  Arrays  Linked Lists  Stacks  Queues
  • 11. 11 Non-Linear Data Structures  A data structure is said to be non-linear if its elements does not form a sequence or a linear list.  Examples:  Trees  Graphs  Hash Tables  Each element may be connected with two or more other nodes or items in a non-linear arrangement.
  • 12. 12 Operations on Data Structures  Traversal: Travel through the data structure  Search: Traversal through the data structure for a given element  Insertion: Adding new elements to the data structure  Deletion: Removing an element from the data structure  Sorting: Arranging the elements in some type of order  Merging: Combining two similar data structures into one
  • 13.  Arrays  Linked List  Stacks  Queues Linear Data Structures 13
  • 14. 14 Arrays  A sequence of n items of the same data type that are stored contiguously in computer memory and made accessible by specifying a value of the array’s index.  Properties:  fixed length (need preliminary reservation of memory)  contiguous memory locations  direct access  Insert/delete a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] 1 2 3 4 5 6 7 8 9 10 Array a with 10 integer elements
  • 15. 15 Linked List  A sequence of zero or more nodes each containing two kinds of information: some data and one or more links called pointers to other nodes of the linked list.  Properties  dynamic length  arbitrary memory locations  access by following links  Insert/delete  Types of Linked List  Singly linked list (next pointer)  Doubly linked list (next + previous pointers)
  • 16. 16 Stacks  A stack is a data structure that uses last-in, first-out (LIFO) ordering and allows reading and writing on the top element only.  Properties  insertion/deletion can be done only at the top  LIFO  Two operations  Push (insertion)  Pop (removal)
  • 17. 17 Queues  Collection with access only to the item that has been present the longest  Properties  Insertion/enqueue from the rear (back) and deletion/ dequeue from the front.  FIFO  Two operations  Enqueue  Dequeue 20 30 10 60 57 29 Front Back
  • 18.  Graphs  Trees  Hash Tables Non-Linear Data Structures 18
  • 19. 19 Graphs  Formal definition: A graph G = <V, E> is defined by a pair of two sets: a finite set V of items called vertices and a set E of vertex pairs called edges.  Undirected and directed graphs (digraphs).  Complete, dense, and sparse graphs Undirected Graph Directed Graph
  • 20. 20 Trees  A Tree is a way of representing the hierarchical nature of a structure in a graphical form.  Properties of trees  Root Node  Child Node  Parent Node  Leaf Node  Types  Unordered Tree  Binary Tree is an ordered tree data structure in which each node has at most two children. Ordered Tree Binary Tree
  • 21. 21 Hash Tables  A hash table is a data structure that uses a hash function to map identifying values, known as keys (e.g., a person's name), to their associated values.
  • 22. 22 Summary  A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.  Linear Data Structures  Arrays  Linked List  Stacks  Queues  Non Linear Data Structures  Graphs  Trees  Hash Tables
  • 23. Selecting a Data Structure Select a data structure as follows: 1. Analyze the problem to determine the resource constraints a solution must meet. 2. Determine the basic operations that must be supported. Quantify the resource constraints for each operation. 3. Select the data structure that best meets these requirements.
  • 24. Data Structure Philosophy  Each data structure has costs and benefits.  Rarely is one data structure better than another in all situations.  A data structure requires:  space for each data item it stores,  time to perform each basic operation,  programming effort.
  • 25. A precise rule (or set of rules) specifying how to solve some problem. Introduction to Algorithms 25
  • 26. 26 What is an Algorithm?  An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.  Properties  Can be represented various forms  Unambiguity/clearness  Effectiveness  Finiteness/termination  Correctness
  • 27. 27 What is an Algorithm?  Recipe, process, method, technique, procedure, routine,… with the following requirements: 1. Finiteness  terminates after a finite number of steps 2. Definiteness  rigorously and unambiguously specified 3. Clearly specified input  valid inputs are clearly specified 4. Clearly specified/expected output  can be proved to produce the correct output given a valid input 5. Effectiveness  steps are sufficiently simple and basic
  • 28. 28 Why Study Algorithms?  Algorithms solve problems  Good choice: more efficient programs  Bad choice: poor programs performance  Example:  Problem: Find the largest element ‘k’ out of ‘N’ integers  Easy algorithms: sort all integers, then list the first or last element  Better algorithm: take first element then read through the list  Different algorithms perform better on different inputs  Input size also affect the performance.
  • 29. 29 Notion of Algorithm and Problem “Computer” Problem Algorithm Input Output
  • 30. 30 Representation of an Algorithms  An algorithm may be represented in different forms:  A description using English/other languages  A real computer program, e.g. C++ or java  A pseudo-code, C-like program, program-language- like program.  Program = algorithms + data structures
  • 31. 31 Basic Issues Related to Algorithms  How to design algorithms  How to express algorithms  Proving correctness  Efficiency (or complexity) analysis  Theoretical analysis  Empirical analysis  Optimality
  • 32. 32 Analysis of Algorithms  How good is the algorithm?  Correctness  Time efficiency  Space efficiency
  • 33. 33 Algorithm Efficiency  There are often many algorithms for a given problem. How do we choose the best?  Goals of program design:  Algorithm is to be easy to understand, code, debug  Algorithm makes efficient use of computer’s resources  How to measure the efficiency?  Empirical comparison (run the program)  Asymptotic algorithm analysis (without running the program)  Factors affecting running time (size of the input)
  • 34. 34 Best, Worst and Average Cases  Not all inputs of a given size take the same time.  Each algorithm has three cases:  Best case:  Worst Case:  Average Case:
  • 35. 35 Example: Best, Worst and Average Cases  Sequential search for ‘k’ in an array of ‘n’ integers:  Best case: ‘k’ is the first element of the array.  Worst case: the search must visit every element once. This happens when the value being searched for is either the last element in the list, or is not in the list  Average case: on average, assuming the value searched for is in the list and each list element is equally likely to be the value searched for, the search visits only n/2 elements.