SlideShare a Scribd company logo
<Day1_Session1>
Analysis of Algorithms
(Time and Space Complexity)
Why Analysis of Algorithm ?
One problem multiple solution (or algorithm)
One single problem can have multiple solution depending on the factor that
what data structure we are choosing, what types of input we are getting and
much more. .
How to decide which algorithm to choose ?
Big Scenario : A complex problem (made up of smaller problems). Each
smaller problems has more than one solution .
How to decide : Which algorithm is best for particular problem ?
Try to run different Algorithm and see which one is better ?
● Intel Dual core v/s Intel i5 11th gen
● Time consuming
Now we all agree
Algorithm analysis helps us to determine which algorithm is most efficient in
terms of time and space consumed (not exactly but precisely and symbolically).
How to Compare Algorithms?
Execution times: Core 2 duo vs i5
Number of statements executed: Not a good measure, since the number of statements varies
with the programming language as well as the style of the individual programmer.
Ideal solution: Let us assume that we express the running time of a given algorithm as a
function of the input size n (i.e., f(n)) and compare these different functions corresponding
to running times. This kind of comparison is independent of machine time, programming
style, etc.
i.e., analysing rate of growth of function
Similarly we can express auxiliary space used in term of a function.
Rate of growth of function
The rate at which the running time increases as a function of input is called rate of
growth.
Example,
Total cost = cost of lamborghini + cost of nano
Total cost = approx. cost of lamborghini
As an example, in the case below, n^4 , 2*n^2 , 100n and 500 are the individual
costs of some function and approximate to n^4 since n^4 is the highest rate of
growth.
f(n) = n^4 + 2*n^2 + 100n + 500 ~ O(n^4)
Big-O Notation (Upper Bounding Function)
f(n) = O(g(n))
That means, at larger values of n, the upper bound of f(n) is 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}.
g(n) is an asymptotic tight upper bound for f(n).
Generally we discard lower values of n. That means the rate of growth at lower values of n is
not important. In the figure, n0 is the point from which we need to consider the rate of
growth for a given algorithm. Below n0 , the rate of growth could be different. n0 is called
threshold for the given function.
Questions
1. f(n) = 3n + 8
2. f(n) = n^2 + 1
3. f(n) = n^4 + 100n^2 + 50
4. f(n) = n^2 = O(n^4)
Binary Search
Binary Search v/s Ternary Search - A keynote
log 2 n ? log 3 n
Best Case, Average Case, Worst Case
Omega-Q Notation (Lower Bounding Function)
This notation gives the tighter lower bound of the given algorithm and we represent it as
f(n) = Ω(g(n)). That means, at larger values of n, the tighter lower bound of f(n) is g(n).
For example, if
f(n) = 100n^2 + 10n + 50, g(n) is Ω(n^2 )
Ω(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤ cg(n) ≤ f(n) for all
n ≥ n0}.
g(n) is an asymptotic tight lower bound for f(n)}
Questions
1. f(n) = n^2 + n
2. f(n) = n^3 + logn
3. f(n) = n^3 != Q(logn)
4. f(n) = n^2 = Q(n^2) = O(n^2)
Theta-Θ Notation (Order Function)
The Theta-notation asymptotically bounds a function from above and below.
Θ(g(n)) = {f(n): there exist positive constants c1 ,c2 and n0 such that 0 ≤ c1g(n) ≤ f(n) ≤
c2g(n) for all n ≥ n0}.
g(n) is an asymptotic tight bound for f(n).
Questions
Now solve this:
If we have recurrence, T(n) = aT(n/b) + Θ(nk logpn),
where a>=1 , b>1 , k>=0 and p is a real number then:
Questions:
More Questions:
1. f(n) = 100n + 100 , g(n) = n^2:
a) f(n) = O(g(n))
b) f(n) = Q(g(n))
c) g(n) = Q(f(n))
d) g(n) = O(f(n))
1. f(n) = n^2 , g(n) = 2^n , h(n) = n^3:
a) f(n) = O(g(n))
b) h(n) = O(g(n))
c) h(n) = O(h(n))
</Day1_Session1>

More Related Content

What's hot

Recursion
RecursionRecursion
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
Nisha Soms
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Learning sparse Neural Networks using L0 Regularization
Learning sparse Neural Networks using L0 RegularizationLearning sparse Neural Networks using L0 Regularization
Learning sparse Neural Networks using L0 Regularization
Varun Reddy
 
Recursion
RecursionRecursion
Recursion
Abdur Rehman
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
Anindita Kundu
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
Vlad Patryshev
 
Reconstruction
ReconstructionReconstruction
Reconstruction
COMSATS Abbottabad
 
Recursion
RecursionRecursion
Recursion
Nalin Adhikari
 
Automata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfaAutomata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfa
Akila Krishnamoorthy
 
Recursion
RecursionRecursion
Recursion
Malainine Zaid
 
Recursion
RecursionRecursion
Recursion
James Wong
 
Strings
StringsStrings
Strings
mandeepcse
 
Strings
StringsStrings
Strings
reet_kaur001
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
Abdul Rahman Sherzad
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
Muhammad Muzammal
 
Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.
mohanrathod18
 
Algorithum Analysis
Algorithum AnalysisAlgorithum Analysis
Algorithum Analysis
Ain-ul-Moiz Khawaja
 
Recursion and looping
Recursion and loopingRecursion and looping
Recursion and looping
xcoolanurag
 
Recurrence relationships
Recurrence relationshipsRecurrence relationships
Recurrence relationships
Devansh16
 

What's hot (20)

Recursion
RecursionRecursion
Recursion
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Learning sparse Neural Networks using L0 Regularization
Learning sparse Neural Networks using L0 RegularizationLearning sparse Neural Networks using L0 Regularization
Learning sparse Neural Networks using L0 Regularization
 
