Activity 1 !!!!!!!!!!!!!!!!!!!, Study notes of Technology

Do your homework at least !!!!!!!!!!!!!!!!!!

Typology: Study notes

2019/2020

Uploaded on 08/18/2021

bui-anh-1
bui-anh-1 🇻🇳

4 documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures and Algorithms
Submission date
11/8/2021
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Bui Hoang Bao Anh
Student ID
GDD19909
Class
GCD0806
Assessor name
Ho Van Phi
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
Anh
Grading grid
P1
P2
P3
M1
M2
M3
D1
D2
1.1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Activity 1 !!!!!!!!!!!!!!!!!!! and more Study notes Technology in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19 : Data Structures and Algorithms

Submission date 11/8/2021 Date Received 1st submission

Re-submission Date Date Received 2nd submission Student Name Bui Hoang Bao Anh Student ID GDD

Class GCD0806 Assessor name Ho Van Phi

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 Anh

Grading grid P1 P2 P3 M1 M2 M3 D1 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

CHAPTER 1: Create a design specification for data structures

explaining the valid operations that can be carried out on the

structures.

1) What is an Abstract Data Type.

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

2) ADT from definition to implementation.

Figure 1 : Abstract data type

2.1 ) Definition:

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

2.2) Implementation of an 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 ).

 ADT support modular design which is very important in software development

2.3) List of Abstract data type.

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.

  • getLast() – Return the last element.
  • getNext(p) - Return the next element at specified position of the list.
  • getPrev(p) – Return the previous element at specified position of the list.
  • get(p) – Return an element from the list at any given position.
  • set(p, x) – Set the x value of the element p.
  • insert(p, x) – Insert an element at any position of the list.
  • remove(p) – Remove the element at a specified location from a non-empty list.
  • removeFirst() – Remove the first element of the list.
  • removeLast() – Remove the last element of the list.
  • removeNext(p) – Remove the next element at specified position of the list.
  • removePrev(p) – Remove the previous element at specified position of the list.
  • find(x) – Find an element with a value of x.
  • size() – Return the number of elements in the list.

2.4) Queue is an abstract data structure, is something similar to the queue in everyday life.

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.

Representing the queue data structure:

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 Queue:

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.

Chapter 2: Determine the operations of a memory stack and how it

is used to implement function calls in a computer.

1) What is stack.

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.

1.2) Operations of stack

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.

1.3) Stack exception.

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.

  • Operations push sometimes can’t be performed if it’s not enough memory. o Attempting the execution of push when there is not enough memory should throws a Out of Memories errors.

1 .4) Application of stacks.

 Any sort of nesting (such as parentheses)

 Evaluating arithmetic expressions (and other sorts of expression)

 Implementing function or method calls.

 Keeping track of previous choices (as in backtracking)

 Keeping track of choices yet to be made (as in creating a maze)

 Undo sequence in a text editor

 Auxiliary data structure for algorithms

 Component of other data structure

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.

2) Method calls and recursion implemetation

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.

2 .1) How does recursion actually work?

 Each time a method is called, an ativation record (AR) is allocated it.

 This record contains the folowing information.

Parameter and local variables used in the called method.

Dynamic address to resume control by the caller ( address of instruction immediately

following the call).

Return value for a method not declared as void

 Since the size of AR may vary from one call to another, returned value is placed right

above the AR of the caller.

Chapter 3: Using an imperative definition, specify the abstract data type for a software stack.

1) Defining an abstract data type.

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.

2) Imperative style definition.

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.

3) Abstract variable.

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.

4) Instance creation

Some algorithms need to create new instances of some ADT (such as new variables, or

new stacks). To describe such algorithms, one usually includes in the ADT definition a

create() operation that yields an instance of the ADT, usually with axioms equivalent to

the result of create() is distinct from any instance in use by the algorithm.

This axiom may be strengthened to exclude also partial aliasing with other instances. On

the other hand, this axiom still allows implementations of create() to yield a previously

created instance that has become inaccessible to the program.

5) The advantages and disadvantages of stack

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.