Project CIS 2203
Project CIS 2203
Project CIS 2203
Faculty:
Dr. Zoheir Ezziane
202110
1.1 Write the Algorithm that describes the process (use the correct keywords covered in
Week7).
1) Randomly choose element as pivot
2) Swap pivot with first element
3) Check if the next element < pivot
4) If false, check the next element
5) If true
6) Swap index 2 with element index 1
7) Check if the next element <pivot
8) If false, check the next element
9) then randomly choose another element as pivot
10) Swap pivot index 3 with first element index 2
11) Check if element < pivot
12) If false, Check next element
13) Now we have two partition
14) Repeat again for partitions
1.2 Write the algorithm as a code in Python and test your code using any input.
return alist
return pIndex
if __name__ == '__main__':
list = [2, 5, 6, 8, 3, 7, 5, 6, 20, 100, 85, -20]
print(quicksort(list, 0, len(list)-1))
1.1 Calculate the total number of steps required by the algorithm, and express it as a
function of n (f(n) ).
1.2 Determine the Time complexity of the algorithm using Big-O notation.
2. #import math to use the sqrt function
3. import math
# A function to print all prime factors of # a given number n
def primeFactors(n):
4. # Print the number of two's that divide n
5. while n % 2 == 0: print (2) n=n/2
6. # n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used, notice i is incremented by 2
for i in range(3,int(math.sqrt(n))+1,2):
7. # while i divides n , print i ad divide n
8. while n % i== 0:
9. print (i)
n=n/i
print (n)
#call the function
primeFactors(315)
Answer :-
The first while loop can run at most m times so that 2rn >= n. Therefor at
worst log2 n times.
O(√n log n)
Part 4 (CLO4): Structures
1. Use Graph coloring to solve one of the following problems
o Class scheduling.
HCT needs to schedule the following classes so that no classes can be at the same time
if they are being taught by the same teacher or they have common students.
CIS3003
CIS1103
CIS1203
CIS1303
CIS1403
CIS3303
CIS2403
CIS2303
CIS3403
You need to consider the following:
All 1000 level classes’ students have students in common.
All 2000 level classes’ students have students in common.
All 3000 level classes’ students have students in common.
CIS3003 and CIS 1403 are taught by Dr. Rashed.
CIS1103 and CIS2403 are taught by Dr. Salem.
CIS 1303 and CIS3403 are taught by Dr. Mohammad.
Use your knowledge in Graph coloring to solve this problem, create the schedule and
identify how many time slots will be needed to schedule the classes.
2. Construct a directed graph using an Adjacency matrix (use a matrix from the Appendix –
Part 4.2 as assigned by your teacher, each group must get a different matrix).
Adjacency Matrix 4
1, 0, 0, 0, 1, 0, 1, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 1, 0,
0, 1, 1, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 1, 0, 0, 0, 1,
0, 1, 0, 0, 0, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 1, 0, 0,
1, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 1, 0,
3. Analyze the following weighed graph, and find the shortest path between two vertices
(each group will be assigned a different vertices by their teacher).
Vertices X and J
(9,5 1 🗸 (1,7 5 🗸
) )
(9,8 2 🗸 (2,4 5 🗸
) )
(0,3 2 🗸 (6,1 6 X
) )
(5,6 4 🗸 (0,7 6 X
) )
(6,9 5 x (8,4 6 🗸
) )
(6,8 5 X (8,0 7
) )
(6,0 5 🗸 (4,3 8
) )
n-1 = 10-
(7,3 5 🗸 (2,3 9 1 =9
) )
total
cost = 35