Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. import java.util.Scanner; 2. public class submission 1 3. { 4. 5. 6. 7. 8. 9. 10. public static void main(String[] args) { Scanner input
1. import java.util.Scanner; 2. public class submission 1 3. { 4. 5. 6. 7. 8. 9. 10. public static void main(String[] args) { Scanner input = new Scanner(System.in); double number = input.nextDouble(); double a = 2; while (Math.abs(a-(number/a))>=0.25) { a = (a+(number/a))/2; } a = Math.floor(a); if (a* a > number) a = a -1; if ((a+1) * (a+1) =0.25) { 10. a = (a+(number/a))/2; 11. } 12. a = Math.floor(a); 13. if (a * a > number) a = a -1; 14. if ((a+1) * (a+1) =0.25) { 10. a = (a+(number/a))/2; 11. } 12. a = Math.floor(a); 13. number = a; 14. a = 2; 15. while (Math.abs(a-(number/a))>=0.25) { 16. a = (a+(number/a))/2; 17. } 18. a = Math.floor(a); 19. System.out.println(int) a); 20. } 21.} In Big O notation, what is the run-time of this algorithm as a function of the input n? Select one: a. O(n) b. O(log n) c. 0(2 log n) d. O(1) e. O(log n) + Odlog n) Suppose that Stack is a properly built Last In First Out (LIFO) data structure. Analyse the next bit of code: 1. Stack numbers = new Stack(); 2. numbers.push(1); 3. numbers.push(2); 4. numbers.push(3); 5. numbers.push(4); 6. numbers.push(5); 7. while (! numbers.isEmpty()) { 8. System.out.print(numbers.pop()); 9. } What is the output of this program at the end of line 9? Hint: Note that the program does NOT write any white spaces. Suppose that Queue is a properly built First in First Out (FIFO) data structure. Analyse the next bit of code: 1. Queue numbers = new Queue(); 2. numbers.push(1); 3. numbers.push(2); 4. numbers.push(3); 5. numbers.push(4); 6. numbers.push(5); 7. while (! numbers.isEmpty()) { 8. System.out.print(numbers.pop()); 9.} What is the output of this program at the end of line 9? Hint: Note that the program does NOT write any white spaces
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started