SlideShare a Scribd company logo
1 of 1
For the following four program fragments, give an analysis of the running time. (Use Big-O)
Sum = 0; for i := 1 to N do for j := i to N do for k := j to N do Sum := Sum + 1; Sum = 0; for i :=
1 to N * N do for j := 1 to 10000 do Sum = Sun + 1; Sum = 0; for i := 1 to N do if i > 10 for j :=
1 to i do Sum := Sum + 1; int product(int n) {if n = 0 then return 0; else return product(n / 2);}
Solution
a)The Time complexity for this is O(n^3) because it is having 3 for loops last statement execute
for the n*n*n times
b)The Time complexity for this is O(n^3) because first loop runs for N^2 times and second loop
runs for N so total O(n^3)
c)The complexity for that is O*(n(n-10)) so the complexity is O(N^2)

More Related Content

More from todd161

FInd the zeros for the following polynomial function and give the mult.docx
FInd the zeros for the following polynomial function and give the mult.docxFInd the zeros for the following polynomial function and give the mult.docx
FInd the zeros for the following polynomial function and give the mult.docxtodd161
 
Find the Thevenin impedance at terminals a-b of the circuit on the rig.docx
Find the Thevenin impedance at terminals a-b of the circuit on the rig.docxFind the Thevenin impedance at terminals a-b of the circuit on the rig.docx
Find the Thevenin impedance at terminals a-b of the circuit on the rig.docxtodd161
 
Find the range and interquartile range and median of the following dat.docx
Find the range and interquartile range and median of the following dat.docxFind the range and interquartile range and median of the following dat.docx
Find the range and interquartile range and median of the following dat.docxtodd161
 
Shen yOu are told to plot log olD versus concentration- what variable.docx
Shen yOu are told to plot log olD versus concentration- what variable.docxShen yOu are told to plot log olD versus concentration- what variable.docx
Shen yOu are told to plot log olD versus concentration- what variable.docxtodd161
 
Should OSs be proprietary so that the manufacturers will be able to ma.docx
Should OSs be proprietary so that the manufacturers will be able to ma.docxShould OSs be proprietary so that the manufacturers will be able to ma.docx
Should OSs be proprietary so that the manufacturers will be able to ma.docxtodd161
 
Social Media in Healthcare What are the strengths of using social medi.docx
Social Media in Healthcare What are the strengths of using social medi.docxSocial Media in Healthcare What are the strengths of using social medi.docx
Social Media in Healthcare What are the strengths of using social medi.docxtodd161
 
Sirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docx
Sirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docxSirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docx
Sirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docxtodd161
 
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0.docx
Simplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0.docxSimplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0.docx
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0.docxtodd161
 
Several years ago a ring of foreign-based hackers broke into Town Bank.docx
Several years ago a ring of foreign-based hackers broke into Town Bank.docxSeveral years ago a ring of foreign-based hackers broke into Town Bank.docx
Several years ago a ring of foreign-based hackers broke into Town Bank.docxtodd161
 
Set up the chemical equation and balance for each (please write out )-.docx
Set up the chemical equation and balance for each (please write out )-.docxSet up the chemical equation and balance for each (please write out )-.docx
Set up the chemical equation and balance for each (please write out )-.docxtodd161
 
Soil Classification systems provide a common language to express conci.docx
Soil Classification systems provide a common language to express conci.docxSoil Classification systems provide a common language to express conci.docx
Soil Classification systems provide a common language to express conci.docxtodd161
 
Solution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docx
Solution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docxSolution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docx
Solution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docxtodd161
 
So I attempted drawing the new signal below- It is reflected- shifted.docx
So I attempted drawing the new signal below- It is reflected- shifted.docxSo I attempted drawing the new signal below- It is reflected- shifted.docx
So I attempted drawing the new signal below- It is reflected- shifted.docxtodd161
 
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0 (1).docx
Simplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0 (1).docxSimplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0 (1).docx
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0 (1).docxtodd161
 
Silver is immediately above gold on the periodic table and the two met.docx
Silver is immediately above gold on the periodic table and the two met.docxSilver is immediately above gold on the periodic table and the two met.docx
Silver is immediately above gold on the periodic table and the two met.docxtodd161
 
Shown below is an oxidation half-reaction in acidic solution- Which of.docx
Shown below is an oxidation half-reaction in acidic solution- Which of.docxShown below is an oxidation half-reaction in acidic solution- Which of.docx
Shown below is an oxidation half-reaction in acidic solution- Which of.docxtodd161
 
Show that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docx
Show that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docxShow that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docx
Show that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docxtodd161
 

More from todd161 (17)

FInd the zeros for the following polynomial function and give the mult.docx
FInd the zeros for the following polynomial function and give the mult.docxFInd the zeros for the following polynomial function and give the mult.docx
FInd the zeros for the following polynomial function and give the mult.docx
 
Find the Thevenin impedance at terminals a-b of the circuit on the rig.docx
Find the Thevenin impedance at terminals a-b of the circuit on the rig.docxFind the Thevenin impedance at terminals a-b of the circuit on the rig.docx
Find the Thevenin impedance at terminals a-b of the circuit on the rig.docx
 
Find the range and interquartile range and median of the following dat.docx
Find the range and interquartile range and median of the following dat.docxFind the range and interquartile range and median of the following dat.docx
Find the range and interquartile range and median of the following dat.docx
 
Shen yOu are told to plot log olD versus concentration- what variable.docx
Shen yOu are told to plot log olD versus concentration- what variable.docxShen yOu are told to plot log olD versus concentration- what variable.docx
Shen yOu are told to plot log olD versus concentration- what variable.docx
 
Should OSs be proprietary so that the manufacturers will be able to ma.docx
Should OSs be proprietary so that the manufacturers will be able to ma.docxShould OSs be proprietary so that the manufacturers will be able to ma.docx
Should OSs be proprietary so that the manufacturers will be able to ma.docx
 
Social Media in Healthcare What are the strengths of using social medi.docx
Social Media in Healthcare What are the strengths of using social medi.docxSocial Media in Healthcare What are the strengths of using social medi.docx
Social Media in Healthcare What are the strengths of using social medi.docx
 
Sirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docx
Sirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docxSirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docx
Sirius is a binary star- consisting of Sirius A and Sirius B- Sirius B.docx
 
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0.docx
Simplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0.docxSimplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0.docx
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0.docx
 
Several years ago a ring of foreign-based hackers broke into Town Bank.docx
Several years ago a ring of foreign-based hackers broke into Town Bank.docxSeveral years ago a ring of foreign-based hackers broke into Town Bank.docx
Several years ago a ring of foreign-based hackers broke into Town Bank.docx
 
Set up the chemical equation and balance for each (please write out )-.docx
Set up the chemical equation and balance for each (please write out )-.docxSet up the chemical equation and balance for each (please write out )-.docx
Set up the chemical equation and balance for each (please write out )-.docx
 
Soil Classification systems provide a common language to express conci.docx
Soil Classification systems provide a common language to express conci.docxSoil Classification systems provide a common language to express conci.docx
Soil Classification systems provide a common language to express conci.docx
 
Solution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docx
Solution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docxSolution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docx
Solution Approximate Acid- Base- or Approximate pH (2- 5- 7- 9- orNeut.docx
 
So I attempted drawing the new signal below- It is reflected- shifted.docx
So I attempted drawing the new signal below- It is reflected- shifted.docxSo I attempted drawing the new signal below- It is reflected- shifted.docx
So I attempted drawing the new signal below- It is reflected- shifted.docx
 
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0 (1).docx
Simplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0 (1).docxSimplify- log 4 1Solution log  4  1 - log 1 - log 4  - 0 (1).docx
Simplify- log 4 1Solution log 4 1 - log 1 - log 4 - 0 (1).docx
 
Silver is immediately above gold on the periodic table and the two met.docx
Silver is immediately above gold on the periodic table and the two met.docxSilver is immediately above gold on the periodic table and the two met.docx
Silver is immediately above gold on the periodic table and the two met.docx
 
Shown below is an oxidation half-reaction in acidic solution- Which of.docx
Shown below is an oxidation half-reaction in acidic solution- Which of.docxShown below is an oxidation half-reaction in acidic solution- Which of.docx
Shown below is an oxidation half-reaction in acidic solution- Which of.docx
 
Show that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docx
Show that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docxShow that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docx
Show that the subset S - {0-2-4-6-8} of Z10 is a subring- Does S have.docx
 

Recently uploaded

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

For the following four program fragments- give an analysis of the runn.docx

  • 1. For the following four program fragments, give an analysis of the running time. (Use Big-O) Sum = 0; for i := 1 to N do for j := i to N do for k := j to N do Sum := Sum + 1; Sum = 0; for i := 1 to N * N do for j := 1 to 10000 do Sum = Sun + 1; Sum = 0; for i := 1 to N do if i > 10 for j := 1 to i do Sum := Sum + 1; int product(int n) {if n = 0 then return 0; else return product(n / 2);} Solution a)The Time complexity for this is O(n^3) because it is having 3 for loops last statement execute for the n*n*n times b)The Time complexity for this is O(n^3) because first loop runs for N^2 times and second loop runs for N so total O(n^3) c)The complexity for that is O*(n(n-10)) so the complexity is O(N^2)