Docsity

Assignment 1 Data Structure and Algorithms, Essays (university) of Software Development

Partial preview of the text

Download Assignment 1 Data Structure and Algorithms and more Essays (university) Software Development in PDF only on Docsity!

Data Structures and Algorithms

ASSIGNMENT 1

No.

Learner’s name : Nguyen Tri Tai Assessor name : Le Ngoc Thanh Class : GCS0903A Learner’s ID : GCS Subject’s ID : 1649 Assignment submitted : 12/06/

ASSIGNMENT 1

Grading grid P1 P2 P3 M1 M2 M3 D1 D 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 Nguyễn Trí Tài Student ID GCS Class GCS0903A Assessor name Lê Ngọc Thành 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 Tai

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 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: 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. 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

Contents

  • A. Introduction:
  • B. Abstract data type (P1):
    • I.Definition:
    • II.Implementation:
    • III.Benefit:
    • IV.ADT in VDM:
    • V.ADT in Java: Bag
  • computer (P2): C. Determine the operations of a memory stack and how it is used to implement function calls in a
    • I. Definition:
  • D. Using an imperative definition, specify the abstract data type for a software stack (P3):
    • I.Identify the problem:
    • II.Solution:
    • III.Example:
  • CONCLUSION:
  • REFERENCES:

A. Introduction: In this assignment, I'll create a Design Specification for a Data Structure that describes the legitimate operations that may be done on the structure. Following that, I'll explain how the memory stack works and how it's utilized in computers to make function calls. Finally, I will describe the abstract data type for a software stack using an imperative description. B. Abstract data type (P1): I.Definition: An abstract data type (ADT) is a kind (or class) of object with a set of values and operations that govern its behavior. It is called "abstract" because it gives a perspective that is unaffected by implementation. The approach of giving simply the fundamentals while concealing the nuances is known as abstraction. ADT's consists are as follows:

  • Data declaration
  • Operational declaration
  • Data and operation encapsulation: data is concealed from the user and can only be manipulated through operations. Language:
  • ADT is a description rather than code, and it is not dependant on any programming language. This means that an abstract type's use is unaffected by its representation (the actual data structure or data fields used to implement it), and that changes in representation have no effect on code outside of the abstract type.
  • Encourage the development of contracts that clearly describe supplier and customer duties so that they may be enforced if required. II. Implementation: Implementaion of an Abstract Data Type (ADT):
  • The user is completely ignorant of this.
  • Different languages may implement the same ADT in various ways.
  • Some programming languages have built-in ADTs and/or capabilities for creating ADTs (user- define types). Modular design, which is critical in software development, is supported by ADTs. System design with ADTs:

IV.ADT in VDM: Definition VDM The Vienna Development Method (VDM) is a well-known formal methodology for developing computer-based systems. It has evolved to include a variety of approaches and tools based on a formal specification language—the VDM Specification Language—developed in the 1970s at the IBM Laboratory Vienna (VDM-SL). VDM++, a more sophisticated version, enabling you to simulate object-oriented and concurrent systems. There are commercial and academic tools for evaluating models, as well as assistance with testing and demonstrating model characteristics and developing program code from verified VDM models. VDM and related tools have a long history of practical use, and a growing corpus of research in the formalism has resulted in major contributions to the field. Example ADT in VDM: Type Name Boolean Code writing Symbol bool data type true, false Operational structure This function will compare 1 information with 1 pre-confirmed information and return true or false answer corresponding to the available setting. a <=> b Bi implication bool * bool - > bool a = b Equality bool * bool - > bool a <> b Inequality bool * bool - > bool **Example:

  • Code:** Figure 2 boolean type code example + Result:

Figure 3 result boolean type code V.ADT in Java: Bag Bags are merely designs that provide an outline of functionality. For example, in a bag of candy, you can only see the shells but not the real candy.

  • The order of the components is not critical, as it is in a list. For example, 3, 2, 7, 8 is similar to 2, 3, 7, 8. Items do not have to be one-of-a-kind (unlike a set). For example, 7,2,10,7,5 is a bag rather than a set. The operations supported by our Bag ADT:
  • add(item): Insert an item into the Bag.
  • remove(item): Remove one instance of item from the Bag (if any)
  • includes(item): check to see whether the item is in the Bag
  • numItems(): Returns the total number of items in the Bag.
  • grab(): obtain a random object without deleting it
  • toArray(): Returns an array containing the bag's current contents. - In Java, we can use interface to specify an ADT: Figure 4 specify an ADT In Java, we can use implement an ADT by a:
  • Pop: Removes an item from the stack. Items are displayed in the reverse order in which they were pushed. If the stack is empty, it is termed a Flow condition.
  • Peek or Top: Returns the top member of the stack.
  • is Empty: Returns true if the stack is empty; otherwise, returns false. (geeksforgeeks, 2021) Key Features: The following are the primary functions of stack memory:
  • It expands and contracts when additional methods are called and returned.
  • Variables inside the stack exist only while the method that produced them is active.
  • It is automatically created and de-allocated when the method executes.
  • If this memory is filled, Java throws the java.lang.StackOverFlowError
  • When compared to heap memory, access to this memory is quick.
  • Because each thread operates in its own stack, this memory is threadsafe. (baeldung, 2020) Explain and example how memory stack is organized: When a function is called, a block at the top of the stack is designated for local variables and specific accounting data. The block will not be used when that function returns, but it can be used in the function call that follows. The stack is always arranged in LIFO (last in, first out) order, with the most recently reserved block being released first. This simplifies stack tracing by making removing a block from the stack as simple as changing a reference. Example code: Program to calculate the sum of a sequence of numbers: Figure 6 memory stack example code Figure 7 memory stack example code (result) If n equals the array's length minus one, the method above calls itself, and the value of n is decremented by one with each call until the base case yields the first unit. The return values of each function call are then advanced until the originating function and the supplied result are reached.

The base case ensures that the function does not make any subsequent recursive calls. If no base case is supplied, the function will continue to call itself until memory is exhausted, resulting in a stack overflow. As a result, a recursive function must have a base case in order to function.

  • The following image illustrates a memory stack implemented function call:
  • When a function call occurs, prior variables are saved in the stack. Figure 8 Variable storage +Returning value from base case to caller function: Figure 9 call function The calls in the example are 'stacked' on top of each other since they are dependent on the outcomes of the preceding functions, and this stacking also makes the base case manageable. Stop the program. This is known as the call stack (or execution stack). D. Using an imperative definition, specify the abstract data type for a software stack (P3): I.Identify the problem: We'll need to make an array to keep the information list. This list will be ordered so that we can quickly access each child element at random. For example, if you want the child element information at the 10th place, the system must display it right away.

Result: Figure 12 result CONCLUSION: After finishing this report, I learnt a lot of previously unknown information and gained a lot of fresh and important information. I will be able to better prepare my items in the future thanks to my new understanding of Data Structures and Algorithms. Above all, I'd want to thank Mr. Vinh for his passionate instruction and assistance. REFERENCES: Baeldung. (2020). baeldung. Retrieved from Stack Memory and Heap https://www.baeldung.com/javastack-heap (11/06/2022) GeeksForGeeks. (2021). geeksforgeeks. Retrieved from Stack Data Structure: https://www.geeksforgeeks.org/stack-data-structure-introduction-program/ (11/06/2022) GeeksForGeeks (2022), Abstract Data Types. Available at: https://www.geeksforgeeks.org/abstract-data- types/ (11/06/2022) ScienceDirect (2022), Stack Memory. Available at: https://www.sciencedirect.com/topics/engineering/stack- memory#:~:text=Stack%20memory%20is%20a%20memory,register%20called%20the%20Stack%20Poi nter. (11/06/2022) Github (2022), Function Calls and the Call Stack. Available at: https://eecs280staff.github.io/notes/02_ProceduralAbstraction_Testing.html (11/06/2022) Wisdomjobs (2022), ABSTRACT DATA TYPE - DATA STRUCTURES. Available at: https://www.wisdomjobs.com/e-university/data-structures-tutorial-290/abstract-data-type-7124.html (11/06/2022)