Assignment 1 BTEC Assignment 1 BTEC, Assignments of Data Structures and Algorithms

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Typology: Assignments

2020/2021

Uploaded on 05/25/2021

h303
h303 🇻🇳

4.3

(5)

2 documents

1 / 18

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 April 12, 2021
Date Received 1st
submission
Re-submission Date Date Received 2nd
submission
Student Name Lê Hoàng Hiệp Student ID GCS190464
Class GCS0805A_PPT Assessor name Vũ Thanh Hiền
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 Hiệp
Grading grid
P1 P2 P3 M1 M2 M3 D1 D2
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Assignment 1 BTEC Assignment 1 BTEC and more Assignments Data Structures and Algorithms 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 April 12, 2021 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Lê Hoàng Hiệp Student ID GCS Class GCS0805A_PPT Assessor name Vũ Thanh Hiền 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 Hiệp Grading grid P1 P2 P3 M1 M2 M3 D1 D

 Summative Feedback:  Resubmission Feedback:

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

a formal notation. Tasks Part 1 You will need to prepare a presentation on how to create a design specification for data structures, explaining the valid operations that can be carried out on the structures using the example of:

  1. A stack ADT, a concrete data structure for a First In First out (FIFO) queue.
  2. Two sorting algorithms.
  3. Two network shortest path algorithms. Part 2 You will need to provide a formal written report that includes the following:
  4. Explanation on how to specify an abstract data type using the example of software stack.
  5. Explanation of the advantages of encapsulation and information hiding when using an ADT.
  6. Discussion of imperative ADTs with regard to object orientation. Learning Outcomes and Assessment Criteria Pass Merit Distinction LO1 Examine abstract data types, concrete data structures and algorithms D1 Analyse the operation, using illustrations, of two network shortest path algorithms, providing an example of each. P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures. P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer. M1 Illustrate, with an example, a concrete data structure for a First In First out (FIFO) queue. M2 Compare the performance of two sorting algorithms. LO2 Specify abstract data types and algorithms in a formal

notation D2 Discuss the view that imperative ADTs are a basis for object orientation and, with justification, state whether you agree. P3 Using an imperative definition, specify the abstract data type for a software stack. M3 Examine the advantages of encapsulation and information hiding when using an ADT.

ASSIGNMENT 1 ANSWERS P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures.

Abstract data type:

− Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of value and a set of operations. − The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is called “abstract” because it gives an implementation-independent view. The process of providing only the essentials and hiding the details is known as abstraction. − The user of data type does not need to know how that data type is implemented, for example, we have been using Primitive values like int, float, char data types only with the knowledge that these

data type can operate and be performed on without any idea of how they are implemented. So, a user only needs to know what a data type can do, but not how it will be implemented. Think of ADT as a black box which hides the inner structure and design of the data type. Now we’ll define three ADTs namely List ADT, Stack ADT, Queue ADT.

1.1. List ADT

List Abstract Data Type is a collection of elements that have a linear relationship with each other. A linear relationship means that, except for the first one, each element on the list has a unique successor. Also lists have a property intuitively called size, which is simply the number of elements on the list. List is mutable. List is also an interface, which means that other classes provide the actual implementation of the data type. These classes include ArrayList which is implemented internally using Arrays and LinkedList which is implemented internally using LinkedList data structure.

  • The operations on List ADT can be classified like below with examples  Creators : java.util.ArrayList and java.util.LinkedList constructors, Collections.singletonList(T t).  Producers : Collections.unmodifiableList(List list).  Observers : size() method of java.util.ArrayList , get(int index) method of java.util.ArrayList.  Mutators : add(Object e), remove(int index), addAll(Collection c) methods of java.util.ArrayList.
  • Java library’s List interface specifies 25 different operations/methods and some of the methods are as follows  get(int index) – Returns an element at a particular index from the list.  add(E e) – Appends the specified element to the end of this list.  remove(Object o) – Remove the first occurrence of the specified element from the list.  remove(int index) – Removes the element at the specified index from the list.  size() – Returns number of elements of the list.  isEmpty() – Return true if the list is empty, else return false.

1.2. Stack ADT

Java data structures like java.util.LinkedList , java.util.concurrent.ArrayBlockingQueue implement Queue ADT using LinkedList and ArrayLists internally respectively. The operations on the queue ADT can be described like below  Creators : Constructor of java.util.LinkedList.  Producers : Constructor method LinkedList(Collection c) of java.util.LinkedList.  Observers : peek() method of java.util.LinkedList.  Mutators : add(E item) method of java.util.LinkedList. Java library provides the below following operations which can be performed on java.util.Queue  add(E e) – Queues an element at the end of queue.  remove() – Dequeues an element from the head of the queue.  peek() – Returns the element of the queue without removing it.  offer(E e) – Inserts the specified element into this queue if it is possible to do without violating capacity restrictions.  size() – Returns the size of the queue. P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer.

2.1. What is memory stack:

  • A stack can be implemented in a random access memory (RAM) attached to a CPU. The implementation of a stack in the CPU is done by assigning a portion of memory to a stack operation and using a processor register as a stack pointer. The starting memory location of the stack is specified by the processor register as stack pointer.

2.2. Operations:

  • A Stack contains elements of the same type arranged in sequential order. All operations take place at a single end that is top of the stack and following operations can be performed:  push() – Insert an element at one end of the stack called top.  pop() – Remove and return the element at the top of the stack, if it is not empty.  peek() – Return the element at the top of the stack without removing it, if the stack is not empty.  size() – Return the number of elements in the stack.  isEmpty() – Return true if the stack is empty, otherwise return false.  isFull() – Return true if the stack is full, otherwise return false.

2.3. Exception

  • Operations pop and top cannot be performed if the stack is empty Attempting the execution of pop or top on an empty stack should throws a StackEmptyException
  • Operations push sometimes cannot be performed if it’s not enough memory Attempting the execution of push when there is not enough memory should throws a OutOfMemoryError

2.4. Application:

  • 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

2.5. Method calls and the implementation by using stack

  • Each time a method is called, an activation record (AR) is allocated for it.
  • This record contains the following information:  Parameters and local variables used in the called method
  1. a[++top] = x;
  2. System.out.println(x + " pushed into stack");
  3. return true;
  4. }
  5. }
  6. int pop()
  7. {
  8. if (top < 0 ) {
  9. System.out.println("Stack Underflow");
  10. return 0 ;
  11. }
  12. else {
  13. int x = a[top--];
  14. return x;
  15. }
  16. }
  17. int peek()
  18. {
  19. if (top < 0 ) {
  20. System.out.println("Stack Underflow");
  21. return 0 ;
  22. }
  23. else {
  24. int x = a[top];
  25. return x;
  26. }
  27. }
  28. }
  29. class Main {
  30. public static void main(String args[])
  31. {
  32. Stack s = new Stack();
  1. s.push( 10 );
  2. s.push( 20 );
  3. s.push( 30 );
  4. System.out.println(s.pop() + " Popped from stack");
  5. }
  6. } Output: P3 Using an imperative definition, specify the abstract data type for a software stack.

3.1. Definition of software stack:

  • An application consists of a set of functions working together in a defined architecture to deliver specified services to the user. The simplest application architecture consist of three layers:  Presentation Layer: The presentation layer is what the client sees when they access the application through a website or web-based application portal.  Logic Layer: The logic layer contains application logic and business rules that help fulfill application requests. This layer makes calculations and decisions about how to process requests while controlling the transmission of data between the data layer and the presentation layer.  Data Layer: The data layer is a server-side system that passes information to the logic layer when it is necessary to complete a calculation or when it needs to be passed to the presentation layer where it becomes visible to users.
  • Each of these layers has unique requirements in terms of the programming languages and software tools that are required to establish and maintain its function. A web-based presentation layer may be

system, Apache web server, MySQL relational database management system and the PHP programming language. 3.3.2. MEAN - Dynamic web sites and web applications are builds using the MEAN software stack, which includes four free and open-source components: a database tool called MongoDB, the Express.js web application server framework, a front-end web framework called Angular.js, and the Node.js runtime environment. 3.3.3. WIMP - The WIMP software stack includes the Windows operating system, IIS web servers, MySQL or MS Access as a data management system and the PHP, Perl or Python programming languages. 3.3.4. NMP - NMP is actually a set of several software stacks that incorporate Nginx web servers, MySQL and the PHP programming language. This set of technologies works with all major operating systems and has been packaged separately with Linux, Windows, and macOS. 3.3.5. MAMP - The MAMP framework can be used to develop web sites that function on computers that use Windows or macOS. The software stack consists of either macOS or Windows operating system, Apache web server, MySQL for relational database management and PHP, Perl or Python for web development.

  • Each software stack provides a unique set of advantages and disadvantages for developers. It is up to application architects to understand and anticipate the specific needs of an application before choosing the best set of software solutions that support the delivery of application services to the end-user.

REFERENCES

1. Adam Drozdek. Data Structures and Algorithms in Java: SECOND EDITION. Available at: file:///C:/Users/ASUS/Downloads/Data%20Structures%20and%20Algorithms%20in %20Java.pdf [Accessed April 12, 2021] 2. Wu, C. Thomas. An Introduction to Object-Oriented Programming with Java, 5th Edition. Available at: file:///C:/Users/ASUS/Downloads/An%20Introduction%20to%20Object-Oriented %20Programming%20with%20Java,%205th%20Edition.pdf [Accessed April 12, 2021] 3. Aarish Ramesh. ADT Java Tutorial. Available at: https://examples.javacodegeeks.com/adt-java-tutorial/#section [Accessed April 12, 2021] 4. Abstract Data Type (ADT) Available at: https://www.cpp.edu/~ftang/courses/CS240/lectures/adt.htm [Accessed April 12, 2021] 5. Reading 11: Abstract Data Types Available at: https://web.mit.edu/6.005/www/fa16/classes/11-abstract-data-types/ [Accessed April 12, 2021] 6. Array implementation of Stack Available at: https://www.javatpoint.com/ds-array-implementation-of-stack [Accessed April 12, 2021] 7. Java Stack Implementation using Array Available at: https://howtodoinjava.com/data-structure/java-stack-implementation-array/ [Accessed April 12, 2021] 8. Software Stack