Consider a queue data structure

Assignment Help Data Structure & Algorithms
Reference no: EM13163613

Consider a queue data structure, where the two operations of interest are enqueue (at the back of the queue) and dequeue (from the front of the queue). A queue is thus a FIFO (first in-first out) structure. Suppose we implement a queue by using two stacks, A and B, which support operations of push and pop, as follows:

enqueue(x): push x onto stack A

dequeue: if B is not empty return x = pop B

if B is empty

repeat until A is empty

x = pop A

push x onto stack B

return x = pop B

a) This implementation seems to correctly emulate a queue. Illustrate (by drawing the two stacks) how it works for the following sequence of enqueue and dequeue operations:

enqueue 5

enqueue 7

dequeue

enqueue 3

enqueue 6

enqueue 9

dequeue

dequeue

dequeue

dequeue

b) The actual cost of a push or a pop operation is1. What is the worst-case single operation possible after a sequence of n enqueue and dequeue operations, and what is its cost?

c) Explain how a simplistic worst-case analysis would lead to the conclusion that this algorithm would be O(n2).

d) Using the accounting method, assign the lowest (integer) amortized cost possible to the enqueue operation and to the dequeue operation so that after any sequence of n1 enqueues and n2 dequeues, n1?n2, the amortized cost is ? the actual cost. Explain why this works.

e) Show that the total amortized cost, which is an upper bound for the actual cost, over a sequence of n operations is O(n).

Reference no: EM13163613

Questions Cloud

With replacement order matters : Given an alphabet of size N=9. Write a c++ program that compares the number of possible sequences of the length L that can be generated inder the following assumptions: With replacement order matters, without replacement order matters, and without..
Write a program to keep track of a cd or dvd collection. : write a program to keep track of a CD or DVD collection. This can only work exclusively with either CDs or DVDs since some of the data is different. The data will be stored ina file. The data from the file will be stored ina text file as records. Eac..
Consider a 2-dimensional mesh : Consider a 2-dimensional mesh with n^2 nodes. The shortest distance that a message travels in the mesh is 1 link; the longest distance is 2(n-1) link
Convert meters to feet and inches. : 1. Write a program that can be used to convert meters to feet and inches. Allow the user to enter a metric meter value in a method .
Consider a queue data structure : Consider a queue data structure, where the two operations of interest are enqueue (at the back of the queue) and dequeue (from the front of the queue). A queue is thus a FIFO (first in-first out) structure. Suppose we implement a queue by using tw..
Find all irreducible polynomials : Find all irreducible polynomials
Consider the predator-prey models : Consider the predator-prey models developed early part of the 20 th  century in which the number of predators and preys may be predicted using the pair of ODEs
Create a crow''s foot erd using a specialization hierarchy : Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if appropriate. Tiny Hospital keeps information on patients and hospital rooms
Define a certain reaction has an activation energy : A certain reaction has an activation energy of 60.0 kj/mol and a frequency factor of A= 3.10×1012 M^-1s^-1 . What is the rate constant k , of this reaction at 30.0 Deg celsius?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Finding majority element

Let A be an array of n elements. An element x is said to be a majority element in A if it occurs in A more than n/2 times.

  Database over electronic files to store data

Discuss the benefits of a database over electronic files to store data determine what kinds of database products are used in your company?

  High bandwidth network for the multimedia team

Assume you have been assigned to build a network for a multimedia development company that currently uses a 10-Mbps Ethernet network. The corporation requires a high bandwidth network for multimedia team.

  Determining worst-case time complexity

The recent discovery of the following fragment of uncommented procedural C code in the Sunlab has caused a big scandal. What is the worst-case time complexity of foo(a,1,N,k), and for which inputsdoes it occur?

  Data warehouse and operational databases

Every big organization has large documents or databases containing data used in operating the business. Does a data warehouse differ from these operational files or databases?

  Implement a nice graph datastructure

Implement a nice graph datastructure. Implement two different greedy graph coloring algorithms. Shortest path algorithm and MST algorithms.

  Write algorithm using pseudo code consensus algorithm

Write an algorithm, using pseudo code, "Consensus algorithm": A group of ten people need to decide which one flavor of ice cream they will all order, out of three options.

  Developing a new customer order entry system

The system development team at Wilson Corporation is working on developing a new consumer order entry system. In the process on designing the new system,

  Designing an algorithm for task-array of person numbers

You have been allotted task of designing an algorithm for following task. Someone has built the array of person numbers of all n students enrolled in 331 this fall.

  Normalized relations for a database

Suppose that a information communications network links a computer at corporate headquarters with a computer in each retail outlet. The chain includes fifty stores with an average of 75 workers per store.

  Determine computational complexity of algorithm

Describe the algorithm in psuedo-code. You should give thought to what data structures(s) make sense for e client implementation. Determine computational complexity of your algorithm.

  Finding total available storage capacity

A certain hard disk has 480 cylinders, sixteen tracks, and thirty-two sectors of 512 bytes each. It spins at 4800 revolutions per minute, and has an adjacent cylinder seek time of eighty msec, and a max seek time of onde hundred msec.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd