












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 overview of two Abstract Data Types (ADTs), stacks and queues. It discusses their definitions, basic operations, and introduces two methods for measuring algorithm efficiency. The document also includes examples of stack and queue implementation and testing plans. Asymptotic analysis is used to assess the effectiveness of algorithms, specifically focusing on time complexity and the use of Θ, Big O, and Ω notations.
Typology: Essays (high school)
1 / 20
This page cannot be seen from the preview
Don't miss anything!













Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit^ 19:^ Data^ Structures^ and^ Algorithms Submission date Date Receiv ed 1st subm issio n Re-sub m issio n Date 26/07/2022^ Date Receiv ed 2nd subm issio n 26/07/ Student Name Lê Văn Đạt 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 Đạt Grading grid P4 P5 P6 P7 M4 M5 D3 D
Grade: Assesso r Signa t ure: Date: Internal Verifier’s Comments: IV Signature:
My report presents two types of ADTs, stack and queue. Define, basic operations, apply it by example are presented in ASM1. Most of the defined Stack and Queue operations as outlined in Exercise 1 are implemented and application. The report also presents a test plan for almost functionsof these two types of ADT. In addition, my report also shows how asymptotic analysis can be used to evaluate the efficiency of an algorithm. I will introduce two ways of measuring the efficiency of an algorithm with illustrative examples. The trade-off between these two algorithms when applied in practice for each problem.
LIFO data structure (Last Input First Output). The elements are pushed first, which will bepoped last. Stack is a Last In First Out (LIFO) data structure, it is based on the Last-In- First-Out principle (LIFO). The elements are pushed into the stack in order of entry first into the bottom of the stack. When getting the data, the elements are pop in reverse order, the top element is getted first (the last one pushed in). Stack in program have behaves like a real-world stack, for example a deck of cardsor a pile of plates. Java collections architecture offers a number of interfaces and classes to manage and implement application Easily. One of them is Stack
Operations of Stack There are mainly two operations: push and pop
Every Node in my Stack have attribute are “ data” and ‘next”. In my stack I stored 2 node
3 Peek Method 4 isEmpty Method
5 Size method
FIFO data structure(First-In-First-Out ). The elements are pushed first, which will be poped first(data item stored first will be accessed first ) Queue is a First-In-First-Out (FIFO) data structure. Queue is an abstract data structure, somewhat similar to Stacks. different from stacks, a queue is open at both its ends. One end is always used toinsert data (enqueue) and the other is used to remove data (dequeue). Figure 5: Queue
Somewhat similar to Stacks, There are mainly two operations: add and remove, calling enqueue() and dequeue()
3.2 Dequeue Method
3.3 Size 3.4 isEmpty
type Input Expected output Actual output Status 1 Enqueue Normal Myqueue:[1,2,3] Enqueue(4) Myqueue:[1,2,3,4] Size of Myqueue: 4 Same as expected Pass 2 Dequeue Normal Myqueue[1,2,3,4] Dequeue(); Myqueue:[1,2,3] Size of Myqueue: Same as expected Pass 3 QueueADT isEmpty Data validation Myqueue[] isEmpty() true Same as expected Pass isEmpty Normal Myqueue:[1,2,3] false Same as expected Pass 4 Size Normal Myqueue:[1,2,3] 3 Same as expected Pass Size Data validation Myqueue[] 0 Same as expected Pass 5 Push Normal Mystack[1,2,3] Push(a) Mystack[1,2,3,a] Same as expected Pass 6 Pop Normal Mystack[1,2,3,a] Pop() Mystack[1,2,3] Same as expected Pass 7 Mystack Peek Normal Mystack[1,2,3] Peek() Mystack[1,2,3] 3 Same as expected Pass 8 isEmpty Normal Mystack[1,2,3] false Same as expected Pass isEmpty Data validation Mystack[] True Same as expected Pass 9 Size Normal Mystack[1,2,3] 3 Same as expected Pass Size Data validation Mystack[] 0 Same as expected Pass 10 removeDumplicate removeDumplicate Normal Myqueue[1,2,2,3] Myqueue[1,2,3] Size: 3 Same as expected Pass removeDumplicate Data validation Myqueuep[1,2,3] Myqueue[1,2,3] Size: 3 Same as expected Pass
that 0 <= c1g(n) <= f(n) <= c2g(n) for all n >= n0 } 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 be non- negative for values of n greater than n0. Big O Notation: The Big O notation defines an upper bound of an algorithm, it bounds a function only from above. For example, consider the case of Insertion Sort. It takes linear time in the best case and quadratic time in the worst case. We can safely say that the time complexity of Insertion sort is O(n^2). Note that O(n^2) also covers linear time. If we use Θ notation to represent time complexity of Insertion sort, we have to use two statements for best and worst cases: The worst-case time complexity of Insertion Sort is Θ(n^2).
Algorithm efficiency A measure of the average execution time necessary for an algorithm to complete work on a set of data. Algorithm efficiency is characterized by its order. 2 kinds of algorithm efficiency are Space efficiency and Time efficiency. In computer science, algorithmic efficiency is a property of an algorithm that relates to the number of computational resources used by the algorithm. Time Complexity: time (computation time or response time) consumed in performing a given task. Space Complexity: the data storage (RAM, HDD etc.) consumed in performing a given task
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. Auxiliary Space is the extra space or temporary space used by an algorithm. Example of Space Complexity Figure 11: example of space complexity The space complexity for Bubble Sort is O(1), because only a single additional memory space is required for temp variable. It is an in-place sorting algorithm i.e. it modifies elements of the original array to sort the given array. Also, the best case time complexity will be O(n), it is when the list is already sorted.
Time Space Trade Off: It is a way of solving a problem or calculation in less time by using more storage space (or memory), or by solving a problem in very little space by spending a long time. It is a case where an algorithm or program trades increased space usage with decreased time. Here, space refers to the data storage consumed in performing a given task (RAM, HDD, etc), and time refers to the time consumed in performing a given task (computation time or response time) Need of Time Space Tradeoff: ❖ Less time by using more memory ❖ By solving a problem in very little space by spending a long time. Example : ArrayList with LinkedList, with two functions: adding and removing elements. ArrayList requires less memory than LinkedList. But ArrayList adding and removing elements is SLOWER than LinkedList. This is quite understandable because LinkedList only needs to change the pointer flow of the nodes in the list, so the complexity is O(1) and ArrayList has to increase/reverse all positions after the position you want to add/remove, so the complexity is is O(n).
8. Reference https://www.geeksforgeeks.org/abstract-data-types/ https://www.geeksforgeeks.org/understanding-time-complexity-simple-examples/ https://www.geeksforgeeks.org/analysis-of-algorithms-set-3asymptotic-notations/ https://adrianmejia.com/most-popular-algorithms-time-complexity-every-programmershould- know-free-online-tutorial-course/ https://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm https://citizenchoice.in/course/Data-Structures-and-Algorithms/Chapter%201/Time-Space-Trade- off-Abstract-Data-Types-ADT-