In graphs, a hyperedge is an edge that is allowed to take on any number of _____
What is the time complexity of Depth-First Search (DFS) algorithm? (V = number of vertices, E = number of edges)
What is the time complexity of the Floyd–Warshall algorithm to calculate all pair shortest paths in a graph with n vertices?
Which of the following is not an application of Breadth-First Search (BFS)?
Which of the following statements about Huffman Coding is true?
Given a directed graph where the weight of every edge is the same, which algorithm can be used to efficiently find the shortest path from a given source to destination?
Which of the following statement(s) is/are correct regarding the Bellman-Ford shortest path algorithm?
P: The Bellman-Ford algorithm can detect negative weighted cycles if they exist.
Q: The Bellman-Ford algorithm can determine whether any negative weighted cycle is reachable from the source.
What does the following code do?
for (int i = 0; i < arr.length-1; i++)
{
for (int j = i+1; j < arr.length; j++)
{
if( (arr[i].equals(arr[j])) && (i != j) )
{
System.out.println(arr[i]);
}
}
}
Fill in the blank to complete the code.
#include<stdio.h>
int main()
{
int coins[10]={1,3,4},lookup[100000];
int i,j,tmp,num_coins = 3,sum=100;
lookup[0]=0;
for(i = 1; i <= sum; i++)
{
int min_coins = i;
for(j = 0;j < num_coins; j++)
{
tmp = i - coins[j];
if(tmp < 0)
continue;
if(lookup[tmp] < min_coins)
min_coins = lookup[tmp];
}
lookup[i] = min_coins + 1;
}
printf("%d",lookup[sum]);
return 0;
}
Complete the following code for Kadane's algorithm:
#include<stdio.h>
int max_num(int a, int b)
{
if(a > b)
return a;
return b;
}
int kadane_algo(int *arr, int len)
{
int ans, sum, idx;
ans =0;
sum =0;
for(idx =0; idx < len; idx++)
{
sum = max_num(0,sum + arr[idx]);
ans = max_num(sum, ans);
}
return ans;
}
int main()
{
int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3},len=7;
int ans = kadane_algo(arr,len);
printf("%d",ans);
return 0;
}