FP305 data structure PAPER FINAL SEM 3
-
Upload
cenyum-cokmo -
Category
Education
-
view
561 -
download
8
Transcript of FP305 data structure PAPER FINAL SEM 3
CONFIDENTIAL FP305 DATA STRUCTURES
Page 2 of 24
SECTION A
OBJECTIVE (50 MARKS)
INSTRUCTION:
This section consists of FORTY (40) objective questions. Answer ALL questions in the
answers booklet.
1. A structure can contain ___________ data type. [CLO 1]
A. Unique
B.
C.
D.
Only
Many
Only one
2. A data structure can be defined as: [CLO 1]
A. a collection of data elements of the same type that are referenced by a
common name.
B. a collection of related data items stored and referenced under one name.
C. a variable containing the address of another variable.
D. a collection of nodes, where each node contains a data along with
information about the next node.
3. A data structure where elements can be added or removed at either end but not
in the middle. [CLO 1]
A. Linked lists
B. Stacks
C. Queues
D. Dequeue
CONFIDENTIAL FP305 DATA STRUCTURES
Page 3 of 24
4. Code given is an initialized data structure. [CLO 1]
English.price = 29.90;
The operator ‘.’ in the code can be replaced with
A. English=> price=29.90
B. EnglishPrice=29.90
C. English-> price=29.90
D. English price=29.90
5. The keyword _____ can be useful to define an alias for a type that is frequently
used within a program. It is also useful when the type that you want to use has a
name that is too long or confusing. [CLO 1]
A. struct
B. typedef
C. define
D. include
CONFIDENTIAL FP305 DATA STRUCTURES
Page 4 of 24
6. The following codes refer to a data structure definition and declaration. Another
way of writing the statement are: [CLO 2]
struct book{
int pages;
float price;
};
struct book Maths, Science;
A. struct book
{
int pages;
float price;
} Maths, Science;
B. struct book Maths, Science
{
int pages;
float price;
};
C. struct book Maths, book Science
{
int pages;
float price;
};
D. struct book{
int pages;
float price;
};
CONFIDENTIAL FP305 DATA STRUCTURES
Page 5 of 24
7. Below is a definition and declaration using array of data structures,
struct employees {
char id[5], gender, name[25];
int age;
} staff[50];
Which one of the following statement is to print or access the name of the
seventh staff? [CLO 2]
A. cout<<staff[6].name;
B. cout<<staff[7].name;
C. cout<<staff7.name;
D. cout<<staff.name7;
8. Which of the following code is used to initialize all the student genders to blanks
and their ages to 0? [CLO 2]
for( i=0; i<50; i++)
A. {
stud[i].gender =[ ];
stud[i].age = 0;
}
B. {
stud[i].gender = ‘ ’;
stud[i].age = 0;
}
CONFIDENTIAL FP305 DATA STRUCTURES
Page 6 of 24
C. {
stud[i].gender =0;
stud[i].age = 0;
}
D. {
stud[i]gender = ‘ ’;
stud[i]age = 0;
}
9. Which one of the following structure declaration are suitable to the given
information below: [CLO 2]
“An express bus has details of bus number, fare, driver name, number of
passenger and destination”.
The structure object name are Transnational, Konsortium , Seri Maju.
A. struct Express_bus
{
int numb_bus;
float fare;
int driver_name[5];
int numb_passenger;
int destination [10];
} Transnational, Konsortium , Seri Maju;
CONFIDENTIAL FP305 DATA STRUCTURES
Page 7 of 24
B. struct Express_bus
{
int numb_bus;
float fare;
char driver_name[5];
int numb_passenger;
char destination [10];
} Transnational, Konsortium , Seri Maju;
C. struct Express_bus Transnational, Konsortium , Seri Maju
{
int numb_bus;
float fare;
char driver_name[5];
int numb_passenger;
char destination [10];
};
D. struct Express_bus
{
int numb_bus;
float fare;
char driver_name[5];
int numb_passenger;
char destination [10];
Transnational, Konsortium , Seri Maju
};
CONFIDENTIAL FP305 DATA STRUCTURES
Page 8 of 24
10. Choose from the following the simplest method to implement a list abstract data
type. [CLO 1]
A. Linked list
B. Structure
C. Pointer
D. Array
11. “Linked list is a method to overcome the problem of array that cannot allow
alteration on it once the program is running.” [CLO 1]
Select a correct statement to justify this statement.
A. A linked list can be used to manage a dynamically growing and shrinking
list of data.
B. A linked list is used to chain a collection of data.
C. A linked list reallocating the array as needed by adding elements at a time.
D. A linked list is slow, in efficient and expensive to use.
12. Identify the code that has similar function to the following code. [CLO 1]
typedef int WAH;
WAH k;
A. typedef k
B. char k
C. int k
D. int *k
CONFIDENTIAL FP305 DATA STRUCTURES
Page 9 of 24
13. Which of the following will point to the first node of the linked list? [CLO 1]
A. Head
B. Tail
C. New
D. Next
14. Match the correct following portion of linked list with the correct function.
[CLO 1]
Codes Purpose
X (*p).data I Access the pointer field
Y Pnext
Z (*p).next II Access the data field
W pdata
A. X + I, Y + I, Z + II, W+II
B. X + II, Y + I, Z + II, W + I
C. X + II, Y + I, Z + I, W + II
D. X + II, Y + II, Z + I, W + I
15. Choose an appropriate coding commonly used to delete an item in a record.
[CLO 2]
A. Prev = curnext
B. Node Ptr Result = NULL;
C. Node Ptr Result = DELETE;
D. Delete cur;
CONFIDENTIAL FP305 DATA STRUCTURES
Page 10 of 24
16. ________ is a LIFO (Last In First Out) data structure concept where the first
data that being inserted will be the last data to delete. [CLO 1]
A. Queue
B. Searching
C. Stack
D. Array
17.
Figure 1
Which operation would you use to return the Applied Math book from the
stack above (Figure 1)? [CLO 1]
A. Top
B. Pop
C. Push
D. None of the above
CONFIDENTIAL FP305 DATA STRUCTURES
Page 11 of 24
18. Based on Figure 2 below, what is the value that will be on the top of the stack
after all of the operation being executed? [CLO 2]
i. J->data[J->top]=45;
ii. J->data[J->top]=30;
iii. J->top--;
Figure 2
A. 30
B. 45
C. 70
D. 50
19. When new data are to be inserted into a data structure, but there is no available
space, this situation is usually called? [CLO 1]
A. underflow
B. housefull
C. overflow
D. saturated
CONFIDENTIAL FP305 DATA STRUCTURES
Page 12 of 24
20. Hafeez and his friends are going to watch ‘The Smurf’ at AEON Bukit Tinggi
Klang. He is going to buy six tickets. He arrives early and is the first in a line,
other people after him stay behind. Hafeez is currently implementing ________
concept. [CLO 2]
A. Queue
B. Stack
C. Trees
D. Linked List
21. Which of the following is the function of delete Queue? [CLO 1]
A. uses one queue to delete another
B. deletes all instances of the queue
C. copies the queue into backup memory
D. removes all elements from the queue leaving an empty queue
22. The first element inserted into a queue is the first element to be removed. For
this reason, a queue is sometimes called a __________, as opposed to a stack
which is __________. [CLO 1]
A. LIFO , FIFO
B. LIFO , LIFO
C. FIFO , FIFO
D. FIFO , LIFO
CONFIDENTIAL FP305 DATA STRUCTURES
Page 13 of 24
23. Which one of the examples below did not refer to the implementation of queue
in a real life application? [CLO 1]
A. Cars at the traffic light junction
B. Clothes folded inside a wardrobe
C. Documents waited to be printed at a network sharing printer
D. Lines at the library counter
24. The linear array of queue can caused a flowed in memory. Which one of the
following types of array is use to solve this problem? [CLO 1]
A. Two dimensional
B. Circular
C. Dynamic
D. Double
25. Three basic activities can be applied to array based implementation of queue are:
[CLO 1]
i. insert items at the rear
ii. remove the element at the front
iii. return whether the queue is empty or full
iv. expand the size according to the total of value to be insert
A. i, ii and iii
B. i, ii and iv
C. ii, iii and iv
D. i, iii and iv
CONFIDENTIAL FP305 DATA STRUCTURES
Page 14 of 24
26. If the letters ‘R’,’S,’T’,’U’,’V’,’W’ are placed in a queue respectively in the
given order, and then removed one at a time, in what order will the letters be
removed? [CLO 2]
A. ‘W’,’V’,’U’,’T’,’S’,’R’
B. ‘U’,’V’,’W’,’R’,’S’,’T’
C. ‘T’,’S’,’R’,’W’,’U’,’V’
D.
‘R’,’S,’T’,’U’,’V’,’W’
27. In binary search tree, left sub-tree consist of values that are smaller than their
parent nodes. [CLO 1]
A. TRUE
B. FALSE
28. The tree of data structure is getting bigger each time a new item is added without
we notice how many nodes are there. Provide the operation that returns the
numbers of the nodes available. [CLO 2]
A. Return ()
B. Children (p)
C. Element()
D. Size()
CONFIDENTIAL FP305 DATA STRUCTURES
Page 15 of 24
29. Consider the node of a complete binary tree whose value is stored in data[i] for an
array implementation. If this node has a right child, where will the right child's
value be stored? [CLO 2]
A. data[i+1]
B. data[i+2]
C. data[2*i + 1]
D. data[2*i + 2]
30. There are 8, 15, 13 and 14 nodes in 4 different trees. Analyze which one of them
can form a full binary tree? [CLO 2]
A. 8
B. 15
C. 13
D. 14
31. Choose the correct statements about tree data structure. [CLO 2]
A. Given a set S of n real keys chosen at random from a uniform distribution
over (a:b) a binary tree can be structured on S in O(n) expected time.
B. In the worse case, a red-black tree insertion requires O(1) rotations.
C. Given a connected, weighted, undirected graph G in which the edge with
minimum weight is unique, that edge belongs to every minimum spanning
tree of G.
D. Deleting a node from a binary search tree on n nodes take O(lg n) time in
the worse case.
CONFIDENTIAL FP305 DATA STRUCTURES
Page 16 of 24
32. Point out the main disadvantageous of tree performance in searching and sorting.
[CLO 2]
A. Reordering the tree on removal of an element is a little more complex than
in a list or stack.
B. Worst case of tree is when all data is in a chain with no sub tree.
C. At worst tree will be as effective for searching and sorting as a linked list, at
best it will be much faster.
D. Tree is seems not practical to be applied in solving computer organization
problem.
33. Finding the location of the element with a given value is: [CLO 1]
A. Linked List
B. Sort
C. Stack
D. Search
34. ________ sorts a list of values by repeatedly comparing neighboring elements
in the list and swapping their position if they are not already in order.
[CLO 1]
A. Merge
B. Insertion
C. Bubble
D. Quick
CONFIDENTIAL FP305 DATA STRUCTURES
Page 17 of 24
35. [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
list 16 30 24 7 25 62 45 5 65 50
Figure 3
How many key comparisons would have to be made on the list above Figure 3
to find the number 24? [CLO 3]
A. 1
B. 2
C. 3
D. 4
36. Identify sorting type that match to Figure 4 below. [CLO 1]
Figure 4
A. Quick
B. Merge
C. Bubble
D. Selection
CONFIDENTIAL FP305 DATA STRUCTURES
Page 18 of 24
37. Below is the following list to search number 4 in Figure 5.
6, 1, 4, 8, 3, 9
Figure 5
1. Compare the key (Key 4) with the first data in the row
2. If the key is the same with the first data, so mission is accomplish do not
need to search more.
3. If key and first data not the same, need to compare the key with the
second data until the mission is accomplish.
4. If the key does not match with all of the data in the row, eliminate the
process.
According to the statement above, what is the type of searching algorithm
implement to solve the problem? [CLO 2]
A. Binary Search
B. Linear Search
C. Not Linear Search
D. Binary Tree Search
CONFIDENTIAL FP305 DATA STRUCTURES
Page 19 of 24
38. What is the correct statement that fit Linear Search and Binary Search
implementation? [CLO 1]
i. Binary Search must be in sorted condition
ii. Linear Search must be in sorted condition
iii. Linear Search will compare one by one with the key until it finds the
same value
iv. Binary Search will compare with the middle element of the list
A. i and iii
B. i, ii and iv
C. i, iii and iv
D. i, ii, iii and iv
39. Evaluate statement 1 – 3 and choose correct statement for :
[CLO 1]
1. First, search item compared with middle element of list
2. If the search item is less than middle element of list, restrict the search to
first half of list
3. Otherwise, search second half of list
A. All True
B.
C.
D.
1 only
1 and 2
2 and 3
40. In the linked list data structure, the insertion and deletion does not require data
movement, only link value is adjusted. [CLO 1]
A. True
B. False
CONFIDENTIAL FP305 DATA STRUCTURES
Page 20 of 24
SECTION B
STRUCTURE/ ESSAY (50 marks)
INSTRUCTION:
This section consists of TWO (2) structure questions. Answer ALL questions.
QUESTION 1
a) Sketch a linked list diagram referred to segment code as below :
[CLO 2]
(4 marks)
b) Answer the question based on the Diagram 1. Assume a variable list,
X and Y as a pointer.
Diagram 1
i. Write a relational expression for X to point to the node containing
value 23.
ii. Write a relational expression for Y to point to the last node in the list
[CLO 2]
(1.5 marks)
[CLO 2]
(1.5 marks)
newPtr=new mark;
newPtr->data=90;
newPtr->link=NULL;
Head=newPTR;
list
18 32 23
32
16 43
32
87
32
25
32
44
32
X Y
CONFIDENTIAL FP305 DATA STRUCTURES
Page 21 of 24
c) Explain TWO (2) differences between list and linked list.
[CLO 1]
(4 marks)
d) Draw suitable stack diagram for each statement below.
a. CreateStack(N);
b. Push(70,N);
c. Push(40,N);
d. Pop();
e. Push(80,N);
f. Pop();
g. Push(90,N);
h. Push(10,N);
[CLO 2]
(4 marks)
(4 marks)
e) State FIVE (5) operation of linear linked list. Explain ONE (1) of them. [CLO 1]
(5 marks)
CONFIDENTIAL FP305 DATA STRUCTURES
Page 22 of 24
f) Write a struct declaration on Student Record based on Table 1. The records are for
student from JTMK and JPH. Then assign value for both variable as in Table 1.
Member of Struct JTMK JPH
(a) student number 17DIP10F1036 01DEP09F1002
(b) student name Quratul’ain Mohd Rayyan
(c) semester 03 05
(d) hpnm 3.78 3.50
Table 1
[CLO 3]
(5 marks) (5 marks)
CONFIDENTIAL FP305 DATA STRUCTURES
Page 23 of 24
QUESTION 2
a) Explain the characteristic of Queue implemented using array.
b) Describe the function of variable front and variable rear in queue.
[CLO 1]
(4 marks)
[CLO 1]
(2 marks)
c) Based on the binary search tree in Figure 2a, draw a binary search tree if
the operation involves (use the original binary search tree in Figure 2a
for each operation).
Figure 2a
i. Delete I
ii. Delete S
iii. Insert K
[CLO 2]
(6 marks)
S
I U
A L
F O
T Z
Y
W
CONFIDENTIAL FP305 DATA STRUCTURES
Page 24 of 24
d) Draw a binary Tree for the expression :
i. A * B - (C + D) * (P / Q)
ii. ( (B+C) * (D-E) ) / A
[CLO 3]
(8 marks)
e) Use selections to sort the following array: {30, 60, 20, 50, 40, 10}.
Show the array content after each step.
[CLO 3]
(5 marks)