Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

A comprehensive overview of abstract data types (adt), explaining their definition, representation, and various aspects such as stack memory, queues, linked lists, and trees. It also discusses the benefits of using adt for data encapsulation and obfuscation, and real-world applications of adt and stacks. A design specification for data structures, a model of adt, and examples of how different programming languages can represent abstract data types.

Typology: Cheat Sheet

2022/2023

Uploaded on 03/04/2024

ba-quan-vo
ba-quan-vo ๐Ÿ‡ป๐Ÿ‡ณ

1 document

1 / 33

Toggle sidebar

Related documents


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/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 1 Contents Introduction ....................................................................................................................................................... 4 P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures ............................................................................................................................................... 5 1. Abstract data type ..................................................................................................................................... 5 1.1 Definition ............................................................................................................................................. 5 1.2 Examples .............................................................................................................................................. 8 1.3 Singly-linked-list ................................................................................................................................... 8 P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer. ......................................................................................................................................................... 18 1. Stack ADT ............................................................................................................................................. 18 2. Overview stack operations ...................................................................................................................... 18 2.1 Push(int): ........................................................................................................................................... 19 2.2 Int pop :.............................................................................................................................................. 20 2.3 Int peekTop() : .................................................................................................................................... 21 2.4 Boolean isEmpty() : ............................................................................................................................ 22 2.5 Top() ................................................................................................................................................... 22 3. Stack Memory .......................................................................................................................................... 23 3.1 Define................................................................................................................................................. 23 3.2 Operations of Stack Memory ............................................................................................................. 24 3.3 How it is implemented in a computer to make function calls ........................................................... 24 3.4 Application ......................................................................................................................................... 25 P3 Using an imperative definition, specify the abstract data type for a software stack. ................................ 28 1. Why did you choose to describe the ADT in ........................................................................................ 28 2. Using an imperative definition, specify your chosen ADT ....................................................................... 28 3. These issues ............................................................................................................................................. 29 4. The problem's resolution ......................................................................................................................... 30 5. Application of ADT ................................................................................................................................... 30 6. What happens if ADT is absent? .......................................................................................................... 30 7. ADT implementation and creation have certain issues. ...................................................................... 30 Conclusion ....................................................................................................................................................... 31 References ....................................................................................................................................................... 32 4 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. 5 P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures 1. Abstract data type 1.1 Definition An abstract data type (ADT) is a type (or class) for objects whose behavior depends on multiple input and output types. The term "ADTโ€ refers only to the actions that should be performed, not how they should be done. The operations to be performed, the way the data is organized in memory, and the algorithms chosen are not specified. Because it presents a perspective unrelated to the implementation, it is called "abstract". Abstract data types (ADTs) are data structure abstractions that only provide operations while hiding the implementation of those operations. For example, the manipulation technique or way of retrieving, sorting, or storing data in memory is not specified. It is a powerful tool to organize and manipulate data efficiently and effectively. They can be used to construct classes and objects and are commonly used in object-oriented programming languages. Here are a few instances of ADTs: ๏ƒ˜ Stack: Data are stored in a stack using the last-in, first-out (LIFO) ordering method. ๏ƒ˜ Queue: Data are stored in a queue using the first-in, first-out (FIFO) ordering system. ๏ƒ˜ Linked list: A linked list is a type of data structure used to store information in a linked list manner. ๏ƒ˜ Tree: A tree is a type of data structure used to store information hierarchically. Usually, to implement ADT, it is necessary to have a set of operational axioms that govern the interaction of operations. Here are some common types of axiomatic operations of a basic ADT: generators (constructors), generators (+, -, *, /, reduce size when removing an element), accessory and converter. Some of the commonly used ADTs are Lists, Stacks, and Queues, and here's a summary of how accessory and their setters work: Table 1 ADT 6 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. 9 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 10 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. 11 Adding at the end of the list Figure 7. At the end of a single linked list Insert A new node can be added to the end of a singly linked list using the following procedures: Step 1: Create a new Node with the desired value and set the new Node next to NULL. Step 2: Check to see if the list is empty (head == NULL). Step 3: Set head = new Node if it is empty. Step 4: If it's not empty, make a temporary node reference and initialize it with the head. Step 5: Up until it reaches the final node in the list (or until temp next = NULL), keep moving the temp to the next node in the list. Step 6: Set temp โ†’ next = new Node. Inserting at a precise location in a list Figure 8 Insertion at a Specific Point in a Singlely Linked List Apply the following procedures to add a new node after a node in a single 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 newNode next = NULL and newNode as the head. Step 4: If it's not empty, make a temporary node reference and initialize it with the head. 14 Step 8: If the list has many nodes, determine if temp1 is the first node (temp1 == head). Step 9: If temp1 is the first node, delete temp1 and change the head to the subsequent node (head = head next). Step 10: Check to check whether temp1 is the last node in the list if it isn't the first (temp1next == NULL). Step 11: If temp1 is the last node, set temp2next = NULL and delete temp1 (free(temp1)). Step 12: If temp1 is not the first or last node, set temp2next = temp1 next and delete it using the free function by calling temp1(temp1). c. Display Figure 12 Display The following techniques can be used to show the elements of a single linked list: Step 1: Check to see if the list is empty (head == NULL). Step 2: If the list is empty, display "List is Empty!!!" and end the procedure. Step 3: If it's not empty, establish a temporary Node reference and initialize it with the head. Step 4: Display the temp data with an arrow (โ€”>) until it reaches the last node. Step 5: Display temp data with an arrow pointing to NULL (temp data โ€”> NULL). First I would create a file called singlelinkedlist and create a Java class called Node. And, it has some properties and methods of ADT. It has not only declarations and no definitions. The size of the variable is the number of elements in the linked list. Its node contains two data fields: info and next. 15 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. 16 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. 19 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 20 2.2 Int pop : "Pop" refers to the process of removing an element from the stack that is at the top. Figure 20 A pop operation ๏ƒ˜ The "pop" action removes the last (top) element of the stack and returns that or the most recently added element. The last inputted element is also the first drawn element, so this operation method implies the order of the input and output elements. ๏ƒ˜ Stack overflow results from calling the "pop" function when the stack is empty. ๏ƒ˜ The underline condition of the "pop" method will then immediately throw a "null pointer exception" or another "RuntimeException" in this case. ๏ƒ˜ The "pop " action returns the integer value of the removed element. 21 2.3 Int peekTop() : The "PeekTop" action, unlike the "pop" function, fetches and returns the top(last) integer element in the stack. Figure 21 PeekTop Operation Illustration ๏ƒ˜ If the stack is empty but the "PeekTop" function is still invoked, this will result in stack underflow just as the "Pop" action. The "PeekTop" method's underflow condition will then instantly throw a "null pointer exception" or another "RuntimeException" if this scenario occurs. 24 3.2 Operations of Stack Memory A stack is a group of identically typed objects that are ordered logically. The following operations are feasible because they can all be done at the top of the stack, which is where all operations are conducted. Since data is added and removed using the last-in-first-out principle based on function calls, there are two main operations in it: ๏ƒ˜ push() - Adds a new element to the top of the stack. ๏ƒ˜ pop() - Remove and return the element at the top of the stack if it is not already empty. ๏ƒ˜ peek() - If the stack is not empty, it returns the element at the top of the stack without deleting it. ๏ƒ˜ size() โ€“ Returns the elemental size of the stack. ๏ƒ˜ isEmpty() โ€“ If the stack is empty, return true; otherwise, return false. ๏ƒ˜ isFull() - If the stack is full, return true; otherwise, return false. 3.3 How it is implemented in a computer to make function calls The concept of trigger subscriptions should be explained before discussing the implementation of function calls. Most implementations store all data for a function call in an activation record, including space for all function parameters and local variables, temporary objects, return addresses, and d. other elements required by the function. This in-thread stack memory mechanism pushes the trigger record, created immediately when a function is called, to the top of the stack (Push). Since the stack frame is an implementation of the trigger record in this case, the trigger record can now also be called a block or stack frame. The last trigger record (stack frame) created is the first to be completed.Stack memory examples and their explanations are provided below. In the getCapital() function, a new stack frame is instantly produced and put on top of the stack when the bribeBoss() function is invoked. After calculating, this stack frame stores the variable bribeMoney(int) = 300 and the input (int m = 1000) supplied to the getCapital() method. 25 This stack frame will be removed from the stack when the bribeBoss() function has finished running, and any data contained in it will likewise be deleted from memory. This function substitutes the function call in the getCapital() function's stack frame by returning the value to that function. Upon completion of this method, the stack frame of getCapital() is popped out. Every piece of data in the stack frame returned by getCapital() is also destroyed. All that is returned to the main() method is the return value, which is briefly stored by the main() function. All stack frames are removed once the program has completed. Table 2 Stack momory work 3.4 Application Applications for recursive function storage include, for instance, waiting for the results of the recursive multi-function below while saving the variable result on the stack and the multi-function itself on the stack. The following computation. Each recursive call will have an additional memory cell to contain the multi-function. When multi (1) returns 1, multi (2), multi (3), and multi (6) are calculated and the stack memory is released. Finally, give the resultant Main variable its value. 26 Figure 25. Stack memory explained with an example Figure 25. Stack memory example Figure 26. Stack memory example 29 3. These issues To control monthly car sales, I want to create an app. I tried using data types, but it didn't work well for me because there is only one data type and operations on it, and those operations are implementation specific and no longer useful. I also use some ADTs from other programming languages, like Java, but that doesn't meet my needs either. Also, I think using the standard data type is not suitable for my needs or does not give my application the capabilities it needs, as I can build complex applications with various actions. Add, remove, and modify item prices and quantities, among other complex operations.factors to calculate sales and determine the most profitable factors for the month when cars are used the most. On the other hand, the standard data format works well for simple applications.Insertion: Adds a new element to the list's first position. ๏ƒ˜ Elimination: Removes the first entry from the list. ๏ƒ˜ Display: Shows the whole list. ๏ƒ˜ Search: Uses the provided key to search for an element. ๏ƒ˜ Delete: Using the specified key, deletes the specified element. Figure 27 code for managing vehicles 30 4. The problem's resolution As a result, I choose to utilize an ADT (a new data type), and its operations are specified by that data type because the program would need to handle a variety of data types. Are you able to satisfy your new demands? ADT will also enable more effective and flexible code reuse by programmers. To address that issue, I would use a linked list. The user (manager of the vehicle showroom) successfully created ADT. 5. Application of ADT Using the appropriate ways, you must include the ADT in your application once it has been developed. After using ADT, it should be examined and adjusted as necessary. This assures the program's abstract data type's consistency and dependability. Finally, the user may integrate this ADT into the application by connecting it to other functions. 6. What happens if ADT is absent? Since the ADT can combine multiple data types and act on them into a relatively independent component, managing data types would be difficult without it. Since the code is not reused, it can be repeated. Since the internal implementation is not masked by the data type, its use becomes more difficult and complex. In addition, it becomes more difficult to develop and use software to solve increasingly complex problems. Inconsistency: The data structure may be used inconsistently by various portions of the code, which might result in mistakes. Complexity: Because the programmer must consider the implementation specifics of the data structure, code that employs data structures may be more complex than necessary. Brittleness: Data-structure-using code may be more brittle, meaning it is more likely to malfunction if the data structure is modified. 7. ADT implementation and creation have certain issues. The ADT that I developed has not been endorsed by any organization because it is impractical, may have flaws, and is difficult to apply to real-world applications. My ADT is academically guaranteed but has some additional flaws compared to other ADTs. For example, compared to the ADT linked list I created myself, it includes more debugging and user support options. The main reason is that Java ADT is created by experienced programmers and is used by many users. 31 Conclusion Finally, this article completes and discusses these imperative tasks: develop a data structure description that lists the legal activities that can control how data structures interact. The use of memory stack techniques to handle function calls will be demonstrated. Also, use the concept of ordering to define an abstract data type for the program stack. A specific data structure for a first- in, first-out (FIFO) queue is provided and illustrated. evaluate the effect of bubble sort versus quick sort.The final work, which involved exploring the benefits of using ADT to encapsulate and hide information, has also been completed. After reading this report, I also learned the basics of data structure and sorting algorithm, will be very helpful for me in the future
Docsity logo



Copyright ยฉ 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved