Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is all part of 1 assignment. What i need the most is the final output. Thank you. This assignment has three parts: 1) Implementing

This is all part of 1 assignment. What i need the most is the final output. Thank you. image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
This assignment has three parts: 1) Implementing a queue data structure using a circular array, 2) implementing a queue data structure using two stacks, and 3) comparing the running times of "enqueue" and "dequeue" operations of both implementations in two given scenarios. 1 Constructing CAQueue: a Queue using a Circular Array As mentioned in the textbook and the slides, you can implement a queue using a circular array. In this implementation, CAQueue is a Java class with two key methods: enqueue and dequeue and two main private instance fields front and back storing the indices of front and back objects in the circular array. You must use an object of type java.util. ArrayList as the underlying data structure which stores the objects in the queue. 2 Constructing SSQueue: a Queue using two Stacks In this part. you need to first implement the java class MyStack and its push and pop methods to store/remove objects in a First-In-Last-Out manner to/from an object of type java.util.ArrayList. Then, you should implement the class SsQueue and its enqueue and dequeue operations using two stacks of type MyStack in the following way: The enqueue operation can be done by simply pushing the explicit input parameter of the method in the first stack. The dequeue operation pops an element from the second stack. If the second stack is empty, but the first one is not empty, you need to transfer all of the elements stored in the first stack to the second one. After emptying the first stack, you simply pop one 2 Constructing SSQueue: a Queue using two Stacks In this part, you need to first implement the java class MyStack and its push and pop methods to store/remove objects in a First-In-Last-Out manner to/from an object of type java.util. ArrayList. Then, you should implement the class SSQueue and its enqueue and dequeue operations using two stacks of type MyStack in the following way: The enqueue operation can be done by simply pushing the explicit input parameter of the method in the first stack. The dequeue operation pops an element from the second stack. If the second stack is empty, but the first one is not empty, you need to transfer all of the elements stored in the first stack to the second one. After emptying the first stack, you simply pop one element from the second stack to complete the dequeue operation. 3 Efficiency Comparison of two Implemented Queues In this part, you need to write a program that compares the efficiency of the queue imple- mentations in parts 1 and 2. To do so, you need to find and compare the running times of the following two scenarios for both queue implementations: 3.1 Scenario 1: Alternating Sequence of Enqueues and Dequeues For every n e {20,50, 100, 1000, 10000, 100000, 1000000), do the following: 1. long start Time = System.nanoTime(); 2. add the first n non-negative integers to the queue. 3. for every i {0,1,...,n-1}, do the following: (a) enqueue(i + n) (b) dequeuel) 4. long end Time = System.nanoTime(); 5. long totalTime = endTime - start Time: 6. System.out.println(n + ", " + totalTime) 3.2 Scenario 2: Random Sequence of Enqeueus and Dequeues For every n = {20,50.100, 1000, 10000 100000, 1000000}, do the following: 1. long start Time = System.nano Time(); 2. add the first non-negative integers to the queue 3.2 Scenario 2: Random Sequence of Enqeueus and Dequeues For every n e {20, 50, 100, 1000, 10000, 100000, 1000000}, do the following: 1. long start Time = System.nano Time(); 2. add the first n non-negative integers to the queue. 3. for every i E {0,1,...,n-1}, do the following: (a) if (Math.random()

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Explain Promotion Mix.

Answered: 1 week ago

Question

Explain the promotional mix elements.

Answered: 1 week ago

Question

1. There are many social organisations around us?

Answered: 1 week ago

Question

Why advertising is important in promotion of a product ?

Answered: 1 week ago