SlideShare a Scribd company logo
Data Structures and Algorithms
(CoSc2092)
Chapter contents
▪Introduction to Data structures
✓Classification of data structure
✓Abstract Data Types
✓Abstraction
▪Algorithms
✓Properties of algorithms
✓Algorithm Analysis Concept
✓Complexity Analysis
▪Asymptotic analysis
2
Introduction
▪What is Data Structure?
✓It is a set of procedures to define, store, access and manipulate data
✓It is the organized collection of data
✓It is the logical or mathematical model of a particular organization
of data
▪ Program = Data Structure + Algorithm
✓Data Structure is the way data is organized in a computer’s memory so
that it can be used effectively and efficiently.
✓Algorithm is the sequence of computational steps to solve a problem.
▪Data Structure is a language construct that the programmer has
defined in order to implement an abstract data type.
3
The easiest way to understand DS
▪Let’s understand Data structure with the help of real Life
▪Examples:
✓In dictionary, words are arranged alphabetically in a dictionary.
You can quickly and efficiently search and discover a term.
✓A business cash-in-cash-out statement. Much as certain data
structures, it is straightforward to aggregate and extract data in
orderly columns.
4
Why Data Structure is Important?
▪Data structures organize data => more efficient programs.
▪ More powerful computers => more complex applications.
▪ More complex applications demand more calculations.
▪ Complex computing tasks are unlike our everyday experience
▪ The choice of data structure and algorithm can make the
difference between a program running in a few seconds or many
days.
▪ You can not do anything without data on the world.
5
Why Data Structure is Important?
▪ Computer Science deal with storing, organizing and retrieving data
effectively.
▪ Computer Programmer should get data from user or another sources and use
them.
▪ It is essential ingredient in creating fast and powerful algorithms.
▪ For this purpose you have to use data structure for every software program or
system.
▪ 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.
6
Classifications Data Structure
▪ There are two types of data structure available for the programming purpose:
✓Primitive data structure: is a fundamental type of data structure that stores the data of
only one type .
✓Non-primitive data structure: is a type of data structure which is a user-defined that
stores the data of different types in a single entity.
7
Abstraction
▪ It is an abstraction of a data structure that provides only the interface to
which the data structure must adhere.
▪ The interface does not give any specific details about something should be
implemented or in what programming language.
▪ Abstraction: It is a technique of hiding the internal details from the user and
only showing the necessary details to the user.
▪ Encapsulation: It is a technique of combining the data and the member
function in a single unit is known as encapsulation.
8
What is Abstract Data Type?
▪An Abstract Data Type is composed of:
✓A collection of data / set of values
✓A set of operations on data
▪Specification of ADT indicate
✓What the ADT operations do, not how to implement them
▪Implementation of an ADT
✓Includes choosing a particular data structure
✓DS is a constructor that can be defined in a programming language to
store a collection of data.
9
What is ADT?
▪ADT consists of an abstract data structure and operations
▪Specifies:
✓What can be stored in the ADT
✓What operations can be done on/by the ADT
▪E.g. if we are going to model employees of an organization:
✓ADT stores employees with
• their relevant attributes and
• discarding irrelevant attributes.
✓ADT supports
• hiring, firing, retiring, … operations.
▪ An ADT tells what is to be done and data structure tells how it is to be
done.
▪ In other words, we can say that ADT gives us the blueprint while data
structure provides the implementation part.
10
What is ADT?
11
What is ADT?
▪There are lots of formalized and standard Abstract data types
✓such as Stacks, Queues, Trees, etc.
12
What is Algorithm?
▪It is a process or a set of rules required to perform calculations or
some other problem-solving operations especially by a computer.
▪The formal definition:
✓It contains the finite set of instructions which are being carried in a
specific order to perform the specific task.
✓It is not the complete program or code; it is just a solution (logic) of a
problem, which can be represented either as an informal description
using a Flowchart or Pseudocode.
13
Properties of an Algorithm
▪ The following are the characteristics of an algorithm:
✓ Input
✓ Output
✓ Finiteness
✓ Definiteness
✓ Sequence
✓ Feasibility
✓ Correctness
✓ Language Independent
14
Why do we need Algorithms?
▪We need algorithms because of the following reasons:
✓Scalability:
• It helps us to understand the scalability.
• When we have a big real-world problem, we need to scale it down into small-
small steps to easily analyze the problem.
✓Performance:
• The real-world is not easily broken down into smaller steps.
• If the problem can be easily broken into smaller steps means that the problem is
feasible.
15
Importance of Algorithms
▪Theoretical importance:
✓When any real-world problem is given to us and we break the problem into
small-small modules.
✓To break down the problem, we should know all the theoretical aspects.
▪Practical importance:
✓As we know that theory cannot be completed without the practical
implementation.
✓So, the importance of algorithm can be considered as both theoretical and
practical.
▪Issues of Algorithms
▪ The following are the issues that come while designing an algorithm:
✓How to design algorithms
✓How to analyze algorithm efficiency
16
Algorithm Analysis Concept
▪ It refers to the process of determining the amount of computing time and
storage space required by different algorithms.
▪ It is a process of predicting the resource requirement of algorithms in a
given environment.
▪ Main resources are:
✓Running Time
✓Memory Usage
✓Communication Bandwidth
17
Algorithm Analysis
▪The algorithm can be analyzed in two levels
✓First is before creating the algorithm and
✓Second is after creating the algorithm.
▪ The following are the two analysis of an algorithm:
✓Priori Analysis:
• Theoretical analysis of an algorithm which is done before implementing
the algorithm. Various factors can be considered before implementing the
algorithm like processor speed, which has no effect on the implementation
part.
✓Posterior Analysis:
• practical analysis of an algorithm.
• The practical analysis is achieved by implementing the algorithm using any
programming language.
• This analysis basically evaluate that how much running time and space
taken by the algorithm.
18
Complexity Analysis of Algorithm
▪ Complexity Analysis of Algorithm is the systematic study of the cost of
computation measured either:
✓in time units or
✓in operations performed, or
✓in the amount of storage space required
▪ The goal is to have a meaningful measure that permits comparison of
algorithms independent of operating platform.
19
Complexity Analysis of Algorithm
▪The performance of the algorithm can be measured in two factors:
✓Time complexity:
• The amount of time required to complete the execution.
• Is denoted by the big O notation. Here, big O notation is the asymptotic
notation to represent the time complexity.
• Is mainly calculated by counting the number of steps to finish the
execution.
✓Space complexity:
• The amount of space required to solve a problem and produce an output.
• Similar to the time complexity, space complexity is also expressed in big O
notation.
20
How to measure the efficiency of algorithms?
▪There are two approaches, Empirical & Theoretical.
▪Empirical:
✓competing algorithms and trying them on different instances.
▪Theoretical:
✓Determining the quantity of resources required mathematically
(Execution time, memory space, etc.) needed by each algorithm
▪However, it is difficult to use actual clock-time as a consistent
measure of an algorithm‘s efficiency, because clock-time can vary
based on many things. For example:
✓Specific processor speed, Current processor load
✓Specific data for a particular run of the program (Input Size, Input
Properties)
✓Operating Environment 21
Cont...
▪An algorithm’s performance depends on internal and external
factors.
▪Internal:
✓The algorithm’s efficiency, in terms of:
• Time required to run
• Space (memory storage) required to run
▪External:
✓The algorithm’s efficiency, in terms of:
• Size of the input to the algorithm
• Speed of the computer on which it is run
• Quality of the compiler
22
Cont...
▪What metric should be used to judge performance of an algorithms?
✓Length of the program (lines of code)
✓Ease of programming (bugs, maintenance)
✓Memory required
✓Running time
▪Running time is the dominant standard.
✓Quantifiable and easy to compare
▪An algorithm may run differently depending on:
✓The hardware platform (PC, processor speed)
✓The programming language (C, Java, C++)
✓The programmer (you, me)
23
Phases of Complexity analysis
▪Complexity analysis involves two distinct phases.
▪Algorithm Analysis:
✓Analysis of the algorithm or data structure to produce a function T(n)
that describes the algorithm in terms of the operations performed in order
to measure the complexity of the algorithm.
▪Order of Magnitude Analysis:
✓Analysis of the function T(n) to determine the general complexity
category to which it belongs.
24
Complexity analysis Rules
▪We assume an arbitrary time unit.
▪Execution of one of the following operations takes time 1:
✓Assignment Operation
✓Single Input/output Operation
✓Single Boolean Operations
✓Single Arithmetic Operations
✓Function Return
25
Cont...
▪Running time of a selection statement (if, switch)is:
✓The time for the condition evaluation + The maximum of the running times
for the individual clauses in the selection.
▪Loops:
✓Running time for a loop is equal to:
• The running time for the statements inside the loop * number of iterations.
✓The total running time of a statement inside a group of nested loops is:
• The running time of the statements multiplied by the product of the sizes of all
the loops.
✓For nested loops, analyze inside out.
✓Always assume that the loop executes the maximum number of iterations
possible.
▪Running time of a function call is:
✓1 for setup + the time for any parameter calculations + the time required
for the execution of the function body.
26
Example
27
void func()
{
int x=0;
int i=0;
int j=1;
cout<<"Enter an Integer value";
cin>>n;
while (i<n)
{ x++;
i++;
}
while (j<n)
{ j++;
}
}
Time Units to Compute
-------------------------------------------------
1 for the first assignment statement: x=0;
1 for the second assignment statement: i=0;
1 for the third assignment statement: j=1;
1 for the output statement.
1 for the input statement.
In the first while loop:
n+1 tests
n loops of 2 units for the two increment (addition)
operations
In the second while loop:
n tests
n-1 increments
-------------------------------------------------------
T (n)= 1+1+1+1+1+n+1+2n+n+n-1 = 5n+5 = O(n)
???
Next class…
28
Asymptotic Analysis
▪While checking the running time for any algorithm, we want three
things:
✓The algorithm should be machine-independent.
✓It should work on all possible inputs.
✓It should be general and not programming language-specific.
▪However, we never do accurate analysis, rather we do approximate
analysis. We are interested in the increase in the running time with
the increase in the input size.
▪Thus, we are only interested in the ‘growth of the function’, which
we can measure/analyses through asymptotic analysis.
29
Asymptotic Analysis
▪The term asymptotic means approaching a value or curve
arbitrarily closely (i.e., as some sort of limit is taken).
▪Asymptotic analysis:
✓It is a general methodology to compare or to find the efficiency of any
algorithm.
✓We measure the efficiency in terms of the growth of the function.
• The growth of any function depends on how much the running time is increasing
with the increase in the size of the input.
▪Asymptotic analysis of an algorithm refers to defining the
mathematical boundary of its run-time performance.
30
Asymptotic Analysis
▪The time required by an algorithm falls under three types.
✓Best Case:
• Minimum time required for program execution.
✓Average Case:
• Average time required for program execution.
✓Worst Case
• Maximum time required for program execution.
31
Asymptotic Notation
▪Asymptotic Notation:
✓Whenever we want to perform analysis of an algorithm, we need to
calculate the complexity of that algorithm.
✓But when we calculate the complexity of an algorithm it does not provide
the exact amount of resource required.
✓So instead of taking the exact amount of resource, we represent that
complexity in a general form (Notation) which produces the basic nature
of that algorithm.
✓We use that general form (Notation) for analysis process.
✓So asymptotic notation is a language that allow us to analyze an
algorithm's running time by identifying its behavior as the input size for
the algorithm increases.
✓It is a mathematical representation of its complexity.
32
Asymptotic Notation
▪In asymptotic notation:
✓When we want to represent the complexity of an algorithm, we use only
the most significant terms in the complexity of that algorithm and ignore
least significant terms in the complexity of that algorithm
• Here, complexity can be Space Complexity or Time Complexity.
▪Example: T(n) = ck nk + ck-1 nk-1 + ck-2 nk-2 + … + c1n + co
✓too complicated
✓too many terms
✓Difficult to compare two expressions, each with 10 or 20 terms
▪Do we really need that many terms?
33
Asymptotic Notation
▪ Keep just one term!
✓the fastest growing term (dominates the runtime)
▪ No constant coefficients are kept
✓Constant coefficients affected by machines, languages, etc.
▪ Asymptotic behavior (as n gets large) is determined entirely by the leading
term.
✓Example. T(n) = 10n3 + n2 + 40n + 800
• If n = 1,000, then T(n) = 10,001,040,800
• error is 0.01% if we drop all but the n3 term leading term.
34
Asymptotic Notation
35
▪Majorly we use three types of asymptotic notations to represent
the complexity of an algorithms.
Asymptotic Notation
▪Big-Oh Notation (O):
✓is used to define the upper bound of an algorithm in terms of Time
Complexity.
✓is always indicates the maximum time required by an algorithm for all
input values.
✓is describes the worst case of an algorithm time complexity.
▪Consider function f(n) as time complexity of an algorithm and g(n)
is the most significant term.
✓If f(n) <= c.g(n) for all n >= n0, c > 0 and n0 >= 1.
✓Then we can represent f(n) as O(g(n)).
✓f(n)=O(g(n))
36
Asymptotic Notation
▪ Example:
▪ Consider the following f(n) and g(n)
✓f(n) = 3n + 2
✓g(n) = n
▪ If we want to represent f(n) as O(g(n)) then it must satisfy
✓f(n) <= c.g(n) for all n >= n0, c > 0 and n0 >= 1
✓f(n) <= c.g(n) ⇒3n + 2 <= cn
▪ Above condition is always TRUE for all values of
✓c = 4 and n >= 2.
▪ By using Big - Oh notation we can represent the time complexity as follows...
✓3n + 2 = O(n)
37
Asymptotic Notation
▪Big-Omega Notation (Ω):
✓ is used to define the lower bound of an algorithm in terms of Time
Complexity.
✓is always indicates the minimum time required by an algorithm for all
input values.
✓describes the best case of an algorithm time complexity.
▪Consider function f(n) as time complexity of an algorithm and g(n)
is the most significant term.
✓If f(n) >= c.g(n) for all n >= n0, c > 0 and n0 >= 1.
✓Then we can represent f(n) as Ω(g(n)).
✓f(n) = Ω(g(n))
38
Asymptotic Notation
▪ Example:
▪ Consider the following f(n) and g(n)
✓f(n) = 3n + 2
✓g(n) = n
▪ If we want to represent f(n) as Ω(g(n)) then it must satisfy
✓f(n) >= c.g(n) for all values of c > 0 and n0>= 1
✓f(n) >= c.g(n) ⇒3n + 2 >= C n
▪ Above condition is always TRUE for all values of
✓c = 1 and n >= 1.
▪ By using Big - Omega notation we can represent the time complexity as
follows
✓3n + 2 = Ω(n)
39
Asymptotic Notation
▪Big-Theta Notation (Θ):
✓is used to define the average bound of an algorithm in terms of Time
Complexity.
✓is always indicates the average time required by an algorithm for all input
values.
✓is describes the average case of an algorithm time complexity.
▪Consider function f(n) as time complexity of an algorithm and g(n)
is the most significant term.
✓If c1.g(n) <= f(n) <= c2. g(n) for all n >= n0, c1 > 0, c2 > 0 and n0 >= 1.
✓Then we can represent f(n) as Θ(g(n)).
✓f(n) = Θ(g(n))
40
Asymptotic Notation
▪ Example:
▪ Consider the following f(n) and g(n).
✓f(n) = 3n + 2
✓g(n) = n
▪ If we want to represent f(n) as Θ(g(n)) then it must satisfy
✓c1.g(n) <= f(n) <= c2.g(n) for all values of c1 > 0, c2 > 0 and n0>= 1
✓c1.g(n) <= f(n) <= c2.g(n) ⇒ c1n <= 3n + 2 <= c2n
▪ Above condition is always TRUE for all values of
✓c1 = 1, c2 = 4 and n >= 2.
▪ By using Big - Theta notation we can represent the time complexity as
follows.
✓3n + 2 = Θ(n)
41
End of Chapter!

