(1) i = N; (2) while (i >= 1) { (3) (4) System.out.print("Enter a number: "); keyboard.nextInt(); num (5) if (num i) { for (k 0 ; k < N ; k++) { (6) (7) aa[i] [k] 0; } } (8) (9) System.out.println (aa [i] [0]); i--; } A. In the worst case, how many times does each of statements 1 through 9 execute? GIVE THE EXACT COUNT FOR EVERY STATEMENT. B. What is the big O complexity of this algorithm in the worst case? C. In the best case, how many times does each of statements 1 through 9 execute? GIVE THE EXACT COUNT FOR EVERY STATEMENT. D. What is the big O complexity of this algorithm in the best case?
(1) i = N; (2) while (i >= 1) { (3) (4) System.out.print("Enter a number: "); keyboard.nextInt(); num (5) if (num i) { for (k 0 ; k < N ; k++) { (6) (7) aa[i] [k] 0; } } (8) (9) System.out.println (aa [i] [0]); i--; } A. In the worst case, how many times does each of statements 1 through 9 execute? GIVE THE EXACT COUNT FOR EVERY STATEMENT. B. What is the big O complexity of this algorithm in the worst case? C. In the best case, how many times does each of statements 1 through 9 execute? GIVE THE EXACT COUNT FOR EVERY STATEMENT. D. What is the big O complexity of this algorithm in the best case?
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
I need it ASAP please Thank you
Given the following Code:-
![```java
(1) i = N;
(2) while (i >= 1) {
(3) System.out.print("Enter a number: ");
(4) num = keyboard.nextInt();
(5) if (num == i) {
(6) for (k = 0; k < N; k++) {
(7) aa[i][k] = 0;
}
}
(8) System.out.println(aa[i][0]);
(9) i--;
}
}
```
### A. In the worst case, how many times does each of statements 1 through 9 execute? **GIVE THE EXACT COUNT FOR EVERY STATEMENT.**
### B. What is the big O complexity of this algorithm in the worst case?
### C. In the best case, how many times does each of statements 1 through 9 execute? **GIVE THE EXACT COUNT FOR EVERY STATEMENT.**
### D. What is the big O complexity of this algorithm in the best case?](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4c9fd2bf-f9db-4a76-9475-ff5ed8d7d882%2Fc7e31364-2e48-4681-bbcf-a893a98f8948%2Forft0wb_processed.jpeg&w=3840&q=75)
Transcribed Image Text:```java
(1) i = N;
(2) while (i >= 1) {
(3) System.out.print("Enter a number: ");
(4) num = keyboard.nextInt();
(5) if (num == i) {
(6) for (k = 0; k < N; k++) {
(7) aa[i][k] = 0;
}
}
(8) System.out.println(aa[i][0]);
(9) i--;
}
}
```
### A. In the worst case, how many times does each of statements 1 through 9 execute? **GIVE THE EXACT COUNT FOR EVERY STATEMENT.**
### B. What is the big O complexity of this algorithm in the worst case?
### C. In the best case, how many times does each of statements 1 through 9 execute? **GIVE THE EXACT COUNT FOR EVERY STATEMENT.**
### D. What is the big O complexity of this algorithm in the best case?
Expert Solution

Step 1) Part A
Here Line 1 will be executed only once.
Then while loop will run from i=N to I=1 i.e it will run N times.
For each time while loop runs inners statement will run.
Line 3,4 run only once for each iteration so it will run N+N = 2 N times.
In worst case user enter value of i only.
So, line number 5 will runs N times. And also inner for loop will runs N times for each iteration.
Hence in total inner for loop and line number 7 will run 2N2 times.
Then line 8,9 will run only once so they will run 2 N times.
Hence in total these statements runs
1+N +2N + N + 2N2 + 2N = 2N2 + 6N + 1 times.
Step by step
Solved in 4 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY