

















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
Do your homework at least !!!!!!!!!!!!!!!!!!
Typology: Study notes
1 / 25
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
Re-submission Date Date Received 2nd submission Student Name Bui Hoang Bao Anh Student ID GDD
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.
Grading grid P1 P2 P3 M1 M2 M3 D1 D
Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:
Abstract Data type (ADT) is a type (or class) for objects whose behaviour is defined by a set of value and a set of operations. It also provides the interface of the object. Therefore, this type is called abstract because it does not give an implementation perspective. An abstract data type should include the following: o Declaration of data o Declaration of operations o Encapsulation of data and operations: data is hidden from user and can be manipulated only by mean of operations
Figure 1 : Abstract data type
The abstract data type (ADT) definition only refers to what activities will be performed, not how this operation will be performed. Moreover, it does not specify how the data will be organized in memory and which algorithm will be used to perform the operations. So why is it called online abstraction? Because it brings an independent look done.
For exam ple : we have used primitive values such as integers (int), real numbers (float), character types (char), string types (string), and so on, only with knowledge of which type This data can work without any idea of how they are implemented. So users only need to know what kind of data they can do, not how to deploy it. Think of ADT as a black box that hides the internal structure and design of the data type. Figure 2 : Example of system design Abstract data type
Hidden from user. Same ADT may be implemented in diffference ways in differenence ways in different languaes. Some languaes offer build in Abstract data types or feature to be used to implement Abstract data types ( user define types ).
A list abstract data type is the type of list which contains similar elements in sequential order and following are the operations which can be performed on list.
Figure 3 : the list of adt functions A list contains elements of the same type arranged in sequential order and following operations can be performed on the list: getFirst() – Return the first element.
A queue is a linear structure in a specific order in which operations are performed. The order is First In First Out (FIFO). A typical example of a queue is any consumer queue for resources that consumers first come first served. The difference between stacks and queues is in elimination. In a stack, we remove the most recently added items; In a queue, we remove less recently added items. The queue is open at both ends. One end is always used to insert data (also known as line-up) and the other end is used to delete data (leave the row). The queue data structure follows the First-In-First-Out method, ie the data that is entered first will be accessed first.
Figure 4 : Queue Similar to the stack data structure, queue data structures can also be implemented using Arrays, Linked Lists, Cursors, and Structures. For the sake of simplicity, the next section will explore the queues deployed by using one-dimensional arrays.
Operations on the queue data structure may involve initializing the queue, using data on the queue, and then deleting data from memory. Listed below are some basic operations that can be performed on the queue data structure: Because the queue data structure maintains two data pointers: front and rear, the operations of this type of data structure are quite complex when compared to stack data structures. Dequeue () operation: deletes an element from the queue. Accessing data from the queue is a two-step process: accessing data at the front cursor is pointing and deleting data after that access. To use the queue effectively, we also need to check the status of the queue.
Figure 7 : Stack The stack can only be used for local variables that use up small amounts of memory. The good news is that memory allocation and management will not be your problem and access to these objects is very fast. It is subject to size limits and the fact that you cannot resize variables on the stack. Also A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data. Such a stack resembles a stack of trays in a cafeteria: New trays are put on the top of the stack and taken off the top. The last tray put on the stack is the first tray removed from the stack. For this reason, a stack is called a LIFO structure: last in/first out.
A tray can be taken only if there are trays on the stack, and a tray can be added to the stack only if there is enough room; that is, if the stack is not too high. Therefore, a stack is defined in terms of operations that change its status and operations that check this status. The operations are as follows: clear() — Clear the stack. isEmpty() — Check to see if the stack is empty. push(el) — Put the element el on the top of the stack. pop() — Take the topmost element from the stack. topEl() — Return the topmost element in the stack without removing it.
After pushing number 10 onto an empty stack, the stack contains only this number. After pushing 5 on the stack, the number is placed on top of 10 so that, when the popping operation is executed, 5 is removed from the stack, because it arrived after 10, and 10 is left on the stack. After pushing 15 and then 7, the topmost element is 7, and this number is removed when executing the popping operation, after which the stack contains 10 at the bottom and 15 above it. Figure 8 : The example of stack Generally, the stack is very useful in situations when data have to be stored and then retrieved in reverse order. One application of the stack is in matching delimiters in a program. This is an important example because delimiter matching is part of any compiler: No program is considered correct if the delimiters are mismatched.
Operations pop and top can’t be performed if the stack is empty. o Attempting the execution of pop or top an empty stack should throws a StackEmptyException.
Figure 9 : The example of Stack Figure 10 : The result
The advantages of Stack-based CPU organization: o Effective calculation of complex arithmetic expressions. o Executing instructions is fast because the operand data is stored in consecutive memory locations. o The length of the instructions is short because they do not have an address field. The disadvantages of organizing CPU based on Stack: o The scale of the program increased.
If the method has formal parameters, they have to be initialized to the values passed as actual parameters. In addition, the system has to know where to resume execution of the program after the method has finished. The method can be called by other methods or by the main program (the method main()). The information indicating where it has been called from has to be remembered by the system. This could be done by storing the return address in main memory in a place set aside for return addresses. For a method call, more information has to be stored than just a return address. Therefore, dynamic allocation using the run-time stack is a much better solution. It needs to be stressed that the run-time stack is maintained by a particular operating system. A Java stack used by the Java Virtual Machine was briefly described. Java stack and run-time stack are two different entities. They are similar in that their role in processing method calls is basically the same; therefore, they store similar information that enables this processing, although they store this information differently. The role of the interpreter java is to convert information bytecodes in .class files so that the run-time stack takes over the function of the Java stack, which is only an abstract construct. The subsequent discussion is presented in terms of the run-time stack rather than the Java stack, which in no way changes the logic of processing method calls, in particular, recursive calls.
Chapter 3: Using an imperative definition, specify the abstract data type for a software stack.
An abstract data type is defined as a mathematical model of the data objects that make up a data type as well as the functions that operate on these objects. There are no standard conventions for defining them. A broad division may be drawn between "imperative" and "functional" definition styles.
In the philosophy of imperative programming languages, an abstract data structure is conceived as an entity that is mutable—meaning that it may be in different states at different times. Some operations may change the state of the ADT; therefore, the order in which operations are evaluated is important, and the same operation on the same entities may have different effects if executed at different times— just like the instructions of a computer, or the commands and procedures of an imperative language. To underscore this view, it is customary to say that the operations are executed or applied, rather than evaluated. The imperative style is often used when describing abstract algorithm.
Imperative-style definitions of ADT often depend on the concept of an abstract variable, which may be regarded as the simplest non-trivial ADT. An abstract variable V is a mutable entity that admits two operations: store(V, x) where x is a value of unspecified nature; fetch(V), that yields a value, With the constraint that: fetch(V) always returns the value x used in the most recent store(V, x) operation on the same variable V. As in so many programming languages, the operation store(V, x) is often written V ← x (or some similar notation), and fetch(V) is implied whenever a variable V is used in a context where a value is required. Thus, for example, V ← V + 1 is commonly understood to be a shorthand for store(V,fetch(V) + 1). In this definition, it is implicitly assumed that storing a value into a variable U has no effect on the state of a distinct variable V. To make this assumption explicit, one could add the constraint that. if U and V are distinct variables, the sequence { store(U, x); store(V, y) } is equivalent to { store(V, y); store(U, x) }.
More generally, ADT definitions often assume that any operation that changes the state of one ADT instance has no effect on the state of any other instance (including other instances of the same ADT) — unless the ADT axioms imply that the two instances are connected (aliased) in that sense. For example, when extending the definition of abstract variable to include abstract records, the operation that selects a field from a record variable R must yield a variable V that is aliased to that part of R. The definition of an abstract variable V may also restrict the stored values x to members of a specific set X, called the range or type of V. As in programming languages, such restrictions may simplify the description and analysis of algorithms, and improve their readability. Note that this definition does not imply anything about the result of evaluating fetch(V) when V is uninitialized, that is, before performing any store operation on V. An algorithm that does so is usually considered invalid, because its effect is not defined. (However, there are some important algorithms whose efficiency strongly depends on the assumption that such a fetch is legal, and returns some arbitrary value in the variable's range.
Stack is a data structure that operates on the principle of: last in first out (LIFO). To be intuitive, you can understand that it is a pile of bowls, you stack the bowls up high, the one you stack on the end will be the one you take out first and vice versa, the first bowl, at the bottom will is the last one you took out. Advantages of stack: Stacks to easy to carry Memory saved because pointer is not relevants. Disadvantages of stack: It’s not dynamic. This means the maximum size of the stack must be predefined and cannot be changed.