0% found this document useful (0 votes)
15 views2 pages

Assignment 10

This is CS assignment in IIT

Uploaded by

Vireshwar Singh
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)
15 views2 pages

Assignment 10

This is CS assignment in IIT

Uploaded by

Vireshwar Singh
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/ 2

CS29003 Algorithms Laboratory

Assignment 10: Shortest Path

General instruction to be followed strictly


1. Do not use any global or static variable unless you are explicitly instructed so.

2. Do not use Standard Template Library (STL) of C++.

3. Use proper indentation in your code and comment.

4. Name your file as <roll_no>_<assignment_no>. For example, if your roll number is


14CS10001 and you are submitting assignment 3, then name your file as 14CS10001_3.c
or 14CS10001_3.cpp as applicable.

5. Write your name, roll number, and assignment number at the beginning of your program.

6. Make your program as efficient as possible. Follow best practices of programming.

7. Submit your program on Moodle before deadline. Submissions by email or any other means will
NOT be considered for evaluation.

You are free to use any code from Internet/book/friend for part I of today’s assignment. Stan-
dard penalty of plagiarism does not apply for part I. However, you must write the other parts
without any external help. Hence, needless to say that standard penalty for plagiarism applies
there. In this assignment, assume all weights are positive integers only. However, you are free to use
float/double variables if you want.

Part I
Write a function which implements the Dijkstra’s algorithm for the single-source shortest path problem
for directed graphs.

Part II
Consider an undirected graph with both vertex and edge weights. In this graph, the cost of a path is the
sum of the weights of the edges plus the product of the weights of the vertices in the path. For example,
P Qk
the cost of a path x0 , x1 , . . . , xk is k−1
i=0 w(xi , xi+1 ) +
0
i=0 w (xi ). Use your function from part I to find
a single-source shortest path lengths in this undirected graph.
Submit one single C/C++ code.

Sample Output
Write the number of vertices in the undirected graph: 5
Write -1 to indicate the end of neighbors
Write neighbors of vertex 1: 2 5 -1

1
Write neighbors of vertex 2: 1 3 4 5 -1
Write neighbors of vertex 3: 2 4 5 -1
Write neighbors of vertex 4: 2 3 -1
Write neighbors of vertex 5: 1 2 3 -1
Weight of the edge {1,2}: 6
Weight of the edge {1,5}: 2
Weight of the edge {2,3}: 5
Weight of the edge {2,4}: 9
Weight of the edge {2,5}: 3
Weight of the edge {3,4}: 2
Weight of the edge {3,5}: 6
Weight of the vertex 1: 1
Weight of the vertex 2: 2
Weight of the vertex 3: 3
Weight of the vertex 4: 1
Weight of the vertex 5: 2
Write source vertex: 1
Distance of vertex 2 from vertex 1: 8
Distance of vertex 3 from vertex 1: 14
Distance of vertex 4 from vertex 1: 17
Distance of vertex 5 from vertex 1: 4

You might also like