ASM 1: Advanced programming, Assignments of Programming Languages

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 .

Typology: Assignments

2021/2022

Uploaded on 08/09/2022

KhoaLd
KhoaLd 🇻🇳

4.9

(53)

13 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Higher Nationals in Computing
Unit 19: Data Structure
ASSIGNMENT 1
Assessor name:
Learner’s name: LE DONGKHOA
ID: GCS200218
Class: GCS0904A
Subject code: 1649
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download ASM 1: Advanced programming and more Assignments Programming Languages in PDF only on Docsity!

Higher Nationals in Computing

Unit 1 9: Data Structure

ASSIGNMENT 1

Assessor name:

Learner’s name: LE DONG KHOA

ID: GCS

Class: GCS0904A

Subject code: 1649

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 Le Dong Khoa Student ID GCS Class GCS0904A 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 Grading grid P1 P2 P3 M1 M2 M3 D1 D

Assignment Brief 1 (RQF) Higher National Certificate/Diploma in Business Student Name/ID Number: Unit Number and Title: Unit 19: Data Structures and Algorithms Academic Year: 2021 Unit Assessor: Le Ngoc Thanh Assignment Title: Examine and specify ADT and DSA Issue Date: Submission Date: Internal Verifier Name: 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:

  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.

CONTENT

  • on the structures. P1 Create a design specification for data structures explaining the valid operations that can be carried out
    • 1.1 Definition of abstract data type
    • 1.2 Example of abstract data type
  • computer. P2 Determine the operations of a memory stack and how it is used to implement function calls in a
    • 2.1 Stack memory operations
    • 2.2 How a method calls is implemented with stack
  • P3 Using an imperative definition, specify the abstract data type for a software stack.
    • 3.1 Definition of Stack as an Abstract Data Type
    • 3.2 When will we need stack
    • 3.3 Implementation
  • Reference

1

Assignment

P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures.

1.1 Definition of abstract data type

ADT stands for Abstract Data Type, and it's a type (or class) for objects whose behavior is specified by a collection of values and actions. The definition of ADT merely specifies what operations are to be carried out, not how they will be carried out. It makes no mention of how data will be stored in memory or which algorithms will be employed to carry out the actions. It's named "abstract" because it provides a view that is independent of implementation. Abstraction is the technique of offering only the basics while concealing the intricacies. The abstract data type is a form of data that may be used in a variety of computer programs. It indicates that the type, such as integer, float, or character, will take up 4-bytes of space, whereas characters will take up 1-byte of space, and so on. The abstract datatype is a type of datatype that has a set of values and actions that define its behavior. Because various datatypes can be used and different operations can be done, the keyword "abstract" is

3 Below is the illustration which shows operations of an arraylist: No Operations Description 1 Boolean add(E element) Adding a new number at the end of the arraylist. A = [1,4,2] add(7)=> A=[1,4,2,7] 2 Boolean add(int index, E element) Method inserts the specified element E at the specified position in this list.It shifts the element currently at that position (if any) and any subsequent elements to the right (will add one to their indices). A =[1,4,2,7] add(2,5)=> A=[1,4,5,2,7] 3 Int size () Returns the number of elements. A =[1,4,5,2,7] Size() => 5; 4 E get (int index) Returns the element at the given index and does not remove it from the collection. (erroneous if index is less than 0 or larger than or equal to size()). A =[1,4,5,2,7] =>Get(4)=> 7; 5 E remove (int index) Removes the element at specified index and returns a new arrays without the element has been deleted. A =[1,4,5,2,7] Remove(0)=> A =[4,5,2,7] 6 Boolean isEmpty() Returns if there are elements stored or no. A = [4,5,2,7] isEmpty(); -> false

4 P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer.

2.1 Stack memory operations

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 be of the same type. 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's assembled, the data items in a stack are stored and accessed in a specific way. In this case, a technique called LIFO (last in first out) is used. This involves a series of insertion and removal operations, which we will discuss in the following section. LIFO (last-in-first-out) When a stack is accessed (things are entered or withdrawn), it is done in a LIFO-style sequence. The abbreviation LIFO stands for "last in first out," and it refers to the computer's strategy of serving data requests received by its memory. According to LIFO, the data that was entered or saved last in a stack must be the first to be deleted. If we applied it to our movie queue in the preceding image, it would be anarchy!

