Download Data Structures and Algorithms: Design Specification and Formal Notation and more Assignments Information Technology 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: Duong Trong Qui
ID: GBS
Class: GCS1005A
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 Dương Trọng Quí Student ID GBS Class GCS1005A 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
- Unit 19: Data Structures and Algorithms ASSIGNMENT
- carried out on the structures. P1. Create a design specification for data structures explaining the valid operations that can be
- Introduction to Abstract Data Type ( ADT ):
- 1.1. What is ADT?
- 1.2. The benefits of ADT:
- 1.3. ADT examples:
- 1.4. ADT vs OOP:
- Linear Data Structures:
- 2.1. Definition:
- 2.2. Array:
- 2.2.1. Definition:.......................................................................................................................
- 2.2.2. Basic operations on Array:
- 2.3. Linked List:.........................................................................................................................
- 2.3.1. Definition:.......................................................................................................................
- 2.3.2. Basic operations on Linked List:
- 2.4. Stack:.................................................................................................................................
- 2.4.1. Definition:.......................................................................................................................
- 2.4.2. Basic operations in Stack:
- 2.5. Queue:...............................................................................................................................
- 2.5.1. Definition:.......................................................................................................................
- 2.5.2. Basic operations in Queue:
- Sorting Algorithm:
- 3.1. Definition:
- 3.2. Common Sorting Algorithm:
- 3.3. Demonstrate two Sorting Algorithm:..................................................................................
- 3.3.1. Bubble sort:
- 3.3.2. Merge sort:
- Searching Algorithm:
- 4.1. Definition:
- 4.2. Common Searching Algorithm:
- 4.3. Demonstrate two Searching Algorithm:
- 4.3.1. Linear search:.................................................................................................................
- 4.3.2. Binary search:
- computer. P2. Determine the operations of a memory stack and how it is used to implement function calls in a
- The operations of a memory stack:
- 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 are pre-condition, post-condition, error-condition:
- 2.1. Pre-condition:
- 2.2. Post-condition:
- 2.3. Error-condition:
- Specify Stack Operations using this formal language:
- REFERENCES
P a g e | 2 improves program modularity.
- Allows for code reuse because the same data structure can be utilized by numerous apps that share an interface.
- Combining data and processes into a single entity improves security and control over the data, and promotes the idea of data concealing.
- Provides flexibility and adaptability to changing requirements by supporting polymorphism, which enables the usage of the same interface with various underlying data structures. 1.3. ADT examples: List ADT: An abstract list data type signifies a list of items with each item having a specific position in a linear grouping of data objects in a set order. List elements may be placed in any sequence, including chronologically, numerically, or neither. A list's components do not need to be unique from one another, unlike an assembly. The List of ADT Functions is given below:
- 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. 1.4. ADT vs OOP: Abstract data type (ADT) Object-oriented programming (OOP) The abstract data type is an abstraction that defines a set of values and a set of operations on It is a self-contained component that consists of methods and properties to make a certain type of
P a g e | 3 these values. data useful. User-defined data type. It is an instance of class. ADT is made of with primitive datatypes. An object is an abstract data type with the addition of polymorphism and inheritance. It is a type (or class) for objects whose behavior is defined by a set of values and a set of operations. It is a basic unit of Object-Oriented Programming. Abstract datatype is not necessarily an OOP concept. Objects is an OOP concept. Common examples include lists, stacks, sets, etc. Objects have states and behaviors Test t = new Test();. Allocate memory when data is stored. When we instantiate an object then memory is allocated.
2. Linear Data Structures:
2.1. Definition: A linear data structure is one where data items are arranged in a linear fashion. Each member is attached to its neighboring elements. The structure permits single-level data storage because the data elements are stored in a linear fashion. The data can be traversed in one run. Common types of linear data structure:
- Array
- Stack
- Queue
- Linked list
P a g e | 5 ✓ 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. ✓ Display − Displays the contents of the array. 2.3. Linked List:
- 3 .1. Definition: A typical data structure made up of one or more nodes is called a linked list. Each node in the chain- like structure is composed of a value and a pointer to the node before or after it. Due to the random storage of these nodes in the system's memory, it has a lower space complexity than an array. Figure 4 : Linked List 2.3.2. Basic operations on Linked List: The basic operations in the linked lists are insertion, deletion, searching, display, and deleting an element at a given key. These operations are performed on Linked Lists as given below: ✓ 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.
P a g e | 6 ✓ Search − Searches an element using the given key. ✓ Delete − Deletes an element using the given key. 2.4. Stack: 2.4.1. Definition: Stack is a linear data structure that follows a particular order in which the operations are performed. The order could be either FILO (First In Last Out) or LIFO (Last In First Out). According to LIFO and FILO, respectively, the element that is inserted last emerges first and the element that is inserted first emerges last. Figure 5 : Stack 2.4.2. Basic operations in Stack: The following are the basic operations served by stacks. ✓ push: Adds an element to the top of the stack. ✓ pop: Removes the topmost element from the stack. ✓ isEmpty: Checks whether the stack is empty. ✓ isFull: Checks whether the stack is full. ✓ top: Displays the topmost element of the stack.
P a g e | 8
3. Sorting Algorithm:
3.1. Definition: A sorting algorithm is a technique for rearranging several elements in a predetermined order, such as shortest to longest distance or alphabetically from highest to lowest. Input data for sorting algorithms are lists of elements, which are subjected to specific procedures to create sorted arrays. Figure 7 : Sorting Algorithm 3.2. Common Sorting Algorithm: There are many common types of sorting algorithms:
- Selection sort
- Bubble sort
- Insertion sort
- Merge sort
- Quick sort
- Heap Sort SN Sorting Algorithm Description
- Selection sort Selection sort is a quick and effective sorting method that functions by continually shifting the lowest (or largest) element from the list's unsorted section to the sorted section.
- Bubble sort Bubble Sort is the most straightforward sorting algorithm
P a g e | 9 that functions by repeatedly switching nearby elements if they are in the wrong order. Large data sets should not be used with this approach due to its high average and worst-case time complexity.
- Insertion sort Insertion sort is a straightforward sorting algorithm that operates in a manner akin to how you would arrange playing cards in your hands. In a sense, the array is divided into sorted and unsorted parts. Values are chosen and assigned to the appropriate positions in the sorted part of the data from the unsorted component.
- Merge sort Merge sort is a sorting method that divides an array into smaller subarrays, sorts each subarray, and then merges the sorted subarrays back into the original array to get the final sorted array.
- Quick sort QuickSort is a sorting method built on the Divide and Conquer algorithm that selects one element as a pivot and divides the supplied array around the pivot by positioning the pivot in the appropriate location in the sorted array.
- Heap Sort Heap sort is a sorting method that uses comparisons and is based on the Binary Heap data structure. It is comparable to the selection sort in which the minimum element is initially located and placed at the start. For the remaining components, follow the same procedure. 3.3. Demonstrate two Sorting Algorithm: 3.3.1. Bubble sort: Bubble Sort is the most basic sorting algorithm, and it operates by frequently switching nearby items if their order is incorrect. This algorithm's average and worst-case time complexity is relatively high, making it unsuitable for large datasets.
P a g e | 11 consume more memory. Figure 9 : Merge Sort Merge Sort Explained: Step 1: Split the list in half to create two subsets. Step 2: Continue to bisect the subsets, until only individual items remain. Step 3: Merge the individual items together in pairs, putting them together in order. Step 4: Continue merging the pairs together, with each subset sorted. Step 5: Once all the subsets have been combined, the list should be in the correct order.
4. Searching Algorithm:
4.1. Definition: A search algorithm is a systematic procedure used to locate specific data within a data source. It is regarded as a crucial stage in computer science. The distinction between a computer program that finds data quickly and one that takes longer can be made by choosing the correct search algorithm.
P a g e | 12 Figure 10 : Searching Algorithms 4 .2. Common Searching Algorithm: There are some types of common Searching Algorithms:
- Linear search
- Binary search SN Common Searching Algorithm: Description
- Linear search Linear Search is a sequential search technique that begins at one end of a list and runs through each item until the required element is discovered; if not, the search continues to the end of the data set.
- Binary search Binary Search is described as a searching algorithm that halves the search interval in half periodically and is employed in a sorted array. Utilizing the knowledge that the array is sorted, binary search attempts to minimize the time complexity to O(log N).