DATE: Page |1
University of Calcutta
Computer Science Honours
Graph Algorithm Using C
Semester: 4rd
Subject: CMSA
CU Roll No: 213111–21-0050
CU Registration No: 111-1111-0143-21
Paper Code: CC-8 Practical
INDEX
DATE: Page |2
SL.NO TOPIC PAGE DATE DATE
NO. WITH
FACULT
Y
1. program to Find Minimum Spanning 03 - 07
Tree using Prim’s Algorithm
2. program to Find Minimum Spanning 08 - 11
Tree using Kruskal's Algorithm
3. Program to Find Shortest Path 12 – 19
from Single Source using
Dijkstra’s Algorithm
4. Program to Implement Floyd- 20 - 23
Warshall Algorithm in C
5. Graph Traversal using Depth-First 24 – 26
Search (DFS) in C
6. Graph Traversal using Breadth- 27 – 30
First Search (BFS) in C
7. Find a valid graph coloring using 31 – 36
a given no. of colors by
backtracking
8. program to implement the 37 - 41
travelling salesman algorithm in
c
Q.1 write a php script to calculate the factorial of a given number using a function?
Code:
DATE: Page |3
<?php
function factorial($num) {
if ($num == 0 || $num == 1) {
return 1;
} else {
return $num * factorial($num - 1);
$number = 5; // Change this to the desired number
$result = factorial($number);
echo "Factorial of $number is $result";
?>
Output:
Q.2 build a php script that generates a random quote from an array and displays it?
Code:
<?php
$quotes = array(
"Quote 1",
"Quote 2",
"Quote 3"
);
$randomIndex = array_rand($quotes);
$randomQuote = $quotes[$randomIndex];
echo $randomQuote;
?>
Output:
DATE: Page |4
Q.3 write s php program that checks if a given string is a palindrome?
Input:
<?php
function isPalindrome($str) {
$str = strtolower(str_replace(' ', '', $str));
return $str === strrev($str);
$string = "racecar"; // Change this to the desired string
if (isPalindrome($string)) {
echo "$string is a palindrome";
} else {
echo "$string is not a palindrome";
?>
Output:
Q.4 write a php program to find the maximum and minimum values in an array of numbers?
Input:
<?php
function findMinMax($arr) {
$min = min($arr);
$max = max($arr);
return array("min" => $min, "max" => $max);
$numbers = array(5, 3, 8, 1, 10); // Replace with your array of numbers
DATE: Page |5
$result = findMinMax($numbers);
echo "Minimum: " . $result["min"] . "<br>";
echo "Maximum: " . $result["max"];
?>
Output: