e time complexity (in milliseconds) of each letter of the given program segment below, then get the total time complexity. Example how to solve it is given below. int main( ) { int a, b, c, d; for (a=0;a<10;a++) for (b=0;b<10;b++) for (c=0;c<10;c++) for (d=0;d<10;d++) { If ((a==0)&&(b==0)&&(c==0)&

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Compute for the time complexity (in milliseconds) of each letter of the given program segment below, then get the total time complexity. Example how to solve it is given below. 

  1.  int main( )
  2.  {
  3.   int a, b, c, d;
  4.      for (a=0;a<10;a++)
  5.        for (b=0;b<10;b++)
  6.          for (c=0;c<10;c++)
  7.            for (d=0;d<10;d++)
  8.               {
  9.                  If ((a==0)&&(b==0)&&(c==0)&&(d==0))
  10.                  {  
  11.                  a=1, b=2,c=3,d=4;
  12.                  }
  13.                  cout<<a<<b<<c<<d;
  14.               }
  15.  }
FOR Statement
FOR Statement
How to compute for heading?
(U - L+ I) + I
U- Upper value in For Loop
L- Lower value in For Loop
Where
How to compute for inside statements of the loop?
(U - L+ I)
Where U - Upper value in For Loop
L- Lower value in For Loop
beginning of the loop = 0
end of the loop
= |
outside statements =
Transcribed Image Text:FOR Statement FOR Statement How to compute for heading? (U - L+ I) + I U- Upper value in For Loop L- Lower value in For Loop Where How to compute for inside statements of the loop? (U - L+ I) Where U - Upper value in For Loop L- Lower value in For Loop beginning of the loop = 0 end of the loop = | outside statements =
Example 1:
(10-1+1) + 1 = 11
= 0
{heading} for (int x =1;x<=10;x++)
{begin}
{
{inside}
{inside}
{end}
system.out.print("input no.");
C = Integer.parseInt(a.readLine()); (10-1+1)
= 10
= 10
(10-1+1)
%3D
wwwwwwwwJ
ww
wwwwww
wwwwwwwwwwwwwwwwwww
wwwww wwwww
}
1
= 1
wwyv
32 ms
Example 2:
{heading} For (int x = 1;X<=10;x++)
{inside}
{outside}
(10-1+1) + 1
= 11
www www
ww
(10-1+1)
= 10
system.out.print("input no.");
c = Integer.parseInt(a.readLine());
w ww
wwww ww w www www w
1
%3D
1
%3D
wwwww wwww wwwwwwww ww
www w
wwwwwwww.
===
22 ms
Transcribed Image Text:Example 1: (10-1+1) + 1 = 11 = 0 {heading} for (int x =1;x<=10;x++) {begin} { {inside} {inside} {end} system.out.print("input no."); C = Integer.parseInt(a.readLine()); (10-1+1) = 10 = 10 (10-1+1) %3D wwwwwwwwJ ww wwwwww wwwwwwwwwwwwwwwwwww wwwww wwwww } 1 = 1 wwyv 32 ms Example 2: {heading} For (int x = 1;X<=10;x++) {inside} {outside} (10-1+1) + 1 = 11 www www ww (10-1+1) = 10 system.out.print("input no."); c = Integer.parseInt(a.readLine()); w ww wwww ww w www www w 1 %3D 1 %3D wwwww wwww wwwwwwww ww www w wwwwwwww. === 22 ms
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education