DS&A - 1649 - Assignment 1, Assignments of Data Structures and Algorithms

This assignment is graded PASS

Typology: Assignments

2022/2023

Uploaded on 09/04/2023

CookieCooka
CookieCooka šŸ‡»šŸ‡³

4.9

(13)

8 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures and Algorithms
Submission date
30/06/2023
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Student ID
Class
GCH1103
Assessor name
Do Hong Quan
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
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download DS&A - 1649 - Assignment 1 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19 : Data Structures and Algorithms Submission date 30/06/2023 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Student ID Class GCH1103 Assessor name Do Hong Quan 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

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

  • I. Part
      1. Abstract data type (P1)
      1. Stack ADT (P1)
      1. Queue ADT (P1)
  • II. Part
      1. Application of Stack in memory (P2)
      1. Application of an ADT (P3)
      • 2.1. Formal specification
      • 2.2. Pre-condition, Post-condition, Error condition
      • 2.3. Specify Stack’s operations using this formal specification language.
  • References
  • Figure 1: Abstract data type (Chauhan, 2023)
  • Figure 2: Push() operation
  • Figure 3: Pop() operation
  • Figure 4: Peek() operation
  • Figure 5: isEmpty() operation
  • Figure 6: Enqueue() operation
  • Figure 7: Dequeue() operation.....................................................................................................................................................................................
  • Figure 8: Stack application in Function call (Kamil, 2019)
  • Figure 9: Formal specification languages (Sommerville, 2009)

I. Part 1

1. Abstract data type (P1)

An abstract data type (ADT) is a concept or model of a data type that describes what operations can be performed on it, but not how they are implemented. An ADT hides the details of the data representation and implementation from the user, and provides an interface that defines the behavior of the data type. (Chauhan, 2023) Figure 1 : Abstract data type (Chauhan, 2023)

Pop (E item): Removes an item from the stack. It returns the item that was removed and updates the stack by making the next item the new top. Figure 3 : Pop() operation Peek(E item): return the top element from the stack without removing it.

Figure 4 : Peek() operation IsEmpty(E item): This operation checks whether the stack is empty. It returns a Boolean value indicating whether the stack contains any elements or not.

Figure 6 : Enqueue() operation Dequeue(E item) : Remove and return the element at the front of the queue. The next element in line becomes the new front of the queue. Figure 7 : Dequeue() operation

II. Part 2

1. Application of Stack in memory (P2)

In computer science, a memory stack is a data structure that stores data in a last-in, first-out (LIFO) order. This means that the most recently added data is the first data that will be removed. Memory stacks are used to store the state of a function call, including the function's parameters, local variables, and return address. A stack is a special area of computer’s memory which stores temporary variables created by a function. In stack, variables are declared, stored and initialized during runtime. It is a temporary storage memory. When the computing task is complete, the memory of the variable will be automatically erased. (Martin, 2023) The basic operations of a memory stack are:

  • Push : This operation adds an element to the top of the stack.
  • Pop : This operation removes the element from the top of the stack and returns it.
  • Peek : This operation returns the element at the top of the stack, without removing it.
  • IsEmpty : This operation returns true if the stack is empty, otherwise, return false.
  • IsFull : This operation returns true if the stack is full, otherwise, return false. How memory stack is used to implement function calls in a computer: Push : When a function is called or a new block of memory is allocated, the system "pushes" information onto the memory stack. This information typically includes the return address of the function, function arguments, and local variables. Pop : As a function completes execution or a block of memory is deallocated, the system "pops" data off the memory stack. This operation involves moving the stack pointer back to the previous position, effectively removing the topmost data from the stack. The popped data is no longer accessible and can be overwritten by following pushes. Example of function call:
  • Requirements analysis: Capture the requirements of a system in a precise and certain way. This can help to avoid misunderstandings between the customer and the developer.
  • Design : Verify the design meets the requirements and to identify potential problems.
  • Verification : Prove the implementation satisfies the specification.
  • Validation : Check the implementation produces the correct results for a given set of inputs. There are two fundamental approaches to formal specification (Sommerville, 2009):
  • An algebraic approach where the system is described in terms of operations and their relationships.
  • A model-based approach where a model of the system is built using mathematical constructs such as sets and sequences, and the system operations are defined by how they modify the system state. Figure 9 : Formal specification languages (Sommerville, 2009)

2.2. Pre-condition, Post-condition, Error condition

A pre-condition is a condition that must be true before a method or function is called. It specifies what must be in place before the method is executed. (Matthew, 2012) A post-condition is a condition that must be true after a method or function has finished executing. It specifies what the method will have accomplished when it finishes. (Matthew, 2012) An error-condition is not as commonly used as pre and post-conditions, but it can refer to conditions that are checked for errors at the beginning of a method. (Matthew, 2012)

2.3. Specify Stack’s operations using this formal specification language.

Note:

  • Stack St;
  • St.size() - > n (n>=0);
  • Max: the total number of elements can be stored Push(E item): Boolean flag Pre-condition:
  • n < max
  • St.size() < max
  • St.isFull() - > false Post – condition:
  • St.size() - > n + 1
  • St.peek() - > item
  • flag - > true Error-condition:
  • St.isFull() - > true Pop(E item): Pre-condition: St.size() > 0 Post-condition: St.size() - > n - 1 Error-condition: St.size() = 0

References Chauhan, A., 2023. GeeksforGeeks. [Online] Available at: https://www.geeksforgeeks.org/abstract-data-types/ [Accessed 16 June 2023]. Kamil, A., 2019. eecs280staff.github.io. [Online] Available at: https://eecs280staff.github.io/notes/02_ProceduralAbstraction_Testing.html [Accessed 27 June 2023]. Martin, M., 2023. Guru99. [Online] Available at: https://www.guru99.com/stack-vs-heap.html [Accessed 27 June 2023]. Matthew, 2012. Devfright. [Online] Available at: https://www.devfright.com/what-are-pre-conditions-and-post-conditions-in-programming/ [Accessed 28 June 2023]. Rai, A., n.d. GeeksforGeeks. [Online] Available at: https://www.geeksforgeeks.org/introduction-to-stack-data-structure-and-algorithm-tutorials/ [Accessed 26 June 2023]. Sommerville, I., 2009. Chapter 27 Formal Specification. [Online] Available at: https://ifs.host.cs.st-andrews.ac.uk/Books/SE9/WebChapters/PDF/Ch_27_Formal_spec.pdf [Accessed 27 June 2023].