SlideShare a Scribd company logo
1 of 1
Download to read offline
Please Explain. Compute the worst case time complexity of the following algorithm. for i = n to
2n do for j = i - n to n do print (i, j).
Solution
for i=n to 2n do
for j=i-n to n do
print (i, j)
Here we have two loops:
1. outer for loop: runs for i=n to 2n : n times
2. inner for loop:
for each value of i, it run :
0 to n
1 to n
2 to n
.......
.......
n-1 to n
n to n
So, T(n): n + (n-1) + (n-2)+ .......+1
= n(n+1)/2
Big-O : O(n^2)

More Related Content

More from omarionmatzmcwill497

The poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdfThe poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdf
omarionmatzmcwill497
 
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdfPlease help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
omarionmatzmcwill497
 
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdfNEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
omarionmatzmcwill497
 
Our understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdfOur understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdf
omarionmatzmcwill497
 
Mendel studied the inheritance of phenotypic characters determined b.pdf
Mendel studied the inheritance of phenotypic characters determined b.pdfMendel studied the inheritance of phenotypic characters determined b.pdf
Mendel studied the inheritance of phenotypic characters determined b.pdf
omarionmatzmcwill497
 
Life history traits are products of natural selection What are life .pdf
Life history traits are products of natural selection  What are life .pdfLife history traits are products of natural selection  What are life .pdf
Life history traits are products of natural selection What are life .pdf
omarionmatzmcwill497
 
How are Ecology and Environmental Science similar to, and different .pdf
How are Ecology and Environmental Science similar to, and different .pdfHow are Ecology and Environmental Science similar to, and different .pdf
How are Ecology and Environmental Science similar to, and different .pdf
omarionmatzmcwill497
 
1. How have the Internet, intranets, and extranets affected the type.pdf
1. How have the Internet, intranets, and extranets affected the type.pdf1. How have the Internet, intranets, and extranets affected the type.pdf
1. How have the Internet, intranets, and extranets affected the type.pdf
omarionmatzmcwill497
 
I need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdfI need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdf
omarionmatzmcwill497
 

More from omarionmatzmcwill497 (20)

what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdfwhat was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
 
Three LR circuits are made with the same resistor but different induc.pdf
Three LR circuits are made with the same resistor but different induc.pdfThree LR circuits are made with the same resistor but different induc.pdf
Three LR circuits are made with the same resistor but different induc.pdf
 
There are several things fundamentally wrong in this illustration. Po.pdf
There are several things fundamentally wrong in this illustration. Po.pdfThere are several things fundamentally wrong in this illustration. Po.pdf
There are several things fundamentally wrong in this illustration. Po.pdf
 
The poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdfThe poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdf
 
Suppose that 14 of people are left handed. If you pick two people a.pdf
Suppose that 14 of people are left handed. If you pick two people a.pdfSuppose that 14 of people are left handed. If you pick two people a.pdf
Suppose that 14 of people are left handed. If you pick two people a.pdf
 
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdfPlease help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
 
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdfNEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
 
Problem 14. Your probability class has 250 undergraduate students and.pdf
Problem 14. Your probability class has 250 undergraduate students and.pdfProblem 14. Your probability class has 250 undergraduate students and.pdf
Problem 14. Your probability class has 250 undergraduate students and.pdf
 
Simplify each expression. Write all ansers without using negative ex.pdf
Simplify each expression. Write all ansers without using negative ex.pdfSimplify each expression. Write all ansers without using negative ex.pdf
Simplify each expression. Write all ansers without using negative ex.pdf
 
Our understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdfOur understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdf
 
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
3. Variance of exponential and uniform distributions(a) Compute Va.pdf3. Variance of exponential and uniform distributions(a) Compute Va.pdf
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
 
Prove using a common notion that if P and Q are any points on a circ.pdf
Prove using a common notion that if P and Q are any points on a circ.pdfProve using a common notion that if P and Q are any points on a circ.pdf
Prove using a common notion that if P and Q are any points on a circ.pdf
 
Material ScienceWhy metals can go through plastic deformation w.pdf
Material ScienceWhy metals can go through plastic deformation w.pdfMaterial ScienceWhy metals can go through plastic deformation w.pdf
Material ScienceWhy metals can go through plastic deformation w.pdf
 
Mendel studied the inheritance of phenotypic characters determined b.pdf
Mendel studied the inheritance of phenotypic characters determined b.pdfMendel studied the inheritance of phenotypic characters determined b.pdf
Mendel studied the inheritance of phenotypic characters determined b.pdf
 
Life history traits are products of natural selection What are life .pdf
Life history traits are products of natural selection  What are life .pdfLife history traits are products of natural selection  What are life .pdf
Life history traits are products of natural selection What are life .pdf
 
How are Ecology and Environmental Science similar to, and different .pdf
How are Ecology and Environmental Science similar to, and different .pdfHow are Ecology and Environmental Science similar to, and different .pdf
How are Ecology and Environmental Science similar to, and different .pdf
 
Identify, with examples, groups that may represent a significant pol.pdf
Identify, with examples, groups that may represent a significant pol.pdfIdentify, with examples, groups that may represent a significant pol.pdf
Identify, with examples, groups that may represent a significant pol.pdf
 
How does a trunk differ from a telephone line please explainSol.pdf
How does a trunk differ from a telephone line please explainSol.pdfHow does a trunk differ from a telephone line please explainSol.pdf
How does a trunk differ from a telephone line please explainSol.pdf
 
1. How have the Internet, intranets, and extranets affected the type.pdf
1. How have the Internet, intranets, and extranets affected the type.pdf1. How have the Internet, intranets, and extranets affected the type.pdf
1. How have the Internet, intranets, and extranets affected the type.pdf
 
I need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdfI need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 

Please Explain. Compute the worst case time complexity of the follow.pdf

  • 1. Please Explain. Compute the worst case time complexity of the following algorithm. for i = n to 2n do for j = i - n to n do print (i, j). Solution for i=n to 2n do for j=i-n to n do print (i, j) Here we have two loops: 1. outer for loop: runs for i=n to 2n : n times 2. inner for loop: for each value of i, it run : 0 to n 1 to n 2 to n ....... ....... n-1 to n n to n So, T(n): n + (n-1) + (n-2)+ .......+1 = n(n+1)/2 Big-O : O(n^2)