Algorithms and Data
Structures in C
Individual Assignment
Student Name
Caleb Tee Yi Zhong
Student ID
TP035926
Module Name
Structures in C
Module Code
Algorithms and Data
CE00894-4-ADSC
Intake Code :
APT1F1506CYB
Lecture
DR. VAZEERUDEEN ABDUL HAMEED
Due Date
Table of Contents
17th March 2016
Individual Assignment
CE00894-4-ADSC
Introduction................................................................................................................ 3
Explanations............................................................................................................... 4
Part A....................................................................................................................... 4
Dijkshtras Algorithm............................................................................................ 4
Depth First Traversal............................................................................................ 6
Breadth First Traversal.......................................................................................... 8
Part B..................................................................................................................... 11
Data Structures.................................................................................................. 11
Output...................................................................................................................... 12
Conclusion................................................................................................................ 13
References................................................................................................................ 14
Caleb Tee Yi Zhong TP035926
Page 2 of 14
Individual Assignment
CE00894-4-ADSC
Introduction
C programming is defined as a structured, procedural programming language that has been
widely used both for operating systems and applications and that has had a wide following in the
academic community. (TechTarget, 2008)
In this documentation, it will cover all part A, part B and the output of the program.
Caleb Tee Yi Zhong TP035926
Page 3 of 14
Individual Assignment
CE00894-4-ADSC
Explanations
Part A
Dijkshtras Algorithm
50
50
60
130
100
100
100
100
Caleb Tee Yi Zhong TP035926
Page 4 of 14
Individual Assignment
CE00894-4-ADSC
Minimum cost of travel from E from the results of the algorithm
1. E F
6. E C
=EBF
=EBFC
= 60
= 70
2. E G
= 30
7.
ED
=EBFD
= 100
3. E H
=EBFCH
= 90
4. E A
=EGA
= 50
5. E B
= 50
Caleb Tee Yi Zhong TP035926
Page 5 of 14
Individual Assignment
CE00894-4-ADSC
Depth First Traversal
Starting vertex B
1.
A
G
D
C
F
B
2.D
C
F
B
G
D
C
F
B
5.
4.
C
F
B
C
F
B
7.
8.
F
B
H
C
F
B
3.
6.
9.
BFCDGAH
Caleb Tee Yi Zhong TP035926
Page 6 of 14
Individual Assignment
CE00894-4-ADSC
Figure 1 Cities
In Depth First Traversal, the starting is vertex B. In
No.1 B is first travel to F, C, D, G and A. In No.2, A is
then popped out and left B, F, C, D, G. Then in No.3 G
is popped out and left B, F, C, D. No.4, D is popped out and left B, F, C. In No.5 C is then travel
to H and now have B, F, C, H. In No.6 H is then popped out and left B, F, C. No. 7 C is popped
out and left B and F. No. 8 F is popped out and left B only. Then at the end No. 9 B is popped out
and left an empty stack. So, the sequence is BFCDGAH.
Breadth First Traversal
Caleb Tee Yi Zhong TP035926
Page 7 of 14
Individual Assignment
CE00894-4-ADSC
Starting vertex B
IN
OUT
1.
F
2.
F
W=B
3.
C
W=F
4.
W=D
5.
Caleb Tee Yi Zhong TP035926
Page 8 of 14
Individual Assignment
CE00894-4-ADSC
W=C
6.
A
H
W=G
7.
A
W=H
8.
W=A
BFDCGHA
Caleb Tee Yi Zhong TP035926
Figure 2 Cities
Page 9 of 14
Individual Assignment
CE00894-4-ADSC
In Breadth First Traversal, the starting vertex is B. In No. 1 B is first travel to F. Then in No. 2, B
is popped and left F. In No. 3, F is popped and then travel to C and D. In No. 4 D is popped and
then travel to G. Then in No.5, C is popped and travel to H. In No.6 G is popped and travel to A.
In No.7 H is popped. Finally, No. 8 A is popped and left and empty stack. So, the sequence is
BFDCGHA.
Part B
Data Structures
node = (struct item*)malloc(sizeof(struct item));
node->itemid = [Link];
Caleb Tee Yi Zhong TP035926
Page 10 of 14
Individual Assignment
CE00894-4-ADSC
node->next = NULL;
When pushing the item, this code creates a memory allocation to the item that is required to
push.
struct item pop(struct item *start, int *count)
{
int i;
struct item *temp;
struct item popped;
[Link] = -1;
[Link] = NULL;
In this code, the item is popped from the stacker. Where the item is unloaded from the stacker.
Output
Caleb Tee Yi Zhong TP035926
Figure 3 Initializing truck
Page 11 of 14
Individual Assignment
When
the
program
CE00894-4-ADSC
is
executed,
user
is
required
to
enter
the
truck
capacity.
Figure 4 Item ID
User is then required to enter the item id five times.
Figure 5 Load and unload from stacker
The item is then unloaded form the stacker.
Conclusion
Caleb Tee Yi Zhong TP035926
Page 12 of 14
Individual Assignment
CE00894-4-ADSC
C programming is a very useful language to develop a program. Throughout this assignment, I
have learned a lot about C programming and also algorithm structure in C. It is something that is
useful in our daily life.
Caleb Tee Yi Zhong TP035926
Page 13 of 14
Individual Assignment
CE00894-4-ADSC
References
TechTarget. (2008, April). Retrieved from
[Link]
Caleb Tee Yi Zhong TP035926
Page 14 of 14