This document contains an examination paper for a Data Structures course consisting of two sections - an objective multiple choice section and a structured question section. The objective section contains 40 questions testing various concepts related to linear data structures, linked lists, stacks, queues, trees, and sorting algorithms. The structured section contains two questions, with subquestions on algorithm expression methods, differences between lists and linked lists, stack underflow, manipulating two character stacks, adding nodes to a linked list, and more. The paper tests students' understanding of fundamental data structures concepts.
1. EXAMINATION AND EVALUATION DIVISION
DEPARTMENT OF POLYTECHNIC EDUCATION
(MINISTRY OF HIGHER EDUCATION)
INFORMATION & COMMUNICATION TECHNOLOGY (ICT)
DEPARTMENT
FINAL EXAMINATION
JUNE 2012 SESSION
FP305: DATA STRUCTURE
DATE: 22 NOVEMBER 2012 (THURSDAY)
DURATION: 2 HOURS (8.30AM – 10.30PM)
This paper consists of SEVENTEEN (17) pages including the front page.
Section A: Objective (40 questions – answer ALL)
Section B: Structure (2 questions – answer ALL).
CONFIDENTIAL
DO NOT OPEN THIS QUESTION PAPER UNTIL INSTRUCTED BY THE CHIEF INVIGILATOR
(The CLO stated is for reference only)
2. CONFIDENTIAL FP305 DATA STRUCTURE
Page 2 of 17
SECTION A
OBJECTIVE QUESTIONS (50 marks)
INSTRUCTION:
This section consists of FORTY (40) objective questions. Answer ALL questions in the answer booklet.
1. Which of the following is a linear data structure?
[CLO1]
A. Tree
B. Graph
C. Queue
D. Binary Tree
2.
Algorithm is _____________
[CLO1]
A.
a smallest named unit of data that has meaning in the real world
B.
a clearly specified finite set of instructions a computer follows to solve a problem
C.
a computerized collection of interrelated stored data that serves the needs of multiple users within one or more organizations
D.
used to make decision based on condition
3.
Which of the following statements that the best describe User-define Data Type?
i. A type which is defined by a programmer
ii. A type which is defined in the language itself
iii. Can contain more than one data type
iv. Can contain only one data type
[CLO1]
A.
i, ii
B.
i, iii
C.
i, iii, iv
D.
i, ii, iii, iv
3. CONFIDENTIAL FP305 DATA STRUCTURE
Page 3 of 17
4.
Linked list is an ordered collection of data in which each element contains the _____________ of the next elements.
[CLO1]
A. data
B. node
C. address
D. list
5.
What is the meaning of a variable START=NULL in linked list?
[CLO1]
A.
full
B.
empty
C.
underflow
D.
overflow
6. What are the main operations of a list?
[CLO1]
A. Insert an item, copy and item, delete an item
B. Create a list, insert an item, delete an item
C. Create a list, move an item, delete an item
D. Create a list, insert an item, delete an item, copy and item
7.
Choose the BEST answer to describe the statement below.
a data structure used for collecting a sequence of objects, which allows efficient addition, removal and retrieval of elements from any position in the sequence
[CLO 1]
A. Linked List
B. List
C. Queue
D. Stack
8.
The difference between a linear array and a record is ____________
[CLO 2]
A.
in a record, there may not be a natural ordering in opposed to linear array.
B.
an array is suitable for homogeneous data but the data items in a record may have different data type
C.
a record form a hierarchical structure but a linear array does not
D.
all of the above
4. CONFIDENTIAL FP305 DATA STRUCTURE
Page 4 of 17
9. What is the relational expression to move B to the last node in the list?
[CLO 2]
A. list = link -> link -> B
B. B = B -> link -> link
C. list = B -> link -> link
D. B -> link -> link =B
10. What is the right statement to delete node ‘23’?
[CLO 3]
A. pList->next = pCur->next;
delete pCur;
B. pPre->next = pCur->next;
clear pCur;
C. pList = pCur;
delete pCur;
D. pPre = pCur;
clear pCur;
pList
11 23 23 27
pPre pCur
list
18 32 23
32
16 43
32
87
32
25
32
44
32
A B
5. CONFIDENTIAL FP305 DATA STRUCTURE
Page 5 of 17
11. Which statement would assign value 3 to the first node in the item part of linked list?
[CLO 3]
A. head=3;
B. head.item=3;
C. *head.item=3;
D. head->item=3;
12. Which of the following principle is used in stack?
[CLO 1]
A. Bottom UP
B. Traversal concept
C. FIFO (First In First Out) concept
D. LIFO (Last In First Out) concept
13.
Which of the following is NOT a basic operation for stack?
[CLO 1]
A.
Push
B.
Pop
C.
Stack Down
D.
Stack Top
14.
Which of the following situation is BEST suit in queue implementation?
[CLO 2]
A.
Simulation on express ticket bus counter
B.
Five cars entering ended road
C.
Storing list of financing applicants
D.
Car waiting at a toll plaza
struct Node
{ int item;
Node* link;
};
typedef Node* NodePtr;
NodePtr head;
head = new Node;
6. CONFIDENTIAL FP305 DATA STRUCTURE
Page 6 of 17
15. "Entries in a stack are ordered".
What is the meaning of this statement?
[CLO2]
A. A collection of Stacks can be sorted
B. Stack entries may be compared with the '<' operation
C. The entries must be stored in a linked list
D. There is a first entry, a second entry, and so on
16.
What is the operation from (a) to (b) in Figure 1?
A.
Figure 1: Stack
[CLO3]
Empty stack
B. Stack top
C. Push stack
D. Pop Stack
17. The difference between queues and stacks is _____________
[CLO 1]
A. queues require dynamic memory but stacks do not.
B. stacks require dynamic memory but queues do not.
C. queues use two ends of the structure, stacks use only one.
D. stacks use two ends of the structure, queues use only one.
7. CONFIDENTIAL FP305 DATA STRUCTURE
Page 7 of 17
18. Which of the following are TRUE about queue?
i. Queue is a data structure which follow first-in first-out (FIFO) concept.
ii. Primary queue operations are enqueue and dequeue
iii. Queue allows node to be added or removed from the front (head).
iv. The similarity between queue and stack is on process for adding and removing data.
[CLO 1]
A. i and ii.
B. ii and iii
C. i, ii and iv.
D. ii, iii and iv.
19.
Two variables used in the queue are __________________.
[CLO 1]
A.
B.
C.
D.
top and down
rear and front
left and right
rear and top
20.
Which data structure type allows deleting data elements from front and inserting at rear?
[CLO 1]
A.
Stacks
B.
Queues
C.
Dequeue
D.
Binary search tree
21. Which node will be deleted in the linked list using queue?
[CLO 2]
A. At the head
B. At the tail
C. After all other entries are greater than the new entry.
D. After all other entries are smaller than the new entry.
8. CONFIDENTIAL FP305 DATA STRUCTURE
Page 8 of 17
22.
Based on Figure 2, which is the correct diagram after the operations are executed?
Figure 2: Queue
[CLO 2]
A.
B.
C.
D.
queue
F
D
F
D
D
F
9. CONFIDENTIAL FP305 DATA STRUCTURE
Page 9 of 17
23.
If letter ‘D’, ‘C’, ‘B’, ‘A’ are sequentially inserted into a queue, and then deleted one by one, in which sequence will the letter be deleted from the queue?
[CLO 3]
A.
‘A’, ‘B’, ‘C’, ‘D’
B.
‘A’, ‘B’, ‘D’, ‘C’
C.
‘D’, ‘C’, ‘A’, ‘B’
D.
D’, ‘C’, ‘B’, ‘A’
24.
Show the content of a queue after the following operations are executed.
[CLO 3]
A.
A and F
B.
A and X
C.
F and X
D.
A, F and X
Questions 25 to 28 are based on Figure 3.
Figure 7 Figure 3: Binary Search Tree
25. The depth of binary search tree is ________
[CLO1]
A. 4
B. 3
C. 2
D. 1
Initialize (Q)
Add (A, Q)
Add (F, Q)
Add (X, Q)
Remove (Q)
9
/
2 15
/ /
1 3 10 43
/ /
8 40 55
10. CONFIDENTIAL FP305 DATA STRUCTURE
Page 10 of 17
26.
How many levels does the binary search tree have ?
[CLO 1]
A.
0
B.
1
C.
2
D.
3
27 Binary tree is _____________
[CLO2]
A. full but not complete.
B. complete but not full.
C. both full and complete
D. neither complete nor full
28. What is the order of nodes using in-order traversal?
[CLO2]
A. 1 2 3 8 10 40 55 43 15 9
B. 1 2 3 9 8 10 15 40 43 55
C. 9 2 1 3 15 10 8 43 40 55
D. 1 3 2 8 10 40 55 43 15 9
29
Which of the following applications is NOT related to binary tree?
[CLO 1]
A.
Arithmetic Tree
B.
Binary Search Tree
C.
Traversal Binary Tree
D.
D-tree
30. Nodes in the tree without children is known as ______________.
[CLO1]
A. parent
B. leave
C. root
D. child
11. CONFIDENTIAL FP305 DATA STRUCTURE
Page 11 of 17
Questions 31 and 32 are based on Figure 4
Figure 4: Binary Search Tree
31.
What is the output for preorder traversal?
[CLO 3]
A.
23, 18, 12, 20, 44, 35, 52
B.
12, 20, 18, 35, 52, 44, 23
C.
12, 18, 20, 23, 35, 44, 52
D.
23, 12, 18, 20, 35, 44, 52
32.
What is the output for postorder traversal?
[CLO 3]
A.
23, 18, 12, 20, 44, 35, 52
B.
12, 20, 18, 35, 52, 44, 23
C.
12, 18, 20, 23, 35, 44, 52
D.
23, 12, 18, 20, 35, 44, 52
33.
Find the smallest element and exchange it with the first element. Then find the second smallest element and exchange it with the second element, and so on until the array is sorted.
The statement above refers to __________________.
[CLO 1]
A.
Quick Sort
B
Bubble Sort
C.
Insertion Sort
D.
Selection Sort
34. ___________ considers the maximum amount of work an algorithm
will require on a problem of a given size.
[CLO1]
A. Worst case analysis
B. Last case analysis
C. Average case analysis
D. Best case analysis
12. CONFIDENTIAL FP305 DATA STRUCTURE
Page 12 of 17
35.
Which of the following statements is NOT the condition that must be followed by Binary Search?
[CLO 1]
A.
The list must be a sorted list
B.
The list must be implemented using Linked List
C.
The list should not be implemented using Linked List
D.
Data in the list can be accessed directly
36.
Which of the following is FALSE about searching?
i. Linear search can be done for sorted data only
ii. Binary search can be done for sorted data only
iii. Both linear and binary search can be done for sorted data only
iv. Binary search can be done for unsorted data
[CLO 1]
A.
i, ii, iii
B.
i, ii, iv
C.
i, iii, iv
D.
ii, iii, iv
37. Rearrange the data given in ascending order by using selection sort.
40, 5, 7, 41, 19
i. 5, 7, 19, 41, 40
ii. 5, 7, 19, 40, 41
iii. 5, 40, 7, 41, 19
iv. 5, 7, 40, 41, 19
[CLO2]
A.
i, ii, iii, iv
B.
iii, iv, i, ii
C.
iii, i, iv, ii
D.
iv, iii, ii, i
38.
Based on Figure 5, what is the sorting type?
Figure 5 : Sorting
[CLO2]
A.
Quick C. Bubble
B.
Merge D. Selection
13. CONFIDENTIAL FP305 DATA STRUCTURE
Page 13 of 17
39. Refer to Figure 6. Use insertion sort and count the steps to complete the sort [CLO3]
5 10 8 100 15 2
Figure 6 : List of Numbers
A. 3
B. 4
C. 5
D. 6
40.
Based on the Figure 7 , select the technique used to sort numbers in ascending order.
11
88
38
12 2
15 2
88
38
12 11
15 2 11
38 12
88
15 2 11 12
38
88 15 2 11 12 15
88 38 2 11 12 15 38 88
Figure 7 : Sorting
Indicates the smallest number to be interchanged
Sorted section
[CLO 3]
A.
Selection Sort
B.
Insertion Sort.
C.
Bubble Sort
D.
Quick Sort
14. CONFIDENTIAL FP305 DATA STRUCTURE
Page 14 of 17
SECTION B
STRUCTURED QUESTIONS (50 marks)
INSTRUCTION:
This section consists of TWO (2) structured questions. Answer ALL questions.
QUESTION 1
(a) Write TWO (2) methods of expressing algorithm that you know. [CLO1]
(2 marks)
(b)
Describe FOUR (4) differences between list and linked list.
[CLO1]
(8 marks)
(c)
Explain the concept of underflow in stack with suitable diagram.
[CLO2]
(3 marks)
(d)
Assume there are two empty stacks of char A and B with the size of A and B are 3. Sketch a diagram of each stack after the following operations are executed.
pushStack(A,"Ahmad")
pushStack(B,"Nathan")
pushStack(B,"Chong")
pushStack(A,"Muthu")
popStack(A,x)
popStack(B,x)
pushStack(B,"Thong")
popStack(B,x)
[CLO3] (4 marks)
15. CONFIDENTIAL FP305 DATA STRUCTURE
Page 15 of 17
(e)
Figure 8 : Linked List
Based on Figure 8, answer the following questions.
i.
Sketch a new linked list when item "N" is added between second and third nodes.
[CLO2] (2 marks)
ii.
Based on your answer in ( i ), sketch a new linked list when item "G" is added at the end of the linked list.
[CLO2] (2 marks)
iii.
Write a pseudocode to delete the node that contain value “T”.
[CLO3] (4 marks)
D
A
T
A
Head
16. CONFIDENTIAL FP305 DATA STRUCTURE
Page 16 of 17
QUESTION 2
(a) Based on Figure 9, complete a code segment to enqueue item in a circular array
[CLO3]
Figure 9 : Circular Array
(8 marks)
(b)
Figure 10: Binary Search Tree
void createQueue(qQueue *q)
{
int i,data;
if (full(q) == 1)
cout<<”Queue is full”;
else
{
cout<< "nKeyin No ";
cin>> data;
//complete these code segment
……………………………………………………….
……………………………………………………….
}
}
30
9
29
17
25
50
58
46
17. CONFIDENTIAL FP305 DATA STRUCTURE
Page 17 of 17
Based on Figure 10, answer the following questions:
i. sketch binary search tree after deleting item with value 30 (2 marks)
ii. based on your answer in (i), sketch binary search tree after insert
item with value 27. (2 marks)
iii. based on your answer in b(ii), write the node sequence of the following
traversals:
Pre-order (2 marks)
Post-order (2 marks)
[CLO 2]
(c) Write THREE (3) advantages of sorted list.
[CLO 1]
(3 marks)
(d) Apply a selection sort for the following array:
90 60 45 30 10 85
i. Show the result after each swap takes place in ascending order. [CLO 3] (5 marks)
ii. How many comparisons have been performed?
[CLO 1]
(1 mark)