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

Data structure & Algorithm, Assignments of Information Technology

This a Assignment 1 of Data structure and Algorithm. #btec #greenwich #datastructure&algorithm #IT

Typology: Assignments

2020/2021

Available from 02/24/2021

trannguyentansang
trannguyentansang ๐Ÿ‡ป๐Ÿ‡ณ

4.4

(130)

15 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Tran Nguyen Tan Sang
GREENWICH | GCS190019
Data Structure &
Algorithm
ASSIGNMENT 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Data structure & Algorithm and more Assignments Information Technology in PDF only on Docsity!

Tran Nguyen Tan Sang

GREENWICH | GCS

Data Structure &

Algorithm

ASSIGNMENT 1

ASSIGNMENT 1 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19: Data Structures and Algorithms Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Tran Nguyen Tan Sang Student ID GCS Class GCS0804_NX Assessor name Le Ngoc Thanh 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 Tan Sang Grading grid P1 P2 P3 M1 M2 M3 D1 D

ASSIGNMENT 1 BRIEF

Qualification BTEC Level 5 HND Diploma in Business Unit number Unit 19 : Data Structures and Algorithms Assignment title Examine and specify ADT and DSA Academic Year 2021 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. 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.
  • LO1. Examine abstract data types, concrete data structures and algorithms
    • the structures. P1. Create a design specification for data structures explaining the valid operations that can be carried out on
      • โ– Abstract data type:
      • โœ“ Student ADT:
      • โœ“ Vehicle ADT:
      • โœ“ Dog ADT:
      • I. What is memory stack:
      • II. Operations:
      • III. Exception
      • IV. Application:
    • M1. Illustrate, with an example, a concrete data structure for a First in First out (FIFO) queue.
      • I. Definition of Queue:
      • II. Queue Representation
      • III. Basic Operations:
      • IV. Applications of Queue:
      • V. Array implementation Of Queue in Java:
    • M2. Compare the performance of two sorting algorithms.
      • I. Selection sort:
      • II. Bubble Sort:
    • of each. D1. Analyze the operation, using illustrations, of two network shortest path algorithms, providing an example
      • I. Dijkstra's algorithm:
      • II. Bellman Ford's Algorithm:
  • LO2. Specify abstract data types and algorithms in a formal notation.
    • P3. Using an imperative definition, specify the abstract data type for a software stack.
      • I. Definition of software stack:
      • II. Parts of a software stack:
      • III. Five Software Stack Examples:
    • M3. Examine the advantages of encapsulation and information hiding when using an ADT.
    • whether you agree. D2. Discuss the view that imperative ADTs are a basis for object orientation and, with justification, state
      • I. Discuss the view that imperative ADTs are a basis for object orientation
    • II. ADTs vs OOP:
  • References:

LO1. Examine abstract data types, concrete data structures and algorithms

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. โœ“ Student ADT: โˆ’ Properties of Student:

  • ID
  • firstName
  • lastName
  • major
  • birthOfDate
  • email โˆ’ Methods of Student
  • Set, Get ID

โœ“ Dog ADT: โˆ’ Properties of Dog:

  • name
  • size
  • type
  • color โˆ’ Method of Dog:
  • Set, Get name
  • Set, Get size
  • Set, Get type
  • Set, Get color
  • bark
  • eat โˆ’ Implement in Java:

P2. Determine the operations of a memory stack and how it is used to implement function calls in a computer. I. 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. II. 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. III. 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 IV. Application:

โˆ’ Output: โˆ’ M1. Illustrate, with an example, a concrete data structure for a First in First out (FIFO) queue. I. Definition of Queue: โˆ’ Like Stack, Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of queue is any queue of consumers for a resource where the consumer that came first is served first. โˆ’ The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added. II. Queue Representation โˆ’ As we now understand that in queue, we access both ends for different reasons. The following diagram given below tries to explain queue representation as data structure โˆ’ โˆ’ As in stacks, a queue can also be implemented using Arrays, Linked-lists, Pointers and Structures. For the sake of simplicity, we shall implement queues using one-dimensional array. III. Basic Operations: โˆ’ Queue operations may involve initializing or defining the queue, utilizing it, and then completely erasing it from the memory. Here we shall try to understand the basic operations associated with queues

  • enqueue() โˆ’ add (store) an item to the queue.
  • dequeue() โˆ’ remove (access) an item from the queue. โˆ’ Few more functions are required to make the above-mentioned queue operation efficient. These are
  • peek() โˆ’ Gets the element at the front of the queue without removing it.
  • isfull() โˆ’ Checks if the queue is full.
  • isempty() โˆ’ Checks if the queue is empty. โˆ’ In queue, we always dequeue (or access) data, pointed by front pointer and while enqueing (or storing) data in the queue we take help of rear pointer. IV. Applications of Queue: โˆ’ Queue is used when things donโ€™t have to be processed immediately, but have to be processed in First In First Out order like Breadth First Search. This property of Queue makes it also useful in following kind of scenarios.
  • When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk Scheduling.
  • When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes. Examples include IO Buffers, pipes, file IO, etc. V. Array implementation Of Queue in Java: โˆ’

1.It can also be used on list structures that make add and remove efficient, such as a linked list. Just remove the smallest element of unsorted part and end at the end of sorted part. 2.The number of swaps reduced. O(N) swaps in all cases. 3.In-Place sort. โˆ’ Disadvantage :

  1. Time complexity in all cases is O(N2), no best-case scenario. โˆ’ Implementation in Java: Output: II. Bubble Sort: โˆ’ Bubble sort repeatedly compares and swaps (if needed) adjacent elements in every pass. In i-th pass of Bubble Sort (ascending order), last (i-1) elements are already sorted, and i-th largest element is placed at (N-i)-th position, i-th last position. โˆ’ Time Complexity:
  • Best Case Sorted array as input. Or almost all elements are in proper place. [ O(N) ]. O(1) swaps.
  • Worst Case: Reversely sorted / Very few elements are in proper place. [O(N2)]. O(N2) swaps.
  • Average Case: [O(N2)]. O(N2) swaps. โˆ’ Space Complexity : A temporary variable is used in swapping [auxiliary, O(1)]. Hence it is In- Place sort. โˆ’ Advantage : 1.It is the simplest sorting approach. 2.Best case complexity is of O(N) [for optimized approach] while the array is sorted. 3.Using optimized approach, it can detect already sorted array in first pass with time complexity of O(1).

4.Stable sort: does not change the relative order of elements with equal keys. 5.In-Place sort. โˆ’ Disadvantage : 1.Bubble sort is comparatively slower algorithm. โˆ’ Implementation in Java: Output: D1. Analyze the operation, using illustrations, of two network shortest path algorithms, providing an example of each. I. Dijkstra's algorithm: โˆ’ Dijkstra's algorithm has many variants but the most common one is to find the shortest paths from the source vertex to all other vertices in the graph. โˆ’ Algorithm Steps: Step 1. Set all vertices distances = infinity except for the source vertex, set the source distance = 0. Step 2. Push the source vertex in a min-priority queue in the form (distance, vertex), as the comparison in the min-priority queue will be according to vertices distances. Step 3. Pop the vertex with the minimum distance from the priority queue (at first the popped vertex = source). Step 4. Update the distances of the connected vertices to the popped vertex in case of "current vertex distance + edge weight < next vertex distance", then push the vertex Step 5. with the new distance to the priority queue. Step 6. If the popped vertex is visited before, just continue without using it. Step 7. Apply the same algorithm again until the priority queue is empty. โˆ’ Example: Step 1. Start with a weighted graph

Step 5. Avoid updating path lengths of already visited vertices โ–ช Step 6. After each iteration, we pick the unvisited vertex with the least path length. So we choose 5 before 7 โ–ช Step 7. Notice how the rightmost vertex has its path length updated twice

Step 8. Repeat until all the vertices have been visited โ–ช โˆ’ Implementation in Java: