SlideShare a Scribd company logo
o-notation
f(n) becomes insignificant relative to g(n) as n
approaches infinity:
lim [f(n) / g(n)] = 0
n
g(n) is an upper bound for f(n) that is not
asymptotically tight.
Observe the difference in this definition from
previous ones. Why?
o(g(n)) = {f(n):  c > 0,  n0 > 0 such that
 n  n0, we have 0  f(n) < cg(n)}.
For a given function g(n), the set little-o:
• f(n)=3n+2 is o(n2)
• f(n)=17n3 + n2 logn is o(n4)
o-notation
Lecture Notes (Slides, Tutorials)
• http://channeli.iitr.ernet.in/lectut/pages
/final_student.php (intranet)
•https://sites.google.com/site/balaiitr/cs102
(internet)
(g(n)) = {f(n):  c > 0,  n0 > 0 such that
 n  n0, we have 0  cg(n) < f(n)}.
 -notation
f(n) becomes arbitrarily large relative to g(n) as n
approaches infinity:
lim [f(n) / g(n)] = .
n
g(n) is a lower bound for f(n) that is not
asymptotically tight.
For a given function g(n), the set little-omega:
• f(n)=3n+2 is
• f(n)=17n3 + n2 is
 -notation
)
1
(

)
( 2
n

Comparison of Functions
f  g  a  b
f (n) = O(g(n))  a  b
f (n) = (g(n))  a  b
f (n) = (g(n))  a = b
f (n) = o(g(n))  a < b
f (n) = (g(n))  a > b
Limits
• lim [f(n) / g(n)] = 0  f(n)  (g(n))
n
• lim [f(n) / g(n)] <   f(n)  (g(n))
n
• 0 < lim [f(n) / g(n)] <   f(n)  (g(n))
n
• 0 < lim [f(n) / g(n)]  f(n) (g(n))
n
• lim [f(n) / g(n)] =   f(n)  (g(n))
n
• lim [f(n) / g(n)] undefined can’t say
n
All Asymptotic Notations
2
4
3
)
( 2
3



 n
n
n
n
T
n
n
n
T log
16
)
( 

Time Complexity
• We analyze time complexity for
a) A very large input size
b) Worst case scenario
• Rules
a) Drop lower order terms
b) Drop Constant multipliers
Time Complexity Calculation in a
fragment of a code
int a; //Example 1
a=5;
a++;
for (int i=0; i<n; i++)
{Simple statements;}
for (int j=0; j<n;j++)
{
for (int k=0; k<n;k++)
{Simple statements;}
}
)
( 2
n
O
int main() //Example 2
{const int n=100;
int arr[n];
for (int i=0; i<n; i++)
for (int j=0; j<i; j++)
{
some statements;
}
return 0;
}
)
( 2
n
O
//Example 3
sum=0;
for(i=1; i<=n; i++)
for(j=1; j<=n;j*=2)
sum+=1;
)
log
( n
n
O
sum=0;
for(i=1; i<=n; i++)
for(j=1; j<=n;j*=2)
sum+=1;
• Suppose the above algorithm takes 10
seconds to complete for an input size of 256.
How large a problem (algorithm) can be
solved in 40 minutes?
const int n=100; //Example 4
int main()
{
for (int i=0;i<n;i++)
f();
return 0;
}
void f()
{ int a[n];
for (j=0;j<n;j++)
{
some statements;
}
}
)
( 2
n
O
int a; //Example 5
a=5;
a++;
int flag;
cin>>flag;
if (flag==0)
for (int i=0; i<n; i++)
{Simple statements;}
else{
for (int j=0; j<n;j++)
{
for (int k=0; k<n;k++)
{Simple statements;}
}
}
Time Complexity-Best, Average and
Worst Case
)
( 2
n
O
Example 6
sum=0;
for(i=1; i<=100; i++)
for(j=1; j<=n;j++)
sum+=i;
)
(n
O
int n=64;
steps=0;
for (int i=1; i<=n;i*=2)
steps++;
cout<<steps;
• Assume that the above algorithm takes 20
seconds for an input size of 64 to complete in
the current configuration of any
system/workstation. How long does it take to
solve a problem of size 4096?
Classification
• O(k) or O(1) -----> Utopian (desirable or more
than excellent)
• O(log n) -----> Excellent
• O( ) -----> Very Very good
• O(n) -----> Very good
• O(n2) -----> Not So good
• O(n3) -----> Pretty Bad
• O(dn) -----> Disaster where d>1
n

More Related Content

PPT
Slides_Unit04_ComplexityAnalysis- Big-O notation
PPTX
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
PPTX
1_Asymptotic_Notation_pptx.pptx
PDF
Asymptotic Notation
PDF
2. Asymptotic Notation- Analysis of Algorithms.pdf
PPTX
Asymptotic notations
PPTX
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
PDF
Lecture3(b).pdf
Slides_Unit04_ComplexityAnalysis- Big-O notation
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
1_Asymptotic_Notation_pptx.pptx
Asymptotic Notation
2. Asymptotic Notation- Analysis of Algorithms.pdf
Asymptotic notations
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Lecture3(b).pdf

Similar to CS-102 DS-class03 Class DS Lectures .pdf (20)

PPTX
DAA-vfyjvtfjtfvfvfthjccghcdhrtchgdT&S_C.pptx
PPTX
DAA Week 2 slide for design algorithm and analysis.pptx
PPT
Asymptotic notations
PPTX
Binary search design and ana algorithm.pptx
PPTX
Dr hasany 2467_16649_1_lec-2-zabist
PDF
CS-102 DS-class_01_02 Lectures Data .pdf
PPTX
Asymptotic notation
PPT
Big O Notation.ppt
PPT
Time complexity
PDF
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
PPT
AsymptoticAnalysis-goal of analysis of algorithms
PPT
Design and analysis of algorithm ppt ppt
PPTX
Asymptotic notation
PDF
1ST_UNIT_DAdefewfrewfgrwefrAdfdgfdsgevedr (2).pdf
PPT
Asymptotic analysis
PPTX
DS Unit-1.pptx very easy to understand..
PDF
DAA_LECT_2.pdf
PDF
Asymptotic notation
PDF
Lecture 3(a) Asymptotic-analysis.pdf
PPT
AsymptoticAnalysis.ppt
DAA-vfyjvtfjtfvfvfthjccghcdhrtchgdT&S_C.pptx
DAA Week 2 slide for design algorithm and analysis.pptx
Asymptotic notations
Binary search design and ana algorithm.pptx
Dr hasany 2467_16649_1_lec-2-zabist
CS-102 DS-class_01_02 Lectures Data .pdf
Asymptotic notation
Big O Notation.ppt
Time complexity
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
AsymptoticAnalysis-goal of analysis of algorithms
Design and analysis of algorithm ppt ppt
Asymptotic notation
1ST_UNIT_DAdefewfrewfgrwefrAdfdgfdsgevedr (2).pdf
Asymptotic analysis
DS Unit-1.pptx very easy to understand..
DAA_LECT_2.pdf
Asymptotic notation
Lecture 3(a) Asymptotic-analysis.pdf
AsymptoticAnalysis.ppt
Ad

More from ssuser034ce1 (20)

PDF
CSN221_Lec_27 Computer Architecture and Microprocessor
PDF
CSN221_Lec_26 Computer Architecture and Microprocessor
PDF
CSN221_Lec_25 Computer Architecture and Microprocessor
PDF
CSN221_Lec_36 Computer Architecture and Microprocessor
PDF
CSN221_Lec_35 Computer Architecture and Microprocessor
PDF
CSN221_Lec_34 Computer Architecture and Microprocessor
PDF
CSN221_Lec_22.pdf Computer Architecture and Microprocessor
PDF
CSN221_Lec_17.pdf Multi Cycle Datapath Design
PDF
CSN221_Lec_16.pdf MIPS ISA and Datapath design
PDF
CSN221_Lec_15.pdf MIPS ISA and Datapath design
PDF
Computer Architecture CSN221_Lec_37_SpecialTopics.pdf
PDF
CSN221_Lec_5.pdf Computer Organization, CPU Structure and Functions
PDF
CSN221_Lec_4.pdf Computer Organization & Architecture
PDF
CS-102 Data Structures huffman coding.pdf
PDF
CS-102 Data Structures HashFunction CS102.pdf
PDF
CS-102 Data Structure lectures on Graphs
PDF
CS-102 DS-class04a Lectures DS Class.pdf
PDF
CS-102 BT_24_3_14 Binary Tree Lectures.pdf
PDF
CS-102 Course_ Binary Tree Lectures .pdf
PDF
CS-102 BST_27_3_14v2.pdf
CSN221_Lec_27 Computer Architecture and Microprocessor
CSN221_Lec_26 Computer Architecture and Microprocessor
CSN221_Lec_25 Computer Architecture and Microprocessor
CSN221_Lec_36 Computer Architecture and Microprocessor
CSN221_Lec_35 Computer Architecture and Microprocessor
CSN221_Lec_34 Computer Architecture and Microprocessor
CSN221_Lec_22.pdf Computer Architecture and Microprocessor
CSN221_Lec_17.pdf Multi Cycle Datapath Design
CSN221_Lec_16.pdf MIPS ISA and Datapath design
CSN221_Lec_15.pdf MIPS ISA and Datapath design
Computer Architecture CSN221_Lec_37_SpecialTopics.pdf
CSN221_Lec_5.pdf Computer Organization, CPU Structure and Functions
CSN221_Lec_4.pdf Computer Organization & Architecture
CS-102 Data Structures huffman coding.pdf
CS-102 Data Structures HashFunction CS102.pdf
CS-102 Data Structure lectures on Graphs
CS-102 DS-class04a Lectures DS Class.pdf
CS-102 BT_24_3_14 Binary Tree Lectures.pdf
CS-102 Course_ Binary Tree Lectures .pdf
CS-102 BST_27_3_14v2.pdf
Ad

Recently uploaded (20)

PDF
PPT on Performance Review to get promotions
PPT
Mechanical Engineering MATERIALS Selection
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Welding lecture in detail for understanding
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
web development for engineering and engineering
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Digital Logic Computer Design lecture notes
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Geodesy 1.pptx...............................................
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPT on Performance Review to get promotions
Mechanical Engineering MATERIALS Selection
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
bas. eng. economics group 4 presentation 1.pptx
Welding lecture in detail for understanding
Internet of Things (IOT) - A guide to understanding
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
web development for engineering and engineering
CYBER-CRIMES AND SECURITY A guide to understanding
Digital Logic Computer Design lecture notes
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Geodesy 1.pptx...............................................
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

CS-102 DS-class03 Class DS Lectures .pdf

  • 1. o-notation f(n) becomes insignificant relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = 0 n g(n) is an upper bound for f(n) that is not asymptotically tight. Observe the difference in this definition from previous ones. Why? o(g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  f(n) < cg(n)}. For a given function g(n), the set little-o:
  • 2. • f(n)=3n+2 is o(n2) • f(n)=17n3 + n2 logn is o(n4) o-notation
  • 3. Lecture Notes (Slides, Tutorials) • http://channeli.iitr.ernet.in/lectut/pages /final_student.php (intranet) •https://sites.google.com/site/balaiitr/cs102 (internet)
  • 4. (g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  cg(n) < f(n)}.  -notation f(n) becomes arbitrarily large relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = . n g(n) is a lower bound for f(n) that is not asymptotically tight. For a given function g(n), the set little-omega:
  • 5. • f(n)=3n+2 is • f(n)=17n3 + n2 is  -notation ) 1 (  ) ( 2 n 
  • 6. Comparison of Functions f  g  a  b f (n) = O(g(n))  a  b f (n) = (g(n))  a  b f (n) = (g(n))  a = b f (n) = o(g(n))  a < b f (n) = (g(n))  a > b
  • 7. Limits • lim [f(n) / g(n)] = 0  f(n)  (g(n)) n • lim [f(n) / g(n)] <   f(n)  (g(n)) n • 0 < lim [f(n) / g(n)] <   f(n)  (g(n)) n • 0 < lim [f(n) / g(n)]  f(n) (g(n)) n • lim [f(n) / g(n)] =   f(n)  (g(n)) n • lim [f(n) / g(n)] undefined can’t say n
  • 8. All Asymptotic Notations 2 4 3 ) ( 2 3     n n n n T n n n T log 16 ) (  
  • 9. Time Complexity • We analyze time complexity for a) A very large input size b) Worst case scenario • Rules a) Drop lower order terms b) Drop Constant multipliers
  • 10. Time Complexity Calculation in a fragment of a code int a; //Example 1 a=5; a++; for (int i=0; i<n; i++) {Simple statements;} for (int j=0; j<n;j++) { for (int k=0; k<n;k++) {Simple statements;} } ) ( 2 n O
  • 11. int main() //Example 2 {const int n=100; int arr[n]; for (int i=0; i<n; i++) for (int j=0; j<i; j++) { some statements; } return 0; } ) ( 2 n O
  • 12. //Example 3 sum=0; for(i=1; i<=n; i++) for(j=1; j<=n;j*=2) sum+=1; ) log ( n n O
  • 13. sum=0; for(i=1; i<=n; i++) for(j=1; j<=n;j*=2) sum+=1; • Suppose the above algorithm takes 10 seconds to complete for an input size of 256. How large a problem (algorithm) can be solved in 40 minutes?
  • 14. const int n=100; //Example 4 int main() { for (int i=0;i<n;i++) f(); return 0; } void f() { int a[n]; for (j=0;j<n;j++) { some statements; } } ) ( 2 n O
  • 15. int a; //Example 5 a=5; a++; int flag; cin>>flag; if (flag==0) for (int i=0; i<n; i++) {Simple statements;} else{ for (int j=0; j<n;j++) { for (int k=0; k<n;k++) {Simple statements;} } } Time Complexity-Best, Average and Worst Case ) ( 2 n O
  • 16. Example 6 sum=0; for(i=1; i<=100; i++) for(j=1; j<=n;j++) sum+=i; ) (n O
  • 17. int n=64; steps=0; for (int i=1; i<=n;i*=2) steps++; cout<<steps; • Assume that the above algorithm takes 20 seconds for an input size of 64 to complete in the current configuration of any system/workstation. How long does it take to solve a problem of size 4096?
  • 18. Classification • O(k) or O(1) -----> Utopian (desirable or more than excellent) • O(log n) -----> Excellent • O( ) -----> Very Very good • O(n) -----> Very good • O(n2) -----> Not So good • O(n3) -----> Pretty Bad • O(dn) -----> Disaster where d>1 n