0% found this document useful (0 votes)
62 views14 pages

Fa CSC508

The document contains the final exam answers for a student named Muhammad Isfahan Bin Mat Samadi for their CSC508 class, including code snippets and explanations for questions about data structures, algorithms, trees, and graphs. Sample outputs and step-by-step workings are provided for problems involving stacks, queues, linked lists, and finding minimum spanning trees.

Uploaded by

Muhammad Isfahan
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)
62 views14 pages

Fa CSC508

The document contains the final exam answers for a student named Muhammad Isfahan Bin Mat Samadi for their CSC508 class, including code snippets and explanations for questions about data structures, algorithms, trees, and graphs. Sample outputs and step-by-step workings are provided for problems involving stacks, queues, linked lists, and finding minimum spanning trees.

Uploaded by

Muhammad Isfahan
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/ 14

FINAL CSC508

NAME : MUHAMMAD ISFAHAN BIN MAT SAMADI


MATRIX NO : 2021156137
PHONE NUM : 013-2067096
GROUP : M3CS2304C
CAMPUS : JASIN
LECTURER NAME : MADAM NURAZIAN BINTI DAHLAN

QUESTION 1
a)
Coordinator obj = (Coordinator)coordinatorLL.getFirst();

while (obj != null) {

if ( obj.getFacultyName.equalsIgnoreCase(“Faculty of Mechanical Engineering”) ) {

System.out.println (“NAME :” +obj.getCoordinatorName() );

System.out.println (“\n PROGRAM NAME :” +obj.getProgramName() );

System.out.println (“\n PHONE NUMBER :” + obj.getPhoneNumber() );

obj = coordinatorLL.getNext();

b)
LinkedList <Coordinator> civilEngineeringLL = new LinkedList<Coordinator> ();

LinkedList <Coordinator> temp = new LinkedList<Coordinator> ();

Coordinator obj2 = (Coordinator) coordinatorLL.getFirst();

while (obj2 != null) {

if ( obj2.getFacultyName.equalsIgnoreCase(“Faculty of Civil Engineering”) ) {

civilEngineeringLL.insertAtBack(obj2);

coordinatorLL.removeFromFront();

temp.insertAtBack(obj2);
obj2 = coordinatorLL.getNext();

c)
Queue shortSleeveQ = new Queue();

Queue shortPantsQ = new Queue();

double totPrice = 0;

Queue temp = new Queue();

while( !prodQueue.isEmpty() ) {

Product obj = (Product) prodQueue.dequeue();

temp.enqueue(obj);

totPricel += obj.getPrice();

if ( obj.getType().equals(“shortSleeve”) ) {

shortSleeveQ.enqueue(obj);

else if ( obj.getType().equals(“shortSleeve”) ) {

shortPantsQ.enqueue(obj);

while ( !temp.isEmpty() ) {

prodQueue.enqueue(temp.dequeue() );

double totPriceSleeve = 0;

double totPricePant = 0;

while ( !shortSleeveQ.isEmpty() ){

Product obj2 = (Product) shortSleeveQ.dequeue();

temp.enqueue(obj2);

totPriceSleeve + = obj2.getPrice();

while ( !temp.isEmpty() ){
shortSleeveQ.enqueue(temp.dequeue() );

while ( ! shortPantsQ.isEmpty() ){

Product obj3 = (Product) shortPantsQ.dequeue();

temp.enqueue(obj3);

totPricePlant + = obj3.getPrice();

while ( !temp.isEmpty() ){

shortPantsQ.enqueue(temp.dequeue() );

System.out.println ( “Total price for prodQueue : RM” +totPricel );

System.out.println ( “Total price for shortSleeveQ: RM” +totPriceSleeve);

System.out.println ( “Total price for shortPantsQ: RM” + totPricePlant );


QUESTION 2

a)

4
5 6 6 10
2 40 40 8 3 3 3 3 13
Stack 22 22 11 11 11 11 88 88 88 88 88 88 75
Postfix 22 2 / 40 5 / * 3 6 4 + + -

Answer : 75

b)
Stack = 1
4
7
1

Output : The Mystery output is = 1 4 7 1

The function is to change decimal number to octal

c)

foo (14,7) + 14
foo (7,6) + 7
foo (1,5) + 1
5

5+ 1 = 6
6 + 7 = 13
13 + 14 = 27
QUESTION 3

a)
void postOrder(Node t)
{
if (t != null )
{
postOrder(node.left );
postOrder(node.right );
System.out.print(node.key + “ “);
}
else
return;
}
class Node {
int key;
Node left, right;

public Node(int item)


{
key = item;
left = right = null;
}
}
b) Answer = S, R, A, M , T , E ,O , M , I , S , P , O, H

C)

FY76

FY76

DD87

FY76

DD87

EU88
EU88

FY76
DD87
EU88

DD87 FY76

RD77

EU88

DD87 FY76

RD77

QA32
EU88

DD87 QA32

FY76 RD77

EU88

DD87 QA32

BL56 FY76
RD77
EU88

DD87 QA32

BL56
FY76 RD77

AA12

EU88

BL56 QA32

AA12 DD87 FY76 RD77


QUESTION 4
a)

b)
38 27 43 3 9 82 10

38 27 43 3 9 82 10

38 27 43 3 9 82 10

38 27 43 3
82 10

38 27 43 3 82 10

43 38 27 3 82 10 9

82 43 38 27 10 9 3
c)
0 140
1 169
2
3 75 143
4
5 285
6 48 190
7
8
9 177
10 66 122
11
12
13
QUESTION 5

a)
From (1)

1 2 3 4 5 6 7
SW 0 2 - 1 - - -
FW T F F F F F F

1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T F F T F F F

1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T T F T F F F

1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T T T T F F F

1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T T T T T F F

1 2 3 4 5 6 7
SW 0 2 3 1 3 6 5
FW T T T T T F T

1 2 3 4 5 6 7
SW 0 2 3 1 3 6 5
FW T T T T T T T
b)
visited = {}
visited = {(c,b)}
visited = {(c,b) , (c,d) }
visited = {(c,b),(c,d),(d,e)}
visited = {(c,b),(c,d),(d,e),(b,f)}
visited = {(c,b),(c,d),(d,e),(b,f),(e,a)}

minimum spanning tree = 1 + 2 + 3 + 5 + 9


= 20

You might also like