Professional Documents
Culture Documents
Unit number and title Unit 19: Data Structures and Algorithms
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
Summative Feedback: Resubmission Feedback:
2.1
IV Signature:
I. Table of Contents
I. Table of Contents ................................................................................................................................... 3
II. Table of Figures...................................................................................................................................... 3
III. Data Structures .................................................................................................................................... 4
A. Abstract Data Type .......................................................................................................................... 4
IV. Example of Abstract Data Type .......................................................................................................... 4
A. Stack ................................................................................................................................................ 4
1. Push operation .............................................................................................................................. 5
2. Pop operation ............................................................................................................................... 6
B. Memory stack .................................................................................................................................. 7
1. The operations of a memory stack ............................................................................................... 7
2. How it used to implement function calls in a computer .............................................................. 8
3. Method call and recursion implementation .................................................................................. 8
C. Queue ............................................................................................................................................... 8
1. Queue Operation .......................................................................................................................... 9
2. Enqueue Operation ....................................................................................................................... 9
3. Dequeue Operation ...................................................................................................................... 9
V. Explanation on how to specify an abstract data type using the example of software stack ................. 10
VI. Conclusion ......................................................................................................................................... 10
VII. References ......................................................................................................................................... 11
Data type users do not need to know how to execute this data type, for example, we have used
primitive values such as data types int, float, char, with no idea how this data type works and how they are
executed. Thus, the user only needs to know what the data type can do, but not how it is executed. Think
of ADT as a black box that hides the internal structure and layout of the data type. We now define three
ADTs, namely List ADT, Stack ADT, Queue ADT (Chauhan, 2019).
1. Push operation
The process of putting a new data element onto stack is known as a Push Operation. Push
operation involves a series of steps:
If the linked list is used to implement the stack, then in step 3, we need to allocate space
dynamically.
N=9
Sum(8)+9;
(sum(7)+8)+9;
((sum(6)+7)+8)+9;
…
Sum(1)+2+3+4+5+6+7+8+9;
1+2+3+4+5+6+7+8+9=45;
Factor(8) * 9;
(factor(7)*8)*9;
((factor(6)*7)*8)*9;
…
Factor(1)*2*3*4*5*6*7*8*9;
o Base case: This is to locate the littlest form of an issue which we definitely know the arrangement
or an ending condition where a capacity can restore the outcome.
o Recursive structure: Here we need to discover the answer for an issue through the arrangement of
its more modest subproblems. Here capacity must call itself to separate the current issue to a
straightforward level.
C. Queue
A Queue is a linear structure which follows a particular order in which the operations are
performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers
for a resource where the consumer that came first is served first. The difference between stacks and
queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the
item the least recently added (geeksforgeeks, 2022).
1. Queue Operation
The basic operations of stack:
2. Enqueue Operation
Queues maintain two data pointers, front and rear. Therefore, its operations are comparatively
difficult to implement than that of stacks.
The following steps should be taken to enqueue (insert) data into a queue:
Sometimes, we also check to see if a queue is initialized or not, to handle any unforeseen
situations.
3. Dequeue Operation
Accessing data from the queue is a process of two tasks − access the data where front is pointing and
remove the data after access. The following steps are taken to perform dequeue operation:
VI. Conclusion
In conclusion, queue and stack data structure give the writer a deeper understanding of these data
structures. Besides the report working in group also help members learn more and comparing the
difference between two sorting algorithms that are quick to sort and bubble sort. These algorithms are
useful for arranged the data for binary searching algorithm to work. In the last section, the report talks
about some specification when using formal notation with creational conditions like error conditions, post-
conditions, and pre-conditions for two abstract data structure queues.
VII. References
Chauhan, A., 2019. Abstract Data Types. [Online] Available at: https://www.geeksforgeeks.org/abstract-
datatypes/#:~:text=Abstract%20Data%20type%20(ADT)%20is,and%20a%20set%20of%20operations.&t
ext=It%20is%20called%20%E2%80%9Cabstract%E2%80%9D%20because,details%20is%20known%20
as%20abstraction.
Martin, M., 2022. Stack vs Heap: Know the Difference. [online] guru99. Available at:
<https://www.guru99.com/stack-vs-heap.html> [Accessed 24 April 2022].
2.1 - P1: A short definition of Stack, Queue ADT and their working mechanism are introduced.
- P2: A particular example is given, however your explanation about the use of memory stack in this function call is
unclear. The presented description was more about recursion.
- P3: The provided specification for Stack's operations can mostly be understood, except the part Exception which
is imprecise.