You are on page 1of 2

-The form of ADT stack?

An Abstract Stack defined on objects which are linearly ordered by the programmer. A
new object placed into the stack is explicitly placed at the front of the stack while the
only defined removal is from the front of the stack. This ensures the behaviour that the
of any collection of objects inserted into the stack, the first that was inserted will also
be the first removed. This behaviour is sometimes called a last-in—first-out.

Critical Operations for Abstract Stacks

• Insert a new object


void push( Type ) const;
• Examine the head of the stack
Type top() const
• Remove the object at the front of the stack
void pop()

By restricting the relevant operations as compared to a general Abstract List, it is


possible to make significant improvements in the run times.

Example Data Structures


The most common data structure for implementing stack are cyclic dynamic arrays and
singly linked lists. All operations are O(1); however, some operations on for dynamic
arrays are amortized O(1).

The requirements of the STL, however, requires a hybrid structure as is shown in


Figure 1: A singly linked list requires too many allocations and deallocations of memory
and accessing an object in the middle of a deque requires O(n) time; a dynamic array
has the occasional operations which run in O(n) time. The stack in the STL is
implemented using the deque data structure.
-The form of ADT priority queue?
*An Abstract Priority Queue is defined on objects linearly ordered by a
value called the priority. We will assume that the priority is a nonnegative
integer with highest priority going to the smallest value.

Critical Operations for Abstract Priority Queues

• Insert a new object


void push( Type, priority ) const;
• Examine the head of the priority queue
Type top() const
• Remove the object at the head of the priority queue
void pop()

By restricting the relevant operations, it is possible to make significant


improvements in the run times.

Example Data Structures


The most common data structure for implementing a priority queue is the
binary heap. In this case, top is O(1), push has an average-case O(1) run
time, and pop is O(ln(n). Almost all other operations on implicit linearly
ordered lists, however, are now O(n).

A N-ary heap is also possible with the same run times as a binary heap.

If other operations are necessary, an AVL tree will still be acceptable;


however, the three operations now all be O(ln(n)).

If merging two priority queues is also flagged as a critical operation, a


leftist heap has O(n) run time for push, pop, and for merging two leftist
heaps.

Another data structure similar to a leftist heap is a skew heap. While the
author has not investigated this, it has been claimed that skew heaps are
better on average than leftist heaps.

Name:HAMZAH MOHAMMED ALQATA.

You might also like