Menu

(Solved) : Consider Following Splay Tree Numbers Shown Tree Nodes Keys Respective Nodes 4 Marks List Q37457962 . . .

I. Consider the following splay tree. The numbers shown in the tree nodes are the keys of the respective nodes. (4 marks) Lislist.h typedef struct listCDT listADT; listADT EmptyList(void); listADT Cons(int, listADT; int Head(listADT); listADT Tail(la) (3 marks) Write the function listADT append(listADT, int); in file queue.c. The function append accepts a listADT argumentI. Consider the following splay tree. The numbers shown in the tree nodes are the keys of the respective nodes. (4 marks) List the sequence of nodes visited if a post-order traversal is performed. a) b) (5 marks) Show the tree after the splay operation is performed after the node with key 3 is accessed c) (5 marks) Suppose node with key 8, instead of the node with key 3, is assessed. Show tho tree after the splay operation is performed after the node with key 8 is accessed. 2. Peter defines an ADT of queue of integers and an ADT of list of integers in two header files queue.h and list.h. The two header files are shown below. *queue.h * typedef struct queueCDT queueADT; queueADT EmptyQueue(void); void Enqueue(queueADT, int); int Dequeue(queueADT); int QueuclsEmpty(queueADT); int QueueLength(queueADT); list.h typedef struct listCDT “listADT; listADT EmptyList(void); listADT Cons(int, listADT; int Head(listADT); listADT Tail(listADT); int ListlsEmpty(listADT); int ListLength(listADT); Peter has correctly implemented the ADT of list of integers in file list.c. Now Peter starts to implement the ADT of queue of integers in file queue.c. Peter wants to try his idea of implementing his queue ADT using his list ADT. Part of his implementation file quene.c is shown below #include <stdio.h> #include “queue-h. #include “list.h” struct queueCDTtADT Q); static listADT append(listADT L, int x) ) queueADT EmptyQueuc0 queueADT queue; queue = (queueADT) malloc(sizeof(“queue)); queue->QEmptyListO: return(queue); void Enqueue(queueADT queue, int x). int Dequeue(queueADT queue) int x if (QueuelsEmpty(queueexit);error x- Head(queue>Q); queue>Q Tail(queue>Q return x int QueuelsEmpty(queueADT queue) int QueueLength(queueADT queue) .) a) (3 marks) Write the function listADT append(listADT, int); in file queue.c. The function append accepts a listADT argument and an int argument. It returns a listADT value that is the same as its first argument, but with the second argument appended to it. For examples, append([4,6,7], 9) = [4,6,7,9] append(l], 8) [8] e append(12], 6) [2,6] e append(12,5,7], 7)- [2,5,7,7] b) (5 marks) Express the complexity of append in a) in big-O notation. c) (5 marks) write the function Enqueue in file queue.. d) (5 marks) Write the function QueuelsEmpty in file queue.c. The function returns an int e) (5 marks) Write the function QueueLength in file queue.c. The function returns an int value if the argument is an empty queue, or 0 otherwise. value that is the length of the queue in the argument. Show transcribed image text

Expert Answer


Answer to Consider Following Splay Tree Numbers Shown Tree Nodes Keys Respective Nodes 4 Marks List Q37457962 . . .

OR