Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q2 [5 pts] What does the following code fragment prints when n is 30? Trace the program and show your work to get full credit

image text in transcribed
image text in transcribed
Q2 [5 pts] What does the following code fragment prints when n is 30? Trace the program and show your work to get full credit Stack Integer s = new stack(); while (n > 0) s. push (n 2); n = n/2; ) while (Is.isEmpty()) System.out.print (s.pop(); System.out.println(); Q3 [5 pts] Given a non-negative int n, write and test a recursive function sumDigit that returns the sum of its digits recursively do not use iterations. What is the time complexity for your algorithm? Q4 [10 pts) Write an algorithm that uses a stack (and maybe more than one) to remove all negative integers without changing the order numbers. What is the time complexity for your algorithm? Using the following format for an algorithm Algorithm Title: Input: Output: Algorithm steps: 1. 2. 25 [5 pts) Write an algorithm that converts a Prefix expression into a Postfix expression using a stack. Read the Postfix expression from left to right If the symbol is an operand, then push it onto the Stack If the symbol is an operator, then pop two operands from the Stack Create a string by concatenating the two operands and the operator before them. string = operator + operand2 + operandi And push the resultant string back to Stack Repeat the above steps until end of Prefix expression. Important Note: 1. 2. 3. Your programs should be well-structures and well-documented. Indicate the expected time complexity of Q3 and Q4 You should submit your own code. i.e. you are not allowed to copy from the internet, any other person or references

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

Students also viewed these Databases questions

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago