Dsa Ta 3-2
Dsa Ta 3-2
Dsa Ta 3-2
Part (b)
Solution:
Breadth-First Search (BFS) traversal also cannot guarantee finding a path that
visits every city once, using each road exactly once, and returning to the starting
point. Because BFS works on a distance based approach from starting point.
Part (c)
Solution:
Firstly the graph should be connected and secondly As Starting and Ending
position of graph is same so the degree of vertices in the graph should be all
even i.e there shouldn’t be any odd degree vertex in the graph
Part (d)
Solution:
We can use these steps for getting vertices in the path:
• If there is a valid adjacent vertex to the current one, we add it to the path
and proceed to the next step.
1
Name: Anitej Jain Roll Number: 220153
• If a valid path is not found, we repeat step 1 for other adjacent vertices
of the starting node.
To establish the validity of the next vertex (v), one of the following conditions
must be met:
2
Name: Anitej Jain Roll Number: 220153
Initialization: Create two arrays, ’distances’ and ’processed,’ each of size ’num-
Cities,’ to keep track of the minimum distances and processed cities. Initially,
set all values in the ’distances’ array to infinity and all values in the ’processed’
array to ’false.’ Set the Source Distance to Zero: Set the distance at the source
city ’S’ to 0. This means that the distance from ’S’ to itself is zero.
For Loop (Repeat for ’numCities - 1’ times): In each iteration of this loop,
you perform the following steps for each city: a. Find the unprocessed city ’u’
with the minimum distance in the ’distances’ array. b. Mark city ’u’ as pro-
cessed by setting ’processed[u]’ to ’true.’ For each neighboring city ’v’ of ’u’:
c. Check if ’v’ is unprocessed and if the power at ’u’ is sufficient to reach ’v.’
d. Calculate a potential new distance as the sum of the current distance at ’u’
and the distance between ’u’ and ’v.’ e. If the potential distance is less than
the current distance at ’v,’ update ’distances[v]’ with the potential distance.
This is done to find the shortest distance from ’S’ to all other cities. Check the
Distance to the Destination:
After the loop, check if the distance at the destination city ’D’ is less than
infinity. If it is less than infinity, it means that there exists a path from ’S’
to ’D’ with the available power, so return ’true’ (Power is sufficient to send a
signal from ’S’ to ’D’). If it is still infinity, it means there is no path from ’S’ to
’D’ with the available power, so return ’false’ (Power is not sufficient to send a
signal from ’S’ to ’D’).
Pseudocode
3
Name: Anitej Jain Roll Number: 220153
4
Name: Anitej Jain Roll Number: 220153
Part (b)
Solution Description
The algorithm uses binary search to efficiently determine the minimum power
needed. It repeatedly calls the ”Check If Signal Can Be Sent for All Powers”
algorithm with different power values, narrowing down the range of possible
power values required to establish a signal path.
Pseudocode
5
Name: Anitej Jain Roll Number: 220153
Initialization: The first step of the procedure is to initialize two arrays. The
first colors of every room are kept in the roomColors array, while modifications
to the room colors are monitored in the second array.
BuildTree: This function creates a tree structure to stand in for the rooms.
It employs a recursive method to give the tree’s nodes colors depending on the
specified room colors. A range of rooms are represented by each node in the
tree due to its construction(segment tree).
UpdateTree Function: When color bombs happen, this function updates the
tree structure. It modifies the range of several rooms in the tree. Before making
any more modifications, it applies any withstanding updates for that node. It
determines if the range that the current node represents and the range of rooms
that need to be updated overlap. It immediately assigns the new color and
marks the children for a pending update if the range is entirely enclosed. If not,
it updates the left and right children recursively.
Now using all these functions we perform all updates continously and stores
and output the roomColors array.
Pseudocode
6
Name: Anitej Jain Roll Number: 220153
Pseudocode
8
Name: Anitej Jain Roll Number: 220153
Pseudocode
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: