0% found this document useful (0 votes)
9 views

Midterm Data Structure 23

Uploaded by

mohamedmegz100
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Midterm Data Structure 23

Uploaded by

mohamedmegz100
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Midterm Data structure 23 Total points 20/20

‫خد بصمج يصاحبي‬

How many stacks are needed to implement a queue. Consider the situation 1/1
where no other data structure like arrays, linked list is available
to you.

How many queues are needed to implement a stack. Consider the situation 1/1
where no other data structure like arrays, linked list is available to you.

4
A priority queue can efficiently implemented using which of the following 1/1
data structures? Assume that the number of insert and peek (operation to
see the current highest priority item) and extraction (remove the highest
priority item) operations are almost same.

Array

Linked List

Heap Data Structures like Binary Heap, Fibonacci Heap

None of the above

Which of the following is true about linked list implementation of queue? 1/1

In push operation, if new nodes are inserted at the beginning of linked list, then in
pop operation, nodes must be removed from end.

In push operation, if new nodes are inserted at the end, then in pop operation,
nodes must be removed from the beginning.

Both of the above

None of the above


Suppose a circular queue of capacity (n – 1) elements is implemented with 1/1
an array of n elements. Assume that the insertion and deletion operation
are carried out using REAR and FRONT as array index variables,
respectively. Initially, REAR = FRONT = 0. The conditions to detect queue
full and queue empty are

Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT

Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT

Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT

Which of the following is NOT a common operation in a queue data 1/1


structure?

Enqueue

Back

Dequeue

None of them
Suppose a stack implementation supports an instruction REVERSE, which 1/1
reverses the order of elements on the stack, in addition to the PUSH and
POP instructions. Which one of the following statements is TRUE with
respect to this modified stack?

A queue cannot be implemented using this stack.

A queue can be implemented where ENQUEUE takes a single instruction and


DEQUEUE takes a sequence of two instructions.

A queue can be implemented where ENQUEUE takes a sequence of three


instructions and DEQUEUE takes a single instruction.

A queue can be implemented where both ENQUEUE and DEQUEUE take a single
instruction each.

A queue is implemented using an array such that ENQUEUE and DEQUEUE 1/1
operations are performed efficiently. Which one of the following
statements is CORRECT (n refers to the number of items in the queue)?

Both operations can be performed in O(1) time

At most one operation can be performed in O(1) time but the worst case time for
the other operation will be Ω(n)

The worst case time complexity for both operations will be Ω(n)

Worst case time complexity for both operations will be Ω(log n)


Consider an implementation of unsorted single linked list. Suppose it has 1/1
its representation with a head and a tail pointer (i.e. pointers to the first and
last nodes of the linked list). Given the representation, which of the
following operation can not be implemented in O(1) time?

Insertion at the front of the linked list.

Insertion at the end of the linked list.

Deletion of the front node of the linked list.

Deletion of the last node of the linked list.

Level of a node is distance from root to that node. For example, level of 1/1
root is 1 and levels of left and right children of root is 2. The maximum
number of nodes on level i of a binary tree is

2^(i-1)

2^I

2^(i+1)

2^[(i+1)/2]
The maximum number of binary trees that can be formed with three 1/1
unlabelled nodes is:

Postorder traversal of a given binary search tree, T produces the following 1/1
sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29
Which one of the following sequences of keys can be the result of an in-
order traversal of the tree T?

9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95

9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29

29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95

95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

Consider a node X in a Binary Tree. Given that X has two children, let Y be 1/1
Inorder successor of X. Which of the following is true about Y?

Y has no right child

Y has no left child

Y has both children

None of the above


The height of a tree is the length of the longest root-to-leaf path in it. The 1/1
maximum and minimum number of nodes in a binary tree of height 5 are

63 and 6, respectively

64 and 5, respectively

32 and 6, respectively

31 and 5, respectively

Which of the following number of nodes can form a full binary tree? 1/1

15

14

13

In a queue, if we implement enqueue(7), enqueue(2), dequeue(), 1/1


enqueue(2), enqueue(7), dequeue(), dequeue() and enqueue(7) the
remaining value in the queue will be 7?

True

False
Linked lists are the best data structure in case the size and structure of the 1/1
data are constantly changing.

True

False

Any Node in the path from the root of a tree data structure to the 1/1
destination node is called ---------- node.

Descendant

Sibling

Ancestor

None of the above

The stack is non-linear type of data structure. 1/1

True

False
What does the following function do for a given Linked List with first node 1/1
as head?

Prints all nodes of linked lists

Prints all nodes of linked list in reverse order

Prints alternate nodes of Linked List

Prints alternate nodes in reverse order

This content is neither created nor endorsed by Google. Report Abuse - Terms of Service - Privacy Policy

Forms

You might also like