SlideShare una empresa de Scribd logo
1 de 35
Algorithms

1
Informally Definition
An algorithm is any well-defined
computational procedure that
takes some values or set of
values as input and produces
some values or set of values as
output
Formal Definition
As a sequence of computational
steps that transforms the input
into output
Algorithms
Properties of algorithms:
•
•
•
•
•
•
•

Input from a specified set,
Output from a specified set (solution),
Definiteness of every step in the computation,
Correctness of output for every possible input,
Finiteness of the number of calculation steps,
Effectiveness of each calculation step and
Generality for a class of problems.
4
?
Suppose computers were infinitely fast and
computer memory are free
Is there any reason to study algorithm ?

Yes
– Demonstrate that solution methods
terminates and does so with correct
answer.
If computers were infinitely fast,
any correct method for solving a
problem would do.

You would probably want your
implementation to be within the
bounds
of
good
software
engineering practice
In reality
Computers may be fast, but they
are not infinitely fast and
Memory may be cheap but it is not
free
Computing time is therefore a
bounded resource and so is the
space in memory
Complexity
In general, we are not so much interested
in the time and space complexity for small
inputs.
For example, while the difference in time
complexity between linear and binary
search is meaningless for a sequence with n
= 10, it is gigantic for n = 230.

8
Complexity
For example, let us assume two algorithms A and
B that solve the same class of problems.
The time complexity of A is 5,000n, the one for
B is 1.1n for an input with n elements.
For n = 10, A requires 50,000 steps, but B only
3, so B seems to be superior to A.
For n = 1000, however, A requires 5,000,000
steps, while B requires 2.51041 steps.

9
Complexity
Comparison: time complexity of algorithms A and B
Input Size

Algorithm A

Algorithm B

n

5,000n

10

50,000

1.1n
3

100

500,000

13,781

1,000

5,000,000

2.51041

1,000,000

5109

4.81041392
10
Complexity
This means that algorithm B cannot be used for
large inputs, while algorithm A is still feasible.
So what is important is the growth of the
complexity functions.

The growth of time and space complexity with
increasing input size n is a suitable measure for
the comparison of algorithms.

11
Growth Function
The order of growth / rate of growth
of the running time of an algorithm
gives a simple characterization of the
algorithm efficiency and allow us to
compare the relative performance of
alternative algorithm

12
Asymptotic Efficiency
Algorithm
When the input size is large enough so
that the rate of growth / order of
growth of the running time is relevant

That is we are concerned with how the
running time of an algorithm
increases with the size of the input in
the limit, as the size of the input
increases without bound
13
Asymptotic Efficiency
Algorithm
Usually, an
algorithm that is
asymptotically more efficient will
be the best choice for all but
very small inputs.

14
Asymptotic Notation
The notations we use to describe
the asymptotic running time of an
algorithm are defined in terms of
functions whose domains are the
set of natural numbers N = {0, 1,
2,…. }
15
Asymptotic Notation
Asymptotic
notations
are
convenient for describing the
worst-case running time function
T(n), which is defined only on
integer input size.

16
Asymptotic Notation

Let n be a non-negative integer
representing the size of the
input to an algorithm

17
Asymptotic Notation
Let f(n) and g(n) be two positive
functions,
representing
the
number of basic calculations
(operations, instructions) that an
algorithm takes (or the number
of memory words an algorithm
needs).
18
Asymptotic Notation
Q - Big Theta
O – Big O
W - Big Omega
o – Small o
w - Small Omega
19
Q - Notation
For a given function g(n), we denote
by Q(g(n)) the set of functions

