Docsity

Data Structures and Algorithms Assignment 1 Brief - Prof. Tam, Assignments of Quantum Computing

Partial preview of the text

Download Data Structures and Algorithms Assignment 1 Brief - Prof. Tam and more Assignments Quantum Computing in PDF only on Docsity!

Higher Nationals in Computing

Unit 19 :Data Structures & Algorithms

ASSIGNMENT 1

Assessor name: VU THANH HIEN

Learner’s name: DANG AN THANH

ID: GCS

Class: GCS0805A_PPT

Subject code: 16 49

Assignment due: 1 6 / 0 4 / 2 0 2 1 Assignment submitted: 1 6 / 0 4 / 2 0 2 1

ASSIGNMENT 1 FRONT SHEET

alification BTEC Level 5 HND Diploma in Computing it number and title Unit 19 : Data Structures and Algorithms bmission date 16/04/2021 Date Received 1st submission

- submission Date Date Received 2nd submission

dent Name Dang An Thanh Student ID GCS ass GCS0805A_PPT Assessor name Vu Thanh Hien dent declaration ertify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understa king a false declaration is a form of malpractice. Student’s signature THANH ding grid 1 P2 P3 M1 M2 M3 D1 D

ASSIGNMENT 1 BRIEF Qualification BTEC Level 5 HND Diploma in Business Unit number Unit 1 9 : Data Structures and Algorithms Assignment title Examine and specify ADT and DSA Academic Year Unit Tutor Issue date Submission date IV name and date Submission Format: Format: The submission is in the form of an individual written report and a presentation. This should be written in a concise, formal business style using single spacing and font size 12. You are required to make use of headings, paragraphs and subsections as appropriate, and all work must be supported with research and referenced using the Harvard referencing system. Please also provide a bibliography using the Harvard referencing system. Submission Students are compulsory to submit the assignment in due date and in a way requested by the Tutors. The form of submission will be a soft copy in PDF posted on corresponding course of http://cms.greenwich.edu.vn/ Note: The Assignment must be your own work, and not copied by or from another student or from books etc. If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you must reference your sources, using the Harvard style. Make sure that you know how to reference properly, and that understand the guidelines on plagiarism. If you do not, you definitely get fail Assignment Brief and Guidance: Scenario : You work as in-house software developer for Softnet Development Ltd, a software body-shop providing network provisioning solutions. Your company is part of a collaborative service provisioning development project and your company has won the contract to design and develop a middleware solution that will interface at the front-end to multiple computer provisioning interfaces including SOAP, HTTP, JML and CLI, and the back-end

telecom provisioning network via CLI. Your account manager has assigned you a special role that is to inform your team about designing and implementing abstract data types. You have been asked to create a presentation for all collaborating partners on how ADTs can be utilised to improve software design, development and testing. Further, you have been asked to write an introductory report for distribution to all partners on how to specify abstract data types and algorithms in 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.

Table of Contents

  • carried out on the structures P1 Create a design specification for data structures explaining the valid operations that can be
      1. Definition of Abstract Data Type(ADT):
      1. List ADT
      • 2 .1. Single – Linked List:
  • computer. P2 Determine the operations of a memory stack and how it is used to implement function calls in a
      1. Stack – Definition:
      • 1.1. Exceptions:
      • 1.2. Applications:
      • 1.3. Operations:
      • 1.4. Implement stack in Java:
      1. Method calls and recursion implementation:
      • 2.1. Definition:
      • 2.2. Code example
  • M1 Illustrate, with an example, a concrete data structure for a First In First out (FIFO) queue.
      1. Definition:
      1. Exception:
      1. Characteristic:
      1. Applications:
      1. Operations:
      1. Code example:
  • M2 Compare the performance of two sorting algorithms
      1. Definition:
      • 1.1. Insertion Sort:
      • 1.2. Merge Sort:
      1. Time complexity Analysis:
      1. In-place/Outplace technique:
      1. Online/Offline technique:
      1. Stable/Unstable technique:...................................................................................................
      1. Analysis of sorting techniques:
      1. Time and Space Complexity Comparison Table:
  • an example of each D1 Analyse the operation, using illustrations, of two networks shortest path algorithms, providing
      1. Dijkstra’s Algorithm:
      • 2.1. Scenario
      • 2.2. Idea
      • 2.3. Initialization
      • 2.4. Evaluation
      1. Bellman-Ford Algorithm:
      • 2.1. Scenario:
      • 2.2. Idea
      • 2.3. Initalization
      • 2.4. Evaluation
      1. Advantages and disadvantages:
      • 3.1.Dijktra’s Algorithm
      • 3.2. Bellman–Ford Algorithm:
      • 3.3. Conclusion:
  • P3 Using an imperative definition, specify the abstract data type for a software stack.
      1. Abstract Data Type................................................................................................................
      • 1.1. Definition – ADT:
      • 1.2. Definition – Imperative-style:
      • 1.3. Abstract variable:
      • 1.4. Instance creation:
      • 1.5. Example about Abstract stack (imperative):
      1. Software Stack:
      • 2.1. Definition – Software Stack:
      • 2.2. Example of Software Stack:
  • M3 Examine the advantages of encapsulation and information hiding when using an ADT
      1. Advantages of encapsulation:
      • 1.1. Overview:
      • 1.2. In Object-Oriented Programming and Design:
      • 1.3. In Software Development:
      • 1.4. Conclusion:
  • state whether you agree D2 Discuss the view that imperative ADTs are a basis for object orientation and with justification,
      1. Definition and my opinions:
      1. Conclusion:
  • REFERENCES

P a g e | 2

2. List ADT The data is generally stored in key sequence in a list which has a head structure consisting of count, pointers and address of compare function needed to compare the data in the list.

  • The data node contains the pointer to a data structure and a self-referential pointer which points to the next node in the list.
  • Operation of List ADT:
  • get() – Return an element from the list at any given position.
  • insert() – Insert an element at any position of the list.
  • remove() – Remove the first occurrence of any element from a non-empty list.
  • removeAt() – Remove the element at a specified location from a non-empty list.
  • replace() – Replace an element at any position by another element.
  • size() – Return the number of elements in the list.
  • isEmpty() – Return true if the list is empty, otherwise return false.
  • isFull() – Return true if the list is full, otherwise return false.
  • A collection of nodes storing data and links to other nodes.
  • A linear DS composed of nodes:

P a g e | 3

  • Each node holds some info and reference to another node in the list.
  • Types of linked lists:
    • Singly-linked list.
    • Doubly-linked list.
  • A list contains elements of same type arranged in sequential order and following operations can be performed on the list. 2.1. Single – Linked List:
  • Its node contains two data fields: info and next.
    • Info stores information which is usable by user.
    • Next links it to its successor in the sequence. z Code example z At first : Create class Node: á Secondly : Create class LinkedList (to print result) :

P a g e | 5 +Out of the program P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer.

1. Stack – Definition: - Memory stacks are linear data structures (locations) used to store data in a computer's memory. They may also be referred to as queues. Data within a stack must always of the same type. - A linear data structure: Can be accessed only at one of its ends for storing and retrieving data. - A stack is a Last In, First Out (LIFO) data structure. - Anything added will go to the top. - Anything removed will be taken from the top: Things are removed in the reverse order that they were inserted. 1.1. Exceptions: - Operations pop and top cannot be performed if the stack is empty:

P a g e | 6

  • 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 throw a OutOfMemoryError. 1.2. Applications:
  • 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. 1.3. Operations:
  • A Stack contains elements of the same type arranged in sequential order.
  • 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. 1.4. Implement stack in Java: public class LinkedListStack { LinkedList list; public LinkedListStack() { list = new LinkedList();

P a g e | 8

  • Since the size of AR may vary from one call to another, returned value is placed right above the AR of the caller.
  • Each new AR is placed on top of the run-time stack. When a method terminates, its AR is removed from the top of the run-time stack. → Thus, the first AR placed on the stack is the last one removed.
  • Method calls in Java.
  • First, some information about the Stack, local variables & parameters:
  • The Stack keeps the state of all active methods (those that have been invoked but have not yet completed)
  • When a method is called a new stack frame for it is added to the top of the stack, this stack frame is where space for the method’s local variables and parameters are allocated.
  • When a method returns, its stack frame is removed from the top of the stack (space for its local vars and params is de-allocated).
  • Space for local variables and parameters exist only while the method is active (it has a stack frame on the Stack).
  • local variables and parameters are only in scope when they are in the top stack frame (when this method’s code is being executed).
  • Creating an activation record:
  • Whenever a method is called. Allows system to handle recursion properly.
  • Recursion is calling a method that happens to have the same name as the caller: + Recursive call is not literally calling itself.
  • These invocations are presented internally by different activation records. z The run-time stack when main () calls method f1() → f1() calls f2() → f2() calls f3()

P a g e | 9 2.2. Code example We start executing code in main:

  • there is a single stack frame containing main’s local variables:

P a g e | 11

  • setVal is called from within this object, so its members are in scope as well as all parameters and local variables of setVal.
  • When main calls add, we are passing the value of object ref f2 :
  • add’s parameter f refers to the same object as f2 does:

P a g e | 12

  • If a method **M1 Illustrate, with an example, a concrete data structure for a First In First out (FIFO) queue.
  1. Definition:**
  • Queue is also an abstract data type or a linear data structure in which the first element is inserted from one end called the REAR (also called tail), and the removal of existing element takes place from the other end called as FRONT (also called head).
  • This makes queue as FIFO (First in First Out) data structure, which means that element inserted first will be removed first.
  • Which is exactly how queue system works in real world. If you go to a shop counter to buy something, and are first in the queue, then you will be the first one to be served. Same is the case with Queue data structure. Data inserted first, will leave the queue first.
  • Queue is a line waiting. It grows by adding elements to its end and shrinks by taking elements from its front.
  • A queue is a structure in which both ends are used: