Categories

# 5120COMP: Algorithm Design A queue is a special kind of list, where items are inserted at one end (the rear) and deleted at the other end (the front). We shall use the following operations on queues. Enqueue(X): Inserts element X at the end of the queue. Dequeue(): Remove the fir

 5120COMP: Algorithm Design
• A queue is a special kind of list, where items are inserted at one end (the rear) and deleted at the other end (the front). We shall use the following operations on queues.

Enqueue(X): Inserts element X at the end of the queue.
Dequeue(): Remove the first element of the queue.

1. Explain the disadvantages of implementing the operations Enqueue and Dequeue, by NOT thinking of the array as a circle (where the first position follows the last). Illustrate your answer using diagrams. [5]
2. Explain how we can implement the operations Enqueue and Dequeue by thinking of an array as a circle. Illustrate your answer only using diagrams (you do not need to write methods for the operations). You should give the contents of the array after each operation and clearly indicate the positions of the front and rear. [10]
3. (i) Draw an undirected connected graph with five vertices and at most five edges. Label the vertices with integers, {1, 2, 3, 4, 5}. You should not use a graph from the lectures or online sources.

(ii) Give the order of the vertices of the graph in part (c) (i) visited using Breadth
First Search (BFS) starting at vertex 1. A queue can be used in BFS traversal.
You should give the elements of the queue after every step. [10]

1. Using suitable diagrams, show how a binary search tree would be built for a sequence of letters from your surname. The order of the letters in the sequence is the same order as in your surname. Assume that all the letters are uppercase letters.
2. Describe the following recursive traversals of a binary tree, and list the values stored at the nodes of the binary search tree you created in part (a)

(i) in order,
(ii) preorder, and
(iii) postorder.

The post 5120COMP: Algorithm Design A queue is a special kind of list, where items are inserted at one end (the rear) and deleted at the other end (the front). We shall use the following operations on queues. Enqueue(X): Inserts element X at the end of the queue. Dequeue(): Remove the fir appeared first on My Academic Papers.