ICT 202 June, 2023
ICT 202 June, 2023
Final Examination
June 2023
Instructions/Information:
3. Which ofthe following tasks cannot be performed using an enhanced for loop?
Select one:
a. Multiplying all the values in an array together.
b. Comparing the elements in an array to a specific value.
c. Incrementing the value stored in each element of the array.
d. Displaying all even element values in an array.
4. What is the result of evaluating the following postfix expression: 4 8 + 2 *
Select one:
20
a.
64
b.
24
c.
40
d.
e. none of the answers are correct
5. Which of the following functions grows faster? (assume “ is the symbol for power eg
n
n’2 means to the power 2)
Select one:
a. logn
b. nlogn
c. n2
d. n
e. 10
6. Suppose you have
a singly linked list with the following elements:
5 ->8->3->1->9->null
What would be the resulting linked list after deleting the node with value 3?
Select one:
a. 5->8->1->9->null
'b. S5S->8-> 1 -> null
ce 5->8->9->null
d. 8->1->9->null
7. What is the time complexity of inserting a node at the beginning
list?
of
a singly linked
Select one:
a. O(1)
b. O(log n)
c. O(n)
d. Of@logn)
8. Which
of the following is a way to implement a stack using a linked list?
Select one:
a. Adding elements to the beginning of the linked list
b. Adding elements to the end of the linked list
c. Removing elements from the beginning of the linked list
d. Removing elements from the end of the linked list
9. Whatis the time complexity of deleting the last node in a singly linked list?
Select one:
a. O(1)
b. O(log n)
c. O(n)
d. O(n log n)
10. Which of the following is an advantage of linked lists over arrays?
Select one:
a. Linked lists have constant time access to any element
b. Linked lists use less memory than arrays
c. Linked lists can be resized without copying data
d. lists can be sorted more efficiently than arrays
Linked
TRUE/FALSE (10Marks)
True or False: A stack follows the Last-In-First-Out (LIFO) principle.
True or False: A linked list
allows for constant time insertion and deletion at any
position.
True or False: A binary search tree guarantees constant time complexity for searching,
insertion, and deletion.
True or False: A hash table provides constant time complexity for insertion, deletion,
and retrieval on average.
True or False: A tree is a connected acyclic graph.
True or False: An array is a dynamic data structure in which elements are stored in
contiguous memory locations.
True or False: A stack follows the First-In-First-Out (FIFO) principle.
True or False: A linked list can be easily traversed in both forward and backward
directions.
True or False: A binary search tree guarantees constant-time insertion and deletion
operations.
True or False: In a heap data structure, the smallest (or largest) element always is
stored at the root.
SECTION
B Answer any THREE (3) questions
Question 1
a) Using the rules and concepts learned for analysis of algorithms, show your working
given that the time complexity for the “for loop” below is O(log2n). (10 marks)
For example, if the original linked list is 1 -> 2 -> 3 -> None and the new node to be
inserted has a value of 0, the new linked list should be 0 -> 1 -> 2 -> 3 -> None. (10
marks)
b) An algorithm takes 5 seconds for an input size of 100. If the algorithm is quadratic,
approximately how long does
working(5 marks)
it take to solve a problem of size 200?.Show your
Write a line of code that creates a 5-element array called primeNums of ints and sets
its value with the first five prime numbers greater than 399 but less than 415. (5
marks)
Question 3
Write and test a java program to demonstrate the use of a stack to evaluate postfix
expression. (10 marks)
Question 4
b) Consider the following array of integers: [5, 2, 9, 1, 7]. Implement the Bubble Sort
algorithm to sort the array in ascending order. Show the step-by-step process and
provide the sorted array as the final result. (10 marks)