100% found this document useful (1 vote)
74 views16 pages

Data Structures and Algorithms

The document provides an assignment brief for a unit on data structures and algorithms. It asks students to create a presentation examining a stack ADT and two sorting/pathfinding algorithms. It also asks for a report specifying an ADT stack using formal notation and discussing advantages of encapsulation/information hiding and imperative ADTs in object orientation. The document provides learning outcomes, assessment criteria, and an example stack algorithm to guide students' work.

Uploaded by

Anh Tuấn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
74 views16 pages

Data Structures and Algorithms

The document provides an assignment brief for a unit on data structures and algorithms. It asks students to create a presentation examining a stack ADT and two sorting/pathfinding algorithms. It also asks for a report specifying an ADT stack using formal notation and discussing advantages of encapsulation/information hiding and imperative ADTs in object orientation. The document provides learning outcomes, assessment criteria, and an example stack algorithm to guide students' work.

Uploaded by

Anh Tuấn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Data Structures and Algorithms

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 Student ID

Class Assessor name

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:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

IV Signature:
Assignment Brief 1 (RQF)
Higher National Certificate/Diploma in Business

Student Name/ID Number:


Unit Number and Title: Unit 19: Data Structures and Algorithms
Academic Year: 2021
Unit Assessor:
Assignment Title: Examine and specify ADT and DSA
Issue Date:
Submission Date:
Internal Verifier Name:
Date:

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.

Unit Learning Outcomes:

LO1 Examine abstract data types, concrete data structures and algorithms
LO2 Specify abstract data types and algorithms in a formal notation

Assignment Brief and Guidance:

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.

Learning Outcomes and Assessment Criteria (Assignment 1)

Pass Merit Distinction

LO1 Examine abstract data types, concrete data structures and


algorithms
D1 Analyse the operation,
P1 Create a design M1 Illustrate, with an example, a using illustrations, of two
specification for data structures concrete data structure for a First network shortest path
explaining the valid operations In First out (FIFO) queue. algorithms, providing an
that can be carried out on the M2 Compare the performance of example of each.
structures. two sorting algorithms.

P2 Determine the operations of


a memory stack and how it is
used to implement function
calls in a computer.

LO2 Specify abstract data types and algorithms in a formal notation

P3 Using an imperative M3 Examine the advantages of D2 Discuss the view that


definition, specify the encapsulation and information imperative ADTs are a basis
abstract data type for a hiding when using an ADT. for object orientation and,
software stack. with justification, state
whether you agree.
LO1 Examine abstract data types,concrete data structures and algorithms

P1 Createadesign specification for data structures explaining the valid operations that can be

carried out on the structures.

Stack Data Structure (Introduction and Program)


What is stack?

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

Peek or Top Returns the top element of the stack. begin


return stack[top]
end procedure

isEmpty Returns true if the stack is empty, else false. begin


if top < 1
return true
else
return false
end procedure

How to understand a stack practically?


There are many real-life examples of a stack. Consider the simple example of plates stacked over one
another in a canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has
been placed at the bottommost position remains in the stack for the longest period of time. So, it can be
simply seen to follow the LIFO/FILO order.
Time Complexities of operations on the stack:
push(), pop(), isEmpty() and peek() all take O(1) time. We do not run any loop in any of these operations.
Types of Stacks:
● Register Stack: This type of stack is also a memory element present in the memory unit and
can handle a small amount of data only. The height of the register stack is always limited as the
size of the register stack is very small compared to the memory.
● Memory Stack: This type of stack can handle a large amount of memory data. The height of
the memory stack is flexible as it occupies a large amount of memory data.

Implementation:
There are two ways to implement a stack:
● Using array
● Using linked list

FOR EXAMPLE : Using Array

/* Java program to implement basic stack


operations */
class Stack {
static final int MAX = 1000;
int top;
int a[] = new int[MAX]; // Maximum size of Stack

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.

●How it is used to implement function calls in computer stack memory in computers


The stack memory is special kind of memory that is used to store information
temporarily,when we want to read the information correctly in the opposite direction to
the recorded memory,without caring about the organization data addressing.Stack
memory is sequential memory with specify access restrictions that allow writing and
reading information to or from only one location in this memory called the top of the
stack.The stack memory acts as queue where data can be written to the top of the stack,
while changing all the information stored in subsequent locations in location according
to the depth of the queue.this.Can only read from the stack from the top of the stack.
Reading makes information from the top of the stack removed and new information is
recorded in its place from the depth of the stack with the displacement of all information
stored in one position to the top.of stack.Then the queue is the last type to enter first.
The stack memory works in the same way as the rifle magazine,in which the introduction
of new bullet box pushes all the remaining cartridges into the depths of the magazine
and the use of cartridges(one shot)makes The top cartridge is removed and replaced with
the first cartridge under the used one.Three instructions are used to manipulate the stack
are push(write data into the stack),read stack(read the top of the stack),pop(delete data
from the top of the stack with shift of its contents up).Sometimes,symmetric operations
involve the top two positions of the stack used as arguments and positions for the results.
After pure operation,pop operation is performed and results are available 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.

LO2 Specify abstract data types and algorithms in formal notation


P3 Using an imperative definition,specify the abstract data type for software stack.
ADT for software stack:
.Specify the abstract data type for software stack
A Software stack is set of programs that work together to produce result,typically an
operating system and its applications.For example,a smartphone software stack
comprises the operating system along with the phone app,Web browser and other basic
applications.Asoftware stack may also refer to any group of applications that work in
sequence towards common result or any set of utilities or routines that work as a group.
See stack,application stack and protocol stack.In addition,to allow them to work
together,the required abstract data types such as Stack(LIFO)and Queue(FIFO).
So in order to better understand the software stack,we find out about stack operation on
Android device. For each application running on an Android device,the runtime system
will maintain an active Stack.When an application is executed,the application's first
operation is started to be placed on the stack.When Second operation is started,it is
placed on the top of the stack and the previous activity is pushed down.Operation at the
top of the recommended stack is active(or running).When the operation is exited,it is
turned off the stack by the running time and the operation is located just below it in the stack to become
the current activity.Operations at the top of the stack can,for example,
just exit because the stack it is responsible for has been completed.In addition,the user
may have selected the Back on screen button to return to the previous activity,causing
the current activity to be disconnected from the stack by the runtime system and
therefore destroyed.A Visual representation of the Android Activity Stack is illustrated in
Figure below:

ả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.

You might also like