Data Structures and Algorithms
Data Structures and Algorithms
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:
IV Signature:
Assignment Brief 1 (RQF)
Higher National Certificate/Diploma in Business
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.
LO1 Examine abstract data types, concrete data structures and algorithms
LO2 Specify abstract data types and algorithms in a formal notation
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:
1. Explanation on how to specify an abstract data type using the example of software stack.
2. Explanation of the advantages of encapsulation and information hiding when using an ADT.
3. Discussion of imperative ADTs with regard to object orientation.
P1 Createadesign specification for data structures explaining the valid operations that can be
Stack is a linear data structure that follows a particular order in which the operations are performed. The
order may be LIFO(Last In First Out) or FILO(First In Last Out).
This strategy states that the element that is inserted last will come out first. You can take a pile of plates
kept on top of each other as a real-life example. The plate which we put last is on the top and since we
remove the plate that is at the top, we can say that the plate that was put last comes out first.
Some of its main operations are: push(), pop(), top(), isEmpty(), size(), etc. In order to make
manipulations in a stack, there are certain operations provided to us: When we want to insert an element
into the stack the operation is known as the push operation whereas when we want to remove an element
from the stack the operation is known as the pop operation. If we try to pop from an empty stack then it is
known as underflow and if we try to push an element in a stack that is already full, then it is known as
overflow.
Mainly the following four basic operations are performed in the stack:
Algorithm EExample
Push Adds an item to the stack. If the stack is full, begin
then it is said to be an Overflow condition. if stack is full
return
endif
else
increment top
stack[top] assign
value
end else
end procedure
Pop Removes an item from the stack. The items are begin
popped in the reversed order in which they are if stack is empty
pushed. If the stack is empty, then it is said to return
endif
be an Underflow condition.
else
store value of
stack[top]
decrement top
return value
end else
end procedure
Implementation:
There are two ways to implement a stack:
● Using array
● Using linked list
boolean isEmpty()
{
return (top < 0);
}
Stack()
{
top = -1;
}
boolean push(int x)
{
if (top >= (MAX - 1)) {
System.out.println("Stack Overflow");
return false;
}
else {
a[++top] = x;
System.out.println(x + " pushed into stack");
return true;
}
}
int pop()
{
if (top < 0) {
System.out.println("Stack Underflow");
return 0;
}
else {
int x = a[top--];
return x;
}
}
int peek()
{
if (top < 0) {
System.out.println("Stack Underflow");
return 0;
}
else {
int x = a[top];
return x;
}
}
void print(){
for(int i = top;i>-1;i--){
System.out.print(" "+ a[i]);
}
}
}
// Driver code
class Main {
public static void main(String args[])
{
Stack s = new Stack();
s.push(10);
s.push(20);
s.push(30);
System.out.println(s.pop() + " Popped from stack");
System.out.println("Top element is :" + s.peek());
System.out.print("Elements present in stack :");
s.print();
}
}
Output
10 pushed into stack
20 pushed into stack
30 pushed into stack
30 Popped from stack
Top element is : 20
Elements present in stack : 20 10
P2 Determine the operations of a memory stack and how it is used to implement function calls in a
computer.
The operations of memory stack
Memory stack is linear data structure(location)used to store data in the computer's memory.They can also
be called queues. Data in stack must always be the same type.
An example of stack is illustrated on the below:
Examples of Stacks/Queues.
Items in the stack are inserted or deleted in linear order and do not follow any random
string.As in any queue or collection that is assembled,data items in the stack are stored
and accessed in specific way.In this case,a technique called LIFO(Last In First Out)is
used.This involves series of insert and removal operations that we will discuss in the
following section.
LIFO(Last In First Out)
When Stack is accessed(there are inserted or deleted items),it is done in an orderly
manner by LIFO.LIFO stands for Last In First Out.Computers use this method to request
service data that the computer's memory receives.LIFO dictates that data is last inserted
or stored in any particular stack,must be the first data to be deleted.If that applies to our
queue for movies in Figure 1 Above,there will be chaos!The operations on the stack are
discussed in the following sections with image on the below:
1. The Push Operation
Push operation involves inserting data items intoastack.Let us check our restaurant
plate dispenser in Figure 9. Operation pushes additional plates(data items)into the
plate dispenser(stack).The first plate is pushed down to the bottom of the stack with
all subsequent plates in the following order after it.The first inserted data item is the
most inaccessible and is located at the bottom of the stack.
2. The Pop Operation
Pop operation involves removing data items from the loaded stack.In our plate
distributor illustration,the last sheet(data item)added is placed at the top of the stack.
This data item is turned off the stack as the first item is deleted.Think of the spring
loading system in the base of the plate distributor.It pushes the stack on top each time
you remove the plate.In memory,items continue to be turned on in that order.
3. The Peek Operation
In this operation,no data items are added or deleted from the stack.The snapshot
operation only requires the address location of the data item at the top of the stack(the
last item is pushed).
4. The Search Operation
In this operation,it does not have any data items added or deleted from the stack.
The search operation require that geographical local of any data items in the stack.It
located the item at the top of the stack.
The first stack deployment is based on the use of registers,in which data is moved ina
parallel manner during Push and Pop operations.Modern stack deployment is based on
the main memory usage supported by special registers that make it easy to access and
manage the stack.Astack is reserved by the operating system,sequences of consecutive
memory locations.The boundary of the stack is determined by two special registers-the
stack base register and the stack limit register hold the address of the stack top and lower
boundary positions.The address space between these addresses is excluded from other
uses than the stack implementation.The top of the stack is determined by keeping the
address in the third register called the stack pointer register.Before the computer starts
executing the program,the top of the stack register is set to the contents of the stack base
register.After each Push operation,the contents of the stack pointer register are changed according to the
number of bytes corresponding to the stack in the stack limit direction. After each Pop operation,the
content of the stack pointer is changed in the direction of
the stack base.
Stack memory implements function call in computer
Among the instructions that control computers,we can find subroutine call instructions
with the acronym"Call"and instructions for returning subroutines with the acronym
"Rent".Subroutine is a series of instructions that end with the"Ret"return command.In
the subroutine the subroutine always has the address of the first instruction ina
subprogram called the subroutine address.Mechanism of subroutine calls and the
execution of the"Call"i"Ret"commands based on the use of the stack.Execute the
"Call"subroutine command including:
1. stored in the stack of the program counter's current content(ie,the return address
executes the next instruction after the call)with the"Push"operation,
2. write to the program that accesses the embedded address in the"Call"guide,
3. take the next tutorial according to the new content of the program counter.
The address written to the stack will be used by the"Ret"return command to
automatically return from the subroutine to the next command.
The return execution from the"Ret"subcommand includes:
1. Read from the top of the stack of the return address(to successfully instruct the"call"
command),
2. write this address to the program counter,
3. perform the"Pop"operation on the stack,
4. Fetchanew guide according to the new content of the program counter.
The address written to the stack in subroutine call is sometimes called trace and the
subroutine call is called shop with trace.Often use nested subroutine calls,in which
during subroutine execution,new subroutine is called from its body.The mechanism of
returning from trace subroutines stored in the stack allows to automatically return the
next program call context with the correct return order preserved.The figure below
shows actions related to nested subroutine calls fromatop program thread.In the
subroutine call1(Call 500 is stored at address 100),the return address 101 is stored in
the stack.In the call of subprogram2(Call 900 is written at address 600),the return
address 601 is saved in the stack.When returning from sub-program2,address 601 is
taken from the stack.When returning from subroutine1,address 101 is taken from the
stack.
ảnh
As show in the diagram,new activities are pushed on to the top of the stack when they
are started.The current active activity is located at the top of the stack until it is either
pushed down the stack by new activity,or popped off the stack when it exits or the user
navigates to the previous activity.In the event that resources become constrained,the
runtime will kill activities,starting with those at the bottom of the stack.The Activity
Stack is what is referred to in programming terminology asaLast- In- First-Out(LIFO)
stack in the last item to be pushed onto the stack is the first to be popped off.
How to stack operations on a website.
Applications have four tiers,three of which are on the server-side.This graphic explain the inner working
of stack.The client is where it all starts and ends.As you know website operation consists of stack of
clients,HTTPS servers,APP servers and Database servers.When The browser send request to the
website,those request will be processed into the Queue in RAM and will be processed for the server that
handles request both in Stack(LIFO)and Queue(FIFO)based on the type of the request.When the request is
successfully processed,it will be sent back to the client to display in browsers.