













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An assignment solution for Unit 19 of a BTEC Level 5 HND Diploma in Computing, focusing on Data Structures and Algorithms. The assignment involves the design and implementation of Stack and Queue Abstract Data Types (ADT) using a linked list. explanations of stack and queue concepts, their operations, and implementation using a linked list in Java. It also includes sample code and output.
Typology: High school final essays
1 / 21
This page cannot be seen from the preview
Don't miss anything!














Resubmission Feedback: Grade: Assessor Signature: (^) Date: Internal Verifier’s Comments:
I. Design and implementation of Stack ADT and Queue ADT (P4)
Figure 2. Node class Then create class Linkedlist, then create head with type Node then check if it null then return true else it have value return false. Figure 3. Linked-list class
Figure 6. Peek operation Figure 7. Main function And the result is:
Figure 8. Result of operations Figure 9. Push As diagram shown above, the last element added to stack is considered as the top of stack. When stack is empty 1 added to stack then 1 is top of stack, then add 2 into stack now 2 is top of stack then add 3 into stack, now 3 is top of stack.
Figure 11. Node class Figure 12. My queue class
Figure 13. enqueue function Figure 14. Dequeue function
Figure 17. Queue result II. Application (P4) Introduction In order to design and implement the remove duplicate value function out of linked-list here is my source code to execute that function First, I create a Node class with next is the next node.
Then in Linked-list class, I declare a Node called head
III. Implement error handling and report test results No Scope Type Operation Input Expected output Actual status output 1 Stack Normal Push() 10,5,4,2 10,5,4,2 was pushed Same as Pass ADT to stack expected Normal Pop() Pop() 2 Same as Pass expected Validation Pop() Empty stack Stack is empty and Same as Pass random min integer expected Validation Peek() Empty stack Stack is empty and Same as pass random min integer expected Normal Peek() stack[5,4,3] 5 Same as pass expected 2 Queue Normal Enqueue() Enqueue(1) Queue Element: 1 2 3 Same as pass ADT Enqueue(2) expected Enqueue(3) Normal Dequeue() Dequeue() Dequeue node: 1 Same as Pass expected Validation Dequeue() Empty queue Queue is empty Same as Pass expected 3 remove Normal removeDump() 10,12,12,13 10,12,13 Same as Pass duplicate expected Table 1. Testing table IV. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm (P6) Asymptotic analysis of an algorithm refers to defining the mathematical boundation/framing of its run-time performance. Using asymptotic analysis, we can very well conclude the best case, average case, and worst case scenario of an algorithm. Asymptotic analysis is input bound i.e., if there 's no input to the algorithm, it is concluded to work in a constant time. Other than the "input" all othe r factors are considered constant.
The above definition means, if f(n) is theta of g(n), then the value f(n) is always between c1g(n) and c2g(n) for large values of n (n >= n0). The definition of theta also requires that f(n) must b e non- negative for values of n greater than n0. (GeeksforGeeks, 2022)
V. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example (P7) space complexity: Space Complexity is misused for Auxiliary Space at many places. Following are the correct definitions of Auxiliary Space and Space Complexity. Auxiliary Space is the extra space or temporary space used by an algorithm. Space Complexity of an algorithm is the total space taken by the algorithm with respect to the input size. Space complexity includes both Auxiliary space and space used by input. Time complexity: The time complexity of an algorithm quantifies the amount of time taken by an algorithm to run as a function of the length of the input. Note that the time to run is a function of the length of the input and not the actual execution time of the machine on which the algorithm is running on. (GeeksforGeeks, 2021) Example: public static int sum(int k) { if (k <= 0 ) { return 0 ; } else { return k + sum(k - 1 ); } } In this example, k=5 each call will add new sum()to stack: sum( 5 ), sum(4), sum(3), sum(2), sum(1), sum(0) and each of these added to stack will take actual memory so the more k we input the more space we need to sum up it takes O(n) space and This function is being called recursively n times before reaching the base case so its O(n). public static int sum() { int a = 1 , b = 2 , c = 3 ; int result = a + b + c; return result; } In this example, space complexity for data will be 4 variable are a, b, c, result and time complexity is O(1) because we the process will do exactly one time.
References GeeksforGeeks (2022, June 14) “Analysis of Algorithms | Set 3 (Asymptotic Notations)”. [Online]. Available at: https://www.geeksforgeeks.org/analysis-of-algorithms-set-3asymptotic-notations/ GeeksforGeeks (2022, June 02) “Analysis of Algorithms | Set 1 (Asymptotic Analysis)”. [Online]. Available at: https://www.geeksforgeeks.org/analysis-of-algorithms-set- 1 - asymptotic- analysis/#:~:text=Asymptotic%20Analysis%20is%20the%20big,increases%20with%20the%20input%20size. Kalkicode (2021, November 06) “Implement queue using doubly linked list in java”. [online]. Available at: https://kalkicode.com/implement-queue-using-doubly-linked-list-in-java GeeksforGeeks (2022, June 18) “Stack Data Structure”. [Online]. Available at: https://www.geeksforgeeks.org/stack-data-structure/