Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 2: The array representation of lists discussed in class can be used for queues. But, it is not very efficient. True, with a pointer

image text in transcribedimage text in transcribed

Project 2: The array representation of lists discussed in class can be used for queues. But, it is not very efficient. True, with a pointer to the last element, we can execute ENQUEUE in a fixed number of steps. But, DEQUEUE, which removes the first element, requires that the entire queue be moved up one position in the array. Thus, DEQUEUE takes O(n) time if the queue has length n. To avoid this expense, we must take a different viewpoint. Think of an array as a circle, where the first position follows the last, as suggested in Figure 3. The queue is found somewhere around the circle in consecutive positions, with the rear of the queue somewhere clockwise from the front Note: "consecutive" must be taken in a circular sense.] To enqueue an element, we move the Q.rear pointer one position clockwise and write the element in that position. To dequeue, we simply move Qfront one position clockwise. Thus, the queue migrates in a clockwise direction as we enqueue and dequeue elements. Observe that the procedures ENQUEUE and DEQUEUE can be written to take some constant number of steps if the circular array model is used. maxlength Q rear Q.front queue Figure 3 There is one subtlety that comes up in the representation of Figure 3 and in any minor variation of that strategy (e.g, if Q.rear points one position clockwise of the last element, rather than to that Project 2: The array representation of lists discussed in class can be used for queues. But, it is not very efficient. True, with a pointer to the last element, we can execute ENQUEUE in a fixed number of steps. But, DEQUEUE, which removes the first element, requires that the entire queue be moved up one position in the array. Thus, DEQUEUE takes O(n) time if the queue has length n. To avoid this expense, we must take a different viewpoint. Think of an array as a circle, where the first position follows the last, as suggested in Figure 3. The queue is found somewhere around the circle in consecutive positions, with the rear of the queue somewhere clockwise from the front Note: "consecutive" must be taken in a circular sense.] To enqueue an element, we move the Q.rear pointer one position clockwise and write the element in that position. To dequeue, we simply move Qfront one position clockwise. Thus, the queue migrates in a clockwise direction as we enqueue and dequeue elements. Observe that the procedures ENQUEUE and DEQUEUE can be written to take some constant number of steps if the circular array model is used. maxlength Q rear Q.front queue Figure 3 There is one subtlety that comes up in the representation of Figure 3 and in any minor variation of that strategy (e.g, if Q.rear points one position clockwise of the last element, rather than to that

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

y = 6(3)x Graph the equation by hand.

Answered: 1 week ago

Question

2 How unemployment and inflation are measured.

Answered: 1 week ago