1649 Frontsheet2
1649 Frontsheet2
P4 P5 P6 P7 M4 M5 D3 D4
Assessor Feedback:
Resubmission Feedback:
*Please note resubmission feedback is focussed only on the resubmitted work
07.03-BM/ĐT/HDCV/FE 1/0
1/19
Internal Verifier’s Comments:
* Please note that grade decisions are provisional. They are only confirmed once internal and external
moderation has taken place and grades decisions have been agreed at the assessment.
07.03-BM/ĐT/HDCV/FE 1/0
2/19
Student Assessment Submission and Declaration
When submitting evidence for assessment, each student must sign a declaration confirming that the
work is their own.
Program: Computing
Plagiarism
Plagiarism is a particular form of cheating. Plagiarism must be avoided at all costs and students who break the
rules, however innocently, may be penalized. It is your responsibility to ensure that you understand correct
referencing practices. As a university level student, you are expected to use appropriate references
throughout and keep carefully detailed notes of all your sources of materials for material you have used in
your work, including any material downloaded from the Internet. Please consult the relevant unit lecturer or
your course tutor if you need any further advice.
Student Declaration
Student declaration
I certify that the assignment submission is entirely my own work, and I fully understand the
consequences of plagiarism. I declare that the work submitted for assessment has been
carried out without assistance other than that which is acceptable according to the rules of the
specification. I certify I have clearly referenced any sources, and any artificial intelligence (AI)
tools used in the work. I understand that making a false declaration is a form of malpractice.
07.03-BM/ĐT/HDCV/FE 1/0
3/19
07.03-BM/ĐT/HDCV/FE 1/0
4/19
Contents
1.Design and implementation of ArrayList ADT and Linked List ADT (P4)..............................................................6
2.1Testing plan......................................................................................................................................................14
3.Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm (P6)..............................15
5.Determine two ways in which the efficiency of an algorithm can be measured, illustrating your..........................18
References................................................................................................................................................................. 20
07.03-BM/ĐT/HDCV/FE 1/0
5/19
1.Design and implementation of ArrayList ADT and Linked List ADT (P4)
By customizing these data structures, I improved system performance and scalability, which was crucial
for handling large data volumes and complex interactions. This optimization led to better network
provisioning efficiency and integration, boosting the middleware's overall functionality and reliability.
My efforts played a key role in deploying a robust middleware solution that bridged telecom systems and
provisioning interfaces, supporting the company’s goal of delivering high-performance, scalable network
services.ArrayList ADT
The code defines an ArrayList class with a generic data type. In it, elements is an array that stores the
elements of the list, with an initial capacity of 12. The size variable keeps track of the number of elements
present, and capacity stores the maximum capacity of the array. When an ArrayList object is created, the
array is initialized with a capacity of 12 elements and size is set to 0.
07.03-BM/ĐT/HDCV/FE 1/0
6/19
Figure 2 resize() method
The resize() method in the code expands the capacity of the elements array by multiplying its capacity by
3, then copies the contents of the old array into a new array of increased capacity. This ensures that the
array has enough space to hold additional elements when needed.
The add(T element) method adds an element to the list. If the list is full (its current size equals its
capacity), it calls the resize() method to expand the array's capacity. The new element is then added to the
current position of size, and size is incremented by one to reflect the number of new elements in the list.
The get(int index) method retrieves the element at the specified position in the list. If the index is within
the valid range (from 0 to size - 1), it returns the element at that position. If the index is invalid, i.e.
outside the current range of the list, the method throws an IndexOutOfBoundsException with the error
message "Index out of bounds".
07.03-BM/ĐT/HDCV/FE 1/0
7/19
Figure 4 set() method
The set(int index, T element) method updates the element at the specified position in the list. If the index
is valid (from 0 to size - 1), the method assigns the element value to that position in the elements array. If
the index is invalid, the method throws an IndexOutOfBoundsException with the error message "Index
out of bounds
The remove() method removes the last element in the list. If the list is not empty (size greater than 0), it
assigns null to the last position of the elements array and reduces the size of the list by one. If the list is
empty, the method throws an IllegalStateException with the error message "List is empty"
The search(T element) method searches for an element in the list from the end to the beginning. It starts at
the last index of the elements array and iterates through the elements in descending order. If an element
07.03-BM/ĐT/HDCV/FE 1/0
8/19
that matches the value of element is found, it returns the index of that element. If the element is not found,
the method returns -1 to indicate that the element is not in the list.
The isEmpty() method checks whether the list is empty or not. If the size of the list is 0, i.e. there are no
elements, the method returns true. Otherwise, if the list has elements, it returns false.
The size() method returns the number of elements currently in the list. It simply returns the value of the
size variable, which reflects the current size of the list.
07.03-BM/ĐT/HDCV/FE 1/0
9/19
Figure 9 Make LinkedList Constructor and Fields
The LinkedList class defines a linked list with a generic data type. It uses two variables, firstNode and
lastNode, to keep track of the first and last nodes in the list, along with a size variable to keep track of the
number of elements. The Node class internally stores data and references to the next and previous nodes.
When a LinkedList object is created, the firstNode and lastNode variables are initialized to null, and size
is set to 0, indicating that the list starts out empty.
The add(T element) method adds an element to the end of a linked list. If the current list is empty (there
are no nodes), it assigns both firstNode and lastNode to the newly created node. If the list is not empty, it
links the new node to the current last node (lastNode) by setting the last node's next reference to the new
node and the new node's prev reference to the last node. It then updates the lastNode to point to the new
node. Finally, the size variable is incremented by one to reflect the change in the number of elements.
07.03-BM/ĐT/HDCV/FE 1/0
10/19
Figure 11 get() method
The get(int index) method retrieves the element at the specified position in the linked list. It first calls the
checkIndex(index) method to verify that the index is valid. Then it uses the getNode(index) method to get
the node at that position and returns the data of that node.
The set(int index, T element) method updates the data at the specified position in the linked list. It first
calls the checkIndex(index) method to ensure the index is valid. Then it gets the node at that position
using the getNode(index) method and assigns the new value element to the data field of that node.
07.03-BM/ĐT/HDCV/FE 1/0
11/19
The remove() method removes the last element from a linked list. If the list is empty (lastNode is null), it
throws an IllegalStateException with the message "List is empty". If the list has only one element
(firstNode and lastNode are the same node), both firstNode and lastNode are set to null, emptying the list.
If the list has more elements, it updates lastNode to point to the previous node and sets the new last node's
next reference to null. Finally, size is decremented by one to reflect the change in the number of elements.
The search(T element) method searches for an element in the linked list from the end to the beginning. It
starts from the last node (lastNode) and checks the data of each node. If an element matching the value of
element is found, the method returns the index of that element. If the element is not found in the entire list,
the method returns -1
The isEmpty() method checks whether the linked list is empty or not. If the number of elements (size) is 0,
meaning the list contains no elements, the method returns true. Otherwise, if the list contains at least one
element, the method returns false.
07.03-BM/ĐT/HDCV/FE 1/0
12/19
Figure 16 size() method
The size() method returns the number of elements currently present in the linked list. It simply returns the
value of the size variable, which indicates the size of the list at the time of calling the method.
The getNode(int index) method finds and returns the node at the specified position in the linked list. If
index is close to the beginning of the list (less than half the size of the list), the method starts at firstNode
and moves through the nodes using the next link until it reaches the desired position. Conversely, if index
is close to the end of the list, the method starts at lastNode and moves back to the beginning of the list
using the prev link. The method returns the node found at the specified position.
07.03-BM/ĐT/HDCV/FE 1/0
13/19
Figure 18 checkIndex() method
The checkIndex(int index) method checks the validity of the index. If index is less than 0 or greater than
or equal to the current size of the list (size), the method throws an IndexOutOfBoundsException with the
message "Index out of bounds". This ensures that the index used is valid and does not exceed the range of
the list.
2.1Testing plan
No Scope Operation Testing Input Expected Actual Status
Type Output OutPut
07.03-BM/ĐT/HDCV/FE 1/0
14/19
10 LinkedList set(int index, T Test Index: 1, Element at Element at Pass
element) Element: Index 1: Index 1:
"5" "5" "5"
- Failure Cases: An analysis of 0 failure cases and recommendations for improvement The absence of
failure situations in this evaluation suggests that the fundamental functions of the LinkedList and
ArrayList ADTs have been implemented correctly and are operating as intended.
3.Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm (P6)
The key concept in algorithm analysis that addresses the aforementioned problems is known as asymptotic
analysis. Asymptotic Analysis measures an algorithm's performance in terms of input size rather than its
actual execution time. We compute the algorithm's time (or space) complexity as a function of input size.
(Geeksforgeeks, n.d.)
An algorithm's space complexity or running time can be expressed in terms of the size of the input by
using asymptotic notation. It is frequently used in complexity analysis to explain how an algorithm
functions as the amount of input increases. Big O, Big Omega, and Big Theta are the three most utilized
notations. (Geeksforgeeks, n.d.)
-The Big O notation (O) gives an upper bound on the rate at which the running time or space usage of an
algorithm grows. It stands for the worst-case situation, or the most time or space that an algorithm might
use to finish a task. For instance, if the running time of an algorithm is O(n), it indicates that the method's
running time grows linearly with an input size of n or less. (Geeksforgeeks, n.d.)
-Omega notation (Ω): This notation gives a lower bound on the rate at which the space or running time of
an algorithm grows. It stands for the best-case scenario, or the smallest possible amount of time or space
required by an algorithm to complete a task. When an algorithm's running time is Ω(n), for instance, it
07.03-BM/ĐT/HDCV/FE 1/0
15/19
indicates that the algorithm's running time grows linearly with an input size of n or greater.
(Geeksforgeeks, n.d.)
-Theta notation (Θ): This notation gives the growth rate of the space or running time of an algorithm both
an upper and lower bound. It stands for the worst-case situation, or the average amount of time or space
required by an algorithm to complete a task. For instance, if the algorithm's running time is Θ(n), it
indicates that the algorithm's running time grows linearly in relation to the input size n. (Geeksforgeeks,
n.d.)
07.03-BM/ĐT/HDCV/FE 1/0
16/19
Figure 19 A graph illustrating how complexity rises with the number of procedures (Salvi,
2023)
Example:
Best-case scenario: Finding the target element at the start of the list in O(1) time is the best-case scenario
for a linear search over an unsorted list.
Average-case scenario: An unsorted list would take O(n/2) or O(n) time to search through linearly,
meaning you would typically need to look through half of the list before finding the requested entry.
Worst-case situation: In the worst-case scenario, a linear search would need to examine all n elements,
taking O(n) time, when the target element lies at the end of an unsorted list.
Best-case scenario: It usually takes O(1) time to access an element by index in an array or list where the
index is known. Regardless of the magnitude of the input, the processing time is constant.
Average-case scenario: As long as collisions are kept at a minimum, searching for an element by key in a
hash table with a well-distributed hash function can be regarded as O(1) on average.
Worst-case scenario: A hash table search may occasionally encounter collisions that prolong the search
time, but if the load factor is managed, the search can still be regarded as O(1).
5.Determine two ways in which the efficiency of an algorithm can be measured, illustrating your
Space Complexity (Big-O notation): When solving problems on a computer, memory is needed to store
temporary information or the outcome of the program while it is running. Space complexity of the
algorithm is the amount of memory needed by the method to solve a particular problem. The quantity of
07.03-BM/ĐT/HDCV/FE 1/0
17/19
space required for an algorithm to execute as a function of the input length is measured by the algorithm's
space complexity (GeeksforGeeks, 2023).
Example:
Time Complexity: The while loop, which continues as long as i > 1, is the main piece of logic. This loop
will, in the worst scenario, execute O(sqrt(n)) times, where n is the input number i.
This is due to the loop's division of i by each of its j components until i equals 1. A number n's maximum
sqrt(n) is its number of factors.
Space Complexity: To store the factors, the technique builds a stack. The stack will hold sqrt(n) factors in
the worst scenario.
Since the stack size will, in the worst scenario, be proportional to the square root of n, the space
complexity is therefore O(sqrt(n)).
07.03-BM/ĐT/HDCV/FE 1/0
18/19
The fun function takes an integer array a and an integer value to search for called item.
- If both conditions are true, increment j to check the next element in the array
- Line 3: Check if item was found based on final j value after loop Time complexity is O(n) because in
worst case we must traverse all n elements. Space complexity is O(1) because only extra variable j is used
References
- GeeksforGeeks, 2024. Types of Asymptotic Notations in Complexity Analysis of Algorithms. [Online]
Available at: https://www.geeksforgeeks.org/types-of-asymptotic-notations-in-complexity-analysis-of-
algorithms/ [Accessed 22 8 2024]
- GeeksforGeeks 2023. Time Complexity and Space Complexity, GeeksforGeeks. Available at:
https://www.geeksforgeeks.org/time-complexity-and-space-complexity/ [Accessed 22 8 2024]
07.03-BM/ĐT/HDCV/FE 1/0
19/19