0% found this document useful (0 votes)
124 views11 pages

CP40064E Algorithms and Data Type S2 FT 2020-2021 v1

This document outlines the coursework assignment for the Algorithms and Data Types module. It includes 6 sections assessing different algorithm topics: efficiency, recursion, stacks, queues, linked lists, and sorting. For each section, students must answer multiple choice and written questions. They are asked to implement algorithms like Fibonacci recursion, stack and queue operations, a linked list with various functions, and bubble sort on a list containing their student ID. Students must submit their work as a logbook in Word or PDF format, including any code and output. Extensions will only be granted in exceptional circumstances with evidence.

Uploaded by

Apurv Siingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views11 pages

CP40064E Algorithms and Data Type S2 FT 2020-2021 v1

This document outlines the coursework assignment for the Algorithms and Data Types module. It includes 6 sections assessing different algorithm topics: efficiency, recursion, stacks, queues, linked lists, and sorting. For each section, students must answer multiple choice and written questions. They are asked to implement algorithms like Fibonacci recursion, stack and queue operations, a linked list with various functions, and bubble sort on a list containing their student ID. Students must submit their work as a logbook in Word or PDF format, including any code and output. Extensions will only be granted in exceptional circumstances with evidence.

Uploaded by

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

University of West London

School of Computing and


Engineering

Title Coursework

Module Algorithms and Data Types

Module Code CP40064E

Module Leader: Sama Aleshaiker

Set by: Sama Aleshaiker

Moderated by: Massoud Zolgharni

Assignment: Coursework

Hand in Online submission via Blackboard


arrangements:
Element Type Weighting Due Date
1 Coursework 40% Friday 28th May 2021 23:59
Extensions will only be granted in exceptional circumstances. Documentary evidence will be
required. Extensions must be agreed before the deadline. A student who fails to submit
course work or dissertation by the applicable deadline shall be deemed to have failed to
submit to assessment.
Learning
1- Apply mathematical skills to approximate running time of programs by analysing and
outcomes:
interpreting algorithms
2- Design algorithms using iteration and recursion
3- Use and implement Lists, Stack and Queues
4- Understand and employ Trees and ADT

5- Describe and use a variety of searching and sorting algorithms

• For this coursework, you should create a logbook containing your answers to the questions below. You can find
a template for the logbook in the Assessments section of the module on Blackboard.
• Coursework should be all printed and submitted either word or PFD document. Photos or scanning to
hand written work is not accepted and will not be marked.
• Any screenshot of your code should include comment that state your student name and ID within the
code such as:

1
Section 1 – Algorithm Efficiency
Question 1.1
Assume that each of the expressions below gives the processing time T(n) spent by an algorithm for
solving a problem of input size n. Specify the dominant term having the steepest increase in n. What
is O() in each case? Give your answers by completing the table.

Expression Dominant term O()


5+ n3 + 0.25n
500n + 50n*log(n)
200 + n/2
n2 + 2n + 0.5n2 + 3n2
n + n1.5 + n0.5 + 20n
3n4 + n2 + 7n + 10

[6 marks]

Question 1.2
What is the time complexity of the following three algorithms? Express your answer in terms of Big-
O notation and justify your answer:

A)

[2 marks]

2
B)

[2 marks]

C)

[2 marks]

3
Section 2 – Recursion

Question 1.2
For the following recursive function, complete the recursion trace on the diagram below.

return
?
sum(5) return
?
sum(4)
return
sum(3) ?
return
sum(2) ?
return
sum(1) ?
return
sum(0) ?

[6 marks]

Question 2.2
Write a Python function that returns the nth Fibonacci number, where n is an integer passed as a
parameter to the function.

[7 marks]

4
Section 3 – Stacks
Question 3.1

For the following Stack operations, complete the table below to show the contents of the stack after
each function call, and value returned – write ‘none’ if no value is returned by the function.

Operation Return value Stack contents


(Top of stack shown on the
right)
s = Stack() none []
s.push(15) none [15]
s.size()
s.pop()
s.isEmpty()
s.push(10)
s.push(7)
s.push(3)
s.isEmpty()
s.peek()
s.push(4)
s.push(2)
s.push(16)
s.pop()
s.size()
s.pop()
s.isEmpty()
s.pop()

[6 marks]

Question 3.2
Evaluate the following postfix expressions, giving your answer as a single number:
a) 5 4 * 9 +
b) 8 3 7 * + 4 –
c) 16 12 + 4 * 2 /

[6 marks]

Question 3.3
Convert the following infix expressions to postfix:
a) 9 + 2 * 20 – 4
b) 4 + 5 * 7 / 3
c) (20 – 8) * (42 – 16) / (21 + 6)

[6 marks]

5
Section 4 – Queues
Question 4.1
Complete the following table to show the return value and contents of the queue after each function
call in the sequence, assuming the queue is initially empty. You can assume the code for the queue is
as shown below.

Operation Return value Queue contents (front of


queue shown on right)
q = Queue() none []
q.enqueue(2) none [2]
q.enqueue(4)
q.enqueue(6)
q.dequeue()
q.enqueue(5)
q.peek()
q.size()
q.dequeue()
q.dequeue()
q.is_empty()
q.enqueue(7)
q.enqueue(10)
q.size()
q.dequeue()
q.dequeue()
q.peek()
q.dequeue()
q.is_empty()
q.enqueue(12)

[7 marks]

6
Question 4.2
What is the output of the following code, assuming the queue is initially empty? You can assume the
code for the queue is as shown in Question 4.1.

[5 marks]

7
Section 5 – Linked Lists
Question 5.1
Write a Python program that creates an unordered, singly-linked list consisting of 8 items. Each item
in the linked list should be a number. You can use the code given in the lecture slides for your Node
and UnorderedList classes.
Your node class should contain the following functions:
• a constructor
• get_data() – returns the data in the node
• get_next() – returns the next node in the list
• set_data() – sets the data in the node to the value given as a parameter
• set_next() – sets the node that this node links to, to the node given as a parameter

Your UnorderedList class should contain the following functions:


• a constructor
• add() – adds a node to the head of the list, containing the number given in the parameter
• is_empty() – returns True if the list is empty, and False otherwise
• size() – returns the size of the list
• print_list() – displays the contents of all nodes in the list

Add code to create an UnorderedList object, and call its add() function to add 8 items to the list. Call
the is_empty(), size() and print_list() functions to show that they work. In your logbook, show your
code and the output when you run the code.
The 8 numbers you will add them to the list should be your student ID.
Example output:

[8 marks]

Question 5.2
Add a function called search() to your UnorderedList class in Question 5.1. This function should take
a number as a parameter and return True if the number is contained in the linked list, or False if the
number is not in the list.

Add code to your program to allow the user to enter a number, and search for the number in your
linked list. Display a message to the user indicating if the number they entered was found in the list
or not. In your logbook, include your code, and also output that shows you have tested the search
function for a number in the list and a number not in the list.

Example output:

[7 marks]

8
Section 6 – Sorting
Question 6.1

Bubble sort: use your student ID as list of integers to be sorted by a bubble sort algorithm. Show the
contents of the list for each stage of each pass through the list.
The list should be your 8-digit student ID.
Example: If your student ID is 21234567 then your list will be
[2, 1, 2, 3, 4, 5, 6, 7]

[5 marks]

Question 6.2
Selection sort: use your student ID as list of integers to be sorted by a selection sort algorithm. Show
the contents of the list after each pass through the list.
The list should be your 8-digit student ID.
Example: If your student ID is 21234567 then your list will be
[2, 1, 2, 3, 4, 5, 6, 7]
[5 marks]

Question 6.3
Insertion sort: use your student ID as list of integers to be sorted by a insertion sort algorithm. Show
the contents of the list after each pass through the list.
The list should be your 8-digit student ID.
Example: If your student ID is 21234567 then your list will be
[2, 1, 2, 3, 4, 5, 6, 7]

[5 marks]

9
Section 7 – Searching
Question 7.1
Create a binary search tree by adding your student ID values in order:
Example: If your student ID is 21234567 then you will add the values in the order given
2, 1, 2, 3, 4, 5, 6, 7

[5 marks]

Question 7.2

The following diagram shows a binary tree with the root node containing the value 8. Write the pre-
order, in-order and post-order traversals of the binary tree shown in the diagram.

[10 marks]

[Total 100 marks]

10
Marking Criteria

Weak / 0% – 39% Sufficient / 40% - 69% G Good / 70% - 100%

1.1
1 mark for each correct answer
6 marks
1.2 1 mark for given correct Big O 2 marks for correct Big O notation
6 mark wrong answer
notation and justifying the answer
2.1 Complete diagram given with
6 marks Minimum given Partially given answer
correct values
2.2 Fully implemented function with
7 marks Incorrect function Partially implemented code
screenshots of the output
3:1 Some parts are Partially correct answer been Table been given with correct
6 marks relevant given Return Value and Stack content
3:2
6 marks 2 marks for each correct answer

3:3
6 marks 2 marks for each correct answer

4.1
7 marks Incorrect answer Partially correct answer Correct answer

4.2
5 marks Incorrect answer Partially correct answer Correct answer

5.1 Fully implemented code with


8 marks Incorrect output Partially implemented code
screenshots of the output
5.2 Fully implemented code with
7 marks Incorrect output Partially implemented code
screenshots of the output
6.1 Partially correct sorting Correct sorting algorithm
5 marks Incorrect sorting
algorithm step by step
6.2 Partially correct sorting Correct sorting algorithm
5 marks Incorrect sorting
algorithm step by step
6.3 Partially correct sorting Correct sorting algorithm
5 marks Incorrect sorting
algorithm step by step
7.1 Incorrect binary Partially correct binary search Correct binary search tree has been
5 marks search tree tree has been given given
7.2 Incorrect pre‐order, Partially correct Incorrect pre‐ Correct Incorrect pre‐order, in‐order
10 marks in‐order and post‐ order, in‐order and post‐order and post‐order traversals of the
order traversals of traversals of the binary tree binary tree has been given.
the binary tree. has been given.

11

You might also like