You are on page 1of 6

lOMoARcPSD|4755966

Sample/practice exam 1 January 2016, questions and


answers
Introduction to Algorithm and Python (Monash University)

StuDocu is not sponsored or endorsed by any college or university


Downloaded by Alan Kafaei (kafaeialireza@gmail.com)
lOMoARcPSD|4755966

Monash University

Sample Mid Semester Test

SOLUTIONS

Faculty of Information Technology

TEST CODE! ! ! FIT1045

TITLE OF PAPER! ! Introduction to Algorithms and Programming

TEST DURATION! ! 45 minutes

READING TIME!! ! 5 minutes

STUDENT ID _________________

During the test, you must not have in your possession, a book, notes, paper, electronic device/s,
calculator, pencil case, mobile phone or other material/item which have not been authorised for the
test or specifically permitted as noted below. Any material or item on your desk, chair or person will
be deemed to be in your possession. You are reminded that possesion of unauthorised materials in
an exam is a discipline offense under Monash Statute 4.1

No test papers are to be removed from the room. Page Mark

2
AUTHORISED MATERIALS
3
CALCULATORS!! ! ! ! NO
4

OPEN BOOK! ! ! ! ! NO 5

6
SPECIFICALLY PERMITTED ITEMS! NO
Total

! !
Page 1 of 6
Downloaded by Alan Kafaei (kafaeialireza@gmail.com)
lOMoARcPSD|4755966

Question 1 [1 + 2 + 2 = 5 Marks]

(a) By marking vertices and edges, draw a spanning tree in the following graph

1 mark for a valid spanning tree

(b) Give a definition of an Eulerian circuit in a connected graph G.

An Eulerian circuit in G is a trail in G which starts and end at the same vertex and contains
every edge in G exactly once.

0.5 marks for stating it was a trail.


0.5 marks for stating that it starts and ends at the same vertex.
1 mark for stating it contains each edge once.

(c) Give two different ways of representing graphs

1 Mark for any of the following methods.

a) A list of vertices and a list of edges


b) A list of vertices and an adjacency matrix/table
c) An adjacency list
d) Incidence matrix/table

! !
Page 2 of 6
Downloaded by Alan Kafaei (kafaeialireza@gmail.com)
lOMoARcPSD|4755966

Question 2 [5 Marks]

Consider the following list of numbers:

10, 8, 2, 7, 6, 9

Using the Insertion Sort algorithm sort the list into increasing order. You should write the
list in the table below after each iteration of the main loop of this algorithm.

10 8 2 7 6 9

8 10 2 7 6 9

2 8 10 7 6 9

2 7 8 10 6 9

2 6 7 8 10 9

2 6 7 8 9 10

1 mark for each correct line.

! !
Page 3 of 6
Downloaded by Alan Kafaei (kafaeialireza@gmail.com)
lOMoARcPSD|4755966

Question 4 [6 marks]

A palindrome is a word which is spelt the same ways forwards as backwards. For
example, abba is a palindrome but abbbaba is not.

Write a Python program that given a string, aString, prints true if aString is a palindrome,
and false otherwise.

You can assume that aString has been given and you do not need to write code to read a
string from a file or ask a user to input a string.

n = len(aString)

result = True

if n > 1:
for k in range(n//2):
if aString[k] != aString[n-k-1]:
result = False

print(result)

1 mark for handling the special cases n= 0 and n= 1.


2 marks for looping through the characters.
1 mark for checking the equality of characters.
1 mark for returning false in the correct circumstances.
1 mark for returning true in correct circumstances.

! !

Page 5 of 6
Downloaded by Alan Kafaei (kafaeialireza@gmail.com)
lOMoARcPSD|4755966

Question 5 [2 + 2 = 4 marks]

For the following fragments of Python code, write what would be printed.

(a)

aList = [1, 2, 3, 4]
for k in range(len(aList)):
print(aList[len(aList)-k-1)])

4
3
2
1

2 marks for correct output

(b)

aStr = “Reverse“
for k in range(-1, -len(aStr), -1):
print(aStr[k])

e
s
r
e
v
e

2 marks for correct output

! Page 6!of 6

End of Test
Downloaded by Alan Kafaei (kafaeialireza@gmail.com)

You might also like