Question

In: Computer Science

Give a pseudo-code description for an array-based implementation of the deque ADT (Abstract Data Type). What...

Give a pseudo-code description for an array-based implementation of the deque ADT (Abstract Data Type). What is the running time for each operation?

Solutions

Expert Solution

BELOW ARE DESCRIBED THE BASIC FUNCTIONALITIES OF DEQUE

IS EMPTY:

isEmpty(){
   if(head==tail)
       return true
   else
   false
}

IS FULL:

isFull(){
   if((tail + 1) == head)
       return true;
else if (tail == (size-1) && head == 0)
       return true;
   else return false;
}

PUSH BACK:

pushBack(element){
if( isFull() )
   output: deque is full
else if( isEmpty() ) pushFront(element);
else if( tail == (size - 1)){
data[tail] = element;
tail = 0;
}
else data[tail++] = element;
}

PUSH FRONT:

pushFront(element){
if( isFull() )
   output: cannot insert more
else if( isEmpty() && tail == size-1 ){
tail = 0;
data[head] = element;
}
else if( isEmpty() ) data[tail++] = element;
else if( head == 0 ){
head = (size - 1);
data[head] = element;
}
else data[--head] = element;
}

POP FRONT:

popFront(){
if( isEmpty() )
output deque is already empty
else if( head == (size - 1))
   head = 0;
else
   head++;
}

POP BACK:

popBack(){
if( is_empty() )
   output: already empty
else if( tail == 0 )
   tail = (size - 1);
else tail--;
}

PEEK FRONT:

peekFront(){
if( is_empty() )
   output: deque is empty
return data[head];
}

PEEK BACK:

peekBack(){
if( is_empty() )
   output: deque is empty
if( tail == 0 )
   return data[size-1];
return data[tail-1];
}

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP


Related Solutions

What do you understand by abstract data type or ADT? Provide examples and discuss implementation mechanisms...
What do you understand by abstract data type or ADT? Provide examples and discuss implementation mechanisms in C++ and in object-oriented programming languages in general.
Write an array-based implementation of the ADT list that expands the size of the array of...
Write an array-based implementation of the ADT list that expands the size of the array of list entries as needed so that the list can always accommodate a new entry. Also reduce the size of the array as needed to accommodate several removals. When the size of the array is greater than 20 and the number of entries in the list is less than half the size of the array, reduce the size of the array so that it is...
1.  What is an abstract data type? In an ADT, what is known and what is hidden?
1.  What is an abstract data type? In an ADT, what is known and what is hidden?
A deque (short for double-ended queue, but pronounced “deck”) is an abstract data type that supports...
A deque (short for double-ended queue, but pronounced “deck”) is an abstract data type that supports adding and removing at both the front and back. So, at a bare minimum, a deque has four operations: addFront(), removeFront(), addBack(), removeBack(). Suppose you have a deque D containing the numbers (1, 2, 3, 4, 5, 6, 7, 8), in this order. Suppose further that you have an initially empty queue Q. Give pseudo-code description of a method that uses only D and...
Create a Deque class based on the following description of deque (double-ended queues). A dequeue is...
Create a Deque class based on the following description of deque (double-ended queues). A dequeue is a double-ended queue. You can insert items at either end and delete them from either end. Therefore, the deque offers two insert operations and two remove operations: insertLeft() and insertRight() removeLeft() and removeRight(). Deques may also have "peek" methods ( peekLeft() and peekRight() )that let you see the left or right item in the deque without remove the item from the deque. For this...
Program Task (C++) The program should contain an abstract data type (ADT) for an Employee, defined...
Program Task (C++) The program should contain an abstract data type (ADT) for an Employee, defined as follows: struct Employee int id; // unique employee identifier string name; // employee’s full name double rate; // employee’s hourly rate double hours; // how many hours they worked since last pay double taxable; // the current year’s taxable income }; This definition should appear above the main() function. The main() function should include: 1. Declare a single array to hold at most...
write an implementation of the ADT stack that uses a resizeable array to represent the stack...
write an implementation of the ADT stack that uses a resizeable array to represent the stack items. Anytime the stack becomes full, double the size of the array. Maintain the stack's top entry at the end of the array. Please use c++ for this question.
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to teach each of the operations in the ADT. Any errors discovered during the processing should be printed as a part of the test result. Please Use C++ language.
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items.
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT