You are on page 1of 15

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 NGUYEN LE NAM GIANG Student ID GCD191097

Class GCD0807B Assessor name Trương Nguyễn Xuân Vinh

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 NGUYEN LE NAM GIANG

Grading grid

P1 P2 P3 M1 M2 M3 D1 D2
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

IV Signature:
Table of Contents
I. Introduction: ..................................................................................................................................................................... 4
II. Create a design specification for data structures explaining the valid operations that can be carried out on the
structures(P1)............................................................................................................................................................................ 4
1. Introduction about Queue: ................................................................................................................................................... 4
1.1. What is a Queue? ........................................................................................................................................................... 4
1.2. Basic operations on queue data structure..................................................................................................................... 5
III. Determine the operations of a memory stack and how it is used to implement function calls in a computer(P2). ..... 8
1. What is a Stack memory ....................................................................................................................................................... 8
2. Function call: ......................................................................................................................................................................... 9
2.1. Function Calls and the Call Stack ................................................................................................................................... 9
2.2. Function-Call Process: .................................................................................................................................................... 9
IV. Using an imperative definition, specify the abstract data type for a software stack (P3). ........................................ 10
1. Definition of Stack:.............................................................................................................................................................. 10
2. Representing the stack data structure (Stack): .................................................................................................................. 10
3. Code .................................................................................................................................................................................... 12
V. Conclusion .............................................................................................................................................................................. 14
VI. References ............................................................................................................................................................................. 14
References .................................................................................................................................................................................. 14

Figure 1: Queue data structure..................................................................................................................................................... 4


Figure 2: Before and after insertion ............................................................................................................................................. 5
Figure 3: Before and retrieving data ............................................................................................................................................. 5
Figure 4: Principle of operation stacks ......................................................................................................................................... 8
Figure 5: Illustrative image of a stack ......................................................................................................................................... 11
I. Introduction:
In this project, I work as an in-house software developer for Softnet Development Ltd, a software company that
specializes in networking solutions. My firm has been awarded a contract to design and create a middleware
solution that would interact with different desktop provisioning interfaces, including SOAP, HTTP, JML and CLI,
and back-end. Networking telecommunications providers via CLI. My team's mission is to create presentations on
how to utilize ADT to enhance software design, development, and testing for all cooperating partners. In
addition, I had to produce an introduction report on how to express abstract data types and algorithms in a
formal notation, which I had to give to all partners.

II. Create a design specification for data structures explaining the valid operations that can be
carried out on the structures(P1).
1. Introduction about Queue:
1.1. What is a Queue?
A queue is a linear list of elements in which an element may only be deleted from one end, the front, and
inserted from the other end, the back. When discussing queues in a linked list, the terms front and back are
commonly employed. The queue will be treated as an array in this chapter.

The first element to be entered in the queue will be the first element to be deleted or removed from the list,
according to the queue idea. As a result, the FIFO (First in First Out) structure is applied to Queue. A real-life
situation that may be used as an example for queue is a line of individuals waiting to complete a job, with the first
person in the line being the first to be served.

Figure 1: Queue data structure

In the queue there are 2 main operations:

Enqueue: Insert data at the end of the queue


Figure 2: Before and after insertion

Dequeue: Get data out of the queue.

Figure 3: Before and retrieving data

1.2. Basic operations on queue data structure.


The queue data structure includes the following activities:

• EnQueue: Add an item to the queue. It is always done behind the queue to add an item to the queue.
• DeQueue: An item that was deleted or canceled from the queue was always placed at the top. There are a
few more features to make the queue run smoothly.
• isEmpty: Checks if the queue is empty
• is Full: Check if the queue is full.
• peek: Bring an element to the front of the queue without removing it from the queue.

Illustration:
We have the rear and the drum set to -1 because this is an empty queue. Then I add numbers 1, 2, and 3 to the
queue, and the outcome is

The element indicated by the forward cursor is deleted. The element to be removed is 1 when the front cursor is
at 0.

Code:
III. Determine the operations of a memory stack and how it is used to implement function calls
in a computer(P2).
1. What is a Stack memory
Stack memory is a type of memory that is used to read data in the exact opposite direction of the recorded
direction, regardless of how the data address is organized, and is only used to store temporary data.

Stack memory is a sequential memory with access limitations that allow it to write and read data to and from a
single point known as the top of the stack.

Stack memory functions as a queue, allowing data to be written to the top of the stack while also changing any
information stored in following locations based on the depth of the queue. this. It is only possible to read from
the top of the stack. Reading causes the top of the stack's information to be removed and a new piece of
information to be placed in its place from the depth of the stack, moving all information stored one position to
the top. The last person in the queue is the one who types first.

Stack memory is a sequential memory that permits just one point, termed the top of the stack, to be written and
retrieved from. The memory stack functions like a queue, and the data in memory changes as the queue depth
increases. The information can only be read from the top of the stack, and getting it from the top of the stack
shifts the internal data to the top of the stack. It's comparable to reloading a rifle bullet using a stack memory box
in that the loading motion removes the top bullet from the cartridge and replaces it at the same time as the
laying bullet.

Figure 4: Principle of operation stacks

Four instructions are used to manipulate the stack:

• Push operation
Inserting data elements into a stack is what a push operation entails. The most inaccessible data item to be
placed is the one at the bottom of the stack.

• Pop activity

The pop operation removes data items from the stack that will be loaded.

• Peek activity

There are no data items added or withdrawn from the stack during this operation. The address of the data item
at the top of the stack is all that is required for the preview action.

• Search activity

There are no folders created or deleted from the stack throughout the search procedure. The address of any
folder in the stack is required for the search function. It determines the item's location in relation to the item at
the top of the stack.

2. Function call:
2.1. Function Calls and the Call Stack
• We saw a rudimentary machine model before, in which the software stores each item in memory at a separate
position. Now we'll look at a more organized type of memory management called stack-based memory
management, which is employed by many language implementations.

• The data for a function call is often saved in an activation record, which includes space for each of the function's
parameters and local variables, temporary objects, the return address, and other items that the function
requires. We will just look at the parameters and local variables in an activation record in this course,
disregarding the rest of the data.

• Activation records are kept in a data structure called a stack in stack-based memory management. A stack
functions similarly to a stack of pancakes: fresh pancakes are added to the top of the stack, and the top pancake
is removed when a pancake is removed from the stack. As a result, the last pancake to be prepared is also the
first to be eaten, resulting in LIFO behavior. Activation records are stored in a similar way: when one is made, it is
placed on top of the stack, and the last activation record created is the first to be deleted. An activation record
has an analogous term stack frame as a result of this.

2.2. Function-Call Process:


To summarize, the following steps occur in a function call:

• The argument expressions for pass-by-value parameters are evaluated to retrieve their values.

• The appropriate argument expression for a pass-by-reference parameter is evaluated to obtain an object 1
rather than its value.

• The call is given its own activation record, with space for the function's parameters, local variables, and
metadata. The stack is pushed with the activation record.
• The parameters are supplied, with the relevant arguments being used to initialize them. The matching
argument value is copied into the parameter for a pass-by-value parameter. The parameter is initialized as an
alias of the argument object for a pass-by-reference parameter.

• The called function's body is executed. Because the code actively informs the computer which function to
perform, this transfer of control is known as active flow.

• If the called function returns a value, that value takes the place of the function call in the caller.

• The invoked function's activation record is deleted. In the most basic circumstances, implementations will
simply leave what is currently in memory, designating the memory as no longer in use.

• The caller's execution starts at the point when the function is called. Because the code does not explicitly
inform the computer which function to perform, this transfer of control is known as passive flow.

IV. Using an imperative definition, specify the abstract data type for a software stack (P3).
1. Definition of Stack:
A stack is an abstract data structure that operates on the "first in, first out" concept. Push and pop are the two basic
operations on a stack, which is a container data structure containing components. After the components are already on the
stack, a push adds an element to the top of the stack. The element at the top of the stack is released and returned by pop.
Items can be added to the stack at any moment, but only the most recently added objects are permitted to be removed.

2. Representing the stack data structure (Stack):


Features of the stack:

The stack is unique in that it can only be accessed from one end for storing and retrieving data. Anything that is added will
be added to the top, and anything that is removed will be removed from the top. When inputting data, the stack allows you
to insert data from the bottom up, and when deleting data, everything is erased in the same order as it was placed.

Working with the stack includes only the following actions:

• Push: Adds an element to the top of the stack, increasing the total number of elements on the stack by 1.
• Pop: The first piece from the top of the stack is removed, reducing the number of items on the stack by 1.
• Top: Get the value of the first element at the top of the stack; the stack's size remains constant.
• IsEmpty: Checks whether or not the stack is empty. A stack with no items is called an empty stack.
• IsFull: Checks whether or not the stack is full. This option isn't available all of the time.
Figure 5: Illustrative image of a stack
3. Code
V. Conclusion
All of the above pertains to my report. This report has allowed me to have a better understanding of data
structures and algorithms. Furthermore, these are quite excellent and useful data that will be extremely
beneficial to me. Finally, I'd want to express my gratitude to Mr. Truong Nguyen Xuan Vinh for his enthusiastic
assistance in finishing this report.

VI. References

References
https://www.faceprep.in/data-structures/types-of-queue-data-structure/, n.d. [Online]
Available at: https://www.faceprep.in/data-structures/types-of-queue-data-structure/

https://www.geeksforgeeks.org/abstract-data-types/, n.d. [Online]


Available at: https://www.geeksforgeeks.org/abstract-data-types/

https://www.sciencedirect.com/topics/engineering/stack-memory, n.d. [Online]


Available at: https://www.sciencedirect.com/topics/engineering/stack-memory

https://www.techopedia.com/definition/9523/stack, n.d. [Online]


Available at: https://www.techopedia.com/definition/9523/stack

https://www.w3schools.in/data-structures-tutorial/queue/, n.d. [Online]


Available at: https://www.w3schools.in/data-structures-tutorial/queue/

You might also like