Refer to Code Segment 1 and Code Segment 2. Assume variables have been declared accordingly with their appropriate data type; and value for n is user supplied. Line numbers are provided for easy referencing. Line Code Segment 1 (1) (2) (3) (4) (5) (6) for i = 1 to n{ for j = 1 to n { val = ij print val Line Code Segment 2 (1) (2) (3) (4) (5) (6) for i = 1 to nn { r = (i-1) / n C = (i-1) % n val = (r+1) * (c+1) print val Answer the questions below: 1. Both Code Segments 1 and 2 perform the same task AND the execution time of Code Segment 1 scales slower than the execution time of Code Segment 2 as we increase n. Write TRUE if the statement is true, FALSE otherwise. 2. In Code Segment 1, how many times will line 4 be executed in terms of n? 3. In Code Segment 2, how many times will line 5 be executed in terms of n?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
Refer to Code Segment 1 and Code Segment 2. Assume variables have been declared accordingly with their appropriate data type; and value for n is user supplied.
Line numbers are provided for easy referencing.
Line
Code Segment 1
(1)
(2)
(3)
(4)
(5)
(6)
for i = 1 to n {
for j = 1 to n {
val = i*j
print val
Line
Code Segment 2
(1)
(2)
(3)
(4)
(5)
(6)
for i = 1 to n *n {
r = (i-1) /n
c = (i-1) % n
val = (r+1) * (c+1)
print val
Answer the questions below:
1. Both Code Segments 1 and 2 perform the same task AND the execution time of Code Segment 1 scales slower than the execution time of Code Segment 2 as we
increase n. Write TRUE if the statement is true, FALSE otherwise.
2. In Code Segment 1, how many times will line 4 be executed in terms of n?
3. In Code Segment 2, how many times will line 5 be executed in terms of n?
Transcribed Image Text:Refer to Code Segment 1 and Code Segment 2. Assume variables have been declared accordingly with their appropriate data type; and value for n is user supplied. Line numbers are provided for easy referencing. Line Code Segment 1 (1) (2) (3) (4) (5) (6) for i = 1 to n { for j = 1 to n { val = i*j print val Line Code Segment 2 (1) (2) (3) (4) (5) (6) for i = 1 to n *n { r = (i-1) /n c = (i-1) % n val = (r+1) * (c+1) print val Answer the questions below: 1. Both Code Segments 1 and 2 perform the same task AND the execution time of Code Segment 1 scales slower than the execution time of Code Segment 2 as we increase n. Write TRUE if the statement is true, FALSE otherwise. 2. In Code Segment 1, how many times will line 4 be executed in terms of n? 3. In Code Segment 2, how many times will line 5 be executed in terms of n?
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning