You are on page 1of 3

The University of Fiji

School of Science and Technology


Department of Information Technology and Computer
Science

ITC215 Data Structures and Algorithms Semester I, 2023

Lab Assessment 2

Due Date: 22 April, 2023 before 12 am midnight

Instructions: Please carefully read the Question and code a suitable solution in Eclipse. This
is a closed book examination so no use of internet or any other material. You can only open
eclipse in your computer.

Referencing: Please reference any work cited. Use Harvard Referencing Style. Remember
that Plagiarism will lead to disciplinary action under the University of Fiji Regulation
“Plagiarism and Dishonest Practice”.

Marking Criteria: Marks will be allocated for preciseness of output and correctness of
syntax. In addition, the quality and the authenticity of explanations will be considered.

Submission: The solutions of each question much be correctly labelled and uploaded with a
brief description of the code used to implement the solutions. Students will need to upload
the answers in a word file in the given Turnitin Submission box on Moodle.

Weight: 10%

QUESTION 1

Create a python program that takes in an array (a) and returns True if all elements in the array
are unique. The program should return False if the array contains duplicate elements and it
should also list the values which are duplicates.

You should test your program with he following applications:


a = [1 , 20, 30, 44, 55 , 19, 16, 78, 45, 16, 87, 98, 71, 14, 21, 32, 66, 83, 85, 91, 22, 11]
Expected output
Are the values in the array unique? False
Which calues are duplicates? 16

a = [1 , 20, 30, 14, 55 , 19, 16, 78, 45, 16, 87, 98, 71, 14, 21, 32, 66, 83, 85, 91, 22, 11]
Expected output
Are the values in the array unique? False
Which calues are duplicates? 16, 14
def check_duplicates(a):
return len(set(a)) == len(a), [x for x in set(a) if a.count(x) > 1]

# Test the function with the given array


a = [1, 20, 30, 44, 55, 19, 16, 78, 45, 16, 87, 98, 71, 14, 21, 32, 66, 83, 85, 91, 22, 11]
are_unique, duplicates = check_duplicates(a)
if are_unique:
print("The values in the array are unique.")
else:
print("The values in the array are not unique.")
print("The following values are duplicates:", duplicates)
a = [1 , 20, 30, 44, 55 , 19, 16, 78, 45, 17, 87, 98, 71, 14, 21, 32, 66, 83, 85, 91, 22, 11]
Expected output
Are the values in the array unique? True

QUESTION 2

Create a python program that checks whether two(2) lists a and b are premutations of each
other. For example if a[1,2,3] and b[3,2,1] are premutations of each other as both have the
same values in the array.

You should test your program with he following applications:


a = [1, 2, 3]
b = [3, 2, 1]
Expected output
True

a = [1, 2, 3]
b = [3, 1, 2]
Expected output
True

a = [1, 2, 3]
b = [3, 2, 4]
Expected output
False

a = [‘a’, ‘b’, ‘c’]


b = [‘c’, ‘a’, ‘b’]
Expected output
True

a = [‘a’, ‘b’, ‘c’]


b = [‘c’, ‘a’, ‘d’]
Expected output
False

QUESTION 3

Create a python program than rotates a N X N matrix by 90 degrees. An example of the


rotation of a 3 x 3 matrix is shown below:

1 2 3 90 degrees 7 4 1
4 5 6 8 5 2
rotation
7 8 9 9 6 3

You should test your program with he following applications:


[[1 2 3]
[4 5 6]
[7 8 9]]
Expected output
[[7 4 1]
[8 5 2]
[9 6 3]]

Good Luck

You might also like