6 Block 1 is how the stack frame is when the processor EIP is within the body of funcA. Note the solid nature of the lower boundary, indicating anything below that is forbidden as far as funcA goes. Similarly, note the dotted boundary at the top of the frame, indicating there is a scope for dynamic expansion and contraction of this top edge as the function is executing. For a moment note that, because this is the topmost function that is executing in that thread, any memory upwards is available to do anything (of course, within limits of the stack size for the thread). Block 2 represents how the stack frames look like when the processor EIP is within the body of funcB. Note now the stack frame for funcA has been frozen at the state when it made a call into funcB. This is indicated red and has a solid boundary at the top indicating, when funcB does return, the stack pointer MUST be at that point. Block 3 represents how the stack frames look when the processor EIP is within the body of funcC. Note now, compared to block 2, the stack frame boundary of funcB is at a lower point than in block 2. This is representative of the fact that, during the execution of func, the compiler might have had code that resulted in a some pushing and some popping of data on the stack. So, at the time funcC was called, it was at a different stack pointer location than it was when block 2 snapshot was taken. Blocks 4 and 5 show how the stack frames are invalidated and are restored to their original state when funcC and funcB have just returned respectively. To recap, stack frames are designed to make the function bodies' work easier. The caller code prepares the stack to push parameters before calling the function, while the callee code prepares the stack for its local variables. When the callee code returns, it must ensure that the stack pointer is set to the same value as when the code was initially entered. The stack frame will be restored as a result of this.

7 Function local variables are perfect candidates to be allocated on the stack. This in fact is the case and the compiler does allocate local variable space right on the stack. This is one of the first things the callee code generated by the compiler will do. It will allocate enough data to accomodate all local variables within a function body. The picture above is a representation of the stack frame setup for a function call. It is interesting to note that the return address location acts as a kind of anchor point for accessing function data.. Note that, to access the arguments, the function body will have to traverse down (higher addresses) from the location where the return address is stored, and to access the local variables, the function body will have to traverse up the stack (lower addresses) relative to the location where the return address is stored. In fact, typical compiler generated code for the function will do exactly this. The compiler dedicates a register called EBP for this (Base Pointer). Another name for the same is frame pointer. The compiler typically, as the first thing for the function body, pushes the current EBP value on to the stack and sets the EBP to the current ESP. This means, once this is done, in any part of the function code, argument 1 is EBP+8 away (4 bytes for each of caller's EBP and the return address), argument 2 is EBP+12(decimal) away, local variables are EBP-4n away.

9

3.2 When will we need stack

A stack is an example of a linear data structure. Linear data structures are collections of components arranged in a straight line. When we add or remove components of linear data structures, they grow and shrink. If we restrict the growth of a linear data structure so that new components can only be added or removed only at one end, we have a stack. Stacks are useful data structures and are used in a variety of ways in computer science. You already know that stacks are used to implement functions and you have seen that each running program has a stack and how a program's stack grows and shrinks during calls to functions/procedures. This is especially important in understanding how recursion works. In general, stacks are useful for processing nested structures or for functions which call other functions (or themselves). A nested structure is one that can contain instances of itself embedded within itself. For example, algebraic expressions can be nested because a subexpression of an algebraic expression can be another algebraic expression. Stacks are used to implement functions, parsers, expression evaluation, and backtracking algorithms. A pile of books, a stack of dinner plates, a box of pringles potato chips can all be thought of examples of stacks. The basic operating principle is that last item you put in is first item you can take out. That is, that a stack is a Last In First Out (LIFO) structure.

3.3 Implementation

TreeSearch:

  1. Starting at Root, your options are A and B. You choose A.
  2. At A, your options are C and D. You choose C.
  3. C is bad. Go back to A.
  4. At A, you have already tried C, and it failed. Try D.
  5. D is bad. Go back to A.
  6. At A, you have no options left to try. Go back to Root.
  7. At Root, you have already tried A. Try B.
  8. At B, your options are E and F. Try E.
  9. E is good. Congratulations!

10 Backtracking is a rather typical recursive algorithm, and any recursive algorithm can be rewritten as a stack algorithm. In fact, that is how your recursive algorithms are translated into machine or assembly language. Starting from the root, the only nodes that can be pushed onto the stack are the children of the node currently on the top of the stack, and these are only pushed on one child at a time; hence, the nodes on the stack at all times describe a valid path in the tree. Nodes are removed from the stack only when it is known that they have no goal nodes among their descendents. Therefore, if the root node gets removed (making the stack empty), there must have been no goal nodes at all, and no solution to the problem. When the stack algorithm terminates successfully, the nodes on the stack form (in reverse order) a path from the root to a goal node.