Csd201 Pe Instructions Students Are ONLY Allowed To Use:: Not Submit The Un-Edited Given Project
Csd201 Pe Instructions Students Are ONLY Allowed To Use:: Not Submit The Un-Edited Given Project
Csd201 Pe Instructions Students Are ONLY Allowed To Use:: Not Submit The Un-Edited Given Project
void f1() – This method is used to test the addLast methode above. You do not need to edit
this function. Output in the file f1.txt must be the following:
(A,9) (C,7) (D,2) (E,6) (F,4)
void f2() – There is a given objects x. You should write statements so that x will be the
first element of the list. Output in the file f2.txt must be the following:
(C,9) (D,6) (E,8) (F,2) (I,6)
(X,1) (C,9) (D,6) (E,8) (F,2) (I,6)
void f3() – Suppose the list contains at least 3 elements. Delete the first node having
price=5. Output in the file f3.txt must be the following:
(C,9) (D,5) (E,3) (F,5) (I,6)
(C,9) (E,3) (F,5) (I,6)
void f4() – Sort the list ascendingly by price. Output in the file f4.txt must be the following:
(C,9) (D,6) (E,5) (F,13) (I,2) (J,1)
(J,1) (I,2) (E,5) (D,6) (C,9) (F,13)
Question 2: (4 marks)
In this question you should complete some methods in BSTree.java files.
The class Car with 2 data members: owner and price is given and you do not need to edit it. The
BSTree class is a binary search tree of Car objects. The variable price is the key of the tree. The
following methods should be completed:
void f1() – You do not need to edit this function. Your task is to complete the insert(...)
function above only. Output in the file f1.txt must be the following:
(A,5) (C,2) (E,4) (G,3) (D,6) (F,7)
(C,2) (G,3) (E,4) (A,5) (D,6) (F,7)
void f2() – Perform pre-order traversal from the root but display to file f2.txt nodes having
price in the interval [3,5] only. Hint: Copy the function preOrder(...) to preOrder2(...) and
modify it. Output in the file f2.txt must be the following:
(C,6) (D,2) (F,4) (H,3) (I,5) (E,8) (G,7)
(F,4) (H,3) (I,5)
void f3() – Perform breadth-first traversal from the root and delete by copying the first node
having both 2 sons and price < 7. Output in the file f3.txt must be the following:
(C,8) (D,6) (E,9) (F,2) (G,7) (H,1) (I,3) (J,5) (K,4)
(C,8) (J,5) (E,9) (F,2) (G,7) (H,1) (I,3) (K,4)
void f4() – Perform breadth-first traversal from the root and find the first node p having left
son and price < 7. Rotate p to right about its’ left son. Output in the file f4.txt must be the
following:
(C,8) (D,6) (E,9) (F,2) (G,7) (H,1) (I,3) (J,5) (K,4)
(C,8) (F,2) (E,9) (H,1) (D,6) (I,3) (G,7) (J,5) (K,4)
Question 3: (2 marks)
In this question you should complete some methods in Graph.java file.
The class Graph is the implementation of a graph. The following methods should be completed:
void f1() - Perfom depth-first traversal (to the file f1.xt) from the vertex i=1 (the vertex B)
but display vertices with their deegrees in bracket. Hint: copy depth(...) to depth2(...) and
modify the latter one. Content of the output file f1.txt must be:
BGAEFICHD
B(1) G(2) A(4) E(3) F(3) I(3) C(1) H(2) D(1)
void f2() – Apply the Dijkstra’s shortest path algorithm to find the shortest path from the
vertex 0 (A) to the vertex 4 (E). (Note that in the weighted matrix, the value 999 is
considered as infinity). Write 2 lines into the file f6.txt. The first line contains the list of
vertices in the shortest path. The second lines contains shortest distances to the vertices in
the first line. Content of the output file f2.txt must be:
A C F E
0 9 11 20
void f3() – Supposed the given graph has Euler's cycle. Apply the pseudocode in the
Graph.java file to write statements to find the Euler's cycle from the vertex 1 (B). Output in
the file f3.txt must be the following:
B D E D C B E G F A B