Professional Documents
Culture Documents
SCOA021 Main Exam Paper 2023
SCOA021 Main Exam Paper 2023
INSTRUCTIONS:
Question 1 [30]
Choose the letter that best answers the question. [1 mark each question].
2. Which of the following data types does not implement the Collection interface?
a. HashSet
b. TreeSet
c. ArrayList
d. LinkedList
e. Map
3. If two objects o1 and o2 are equal, what are the values for o1.equals(o2) and o1.hashCode() ==
o2.hashCode()?
a. true true
b. true false
c. false true
d. false false
4. Suppose set s1 is [1, 2, 5] and set s2 is [2, 3, 6]. After s1.addAll(s2), s1 is __________.
a. [1, 2, 2, 3, 5, 6]
b. [1, 2, 3, 5, 6]
c. [1, 5]
d. [2]
2|Page
SCOA021 MAY/JUNE EXAMINATION 2023
6. If you want to store non-duplicated objects in the order in which they are inserted, you should use
____________.
a. HashSet
b. LinkedHashSet
c. TreeSet
d. ArrayList
e. LinkedList
7. Which of the following is correct to perform the set intersection of two sets s1 and s2?
a. s1.intersect(s2)
b. s1.join(s2)
c. s1.retainAll(s2)
d. s1.intersection(s2)
3|Page
SCOA021 MAY/JUNE EXAMINATION 2023
9. Suppose your program frequently tests whether a student is in a soccer team and also need to know
the student’s information such as phone number, address, and age, what is the best data structure to
store the students in a soccer team?
a. ArrayList
b. HashMap
c. TreeMap
d. LinkedList
e. HashSet
12. An input that results in the shortest execution time is called the _____________.
a. best-case input
b. worst-case input
c. average-case input
14. For a sorted list of 1024 elements, a binary search takes at most _______ comparisons.
a. 11
b. 100
c. 512
d. 6
16. The time complexity for the Towers of Honoi algorithm in the text is ________.
a. O(n)
b. O(n^2)
c. O(n^3)
d. O(2^n)
17. The time complexity for the selection sort algorithm in the text is ________.
a. O(nlogn)
b. O(n^2)
c. O(logn)
5|Page
SCOA021 MAY/JUNE EXAMINATION 2023
d. O(2^n)
18. ______________ approach is the process of solving subproblems, then combining the solutions of
the subproblems to obtain an overall solution. This naturally leads to a recursive solution. However, it
would be inefficient to use recursion, because the subproblems overlap. The key idea behind dynamic
programming is to solve each subproblem only once and store the results for subproblems for later use
to avoid redundant computing of the subproblems.
a. Divide-and-conquer
b. Dynamic programming
c. Brutal-force
d. Backtracking
19. The time complexity for the closest pair of points problem using divide-and-conquer is ________.
a. O(n)
b. O(nlogn)
c. O(logn)
d. O(2^n)
20. ______________ approach divides the problem into subproblems, solves the subproblems, then
combines the solutions of the subproblems to obtain the solution for the entire problem. Unlike the
________ approach, the subproblems in the divide-and-conquer approach don’t overlap. A subproblem
is like the original problem with a smaller size, so you can apply recursion to solve the problem.
a. Divide-and-conquer/dynamic programming
b. Dynamic programming/divide-and-conquer
c. Brutal-force/divide-and-conquer
d. Backtracking/dynamic programming
6|Page
SCOA021 MAY/JUNE EXAMINATION 2023
26. Suppose you choose the first element as a pivot in the list {5 2 9 3 8 4 0 1 6 7}. Using the partition
algorithm in the book, what is the new list after the partition?
a. 5 2 9 3 8 4 0 1 6 7
b. 4 2 3 0 1 5 6 7 9 8
c. 4 2 1 3 0 5 8 9 6 7
d. 2 3 4 0 1 5 9 8 6 7
7|Page
SCOA021 MAY/JUNE EXAMINATION 2023
e. 2 3 4 0 1 5 6 7 8 9
28. To add a new node, you need to start a process by first placing it as _______ and move it up to
maintain the heap property.
a. the new root
b. the last node in the heap
c. the left child of the root
d. the right child of the root
29. Suppose a heap is stored in an array list as follows: {100, 55, 92, 23, 33, 81}. The parent of 81 is
_______.
a. 100
b. 55
c. 92
d. 23
e. 33
30. Suppose a heap is stored in an array list as follows: {100, 55, 92, 23, 33, 81}. After inserting 103,
what is the content of the array list?
a. {100, 55, 92, 23, 33, 81, 103}
b. {100, 55, 103, 23, 33, 92, 81}
c. {103, 55, 92, 23, 33, 81, 92}
d. {103, 55, 100, 23, 33, 81, 92}
e. {103, 55, 92, 23, 33, 81, 100}
Question 2 [10]
8|Page
SCOA021 MAY/JUNE EXAMINATION 2023
2.2 Suppose a list contains {"red", "green", "red", "green"}. What is the list after the following
code? [5]
Question 3 [10]
3.1 Write a Java program that lets the user enter any five (5) unordered numbers from a graphical
user interface and displays them in a text area, Use a linked list to store the numbers. Do not
duplicate numbers. Add the buttons Sort and Reverse to sort and reverse the list. [10]
Question 1 [25]
Write down the correct answer for each of the following questions.
1. What is the name of the process that determines whether a string of tokens can be generated by
a grammar? [01]
A. Analysing
B. Recognizing
C. Translating
D. Parsing
9|Page
SCOA021 MAY/JUNE EXAMINATION 2023
A. synthesized attribute
B. inherited attribute
C. canonical attribute
D. none of the above
C. constant folding
D. none of these
S→F⎪H
F→p⎪c
H→d⎪c
Where S, F and H are non-terminal symbols, p, d and c are terminal symbols. Which of the
following statement(s) is/are correct? [02]
S1: LL(1) can parse all strings that are generated using grammar G.
S2: LR(1) can parse all strings that are generated using grammar G.
A. Only S1
B. Only S2
C. Both S1 and S2
D. Neither S1 and S2
9. Write a regular expression for all strings that doesn't contain the substring 110
[02]
A. ((0|10)1)*
B. ((0|10)*1)
C. ((0|10)*1)*
D. None of the above
10. Write a regular definition for all strings of a’s and b’s with an even number of a’s and odd number
of b’s [02]
A. a*ba(bb)*
B. (aa)*b(bb)*
C. (aa)*b(bb)
D. (aa)b(bb)*
11 | P a g e
SCOA021 MAY/JUNE EXAMINATION 2023
Question 2 [25]
2.1 What is the difference between the compiler and the Interpreter? [02]
2.3 With aid of a diagram, list and explain all the phases of a complier. [08]
2.4 Minimize the DFA in Fig 1. Indicate all the groups and subgroups [04]
12 | P a g e
SCOA021 MAY/JUNE EXAMINATION 2023
Fig 1. DFA
2.5 Given the sematic rules in Fig 2, draw an annotated parse tree for the following expression.
[05]
(3+4) x (5+6)n
2.6 Given Table 1, determine the costs of the following instruction sequences
14 | P a g e