Question

In: Computer Science

A Deque is an ADT which allows efficient (O(1)) insertion and removal at either end of...

A Deque is an ADT which allows efficient (O(1)) insertion and removal at either end of the structure. Typically, a deque is implemented with a doubly-linked list (DLL), and has the following API:

addFront(data)  # adds element to head of the DLL
removeFront()   # removes (and returns) element from head of the DLL
addRear(data)   # adds element to the tail of the DLL
removeRear()    # removes (and returns) element from the tail of the DLL

Which of the Deque operations could be used to implement the Queue ADT enqueue and dequeue methods, respectively:

A deque cannot be used to implement a queue


addFront, removeFront


addFront, removeRear


addRear, removeFront


(addFront, removeRear) or (addRear, removeFront)


addRear, removeRear


(addFront, removeFront) or (addRear, removeRear)

Solutions

Expert Solution

As Deque as Defined in Question it self that we can insert and delete Both sides.

Front Side Known as : Head(front pointer)

Back Side Know as : Tail (rear pointer)

So, In Order to make Deque as Queue , Let's understand Queue's functionality first.

Queue : It is a data-structure that works in passion of FIFO(first in first out). Like copy-paste works(it uses Queue).

Now, there is two operation inside this.

Enqueue : Intsert a element into Queue.

Dequeue : Delete element from Queue.

From above Options , Let's evaluate them One by One-->>


1. addFront, removeFront------------------>>Rejected
2. addFront, removeRear--------------------->>> Selected
3. addRear, removeFront ------------------>> Selected
4. (addFront, removeRear) or (addRear, removeFront)---->>Selected
5.addRear, removeRear----------->> Rejected
6.(addFront, removeFront) or (addRear, removeRear) --->> Rejected

So as we can see the Best option is 4.

We can insert from Front and delete from Rear or can insert from Rear and delete from Front.

So, (addFront, removeRear) or (addRear, removeFront) are valid for implemention of Queue from Deque.

Void Enqueue(x) :: To enqueue an element x in the Queue, add element at front of Deque.

Integer Dequeue() :: To dequeue an element from Queue, remove element at rear of Deque and return it.

Time Complexity for Both Operation WIll be O(1).


Related Solutions

Write an efficient java program to implement an integer doubly linked list Dequeue which insertion and...
Write an efficient java program to implement an integer doubly linked list Dequeue which insertion and deletion can be than at either end. You have to write 6 methods: add front, delete front, add rear, delete rear, print forward (left to right) and print backward (right to left). After each addition or deletion dequeue elements are printed forward or backward respectively. Your main method should be as follow: public static void main(String args[]) { xxxxx dq = new xxxxx ();...
the following questions are either true or false answers 1. The Central Limit Theorem allows one...
the following questions are either true or false answers 1. The Central Limit Theorem allows one to use the Normal Distribution for both normally and non-normally distributed populations. 2. A random sample of 25 observations yields a mean of 106 and a standard deviation of 12. Find the probability that the sample mean exceeds 110. The probability of exceeding 110 is 0.9525. 3. Suppose the average time spent driving for drivers age 20-to-24 is 25 minutes and you randomly select...
1. Which market structure results in an efficient outcome and why?
  1. Which market structure results in an efficient outcome and why? 2. Since a perfectly competitive firm can sell as much as it wishes at the market price, why can the firm not simply increase its profits by selling an extremely high quantity? 3. Business is booming at the local McDonald’s restaurant. It is contemplating adding a new grill and french-fry machine, but the day supervisor suggests simply hiring more workers. How should the manager decide which alternative to...
72. Removal of the anterior pituitary gland would affect which of the following?   (1) flow of...
72. Removal of the anterior pituitary gland would affect which of the following?   (1) flow of urine (2) pancreas (3) adrenal medulla (4) thyroid gland (5) ovaries Select one: a. 1 and 5 b. 4 and 5 c. 1 and 3 d. 3 and 4 e. 3 and 5
1. snRNA are used for which process or transcription or translation? a. Intron removal during RNA...
1. snRNA are used for which process or transcription or translation? a. Intron removal during RNA editing b. Recognition of small subunits of the ribosome during translation c. Recognition of the promoter region during transcription d. Recognition of start codon during translation 2. Epistasis is the term that describe when a. There are multiple version of a gene b. A gene is responsible for multiple phenotype c. 2 or more gene interact to produce the phenotype d. There is a...
1 ) Which of the followings is not a goal of the I/O software?    A. Device...
1 ) Which of the followings is not a goal of the I/O software?    A. Device independence B. Uniform naming C. Buffering D. Error handling E. Cost reduction 2) According to the data rate, which of the following is not true? A. SONET OC-768 network is faster than Gigabit Ethernet B. FireWire 800 is slower than USB 3.0 C. SCSI Ultra 5 bus is faster than Thunderbolt 2 bus D. Keyboard is slower than mouse 3) Which of the following...
1. What are the strengths and weaknesses of mercantilism and liberalism? Which would be more efficient...
1. What are the strengths and weaknesses of mercantilism and liberalism? Which would be more efficient in addressing global economic issues? 2. What are the reasons states impose protectionists policies on other countries? 3. What are the advantages and disadvantages of state ownership of the economy and private ownership? 4. How important is a stable international monetary system to cooperation among countries trade relations? Why would this be considered a collective good? 5. What are the factors that multinational corporations...
1. Which statement is consistent with the efficient markets hypothesis?    A.   No one can earn...
1. Which statement is consistent with the efficient markets hypothesis?    A.   No one can earn a return in the stock market.    B.   No mutual funds can outperform stock composite indexes at any time.    C.   The majority of stock mutual funds cannot outperform stock composite indexes.    D.   Technical analysis is the only way to beat the market over time. 2. Which statement is TRUE?    A.   One can earn higher returns by investing in funds with high...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT