Download Data structures and algorithms assignment 1 and more Assignments Data Structures and Algorithms in PDF only on Docsity!
Higher Nationals in Computing
Unit 19: Data Structures and Algorithms
ASSIGNMENT 1
Assessor name: PHAN MINH TAM
Learner’s name: Pham Nguyen Hung Cuong
ID: GCS
Class: GCS0905B
Subject code: 1649
Assignment due: Assignment submitted:
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 Pham Nguyen Hung Cuong Student ID GCS Class GCS0905B Assessor name Phan Minh Tam 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 Grading grid P1 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 2022 Unit Tutor TamPM Issue date 12 – September – 2022 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 Tutor. ● The form of submission will be a soft copy posted on http://cms.greenwich.edu.vn/. ● Remember to convert the word file into PDF file before the submission on CMS. Note: ● The individual Assignment must be your own work, and not copied by or from another student. ● 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 understand and follow the guidelines to avoid plagiarism. Failure to comply this
requirement will result in a failed assignment. Unit Learning Outcomes: LO1 Examine abstract data types, concrete data structures and algorithms LO2 Specify abstract data types and algorithms in a formal notation Assignment Brief and Guidance: Assignment 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:
- A stack ADT, a concrete data structure for a First In First out (FIFO) queue.
- Two sorting algorithms.
- Two network shortest path algorithms. Part 2 You will need to provide a formal written report that includes the following:
- Explanation on how to specify an abstract data type using the example of software stack.
- Explanation of the advantages of encapsulation and information hiding when using an ADT.
- Discussion of imperative ADTs with regard to object orientation.
Table of Contents
P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures.
- Introduction to Abstract data type (ADT) 1.1. What is ADT 1.2. The benefit of ADT 1.3. ADT example 1.4. ADT vs OOP Examples
- Linear Data Structure 2.1. Definition 2.2. Linked List 2.3. Stack 2.4. Queue
- Sorting algorithm
- Searching algorithm P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer.
- Stack Memory-Operation
- How it is used to implement function calls in a computer P3 Using an imperative definition, specify the abstract data type for a software stack.
- Formal specification
- What is pre-condition, post-condition, error condition
- Specify Stack’s operation using VDM (Vienna Development Method)
P a g e | 1 ASSIGNMENT 1 ANSWERS P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures.
- Introduction to Abstract data type (ADT) 1.1. What is ADT
Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of
values 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.
1.2. The benefit of ADT
- Representation Independence: Most of the program becomes independent of the abstract data type's representation, so that representation can be improved without breaking the entire program.
- Modularity: With representation independence, the different parts of a program become less dependent on other parts and on how those other parts are implemented.
- Interchangeability of Parts: Different implementations of an abstract data type may have different performance characteristics. With abstract data types, it becomes easier for each part of a program to use an implementation of its data types that will be more efficient for that
P a g e | 3 Examples
- Linear Data Structure 2.1. Definition It is a type of data structure where the arrangement of the data follows a linear trend. The data elements are arranged linearly such that the element is directly linked to its previous and the next elements. As the elements are stored linearly, the structure supports single-level storage of data. And hence, traversal of the data is achieved through a single run only. There are four types: Array, linked list, Stack, Queue 2.2 Array In computer science, an array is a data structure consisting of a collection of elements, each identified by at least one array index or key. Basic operations: - Traverse − print all the array elements one by one. - Insertion − Adds an element at the given index. - Deletion − Deletes an element at the given index. - Search − Searches an element using the given index or by the value. - Update − Updates an element at the given index. 2.3. Linked List It is a data structure that contains a finite sequence of n data element. Linked list is the second
P a g e | 4 most-used data structure after array. Linked list can be visualized as a chain of nodes, where every node point to the next node. Fig: representation of the link list. Types of link list: Following are the various types of the link list:
- Simple Linked List − Item navigation is forward only.
- Doubly Linked List − Items can be navigated forward and backward.
- Circular Linked List − Last item contains link of the first element as next and the first element has a link to the last element as previous. Basic operations: Following are the basic operation supported by the link list:
- Insertion − Adds an element at the beginning of the list.
- Deletion − Deletes an element at the beginning of the list.
- Display − Displays the complete list.
- Search − Searches an element using the given key.
- Delete − Deletes an element using the given key. 2.4. Stack Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO (Last in First Out) or FILO (First in Last Out).
P a g e | 6 Basic operations:
- Enqueue() - Insertion of elements to the queue.
- Dequeue() - Removal of elements from the queue.
- Sorting algorithm 3.1. Definition A Sorting Algorithm is used to rearrange a given array or list of elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of elements in the respective data structure. 3.2. Common Sorting algorithm Sorting algorithm Description Bubble Sort Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order.
P a g e | 7 Insertion Sort Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands. Merge Sort The Merge Sort algorithm is a sorting algorithm that is based on the Divide and Conquer paradigm. QuickSort Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given array around the picked pivot. 3.3. Demonstrating two sorting algorithms Bubble Sort
P a g e | 9 4.2. Common Searching algorithm Searching algorithm Description Linear Search Algorithm Linear Search is defined as a sequential search algorithm that starts at one end and goes through each element of a list until the desired element is found Binary Search Binary Search is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half.
Jump Search Jump Search is a searching algorithm for sorted
arrays.
Interpolation Search The Interpolation Search is an improvement over Binary Search for instances, where the values in a sorted array are uniformly distributed. 4.3. Demonstrating two searching algorithms Linear Search Algorithm Binary Search
P a g e | 10 P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer.
- Stack Memory-Operation Stack memory is a memory usage mechanism that allows the system memory to be used as temporary data storage that behaves as a first-in-last-out buffer. One of the essential elements of stack memory operation is a register called the Stack Pointer. An example of a stack is illustrated on the below: Figure 1 Example of stacks / queues Items in a stack are inserted or removed in a linear order and not in any random sequence. As in any queue or collection that is assembled, the data items in a stack are stored and accessed in a specific way.
- How it is used to implement function calls in a computer The stack memory is a special kind of memory that is used to store information temporarily, when we want to read the information correctly in the opposite direction to the recorded memory, without caring about the organization data addressing. Stack memory is sequential memory with specify access restrictions that allow writing and reading information to or from only one location in this memory called the top of the stack. Figure 3 Stack functioning principles
P a g e | 12 Figure 5 Stack implementation in the computer- the top of the stack in registers.. P3 Using an imperative definition, specify the abstract data type for a software stack.
- Formal specification Formal specification of data and algorithm properties is a well-known technique, e.g., in software engineering, mostly used for verification of (simple) programs or specification of abstract data types. It is a statement expressed in a language whose vocabulary, syntax, and semantics are formally defined. The need for a formal semantic definition means that the specification languages cannot be based on natural language; it must be based on mathematics.
- What is pre-condition, post-condition, error condition
- A pre-condition is a predicate that should hold upon entry into a function. It expresses a function's expectation on its arguments and/or the state of objects that may be used by the function. − An In Contract Expression is a precondition. − The first AssignExpression of the Assert Arguments must evaluate to true. If it does not, the precondition has failed. − The second AssignExpression, if present, must be implicitly convertible to type const(char)[]. − An In Statement is also a precondition. Any Assert Expression appearing in an In Statement will be an In Contract Expression. − Preconditions must semantically be satisfied before the function starts executing. If it is not, the program enters an Invalid State. − Implementation Defined: Whether the preconditions are actually run or not is implementation defined. This is usually selectable with a compiler switch. Its behaviour upon precondition failure is also usually
P a g e | 13 selectable with a compiler switch. One option is to throw an Assert Error with a message consisting of the optional second AssignExpression. − Best Practices: Use preconditions to validate that input arguments have values that are expected by the function. − Best Practices: Since preconditions may or may not be actually checked at runtime, avoid using preconditions that have side effects.
- A post-condition is a predicate that should hold upon exit from a function. It expresses the conditions that a function should ensure for the return value and/or the state of objects that may be used by the function. − An Out Contract Expression is a postcondition. − The first AssignExpression of the Assert Arguments must evaluate to true. If it does not, the postcondition has failed. − The second AssignExpression, if present, must be implicitly convertible to type const(char)[]. − An Out Statement is also a postcondition. Any Assert Expression appearing in an Out Statement will be an Out Contract Expression. − Postconditions must semantically be satisfied after the function finishes executing. If it is not, the program enters an Invalid State. − Implementation Defined: Whether the postconditions are actually run or not is implementation defined. This is usually selectable with a compiler switch. Its behavior upon postcondition failure is also usually selectable with a compiler switch. One option is to throw an Assert Error with a message consisting of the optional second AssignExpression. − Best Practices: Use postconditions to validate that the input arguments and return value have values that are expected by the function. − Best Practices: Since postconditions may or may not be actually checked at runtime, avoid using postconditions that have side effects.