Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please give details of the alogrithms The following hybrid method of representin

ID: 3703588 • Letter: P

Question

please give details of the alogrithms

The following hybrid method of representing a queue has, to a certain extent, the advantages of both the linked and sequential representations. The queue is represented using a linked list of nodes with two pointers, Fand R, to the first and last nodes of the list respectively. The nodes have two fields, ITEM and LINK. LINK is a pointer to the next node in the list and ITEM is an array of M queue entries, where M is some fixed constant. For example, with M-5, suppose that the 12 values a, b, c, £, g, h, k, m, p, q,t,x were inserted into an empty queue in that order and then two values were deleted from the queue. The resulting queue would be represented by the following list The front of the queue is accessed using the pointer F and an index FIRST indicating the position in the array FT ITEM of the first element in the queue. The rear of the queue is accessed using the pointer R and an index LAST indicating the position in the array R ITEM of the last element in the queue. In the above example the value of FIRST would be 3 and the value of LAST would be 2. Notes: () It is assumed here that array elements are indexed starting from 1 (i) An empty queue is represented by Fnil. Give algorithms for the QUEUE and UNQUEUE operations.

Explanation / Answer

Queue Algorithm

Basic Operations

1 enqueue() ? add (store) an item to the queue.

2 dequeue() ? remove (access) an item from the queue.

3 peek() ? Gets the element at the front of the queue without removing it.

4isfull() ? Checks if the queue is full.

5 isempty() ? Checks if the queue is empty.

1 )Enqueue Operation of Queue

Queues maintain two data pointers, front and rear. Therefore, its operations are comparatively difficult to implement than that of stacks.

The following steps should be taken to enqueue (insert) data into a queue ?

Step 1 ? Check if the queue is full.

Step 2 ? If the queue is full, produce overflow error and exit.

Step 3 ? If the queue is not full, increment rear pointer to point the next empty space.

Step 4 ? Add data element to the queue location, where the rear is pointing.

Step 5 ? return success,.

2)Dequeue Operation

Accessing data from the queue is a process of two tasks ? access the data where front is pointing and remove the data after access.

The following steps are taken to perform dequeue operation ?

Step 1 ? Check if the queue is empty.

Step 2 ? If the queue is empty, produce underflow error and exit.

Step 3 ? If the queue is not empty, access the data where front is pointing.

Step 4 ? Increment front pointer to point to the next available data element.

Step 5 ? Return success.

3)peek()

This function helps to see the data at the front of the queue

4) isfull()

As we are using single dimension array to implement queue, we just check for the rear pointer to reach at MAXSIZE to determine that the queue is full.

5)

isempty()

Algorithm of isempty() function ?

..............................................................................................................................................................................