assignment 1-1649-pass, Assignments of Information Technology

assignment 1-1649-pass (data structure)

Typology: Assignments

2022/2023

Uploaded on 12/06/2023

tuong-tran-4
tuong-tran-4 🇻🇳

21 documents

1 / 12

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
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Trần Văn Tưởng
Student ID
GCH211184
Class
GCH1107
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
Tưởng
Grading grid
P1
P2
P3
M1
M2
M3
D1
D2
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download assignment 1-1649-pass and more Assignments Information Technology 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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Trần Văn Tưởng Student ID GCH Class GCH1107 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 Tưởng Grading grid P1 P2 P3 M1 M2 M3 D1 D

 Summative Feedback:  Resubmission Feedback:

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

  • PART
      1. ADT
      1. Stack ADT
      1. Memory Stack
      1. Queue ADT
  • PART
      1. Explanation on how to specify an abstract data type using the example of software stack
      • specifications, VDM). a. Introduction to formal specification, types of formal specification languages (E.g., Axiomatic
      • b. Describe what are pre-condition, post-condition, error-condition.
      • c. Specify Stack’s operations using this formal specification language.
  • Figure 1:Abstract data type (GeeksforGeeks, 2023) Contents of figures
  • Figure 2:Stack application in Function call
  • Figure 3:Stack application in Function call
  • Figure 4:Formal specification languages (Sommerville, 2009)
PART 1
1. ADT

An object's behavior is determined by a set of values and a set of actions, and they are referred to as the abstract data type (ADT) or class. The ADT specification merely specifies the tasks that must be completed; it makes no statement of how they will be carried out. It is unclear what algorithms will be applied to carry out the operations and how the data will be arranged in memory. Because it provides an implementation- independent view, it is referred to be "abstract." (GeeksforGeeks, 2023). Figure 1 :Abstract data type (GeeksforGeeks, 2023) For example, a list ADT can store a collection of values of the same type, and allow operations such as adding, removing, or accessing an element at a given position. However, the user does not need to know how the list is stored in memory, or what algorithms are used to perform the operations. An ADT is like a black box that only shows its functionality, but not its inner structure. ADT provides several benefits for software development, such as:

  • Abstraction: The user does not need to know the details of the data structure implementation, only the essentials.
  • Encapsulation: ADT hides the internal details of the data and provides a public interface for users to interact with the data.
  • Modularity: ADT can be combined with other ADTs to form larger and more complex data structures.
  • 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: Figure 2 :Stack application in Function call

Figure 3 :Stack application in Function call The food() function is empty, myFavouriteFood() calls food(), and main() calls myFavouriteFood(). When the program is executed, it starts from main(), which calls myFavouriteFood (), which in turn calls food(). Since food() has no code, it does nothing and returns. Execution then goes back to myFavouriteFood (), which completes execution and returns. Finally, main() finishes executing, and the program ends.

4. Queue ADT A queue is an abstract data type (ADT) that represents a collection of elements in a specific order. It follows the First-In-First-Out (FIFO) principle, meaning that the element added first will be the first one to be removed. Just like people standing in a queue, the first person to join the queue is the first one to proceed. Queue operations: Boolean enQueue(E data ): add a new element to the end of the queue. Parameters: a new element with value is data and data is the element added to the end of the queue. Return: true when when the element is successfully added to the end of the queue. False when the element enters the queue item due to capacity limitations and other reasons. Dequeue (): remove and return the front element from the queue. Return: returns the element removed from the front of the queue. Peek (): allows you to access the front element of the queue without removing it. Return: returns the element at the front of the queue without modifying the queue.

b. Describe what are 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) c. Specify Stack’s operations using this formal specification language. Stack stack; Vt.size() - > n(n>=0); Max: the total number of elements can be stored. Push(E data): Boolean flag Pre-condition:

  • n < max
  • stack.size() < max
  • stack.isFull() - > false Post – condition:
  • stack.size() - > n + 1
  • stack.peek() - > item
  • flag - > true Error-condition:
  • stack.isFull() - > true Pop(): Pre-condition: stack.size() > 0 Post-condition: stack.size() - > n - 1 Error-condition: stack.size() = 0

Peek(): Pre-condition: stack.size() > 0 Post-condition: data Error-condition: stack.size() = 0 isEmpty(): boolean flag Pre-condition: none Post-condition:

  • stack.size() = 0, flag - > true
  • stack.size() < 0, flag - > false Error-condition: none