More Related Content

Similar to Data structure and algorithm Chapter_1.pdf

Introduction of data_structure
Introduction of data_structureIntroduction of data_structure
Introduction of data_structureeShikshak
 
Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Jay Patel
 
part 1 - intorduction data structure 2021 mte.ppt
part 1 -  intorduction data structure  2021 mte.pptpart 1 -  intorduction data structure  2021 mte.ppt
part 1 - intorduction data structure 2021 mte.ppt
abdoSelem1
 
Clean architecture
Clean architectureClean architecture
Clean architecture
.NET Crowd
 
Result processing system (Project)
Result processing system (Project) Result processing system (Project)
Result processing system (Project)
Pritam Shil
 
ORACLE 12C-New-Features
ORACLE 12C-New-FeaturesORACLE 12C-New-Features
ORACLE 12C-New-FeaturesNavneet Upneja
 
CH-1.2 Performance analysis for mca.pptx
CH-1.2 Performance analysis for mca.pptxCH-1.2 Performance analysis for mca.pptx
CH-1.2 Performance analysis for mca.pptx
shivam7050174471
 
Structured Data Extraction
Structured Data ExtractionStructured Data Extraction
Structured Data Extraction
KaustubhPatange2
 
Data structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdfData structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdf
DukeCalvin
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Daniel Zivkovic
 
Unit 1 abstract data types
Unit 1 abstract data typesUnit 1 abstract data types
Unit 1 abstract data types
LavanyaJ28
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
SayedMohdAsim2
 
Spring batch overivew
Spring batch overivewSpring batch overivew
Spring batch overivew
Chanyeong Choi
 
Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)
MUHAMMAD AAMIR
 
data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance
Anaya Zafar
 
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptxMOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
mh3473
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
Abdul salam
 

Similar to Data structure and algorithm Chapter_1.pdf (20)

Introduction of data_structure
Introduction of data_structureIntroduction of data_structure
Introduction of data_structure
 
Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01
 
part 1 - intorduction data structure 2021 mte.ppt
part 1 -  intorduction data structure  2021 mte.pptpart 1 -  intorduction data structure  2021 mte.ppt
part 1 - intorduction data structure 2021 mte.ppt
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Result processing system (Project)
Result processing system (Project) Result processing system (Project)
Result processing system (Project)
 
data structure
data structuredata structure
data structure
 
ORACLE 12C-New-Features
ORACLE 12C-New-FeaturesORACLE 12C-New-Features
ORACLE 12C-New-Features
 
CH-1.2 Performance analysis for mca.pptx
CH-1.2 Performance analysis for mca.pptxCH-1.2 Performance analysis for mca.pptx
CH-1.2 Performance analysis for mca.pptx
 