Q(g(n)) = {f(n) : there exist positive
constants c1 , c2 , and n0 such
that 0  c1 g(n)  f(n)  c2 g(n)
for all n  n0
f(n)  Q(g(n))
f(n) = Q(g(n))
20
Q - Notation
g(n) is an
asymptotically tight
bound for f(n).

f(n) and g(n) are

nonnegative, for large
n.

21
Example
Q(g(n)) = {f(n) :  positive constants c1, c2,
and n0, such that n  n0,
0  c1g(n)
 f(n)  c2g(n) }

1/2n2 - 3n = Q(n2)
Determine the positive constant n0,
c1, and c2 such that
c1 n2  1/2n2 - 3n  c2 n2 n  n0
22
Example Contd ...
c1  1/2 – 3/n  c2 (Divide by n2)
c1 = 1/14 , c2 = ½ , n0 = 7
1/2n2 - 3n = Q(n2)
23
O-Notation
For a given function g(n)
O(g(n)) = {f(n) : there exist
positive constants c and n0 such
that 0  f(n)  c g(n) for all n 
n0 }
Intuitively: Set of all functions whose rate of
growth is the same as or lower than that of
c. g(n)
24
O-Notation

g(n) is an asymptotic upper bound for f(n).

f(n) = Q(g(n))  f(n) = O(g(n)).
Q(g(n))  O(g(n)).

25
Example
O(g(n)) = {f(n) : there exist positive
constants c and n0 such that 0  f(n) 
c g(n) for all n  n0 }

Any linear function an + b is in
O(n2). How?
C = a + |b| and n0 = 1
26
Big-O Notation
(Examples)
f(n) = 5n+2 = O(n)

// g(n) = n

–

f(n)  6n, for n  3 (C=6, n0=3)

–

f(n)  0.5 n for n  0 (C=0.5, n0=0)

–

n2-n  n2 for n  0 (C=1, n0=0)

–

n(n+1)/2  n2 for n  0 (C=1, n0=0)

f(n)=n/2 –3 = O(n)

n2-n = O(n2) // g(n) = n2
n(n+1)/2 = O(n2)

27
W - Notation
For a given function g(n)
W(g(n)) = {f(n) : there exist
positive constants c and n0 such
that 0  c g(n)  f(n) for all
n  n0}
Intuitively: Set of all functions whose
rate of growth is the same as or higher
than that of g(n).
28
W - Notation

g(n) is an asymptotic lower bound for f(n).

f(n) = Q(g(n))  f(n) = W(g(n)).
Q(g(n))  W(g(n)).

29
Relations Between Q, O, W

30
Relations Between Q, O, W
For any two function f(n) and g(n),
we have f(n) = Q(g(n)) if and only
if f(n) = O(g(n)) and f(n) =
W(g(n))
That is

Q(g(n)) = O(g(n))  W(g(n))
31
The Growth of Functions
“Popular” functions g(n) are
n log n, 1, 2n, n2, n!, n, n3, log n

Listed from slowest to fastest growth:
• 1
• log n
• n
• n log n
• n2
• n3
• 2n
• n!
32
Comparing Growth Rates
2n

n2

n log2 n
n

T(n)

log2 n

Problem Size
Example: Find sum of array elements
Algorithm arraySum (A, n)
Input array A of n integers
Output Sum of elements of A
sum  0
for i  0 to n  1 do
sum  sum + A [i]
return sum

# operations
1
n+1
n
1

Input size: n (number of array elements)
Total number of steps: 2n + 3
Example: Find max element of an
array
Algorithm arrayMax(A, n)
Input array A of n integers
Output maximum element of A
currentMax  A[0]
for i  1 to n  1 do
if A [i]  currentMax then
currentMax  A [i]
return currentMax



# operations
1
n
n -1
n -1
1

Input size: n (number of array elements)
 Total number of steps: 3n

Más contenido relacionado

La actualidad más candente

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Computer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module iComputer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module iAjit Nayak
 
Specification and complexity - algorithm
Specification and complexity - algorithmSpecification and complexity - algorithm
Specification and complexity - algorithmBipul Roy Bpl
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and ComplexityRajandeep Gill
 
Job sequencing with deadline
Job sequencing with deadlineJob sequencing with deadline
Job sequencing with deadlineArafat Hossan
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.Tariq Khan
 
Lec 2 algorithms efficiency complexity
Lec 2 algorithms efficiency  complexityLec 2 algorithms efficiency  complexity
Lec 2 algorithms efficiency complexityAnaya Zafar
 
Introduction to Data Structures & Algorithms
Introduction to Data Structures & AlgorithmsIntroduction to Data Structures & Algorithms
Introduction to Data Structures & AlgorithmsAfaq Mansoor Khan
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 

La actualidad más candente (20)

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Computer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module iComputer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module i
 
Specification and complexity - algorithm
Specification and complexity - algorithmSpecification and complexity - algorithm
Specification and complexity - algorithm
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Quick sort
Quick sortQuick sort
Quick sort
 
Job sequencing with deadline
Job sequencing with deadlineJob sequencing with deadline
Job sequencing with deadline
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Lec 2 algorithms efficiency complexity
Lec 2 algorithms efficiency  complexityLec 2 algorithms efficiency  complexity
Lec 2 algorithms efficiency complexity
 
Introduction to Data Structures & Algorithms
Introduction to Data Structures & AlgorithmsIntroduction to Data Structures & Algorithms
Introduction to Data Structures & Algorithms
 
Fragmentaton
Fragmentaton Fragmentaton
Fragmentaton
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 

Destacado

Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsAakash deep Singhal
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsAakash deep Singhal
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
Lecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsLecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsAakash deep Singhal
 
Lecture 16 data structures and algorithms
Lecture 16 data structures and algorithmsLecture 16 data structures and algorithms
Lecture 16 data structures and algorithmsAakash deep Singhal
 
Lecture 15 data structures and algorithms
Lecture 15 data structures and algorithmsLecture 15 data structures and algorithms
Lecture 15 data structures and algorithmsAakash deep Singhal
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsAakash deep Singhal
 
Lecture 9 data structures and algorithms
Lecture 9 data structures and algorithmsLecture 9 data structures and algorithms
Lecture 9 data structures and algorithmsAakash deep Singhal
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsAakash deep Singhal
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6Teksify
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsAakash deep Singhal
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computingjayavignesh86
 
Double linked list
Double linked listDouble linked list
Double linked listSayantan Sur
 

Destacado (20)

Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithms
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Lecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsLecture 6 data structures and algorithms
Lecture 6 data structures and algorithms
 
12111 data structure
12111 data structure12111 data structure
12111 data structure
 
Lecture 16 data structures and algorithms
Lecture 16 data structures and algorithmsLecture 16 data structures and algorithms
Lecture 16 data structures and algorithms
 
Lecture 15 data structures and algorithms
Lecture 15 data structures and algorithmsLecture 15 data structures and algorithms
Lecture 15 data structures and algorithms
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
 
Lecture 9 data structures and algorithms
Lecture 9 data structures and algorithmsLecture 9 data structures and algorithms
Lecture 9 data structures and algorithms
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
 
#1 designandanalysis of algo
#1 designandanalysis of algo#1 designandanalysis of algo
#1 designandanalysis of algo
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Slide1
Slide1Slide1
Slide1
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
Subsidence in coal mines
Subsidence in coal minesSubsidence in coal mines
Subsidence in coal mines
 
Data structures1
Data structures1Data structures1
Data structures1
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 

Similar a Lecture 2 data structures and algorithms

Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...DebiPrasadSen
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
 
Asymptotic notation ada
Asymptotic notation adaAsymptotic notation ada
Asymptotic notation adaravinlaheri2
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexityAbbas Ali
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Vai Jayanthi
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm AnalysisMegha V
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notationsajinis3
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptxSunilWork1
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02mansab MIRZA
 
Design and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptDesign and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptsrushtiivp
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2chidabdu
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfShaistaRiaz4
 

Similar a Lecture 2 data structures and algorithms (20)

1.algorithms
1.algorithms1.algorithms
1.algorithms
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Asymptotic notation ada
Asymptotic notation adaAsymptotic notation ada
Asymptotic notation ada
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
analysis.ppt
analysis.pptanalysis.ppt
analysis.ppt
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptx
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
 
Design and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptDesign and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt ppt
 
lecture 1
lecture 1lecture 1
lecture 1
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2
 
Lec1
Lec1Lec1
Lec1
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
DAA_LECT_2.pdf
DAA_LECT_2.pdfDAA_LECT_2.pdf
DAA_LECT_2.pdf
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
 

Último

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Último (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Lecture 2 data structures and algorithms

  • 2. Informally Definition An algorithm is any well-defined computational procedure that takes some values or set of values as input and produces some values or set of values as output
  • 3. Formal Definition As a sequence of computational steps that transforms the input into output
  • 4. Algorithms Properties of algorithms: • • • • • • • Input from a specified set, Output from a specified set (solution), Definiteness of every step in the computation, Correctness of output for every possible input, Finiteness of the number of calculation steps, Effectiveness of each calculation step and Generality for a class of problems. 4
  • 5. ? Suppose computers were infinitely fast and computer memory are free Is there any reason to study algorithm ? Yes – Demonstrate that solution methods terminates and does so with correct answer.
  • 6. If computers were infinitely fast, any correct method for solving a problem would do. You would probably want your implementation to be within the bounds of good software engineering practice
  • 7. In reality Computers may be fast, but they are not infinitely fast and Memory may be cheap but it is not free Computing time is therefore a bounded resource and so is the space in memory
  • 8. Complexity In general, we are not so much interested in the time and space complexity for small inputs. For example, while the difference in time complexity between linear and binary search is meaningless for a sequence with n = 10, it is gigantic for n = 230. 8
  • 9. Complexity For example, let us assume two algorithms A and B that solve the same class of problems. The time complexity of A is 5,000n, the one for B is 1.1n for an input with n elements. For n = 10, A requires 50,000 steps, but B only 3, so B seems to be superior to A. For n = 1000, however, A requires 5,000,000 steps, while B requires 2.51041 steps. 9
  • 10. Complexity Comparison: time complexity of algorithms A and B Input Size Algorithm A Algorithm B n 5,000n 10 50,000 1.1n 3 100 500,000 13,781 1,000 5,000,000 2.51041 1,000,000 5109 4.81041392 10
  • 11. Complexity This means that algorithm B cannot be used for large inputs, while algorithm A is still feasible. So what is important is the growth of the complexity functions. The growth of time and space complexity with increasing input size n is a suitable measure for the comparison of algorithms. 11
  • 12. Growth Function The order of growth / rate of growth of the running time of an algorithm gives a simple characterization of the algorithm efficiency and allow us to compare the relative performance of alternative algorithm 12
  • 13. Asymptotic Efficiency Algorithm When the input size is large enough so that the rate of growth / order of growth of the running time is relevant That is we are concerned with how the running time of an algorithm increases with the size of the input in the limit, as the size of the input increases without bound 13
  • 14. Asymptotic Efficiency Algorithm Usually, an algorithm that is asymptotically more efficient will be the best choice for all but very small inputs. 14
  • 15. Asymptotic Notation The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains are the set of natural numbers N = {0, 1, 2,…. } 15
  • 16. Asymptotic Notation Asymptotic notations are convenient for describing the worst-case running time function T(n), which is defined only on integer input size. 16
  • 17. Asymptotic Notation Let n be a non-negative integer representing the size of the input to an algorithm 17
  • 18. Asymptotic Notation Let f(n) and g(n) be two positive functions, representing the number of basic calculations (operations, instructions) that an algorithm takes (or the number of memory words an algorithm needs). 18
  • 19. Asymptotic Notation Q - Big Theta O – Big O W - Big Omega o – Small o w - Small Omega 19
  • 20. Q - Notation For a given function g(n), we denote by Q(g(n)) the set of functions Q(g(n)) = {f(n) : there exist positive constants c1 , c2 , and n0 such that 0  c1 g(n)  f(n)  c2 g(n) for all n  n0 f(n)  Q(g(n)) f(n) = Q(g(n)) 20
  • 21. Q - Notation g(n) is an asymptotically tight bound for f(n). f(n) and g(n) are nonnegative, for large n. 21
  • 22. Example Q(g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, 0  c1g(n)  f(n)  c2g(n) } 1/2n2 - 3n = Q(n2) Determine the positive constant n0, c1, and c2 such that c1 n2  1/2n2 - 3n  c2 n2 n  n0 22
  • 23. Example Contd ... c1  1/2 – 3/n  c2 (Divide by n2) c1 = 1/14 , c2 = ½ , n0 = 7 1/2n2 - 3n = Q(n2) 23
  • 24. O-Notation For a given function g(n) O(g(n)) = {f(n) : there exist positive constants c and n0 such that 0  f(n)  c g(n) for all n  n0 } Intuitively: Set of all functions whose rate of growth is the same as or lower than that of c. g(n) 24
  • 25. O-Notation g(n) is an asymptotic upper bound for f(n). f(n) = Q(g(n))  f(n) = O(g(n)). Q(g(n))  O(g(n)). 25
  • 26. Example O(g(n)) = {f(n) : there exist positive constants c and n0 such that 0  f(n)  c g(n) for all n  n0 } Any linear function an + b is in O(n2). How? C = a + |b| and n0 = 1 26
  • 27. Big-O Notation (Examples) f(n) = 5n+2 = O(n) // g(n) = n – f(n)  6n, for n  3 (C=6, n0=3) – f(n)  0.5 n for n  0 (C=0.5, n0=0) – n2-n  n2 for n  0 (C=1, n0=0) – n(n+1)/2  n2 for n  0 (C=1, n0=0) f(n)=n/2 –3 = O(n) n2-n = O(n2) // g(n) = n2 n(n+1)/2 = O(n2) 27
  • 28. W - Notation For a given function g(n) W(g(n)) = {f(n) : there exist positive constants c and n0 such that 0  c g(n)  f(n) for all n  n0} Intuitively: Set of all functions whose rate of growth is the same as or higher than that of g(n). 28
  • 29. W - Notation g(n) is an asymptotic lower bound for f(n). f(n) = Q(g(n))  f(n) = W(g(n)). Q(g(n))  W(g(n)). 29
  • 31. Relations Between Q, O, W For any two function f(n) and g(n), we have f(n) = Q(g(n)) if and only if f(n) = O(g(n)) and f(n) = W(g(n)) That is Q(g(n)) = O(g(n))  W(g(n)) 31
  • 32. The Growth of Functions “Popular” functions g(n) are n log n, 1, 2n, n2, n!, n, n3, log n Listed from slowest to fastest growth: • 1 • log n • n • n log n • n2 • n3 • 2n • n! 32
  • 33. Comparing Growth Rates 2n n2 n log2 n n T(n) log2 n Problem Size
  • 34. Example: Find sum of array elements Algorithm arraySum (A, n) Input array A of n integers Output Sum of elements of A sum  0 for i  0 to n  1 do sum  sum + A [i] return sum # operations 1 n+1 n 1 Input size: n (number of array elements) Total number of steps: 2n + 3
  • 35. Example: Find max element of an array Algorithm arrayMax(A, n) Input array A of n integers Output maximum element of A currentMax  A[0] for i  1 to n  1 do if A [i]  currentMax then currentMax  A [i] return currentMax  # operations 1 n n -1 n -1 1 Input size: n (number of array elements)  Total number of steps: 3n