Recursion
RecursionRecursion
Recursion
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
 
Reconstruction
ReconstructionReconstruction
Reconstruction
 
Recursion
RecursionRecursion
Recursion
 
Automata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfaAutomata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfa
 
Recursion
RecursionRecursion
Recursion
 
Recursion
RecursionRecursion
Recursion
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
 
Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.
 
Algorithum Analysis
Algorithum AnalysisAlgorithum Analysis
Algorithum Analysis
 
Recursion and looping
Recursion and loopingRecursion and looping
Recursion and looping
 
Recurrence relationships
Recurrence relationshipsRecurrence relationships
Recurrence relationships
 

Similar to Weekends with Competitive Programming

Asymptotic notations
Asymptotic notationsAsymptotic notations
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
Deepak John
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
Sri Prasanna
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
NagendraK18
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
ShaistaRiaz4
 
big_oh
big_ohbig_oh
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
Abdullah Al-hazmy
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
Abbas Ali
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
Time complexity
Time complexityTime complexity
Time complexity
LAKSHMITHARUN PONNAM
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
Sajid Marwat
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
YekoyeTigabuYeko
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
Lec1
Lec1Lec1
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
Mallikarjun Biradar
 
Asymptoptic notations
Asymptoptic notationsAsymptoptic notations
Asymptoptic notations
Alisha Jindal
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
KarthikeyaLanka1
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
Saranya Natarajan
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
NANDINI SHARMA
 

Similar to Weekends with Competitive Programming (20)

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
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
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
 
big_oh
big_ohbig_oh
big_oh
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
Time complexity
Time complexityTime complexity
Time complexity
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Lec1
Lec1Lec1
Lec1
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Asymptoptic notations
Asymptoptic notationsAsymptoptic notations
Asymptoptic notations
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 

Recently uploaded

B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 

Weekends with Competitive Programming

  • 2. Analysis of Algorithms (Time and Space Complexity)
  • 3. Why Analysis of Algorithm ? One problem multiple solution (or algorithm) One single problem can have multiple solution depending on the factor that what data structure we are choosing, what types of input we are getting and much more. . How to decide which algorithm to choose ? Big Scenario : A complex problem (made up of smaller problems). Each smaller problems has more than one solution . How to decide : Which algorithm is best for particular problem ?
  • 4. Try to run different Algorithm and see which one is better ? ● Intel Dual core v/s Intel i5 11th gen ● Time consuming Now we all agree Algorithm analysis helps us to determine which algorithm is most efficient in terms of time and space consumed (not exactly but precisely and symbolically).
  • 5. How to Compare Algorithms? Execution times: Core 2 duo vs i5 Number of statements executed: Not a good measure, since the number of statements varies with the programming language as well as the style of the individual programmer. Ideal solution: Let us assume that we express the running time of a given algorithm as a function of the input size n (i.e., f(n)) and compare these different functions corresponding to running times. This kind of comparison is independent of machine time, programming style, etc. i.e., analysing rate of growth of function Similarly we can express auxiliary space used in term of a function.
  • 6. Rate of growth of function The rate at which the running time increases as a function of input is called rate of growth. Example, Total cost = cost of lamborghini + cost of nano Total cost = approx. cost of lamborghini As an example, in the case below, n^4 , 2*n^2 , 100n and 500 are the individual costs of some function and approximate to n^4 since n^4 is the highest rate of growth. f(n) = n^4 + 2*n^2 + 100n + 500 ~ O(n^4)
  • 7.
  • 8. Big-O Notation (Upper Bounding Function) f(n) = O(g(n)) That means, at larger values of n, the upper bound of f(n) is 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}. g(n) is an asymptotic tight upper bound for f(n). Generally we discard lower values of n. That means the rate of growth at lower values of n is not important. In the figure, n0 is the point from which we need to consider the rate of growth for a given algorithm. Below n0 , the rate of growth could be different. n0 is called threshold for the given function.
  • 9. Questions 1. f(n) = 3n + 8 2. f(n) = n^2 + 1 3. f(n) = n^4 + 100n^2 + 50 4. f(n) = n^2 = O(n^4)
  • 10.
  • 11. Binary Search Binary Search v/s Ternary Search - A keynote log 2 n ? log 3 n
  • 12. Best Case, Average Case, Worst Case
  • 13. Omega-Q Notation (Lower Bounding Function) This notation gives the tighter lower bound of the given algorithm and we represent it as f(n) = Ω(g(n)). That means, at larger values of n, the tighter lower bound of f(n) is g(n). For example, if f(n) = 100n^2 + 10n + 50, g(n) is Ω(n^2 ) Ω(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n0}. g(n) is an asymptotic tight lower bound for f(n)}
  • 14. Questions 1. f(n) = n^2 + n 2. f(n) = n^3 + logn 3. f(n) = n^3 != Q(logn) 4. f(n) = n^2 = Q(n^2) = O(n^2)
  • 15. Theta-Θ Notation (Order Function) The Theta-notation asymptotically bounds a function from above and below. Θ(g(n)) = {f(n): there exist positive constants c1 ,c2 and n0 such that 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ n0}. g(n) is an asymptotic tight bound for f(n).
  • 18. If we have recurrence, T(n) = aT(n/b) + Θ(nk logpn), where a>=1 , b>1 , k>=0 and p is a real number then:
  • 19. Questions: More Questions: 1. f(n) = 100n + 100 , g(n) = n^2: a) f(n) = O(g(n)) b) f(n) = Q(g(n)) c) g(n) = Q(f(n)) d) g(n) = O(f(n)) 1. f(n) = n^2 , g(n) = 2^n , h(n) = n^3: a) f(n) = O(g(n)) b) h(n) = O(g(n)) c) h(n) = O(h(n))