Structured Data Extraction
Structured Data ExtractionStructured Data Extraction
Structured Data Extraction
 
Data structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdfData structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdf
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
 
Unit 1 abstract data types
Unit 1 abstract data typesUnit 1 abstract data types
Unit 1 abstract data types
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
Spring batch overivew
Spring batch overivewSpring batch overivew
Spring batch overivew
 
Lec1
Lec1Lec1
Lec1
 
Lec1
Lec1Lec1
Lec1
 
Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)
 
data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance
 
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptxMOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
 

Recently uploaded

在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 

Recently uploaded (20)

在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 

Data structure and algorithm Chapter_1.pdf

  • 1. Data Structures and Algorithms (CoSc2092)
  • 2. Chapter contents ▪Introduction to Data structures ✓Classification of data structure ✓Abstract Data Types ✓Abstraction ▪Algorithms ✓Properties of algorithms ✓Algorithm Analysis Concept ✓Complexity Analysis ▪Asymptotic analysis 2
  • 3. Introduction ▪What is Data Structure? ✓It is a set of procedures to define, store, access and manipulate data ✓It is the organized collection of data ✓It is the logical or mathematical model of a particular organization of data ▪ Program = Data Structure + Algorithm ✓Data Structure is the way data is organized in a computer’s memory so that it can be used effectively and efficiently. ✓Algorithm is the sequence of computational steps to solve a problem. ▪Data Structure is a language construct that the programmer has defined in order to implement an abstract data type. 3
  • 4. The easiest way to understand DS ▪Let’s understand Data structure with the help of real Life ▪Examples: ✓In dictionary, words are arranged alphabetically in a dictionary. You can quickly and efficiently search and discover a term. ✓A business cash-in-cash-out statement. Much as certain data structures, it is straightforward to aggregate and extract data in orderly columns. 4
  • 5. Why Data Structure is Important? ▪Data structures organize data => more efficient programs. ▪ More powerful computers => more complex applications. ▪ More complex applications demand more calculations. ▪ Complex computing tasks are unlike our everyday experience ▪ The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days. ▪ You can not do anything without data on the world. 5
  • 6. Why Data Structure is Important? ▪ Computer Science deal with storing, organizing and retrieving data effectively. ▪ Computer Programmer should get data from user or another sources and use them. ▪ It is essential ingredient in creating fast and powerful algorithms. ▪ For this purpose you have to use data structure for every software program or system. ▪ 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. 6
  • 7. Classifications Data Structure ▪ There are two types of data structure available for the programming purpose: ✓Primitive data structure: is a fundamental type of data structure that stores the data of only one type . ✓Non-primitive data structure: is a type of data structure which is a user-defined that stores the data of different types in a single entity. 7
  • 8. Abstraction ▪ It is an abstraction of a data structure that provides only the interface to which the data structure must adhere. ▪ The interface does not give any specific details about something should be implemented or in what programming language. ▪ Abstraction: It is a technique of hiding the internal details from the user and only showing the necessary details to the user. ▪ Encapsulation: It is a technique of combining the data and the member function in a single unit is known as encapsulation. 8
  • 9. What is Abstract Data Type? ▪An Abstract Data Type is composed of: ✓A collection of data / set of values ✓A set of operations on data ▪Specification of ADT indicate ✓What the ADT operations do, not how to implement them ▪Implementation of an ADT ✓Includes choosing a particular data structure ✓DS is a constructor that can be defined in a programming language to store a collection of data. 9
  • 10. What is ADT? ▪ADT consists of an abstract data structure and operations ▪Specifies: ✓What can be stored in the ADT ✓What operations can be done on/by the ADT ▪E.g. if we are going to model employees of an organization: ✓ADT stores employees with • their relevant attributes and • discarding irrelevant attributes. ✓ADT supports • hiring, firing, retiring, … operations. ▪ An ADT tells what is to be done and data structure tells how it is to be done. ▪ In other words, we can say that ADT gives us the blueprint while data structure provides the implementation part. 10
  • 12. What is ADT? ▪There are lots of formalized and standard Abstract data types ✓such as Stacks, Queues, Trees, etc. 12
  • 13. What is Algorithm? ▪It is a process or a set of rules required to perform calculations or some other problem-solving operations especially by a computer. ▪The formal definition: ✓It contains the finite set of instructions which are being carried in a specific order to perform the specific task. ✓It is not the complete program or code; it is just a solution (logic) of a problem, which can be represented either as an informal description using a Flowchart or Pseudocode. 13
  • 14. Properties of an Algorithm ▪ The following are the characteristics of an algorithm: ✓ Input ✓ Output ✓ Finiteness ✓ Definiteness ✓ Sequence ✓ Feasibility ✓ Correctness ✓ Language Independent 14
  • 15. Why do we need Algorithms? ▪We need algorithms because of the following reasons: ✓Scalability: • It helps us to understand the scalability. • When we have a big real-world problem, we need to scale it down into small- small steps to easily analyze the problem. ✓Performance: • The real-world is not easily broken down into smaller steps. • If the problem can be easily broken into smaller steps means that the problem is feasible. 15
  • 16. Importance of Algorithms ▪Theoretical importance: ✓When any real-world problem is given to us and we break the problem into small-small modules. ✓To break down the problem, we should know all the theoretical aspects. ▪Practical importance: ✓As we know that theory cannot be completed without the practical implementation. ✓So, the importance of algorithm can be considered as both theoretical and practical. ▪Issues of Algorithms ▪ The following are the issues that come while designing an algorithm: ✓How to design algorithms ✓How to analyze algorithm efficiency 16
  • 17. Algorithm Analysis Concept ▪ It refers to the process of determining the amount of computing time and storage space required by different algorithms. ▪ It is a process of predicting the resource requirement of algorithms in a given environment. ▪ Main resources are: ✓Running Time ✓Memory Usage ✓Communication Bandwidth 17
  • 18. Algorithm Analysis ▪The algorithm can be analyzed in two levels ✓First is before creating the algorithm and ✓Second is after creating the algorithm. ▪ The following are the two analysis of an algorithm: ✓Priori Analysis: • Theoretical analysis of an algorithm which is done before implementing the algorithm. Various factors can be considered before implementing the algorithm like processor speed, which has no effect on the implementation part. ✓Posterior Analysis: • practical analysis of an algorithm. • The practical analysis is achieved by implementing the algorithm using any programming language. • This analysis basically evaluate that how much running time and space taken by the algorithm. 18
  • 19. Complexity Analysis of Algorithm ▪ Complexity Analysis of Algorithm is the systematic study of the cost of computation measured either: ✓in time units or ✓in operations performed, or ✓in the amount of storage space required ▪ The goal is to have a meaningful measure that permits comparison of algorithms independent of operating platform. 19
  • 20. Complexity Analysis of Algorithm ▪The performance of the algorithm can be measured in two factors: ✓Time complexity: • The amount of time required to complete the execution. • Is denoted by the big O notation. Here, big O notation is the asymptotic notation to represent the time complexity. • Is mainly calculated by counting the number of steps to finish the execution. ✓Space complexity: • The amount of space required to solve a problem and produce an output. • Similar to the time complexity, space complexity is also expressed in big O notation. 20
  • 21. How to measure the efficiency of algorithms? ▪There are two approaches, Empirical & Theoretical. ▪Empirical: ✓competing algorithms and trying them on different instances. ▪Theoretical: ✓Determining the quantity of resources required mathematically (Execution time, memory space, etc.) needed by each algorithm ▪However, it is difficult to use actual clock-time as a consistent measure of an algorithm‘s efficiency, because clock-time can vary based on many things. For example: ✓Specific processor speed, Current processor load ✓Specific data for a particular run of the program (Input Size, Input Properties) ✓Operating Environment 21
  • 22. Cont... ▪An algorithm’s performance depends on internal and external factors. ▪Internal: ✓The algorithm’s efficiency, in terms of: • Time required to run • Space (memory storage) required to run ▪External: ✓The algorithm’s efficiency, in terms of: • Size of the input to the algorithm • Speed of the computer on which it is run • Quality of the compiler 22
  • 23. Cont... ▪What metric should be used to judge performance of an algorithms? ✓Length of the program (lines of code) ✓Ease of programming (bugs, maintenance) ✓Memory required ✓Running time ▪Running time is the dominant standard. ✓Quantifiable and easy to compare ▪An algorithm may run differently depending on: ✓The hardware platform (PC, processor speed) ✓The programming language (C, Java, C++) ✓The programmer (you, me) 23
  • 24. Phases of Complexity analysis ▪Complexity analysis involves two distinct phases. ▪Algorithm Analysis: ✓Analysis of the algorithm or data structure to produce a function T(n) that describes the algorithm in terms of the operations performed in order to measure the complexity of the algorithm. ▪Order of Magnitude Analysis: ✓Analysis of the function T(n) to determine the general complexity category to which it belongs. 24
  • 25. Complexity analysis Rules ▪We assume an arbitrary time unit. ▪Execution of one of the following operations takes time 1: ✓Assignment Operation ✓Single Input/output Operation ✓Single Boolean Operations ✓Single Arithmetic Operations ✓Function Return 25
  • 26. Cont... ▪Running time of a selection statement (if, switch)is: ✓The time for the condition evaluation + The maximum of the running times for the individual clauses in the selection. ▪Loops: ✓Running time for a loop is equal to: • The running time for the statements inside the loop * number of iterations. ✓The total running time of a statement inside a group of nested loops is: • The running time of the statements multiplied by the product of the sizes of all the loops. ✓For nested loops, analyze inside out. ✓Always assume that the loop executes the maximum number of iterations possible. ▪Running time of a function call is: ✓1 for setup + the time for any parameter calculations + the time required for the execution of the function body. 26
  • 27. Example 27 void func() { int x=0; int i=0; int j=1; cout<<"Enter an Integer value"; cin>>n; while (i<n) { x++; i++; } while (j<n) { j++; } } Time Units to Compute ------------------------------------------------- 1 for the first assignment statement: x=0; 1 for the second assignment statement: i=0; 1 for the third assignment statement: j=1; 1 for the output statement. 1 for the input statement. In the first while loop: n+1 tests n loops of 2 units for the two increment (addition) operations In the second while loop: n tests n-1 increments ------------------------------------------------------- T (n)= 1+1+1+1+1+n+1+2n+n+n-1 = 5n+5 = O(n)
  • 29. Asymptotic Analysis ▪While checking the running time for any algorithm, we want three things: ✓The algorithm should be machine-independent. ✓It should work on all possible inputs. ✓It should be general and not programming language-specific. ▪However, we never do accurate analysis, rather we do approximate analysis. We are interested in the increase in the running time with the increase in the input size. ▪Thus, we are only interested in the ‘growth of the function’, which we can measure/analyses through asymptotic analysis. 29
  • 30. Asymptotic Analysis ▪The term asymptotic means approaching a value or curve arbitrarily closely (i.e., as some sort of limit is taken). ▪Asymptotic analysis: ✓It is a general methodology to compare or to find the efficiency of any algorithm. ✓We measure the efficiency in terms of the growth of the function. • The growth of any function depends on how much the running time is increasing with the increase in the size of the input. ▪Asymptotic analysis of an algorithm refers to defining the mathematical boundary of its run-time performance. 30
  • 31. Asymptotic Analysis ▪The time required by an algorithm falls under three types. ✓Best Case: • Minimum time required for program execution. ✓Average Case: • Average time required for program execution. ✓Worst Case • Maximum time required for program execution. 31
  • 32. Asymptotic Notation ▪Asymptotic Notation: ✓Whenever we want to perform analysis of an algorithm, we need to calculate the complexity of that algorithm. ✓But when we calculate the complexity of an algorithm it does not provide the exact amount of resource required. ✓So instead of taking the exact amount of resource, we represent that complexity in a general form (Notation) which produces the basic nature of that algorithm. ✓We use that general form (Notation) for analysis process. ✓So asymptotic notation is a language that allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases. ✓It is a mathematical representation of its complexity. 32
  • 33. Asymptotic Notation ▪In asymptotic notation: ✓When we want to represent the complexity of an algorithm, we use only the most significant terms in the complexity of that algorithm and ignore least significant terms in the complexity of that algorithm • Here, complexity can be Space Complexity or Time Complexity. ▪Example: T(n) = ck nk + ck-1 nk-1 + ck-2 nk-2 + … + c1n + co ✓too complicated ✓too many terms ✓Difficult to compare two expressions, each with 10 or 20 terms ▪Do we really need that many terms? 33
  • 34. Asymptotic Notation ▪ Keep just one term! ✓the fastest growing term (dominates the runtime) ▪ No constant coefficients are kept ✓Constant coefficients affected by machines, languages, etc. ▪ Asymptotic behavior (as n gets large) is determined entirely by the leading term. ✓Example. T(n) = 10n3 + n2 + 40n + 800 • If n = 1,000, then T(n) = 10,001,040,800 • error is 0.01% if we drop all but the n3 term leading term. 34
  • 35. Asymptotic Notation 35 ▪Majorly we use three types of asymptotic notations to represent the complexity of an algorithms.
  • 36. Asymptotic Notation ▪Big-Oh Notation (O): ✓is used to define the upper bound of an algorithm in terms of Time Complexity. ✓is always indicates the maximum time required by an algorithm for all input values. ✓is describes the worst case of an algorithm time complexity. ▪Consider function f(n) as time complexity of an algorithm and g(n) is the most significant term. ✓If f(n) <= c.g(n) for all n >= n0, c > 0 and n0 >= 1. ✓Then we can represent f(n) as O(g(n)). ✓f(n)=O(g(n)) 36
  • 37. Asymptotic Notation ▪ Example: ▪ Consider the following f(n) and g(n) ✓f(n) = 3n + 2 ✓g(n) = n ▪ If we want to represent f(n) as O(g(n)) then it must satisfy ✓f(n) <= c.g(n) for all n >= n0, c > 0 and n0 >= 1 ✓f(n) <= c.g(n) ⇒3n + 2 <= cn ▪ Above condition is always TRUE for all values of ✓c = 4 and n >= 2. ▪ By using Big - Oh notation we can represent the time complexity as follows... ✓3n + 2 = O(n) 37
  • 38. Asymptotic Notation ▪Big-Omega Notation (Ω): ✓ is used to define the lower bound of an algorithm in terms of Time Complexity. ✓is always indicates the minimum time required by an algorithm for all input values. ✓describes the best case of an algorithm time complexity. ▪Consider function f(n) as time complexity of an algorithm and g(n) is the most significant term. ✓If f(n) >= c.g(n) for all n >= n0, c > 0 and n0 >= 1. ✓Then we can represent f(n) as Ω(g(n)). ✓f(n) = Ω(g(n)) 38
  • 39. Asymptotic Notation ▪ Example: ▪ Consider the following f(n) and g(n) ✓f(n) = 3n + 2 ✓g(n) = n ▪ If we want to represent f(n) as Ω(g(n)) then it must satisfy ✓f(n) >= c.g(n) for all values of c > 0 and n0>= 1 ✓f(n) >= c.g(n) ⇒3n + 2 >= C n ▪ Above condition is always TRUE for all values of ✓c = 1 and n >= 1. ▪ By using Big - Omega notation we can represent the time complexity as follows ✓3n + 2 = Ω(n) 39
  • 40. Asymptotic Notation ▪Big-Theta Notation (Θ): ✓is used to define the average bound of an algorithm in terms of Time Complexity. ✓is always indicates the average time required by an algorithm for all input values. ✓is describes the average case of an algorithm time complexity. ▪Consider function f(n) as time complexity of an algorithm and g(n) is the most significant term. ✓If c1.g(n) <= f(n) <= c2. g(n) for all n >= n0, c1 > 0, c2 > 0 and n0 >= 1. ✓Then we can represent f(n) as Θ(g(n)). ✓f(n) = Θ(g(n)) 40
  • 41. Asymptotic Notation ▪ Example: ▪ Consider the following f(n) and g(n). ✓f(n) = 3n + 2 ✓g(n) = n ▪ If we want to represent f(n) as Θ(g(n)) then it must satisfy ✓c1.g(n) <= f(n) <= c2.g(n) for all values of c1 > 0, c2 > 0 and n0>= 1 ✓c1.g(n) <= f(n) <= c2.g(n) ⇒ c1n <= 3n + 2 <= c2n ▪ Above condition is always TRUE for all values of ✓c1 = 1, c2 = 4 and n >= 2. ▪ By using Big - Theta notation we can represent the time complexity as follows. ✓3n + 2 = Θ(n) 41