Data Structure Exam Sample - 2020
Data Structure Exam Sample - 2020
a. Size __________________________________
b. Complexity ____________________________
c. Order _________________________________
d. Big-O _________________________________
a. size __________________________________
b. Complexity ____________________________
c. Order _________________________________
d. Big-O _________________________________
3. { I = 0;
while(I <= n )
{
a. Size __________________________________
b. Complexity ____________________________
c. Order _________________________________
d. Big-O _________________________________
PART I : For each of the following choose the best answer and write the
letter of your choice on the answer sheet
2. A data structure whose operations are already implemented as a machine instruction is:
a. Primitive data structure b. Non-primitive data structure
c. Non-primitive linear data structure d. Both b and c e. None
3. After nlogn, the next function which describes algorithm running time in order of increasing
growth rate is:
a. n 2logn b. logn c. n3 d. n2 e. None
5. Which of the following operations on lists can be easily implemented using linked lists than
arrays?
a. Creation b. accessing an element c. Deletion d. b and c e. All
6. One of the following operations will not be successful if a stack is already full?
a. Push b. Top c. Pop d. Create e. IsEmpty
7. Which data structure reduces the running- time complexity of most operations to O(logn)
a. Array b. Linked List c. Stack d. Tree e. None
8. Data structure helps designing program which satisfies the following except
27. Why do we make the position of the array pointed by ‘front’ vacant in a circular
queue
a. to facilitate insertion b. to identify empty and full condition of the queue
Part II – True or False. Write TRUE if the statement is true, otherwise FALSE on the space provide
(5 marks)
PART III : For each of the following questions give your answer on the space provided
Part III – Short Answers. Write your answers on the blank spaces provided after each
15. Give examples of an algorithm that is O(1) and O(n3). Give simple C++ statements. (2 marks)
O(1) O(n3)
16. Device sample data types to demonstrate the best case and worst-case behaviors of each of the
following algorithms:
Bubble sort, Selection sort, Linear search, and Binary search. (6 marks)
Sample data
Algorithm
Best-Case Worst-Case
Bubble Sort
Selection Sort
Linear Search
17. Searching an item from a Complete Binary Search Tree (BST) of size n has running-time complexity
O(nlogn) in the worst-case. Explain. (2 marks)
18. Algorithm A does a certain task in a “time” 100n2logn and algorithm B does the same task in a “time”
of 5000n2 + n where n is the number of elements processed. (4 marks)
a. What are the Big-O requirements of each algorithm?
i. O(A):___________________________________
ii. O(B):___________________________________
________________________________________________________________________________
__________________________________________________________________________________
19. Give examples of applications that need Stack data structure (LIFO basis) and Queue data structure
(FIFO basis) for manipulation. (3 marks)
i._______________________________________________________________________
Stack ii.______________________________________________________________________
iii.______________________________________________________________________
i._______________________________________________________________________
Queue ii.______________________________________________________________________
iii.________________________________________________________________________
20. Compare and contrast the Sequential and Linked List storage representations of lists. (2 marks)
22. Convert the following infix arithmetic expression in to postfix (RPN). Trace using Stack Algorithm in
conversion process. (2marks)
A + (B - C) *D+B
root
70
65 90
60
68 85 95
40 62 69 80 88
5. draw a possible binary tree with ordering property containing the following
integers
3,12,17,49,22,65,51,56,70,68
PART IV : For each of the following questions, write a function on the space provided
1. write a function stores the common elements of two linked lists of integer headed
by head1 and head2 into the third list headed by head3 .
use the following declaration
struct node
{ int data;
node *next;
};
typedef node *pnode;
3. write a function that deletes and returns the top element of a stack. Use the
following declaration
struct node
{ int data;
Node *next;
};
struct stack
{
node *top;
};
4. write a function that calculates average, sum, minimum and maximum of a stack
5. write a function that inserts an item into a given queue. Use the following declaration
struct node
{int data;
node *next;
};
struct queue
{ node *front;
node *rear;
};
float average(queue q)
6. write a function that sorts elements of a stack in ascending order of its size.
7. write a function that calculates average, sum, minimum and maximum of a queue.
9. write a program that move elements of stack s into stack ss and stack ss store the
elements in the same order of stack s. (HINT: uses additional variable, or
additional stack.)
10. write a function that reverse elements of a linked list
11. write a function that converts infix notation to postfix
12. write a function that converts postfix into infix