Design and Implement Stacks and Queues with Duplicate Removal, Essays (high school) of Computer science

A BTEC Level 5 HND Diploma in Computing assignment focusing on Unit 19: Data Structures and Algorithms. The student, Nguyen Le Hoang Anh, has submitted their work for assessment, which includes the design and implementation of stack and queue Abstract Data Types (ADTs) and the removal of duplicate values from these data structures. an in-depth explanation of the operations of stack and queue, including push, peek, pop, size, enqueue, and dequeue. Additionally, the document discusses the concept of asymptotic analysis and its use in assessing the effectiveness of algorithms.

Typology: Essays (high school)

2021/2022

Uploaded on 10/18/2022

handsome-hoang
handsome-hoang 🇻🇳

3.7

(7)

8 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 2 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures and Algorithms
Submission date
29/06/2022
Date Received 1st submission
29/06/2022
Re-submission Date
26/07/2022
Date Received 2nd submission
26/07/2022
Student Name
Nguyen Le Hoang Anh
Student ID
GCH200057
Class
GCH0906
Assessor name
Do Hong Quan
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand
that making a false declaration is a form of malpractice.
Student’s signature
Grading grid
P4
P5
P6
P7
M4
M5
D3
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Design and Implement Stacks and Queues with Duplicate Removal and more Essays (high school) Computer science in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 19: Data Structures and Algorithms

Submission date 29 /06/2022 Date Received 1st submission 29/06/ 2022

Re-submission Date 26/07/2022 Date Received 2nd submission 26/07/

Student Name Nguyen Le Hoang Anh Student ID GCH

Class GCH0906 Assessor name Do Hong Quan

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand

that making a false declaration is a form of malpractice.

Student’s signature

Grading grid

P4 P5 P6 P7^ M4 M5 D3 D

Summative Feedback:

Resubmission Feedback: Grade: Assessor Signature: (^) Date: Internal Verifier’s Comments:

IV Signature:

I. Design and implementation of stack ADT and Queue ADT (P4)

  1. Stack Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). Operation of stack: Push():

Figure 1. Push operation First I declared new node then check if it null then will print to screen message, if not null will insert x to data of node then link node to top then assign top to node, finally I will plus 1 to nodesCount. Peek(): Figure 2. Peek operation I will check if stack is empty, if true then print to screen message, if not then print data of top node.

Queue operation: Enqueue: First I created new node then check if this front of node is empty is not which mean queue already have node or not, if not then assign this.front = node and increase size by 1 and rear is also node, if front is not null then the node next to rear will be node then increase size by 1, rear now is node. Figure 5. Enqueue operation

Dequeue: first thing to do is check if queue is empty or not, if it empty then return - 1, if not empty then declare data equal to this.peek() and peek() operation return data of front node of queue, next create Node temp equal to front then check if queue has only one node then assign rear and front to null, else this.front will be moved to next node and prev will be null. After all decrease size to 1 and return data. Figure 6. Dequeue operation II. Application

  1. Introduction to design and implement the operations that take Stack and Queue as their inputs respectively, then remove those duplicate values from these data structures here is my source code to do that function.
  2. Implementation First I declare three nodes are current, index and tmp, the node current will point to head, next on line 32 I will check if list is empty or not if it not empty then Code in else on line 35 will run, first current will st art from head and for loop will run until current is null, after each loop current will equal to current.next, inside first for loop, I

III. Implement error handling and report test results

  1. Testing plan

Scope Operation Testing Input Expected output Actual output Status

type Push() Normal LinkedList:[1,3,4]; LinkedList:[5,3,2 Same as Pass Push(5); ,1]; expected Size: 4 Peek() return 5 1 Stack ADT Pop() Normal LinkedList:[1,3,4]; LinkedList:[3,2 ,1]; Same as Pass Pop() Removed: 5 expected Size: 3 Peek() return 3 Pop() Data LinkedList[] Print “stack is Same as Pass validation Pop() empty” expected Peek() Normal LinkedList:[1,3,4]; Return 3 Same as Pass Peek() expected Peek() Data LinkedList[] Print “stack is Same as Pass validation empty” expected Enqueue( Normal DoubleLinkedlist[1,2, DoubleLinkedlist[1 Same as Pass ) 3]; ,2,3,10]; expected Enqueue(10) Size: 4 Peek() return 1 2 Queue Dequeue Normal DoubleLinkedlist[1,2, DoubleLinkedlist[1 Same as Pass ADT 3,10]; ,2,3]; expected Dequeue() Size: 3 Removed 10 Peek() return 1 isEmpty() Data DoubleLinkedlist[] Print message “list Same as Pass validation isEmpty() is empty” expected isEmpty() Data DoubleLinkedlist[1,2, Print message “list Same as Pass validation 3] is not empty” expected isEmpty() 3 Remove RemoveD Normal Linkedlist[1,2,2,3] Linkedlist[1,2,3] Same as Pass Duplicate up() expected

  1. Evaluation There are 10 testcases have been shown and none of them fail

IV. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm Asymptotic analysis refers to the computing of the running time of any piece of code or the operation in a mathematical unit of a computation. Its operation is computed in terms of a function like f(n). (Khatri, 2018)

  • Big-O: Big O is used to measure the performance or complexity of an algorithm. In more mathematical term, it is the upper bound of the growth rate of a function, or that if a function g(x) grows no faster than a function f(x), then g is said to be a member of O(f). In general, it is used to express the upper bound of an algorithm and which gives the measure for the worst time complexity or the longest time an algorithm possibly takes to complete. Example: O(g(n)) = { f(n): there exist positive constants c and n0, such that 0 ≤ f(n) ≤ cg(n) for all n ≥ n0 } (Studios guy,2022)
  • Big-Omega: is the formal way to express the lower bound of an algorithm's running time. It measures the best case time complexity or the best amount of time an algorithm can possibly take to complete Big- Omega: is the formal way to express the lower bound of an algorithm's running time. It measures the best case time complexity or the best amount of time an algorithm can possibly take to complete.

(Studios guy,2022)

  • O(1) : Often referred as constant time, it not depends on the number of items. Which always be th e best scenario
  • O(n): represents the complexity of a function that increases linearly and in direct proportion to the number of inputs.
  • O(log n): O(log n) represents a function whose complexity increases logarithmically as the input size increases. Example: class BubbleSort { void bubbleSort(int arr[]) { int n = arr.length; for (int i = 0 ; i < n - 1 ; i++) for (int j = 0 ; j < n - i - 1 ; j++) if (arr[j] > arr[j + 1 ]) { int temp = arr[j]; arr[j] = arr[j + 1 ]; arr[j + 1 ] = temp; } } } In Bubble sort algorithm above, If the numbers are already sorted in ascending order, the algorithm will determine in the first iteration that no number pairs need to be swapped and will then terminate immediately. Best case time complexity: O(n). Worst case is when the array is in reverse order: Worst case time complexity: O(n²) The Average case occur when the array is in random order: Average case Time complexity: O(n²) V. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example two ways measured an algorithm are:
  • Time complexity
  • Space complexity Space complexity: Space Complexity of an algorithm is the total space taken by the algorithm with respect to the inputsize. Space complexity includes both Auxiliary space and space used by input. For example, if we want to compare standard sorting algorithms on the basis of space, then Auxiliary Space would be a better criterion than Space Complexity. Merge Sort uses O(n) auxiliary space, Insertion sort, and Heap Sort use O(1) auxiliary space. The space complexity of all these sorting algorithms is O(n) though. (GeeksforGeeks, 2022).

Time complexity Time complexity estimates how an algorithm performs regardless of the kind of machine it runs on. You can get the time complexity by “counting” the number of operations performed by your code. This time complexity is defined as a function of the input size n using Big-O notation. n indicates the input size, while O is the worst- case scenario growth rate function. Example: In this example, the time complexity is O(1) because the process will run only one time and the space complexity will be 3 variables are x, y and sum. In this example, the loop will loop n time base on array length so time complexity here is O(n), auxiliary space are 2 variables sum and I and space for input data is size of array, in this example is 5.

References Anon., 2021. geeksforgeeks.org. [Online] Available at: https://www.geeksforgeeks.org/g-fact-86/ [Accessed 26 6 2022]. Jalli, A., n.d. codingem. [Online] Available at: https://www.codingem.com/what-is-a-fifo-queue/ [Accessed 23 6 2022]. Vineet Choudhary. [Online] Available at: https://developerinsider.co/big-o-notation-explained-with- examples/ [Accessed 2022]. GeeksforGeeks. “Analysis of Algorithms | Set 1 (Asymptotic Analysis)”. [Online]. Available at: https://www.geeksforgeeks.org/analysis-of-algorithms-set- 1 - asymptoticanalysis/#:~:text=Asymptotic%20Analysis%20is%20the%20big,increases%20with%20the%20input%20si ze. [Accessed 2022, June 02] Kalkicode “Implement queue using doubly linked list in java”. [online]. Available at: https://kalkicode.com/implement-queue-using-doubly-linked-list-in-java [Accessed 2021, November 06]