Docsity

Understanding Abstract Data Types (ADT) and Their Applications, Cheat Sheet of Data Structures and Algorithms

Toggle sidebar
bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
TEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures and Algorithms
Submission date
22/06/2023
Date Received 1st submission
22/06/2023
Re-submission Date
Date Received 2nd submission
Student Name
Vo Ba Quan
Student ID
BS00216
Class
PBIT170101
Assessor name
Ms THAI THI THANH THAO
Student declaration
I certify that the assignment submission is entirely my work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Student’s signature
Quan
Grading grid
P1
P2
P3
P4
P5
M2
M3
M4
M5
D2
D3
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21

Partial preview of the text

Download Understanding Abstract Data Types (ADT) and Their Applications and more Cheat Sheet Data Structures and Algorithms in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification TEC Level 5 HND Diploma in Computing Unit number and title Unit 19: Data Structures and Algorithms Submission date 22 /06/2023 Date Received 1st submission 22 /06/ Re-submission Date Date Received 2nd submission Student Name Vo Ba Quan Student ID BS Class PBIT170101 Assessor name Ms THAI THI THANH THAO Student declaration I certify that the assignment submission is entirely my work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Quan Grading grid P1 P2 P3 P4 P5 M2 M3 M4 M5 D2 D

Contents

LIST OF TABLE

Table 1 ADT........................................................................................................................................... 5 Table 2 Stack momory work ............................................................................................................... 25

Introduction This quest has been of no help to me regarding the ADT that asked for this quest. It provides a lot of in-depth information, including the definition, representation, stack memory, and other aspects of ADT. In addition, I will use the description to create software for the abstract data type of the stack. Then I learned about some real-world applications of ADT and stacks. In the last section, we will go over the advantages of using ADT for data encapsulation and obfuscation. As a result, I can view the ADT request script and send the task request.

Figure 1. Abstract data type model These actions provide (List, Stack, and Queue) the capacity to communicate with the data of their instances. The phrase in the operation's name also demonstrates each participant's distinct objective and sensible conduct. Users do not need to re-program from scratch instead, they may utilize the built-in functions. It simply gives users public functions to use and hides the complexity of handling those functions. ADTs are constantly updated with improvements made over time, which saves time. Popular ADT includes List, Stack, and Queue. Features of ADT: Abstraction: The user simply has to know the bare minimum because the implementation of the data structure is not required. An improved conceptualization : ADT helps us have a more accurate understanding of reality. Robust: The software can detect flaws and is resilient. Encapsulation : ADTs give a public interface for users to interact with the data while hiding the data's underlying features. As a result, the data structure may be maintained and modified more easily. Abstraction of Data: ADTs offer a degree of abstraction from the specifics of the data's implementation. Users simply need to be aware of the operations that can be carried out on the data, not how those operations are carried out. Independence of Data Structure: Different data structures, such as arrays or linked lists, can be used to implement ADTs without impairing their usefulness. Information Withholding: Only by providing access to legitimate users and operations, ADTs can safeguard the data's integrity. This lessens the chance of mistakes and data abuse. Modularity: ADTs can be joined to create bigger, more complicated data structures. Programming may now be more flexible and modular because of this.

Benefits Encapsulation: To make the data structure easier to manage and alter, ADTs offer a mechanism to combine data and actions into a single unit. Abstraction: Programming can be made simpler and less likely to make mistakes by using ADTs, which let users deal with data structures without being aware of the implementation specifics. Disadvantage Overhead: Performance may be impacted by memory and processing overhead caused by the implementation of ADTs. Complexity: Especially for big and complicated data structures, ADTs can be difficult to construct. Curve of Learning: Utilizing ADTs necessitates understanding how they are implemented and used, which might take some time and effort to master. Limited adaptability: Some ADTs may not be functionally complete or appropriate for all kinds of data structures. Cost: The cost of development may rise as a result of the implementation of ADTs, which might necessitate more funding and investment. Abstract data types can be portrayed in several ways that are widespread. The most typical ones are as follows: Interfaces: An interface is a contract that specifies the methods that a type must have. It does not specify how those techniques are used. This permits many implementations of the same interface, which can be advantageous for flexibility and performance. Abstract classes : A class that can't be directly instantiated is said to be abstract. The requirement is that it be subclassed and that the subclass implements the abstract methods of the abstract class. Defining similar functionality for a collection of related classes enables code reuse. Database structures : A data structure is an abstract data type that is implemented in tangible form. It offers a specialized system for storing and managing data. The performance of operations on data can be enhanced by the usage of data structures. Depending on the particular requirements of the application, there are many ways to represent abstract data types. An interface could be the best option in certain circumstances, but an abstract class or data structure might be a better fit in others.

Figure 3 Linked list Visualization of a Node Each component of a linked list has a name, known as a node. Each node contributes to the structure of the list by containing data and a reference to the next node. The head, which links to the list's top node and gives us access to all of the other items in the list, is the list's initial node. We can tell when the list ends since the final node, sometimes referred to as the tail corresponds to NULL. A node in a single linked list is shown graphically below: Figure 4. node in a singly linked list Figure 5. single-linked list

Basic operations on singly linked lists The following procedures are carried out on a singly linked list:  Insertion  Deletion  Display We must first build an empty list by utilizing the subsequent method to accomplish the procedures indicated above: Step 1: Verify that all of the program's header files are present. Step 2: Compile a list of all user-defined functions. Step 3: Construct a Node structure with two data elements. Step 4: Create a "head" for the Node pointer and set it to NULL. Step 5: Put the main method into action by displaying an operations menu and calling the relevant methods in the main method to carry out the user's selected operation. a. Insertion We can insert data into the list after it has been created. In a single linked list, the insertion operation may be performed in three distinct ways.  Adding at the beginning of a list  Adding at the end of the list  Inserting at a precise location in a list Adding at the beginning of a list Figure 6 Start of Singlely Linked List Insertion The steps shown below can be used to add a new node to the beginning of a singly linked list: Step 1: Create a new Node using the provided value. Step 2: Confirm that the list is empty (head == NULL). Step 3: If the head is empty, set newNodenext = NULL and newNode as the next node. Step 4: If it's not empty, set newNodenext = head and head = newNode.

Step 5: Move the temp one node at a time until it reaches the node where the new node should be placed (until temp1data equals location, where location is the node value). Step 6: At regular intervals, determine if the temperature has reached the final node. The notice "Given node is not found in the list!" appears if you reach the last node. The message "Insertion is not possible!" will show up, and the function will be ended. If not, raise the temperature to the subsequent node. Step 7: Finally, set the values for "newNodenext = tempnext" and "tempnext = newNode." b. Deletion There are three ways to delete items from a single linked list. The details are as follows:  Delete first on the list  Delete starting at the end of the list.  Delete a Specific Node Delete first on the list Figure 9 Deleting the first node of a singly linked list Apply the following steps to remove a node from the starting point of the single linked list: Step 1: determine whether the list is empty (head == NULL). Step 2: Display the message "List is Empty!" if the list is empty. The function is ended with the message "Deletion is not possible!" Step 3: Create a temporary Node reference and initialize it with the head if it is not already there. Step 4: Make sure there is just one node in the list (temp next == NULL). Step 5: If TRUE, set the requirements for an empty list and change the head to NULL. Step 6: Set head = temp next and remove temp if the response is FALSE Delete starting at the end of the list.

Figure 10 End Node of Singlely Linked List gets deleted A node can be taken out of the single linked list's end using the following procedures: Step 1: is to determine whether the list is empty (head == NULL). Step 2: If the list is empty, proceed and display the message "List is Empty!" The function is ended as deletion is not possible. Step 3: If it's not empty, make two Node pointers called "temp1" and "temp2," and set "temp1" to the head. Step 4: Check (temp1 next == NULL) that there is only one Node on the list Step 5 : Find out whether it is TRUE. Once temp1 has been deleted, set head to NULL. The function is then shut down altogether. (Determining what constitutes an empty list). Step 6: If the response is false. Set "temp2 = temp1" before shifting temp1 to the following node. Till you reach the final node in the list, keep going in this manner. (Until after temp1 == NULL). Step 7: Remove temp1 and change temp2 next to NULL to complete the process. Delete a Specific Node Figure 11 Eliminating a Specific Node from an Individually Linked List To eliminate a specific node from the single linked list, follow these instructions: Step 1: determine whether the list is empty (head == NULL). Step 2: The function is ended and the message "List is Empty!!! Deletion is not possible" is displayed if the list is empty. Step 3: Create two Node pointers, "temp1" and "temp2," and set "temp1" to the head if it is not already empty. Step 4: Drag the temp1 till it reaches the last node or the specific node that has to be erased. And be sure to set "temp2 = temp1" before transferring "temp1" to the following node. Step 5: The notice "Given node not found in the list! Deletion Not Pssible" shows after you reach the last node. The function is then finished. Step 6: If you have located the specific node that you wish to remove, confirm that there is only one node in the list. Step 7: If the list only has one node and that node is the one to be eliminated, set head = NULL and remove temp1 (free(temp1)).

Figure 13 Node Example Then the next step is to build a Java class called "singlylinkedlist"; sometimes it is shortened to "SLLLlist", but we can change that and put a list of words after it. Make the Round List & Checklist function public. A variety of techniques, including add, delete, search and empty enumeration, will be developed. A value will be added to an index using the add method. Old components of a position are pushed back when value is added to it.

The delete method deletes the index value and verifies that the previous index is valid. The value of the desired index, including delete tail, delete Node, delete head etc., will be returned by get method, after writing a single line of code we always create a note so that we can then have its purpose can be assessed. Figure 14 Example of ADT To print the outcome, the user must simply utilize this ADT-called function to print the entire ring list. Figure 15 Example of ADT After testing, results will be available.

P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer.

1. Stack ADT Stack ADT is a type of linear data structure that is used to store data; it is quite similar to a linked list. To put it another way, the stack may also be thought of as an ordered list. As a result, the stack depends on the order in which data is saved and retrieved. In essence, the final element inserted also becomes the first element taken out of the stack. The ADT stack method is also known as LIFO (Last In First Out) or FILO (First Out) in the final list. All additions are made at the top. Everything that is removed will be rebuilt from scratch. In the opposite sequence from which they were added, everything is removed. The stack is represented by a stack of disks; to remove the bottom disk, you must first remove the top disk; to add a new disk, you must first place the top disk. Figure 17 Stack 2. Overview stack operations  push (Element item): Return true (successful) or false (failed) after adding a data type Element item to the top of the stack.  pop (): Remove a stack item from the top and give its value back.  peek (): Get the value that is at the top of the stack.  Isempty (): Checks to see whether there is an item on the stack and returns true or false depending on the result.  topEl(): Return the topmost element in the stack without removing it For each of the two modifications that the stack is most likely to experience, an operating clause number with a specified operation period is allocated. It is easier if the data parameter is regarded as an integer data type:

2.1 Push(int): An operation known as "push" occurs when an element is added to the top of a stack. Figure 18 Push stack operation  The element argument is inserted and stored at the top of the stack using the "push" method.  Each stack also has a set capacity, thus if a stack isn't filled, the operation "push" may still be used. The push operation mechanism will throw a "stack overflow error" exception if the stack is full and the push operation is still invoked to insert an element.  The push mechanism returns the value of the inserted element when an element is successfully pushed. Figure 19 Stack overload