0% found this document useful (0 votes)
14 views

CS221 Module Week1

Spinning Tree (Discrete Structure)

Uploaded by

danielatparoni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

CS221 Module Week1

Spinning Tree (Discrete Structure)

Uploaded by

danielatparoni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

CATANDUANES STATE UNIVERSITY

College of Information and Communications Technologies

CS221
DISCRETE STRUCTURES 2

MARIE STELLA GERODIAS


INSTRUCTOR I
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

SPANNING TREE

What is a Spanning Tree?

A spanning tree is a subset of Graph G, such that all the vertices are connected using minimum possible number of edges. Hence, a
spanning tree does not have cycles and a graph may have more than one spanning tree.

Properties of a Spanning Tree:

• A Spanning tree does not exist for a disconnected graph.


• For a connected graph having N vertices then the number of edges in the spanning tree for that graph will be N-1.
• A Spanning tree does not have any cycle.
• We can construct a spanning tree for a complete graph by removing E-N+1 edges, where E is the number of Edges and N is
the number of vertices.
• Cayley's Formula: It states that the number of spanning trees in a complete graph with N vertices is N^{N-2}
o For example: N=4, then maximum number of spanning tree possible =4^{4-2} = 16 (shown in the above image).

Real World Applications of A Spanning Tree:

• Several path finding algorithms, such as Dijkstra's algorithm and A* search algorithm, internally build a spanning tree as an
intermediate step.
• Building Telecommunication Network.
• Image Segmentation to break an image into distinguishable components.
• Computer Network Routing Protocol
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Minimum Spanning Tree(MST):

The weight of a spanning tree is determined by the sum of weight of all the edge involved in it.
A minimum spanning tree (MST) is defined as a spanning tree that has the minimum weight among all the possible spanning trees.

Properties of Minimum Spanning Tree:

• A minimum spanning tree connects all the vertices in the graph, ensuring that there is a path between any pair of nodes.
• An MST is acyclic, meaning it contains no cycles. This property ensures that it remains a tree and not a graph with loops.
• An MST with V vertices (where V is the number of vertices in the original graph) will have exactly V - 1 edges, where V is
the number of vertices.
• An MST is optimal for minimizing the total edge weight, but it may not necessarily be unique.
• The cut property states that if you take any cut (a partition of the vertices into two sets) in the original graph and consider
the minimum-weight edge that crosses the cut, that edge is part of the MST.

Minimum Spanning Tree of a Graph may not be Unique:

Like a spanning tree, there can also be many possible MSTs for a graph as shown in the below image:

Algorithms to Find Minimum Spanning Tree of a Graph:


There are several algorithms to find the minimum spanning tree from a given graph, some of them are listed below:
1. Krushkal's MST Algorithm
2. Prim's MST Algorithm
3. Boruvka's Algorithm
4. Reverse-Delete Algorithm
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Let us discuss these algorithms one by one.

1. Krushkal's Minimum Spanning Tree:

Kruskal's Minimum Spanning Tree (MST) algorithm is to connect all the vertices of a graph with the minimum total edge weight while
avoiding cycles. This algorithm employs a greedy approach, meaning it makes locally optimal choices at each step to achieve a
globally optimal solution.

Algorithm:
• First, it sorts all the edges of the graph by their weights,
• Then starts the iterations of finding the spanning tree.
• At each iteration, the algorithm adds the next lowest-weight edge one by one, such that the edges picked until now does
not form a cycle.

This algorithm can be implemented efficiently using a DSU ( Disjoint-Set ) data structure to keep track of the connected components
of the graph. This is used in a variety of practical applications such as network design, clustering, and data analysis.

2. Prim's Minimum Spanning Tree:

Minimum Spanning Tree (MST) is to build the MST incrementally by starting with a single vertex and gradually extending the tree by
adding the closest neighbouring vertex at each step.

Algorithm:
• It starts by selecting an arbitrary vertex and then adding it to the MST.
• Then, it repeatedly checks for the minimum edge weight that connects one vertex of MST to another vertex that is not yet
in the MST.
• This process is continued until all the vertices are included in the MST.
To efficiently select the minimum weight edge for each iteration, this algorithm uses priority_queue to store the vertices sorted by
their minimum edge weight currently. It also simultaneously keeps track of the MST using an array or other data structure suitable
considering the data type it is storing.
This algorithm can be used in various scenarios such as image segmentation based on color, texture, or other features. For Routing,
as in finding the shortest path between two points for a delivery truck to follow.

3. Boruvka's Algorithm:

This is also a graph traversal algorithm used to find the minimum spanning tree of a connected, undirected graph. This is one of the
oldest algorithms. The algorithm works by iteratively building the minimum spanning tree, starting with each vertex in the graph as
its own tree. In each iteration, the algorithm finds the cheapest edge that connects a tree to another tree, and adds that edge to the
minimum spanning tree. This is almost similar to the Prim’s algorithm for finding the minimum spanning tree.

Algorithm:
Learn more
• Initialize a forest of trees, with each vertex in the graph as its own tree.
• For each tree in the forest:
o Find the cheapest edge that connects it to another tree. Add these edges to the minimum spanning tree.
o Update the forest by merging the trees connected by the added edges.
• Repeat the above steps until the forest contains only one tree, which is the minimum spanning tree.
The algorithm can be implemented using a data structure such as a priority queue to efficiently find the cheapest edge between
trees. Boruvka’s algorithm is a simple and easy-to-implement algorithm for finding minimum spanning trees, but it may not be as
efficient as other algorithms for large graphs with many edges.

4. Reverse-Delete Algorithm:

Reverse Delete algorithm is closely related to Kruskal’s algorithm. In Kruskal’s algorithm what we do is : Sort edges by increasing
order of their weights. After sorting, we one by one pick edges in increasing order. We include current picked edge if by including this
in spanning tree not form any cycle until there are V-1 edges in spanning tree, where V = number of vertices.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

In Reverse Delete algorithm, we sort all edges in decreasing order of their weights. After sorting, we one by one pick edges in
decreasing order. We include current picked edge if excluding current edge causes disconnection in current graph. The main idea is
delete edge if its deletion does not lead to disconnection of graph.

Algorithm:
1. Sort all edges of graph in non-increasing order of edge weights.
2. Initialize MST as original graph and remove extra edges using step 3.
3. Pick highest weight edge from remaining edges and check if deleting the edge disconnects the graph or not.
4. If disconnects, then we don’t delete the edge.
5. Else we delete the edge and continue.

Real World Application of A Minimum Spanning Tree:

• Network design: Spanning trees can be used in network design to find the minimum number of connections required to
connect all nodes. Minimum spanning trees, in particular, can help minimize the cost of the connections by selecting the
cheapest edges.

• Image processing: Spanning trees can be used in image processing to identify regions of similar intensity or color, which
can be useful for segmentation and classification tasks.

• Social network analysis: Spanning trees and minimum spanning trees can be used in social network analysis to identify
important connections and relationships among individuals or groups.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Quiz #1. Spanning Trees and Minimum Spanning Trees (MST)

True / False (5 items)


1. A spanning tree of a graph can have cycles.
o Answer: _____________
2. A minimum spanning tree (MST) always has a unique solution for a given graph.
o Answer: _____________
3. In a graph with N vertices, a spanning tree will always have N-1 edges.
o Answer: _____________
4. The number of spanning trees in a complete graph with N vertices is given by Cayley’s Formula: N^(N-2).
o Answer: _____________
5. A minimum spanning tree can be used to minimize the total cost of connecting a set of nodes in a network.
o Answer: _____________

Identification (5 items)
6. This type of tree connects all the vertices of a graph with the minimum number of edges and does not contain any cycles.
o Answer: _____________
7. This algorithm uses a greedy approach to find the minimum spanning tree by adding the edge with the smallest weight that
doesn’t form a cycle.
o Answer: _____________
8. In this algorithm, a spanning tree is built incrementally by starting with a single vertex and adding the closest neighboring
vertex at each step.
o Answer: _____________
9. This graph traversal algorithm works by iteratively finding the cheapest edge that connects two trees in a forest.
o Answer: _____________
10. This algorithm sorts all the edges of a graph in decreasing order of their weights and removes edges if their deletion does
not disconnect the graph.
o Answer: _____________

Multiple Choice (10 items)


11. Which of the following is true about a spanning tree?
o A) It connects all vertices using the maximum number of edges.
o B) It can have cycles.
o C) It has exactly N−1N-1N−1 edges if the graph has NNN vertices.
o D) It is only possible in directed graphs.
o Answer: _____________
12. In a minimum spanning tree (MST), what is minimized?
o A) The number of edges in the tree.
o B) The total weight of all the edges in the tree.
o C) The number of vertices.
o D) The number of disconnected components.
o Answer: _____________
13. Which of the following algorithms is not used to find a minimum spanning tree (MST)?
o A) Kruskal's Algorithm
o B) Prim's Algorithm
o C) Dijkstra's Algorithm
o D) Boruvka's Algorithm
o Answer: _____________
14. The cut property of minimum spanning trees states that:
o A) The MST will always be unique.
o B) The MST connects the most distant vertices.
o C) Any cut of the graph has a minimum-weight edge crossing the cut, and that edge is part of the MST.
o D) The MST will always include the highest-weight edges.
o Answer: _____________
15. Which of the following is true about Kruskal's MST algorithm?
o A) It builds the tree incrementally by adding the closest neighboring vertex.
o B) It uses a priority queue to select the minimum-weight edge.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

o C) It selects the minimum-weight edges and adds them to the tree while avoiding cycles.
o D) It is not efficient for sparse graphs.
o Answer: _____________
16. Prim’s MST algorithm starts by:
o A) Sorting all the edges by their weight.
o B) Selecting a random vertex and adding it to the MST.
o C) Removing edges that would create cycles.
o D) Building the tree by selecting the highest-weight edges.
o Answer: _____________
17. What is a key feature of Boruvka’s Algorithm for finding MST?
o A) It starts with an empty tree and adds edges randomly.
o B) It builds the MST by selecting the cheapest edge connecting two trees in the forest.
o C) It always results in a unique MST.
o D) It uses dynamic programming for edge selection.
o Answer: _____________
18. Which of the following best describes the Reverse-Delete MST algorithm?
o A) It removes the highest-weight edges and checks if the graph remains connected.
o B) It sorts edges in ascending order and adds them to the MST.
o C) It builds the MST by gradually deleting edges.
o D) It always results in the same MST regardless of the graph structure.
o Answer: _____________
19. In a graph with multiple edges having the same weight, which of the following is true regarding MSTs?
o A) There is only one unique minimum spanning tree.
o B) There can be multiple minimum spanning trees.
o C) The MST will always be disconnected.
o D) The MST will always include the highest-weight edges.
o Answer: _____________
20. Which of the following is NOT a real-world application of a minimum spanning tree?
o A) Network design
o B) Image segmentation
o C) Social network analysis
o D) Finding the shortest path between two points
o Answer: _____________
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Euler and Hamiltonian Paths and Circuits

Learning Outcomes
• Determine whether a graph has an Euler path and/ or circuit
• Add edges to a graph to create an Euler circuit if one doesn’t exist
• Identify whether a graph has a Hamiltonian circuit or path
• Find the optimal Hamiltonian circuit for a graph using the brute force algorithm, the nearest neighbor algorithm, and the
sorted edges algorithm
• Identify a connected graph that is a spanning tree
• Use Kruskal’s algorithm to form a spanning tree, and a minimum cost spanning tree

Euler Circuits

Euler Path

An Euler path is a path that uses every edge in a graph with no repeats. Being a path, it does not have to return to the
starting vertex.

Example
In the graph shown below, there are several Euler paths. One such path is CABDCB. The path is shown in
arrows to the right, with the order of edges numbered.

Euler Circuit

An Euler circuit is a circuit that uses every edge in a graph with no repeats. Being a circuit, it must start and end at the same
vertex.

Example
The graph below has several possible Euler circuits. Here’s a couple, starting and ending at vertex A:
ADEACEFCBA and AECABCFEDA. The second is shown in arrows.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Look back at the example used for Euler paths—does that graph have an Euler circuit? A few tries will tell you no; that graph does
not have an Euler circuit. When we were working with shortest paths, we were interested in the optimal path. With Euler paths and
circuits, we’re primarily interested in whether an Euler path or circuit exists.

Why do we care if an Euler circuit exists? Think back to our housing development lawn inspector from the beginning of the chapter.
The lawn inspector is interested in walking as little as possible. The ideal situation would be a circuit that covers every street with no
repeats. That’s an Euler circuit! Luckily, Euler solved the question of whether or not an Euler path or circuit will exist.

Euler’s Path and Circuit Theorems

A graph will contain an Euler path if it contains at most two vertices of odd degree.
A graph will contain an Euler circuit if all vertices have even degree

Example

In the graph below, vertices A and C have degree 4, since there are 4 edges leading into each vertex. B is degree 2, D is
degree 3, and E is degree 1. This graph contains two vertices with odd degree (D and E) and three vertices with even degree
(A, B, and C), so Euler’s theorems tell us this graph has an Euler path, but not an Euler circuit.

Example

Is there an Euler circuit on the housing development lawn inspector graph we created earlier in the chapter? All the
highlighted vertices have odd degree. Since there are more than two vertices with odd degree, there are no Euler paths or
Euler circuits on this graph. Unfortunately, our lawn inspector will need to do some backtracking.

Example

When it snows in the same housing development, the snowplow has to plow both sides of every street. For simplicity, we’ll
assume the plow is out early enough that it can ignore traffic laws and drive down either side of the street in either
direction. This can be visualized in the graph by drawing two edges for each street, representing the two sides of the street.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Notice that every vertex in this graph has even degree, so this graph does have an Euler circuit.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Hamiltonian Circuits

Hamiltonian Circuits and Paths

A Hamiltonian circuit is a circuit that visits every vertex once with no repeats. Being a circuit, it must start and end at the same
vertex. A Hamiltonian path also visits every vertex once with no repeats, but does not have to start and end at the same vertex.
Hamiltonian circuits are named for William Rowan Hamilton who studied them in the 1800’s.

Example
One Hamiltonian circuit is shown on the graph below. There are several other Hamiltonian circuits possible on this graph.
Notice that the circuit only has to visit every vertex once; it does not need to use every edge.

This circuit could be notated by the sequence of vertices visited, starting and ending at the same vertex: ABFGCDHMLKJEA.
Notice that the same circuit could be written in reverse order, or starting and ending at a different vertex.

Unlike with Euler circuits, there is no nice theorem that allows us to instantly determine whether or not a Hamiltonian circuit exists
for all graphs.[1]

Example

Does a Hamiltonian path or circuit exist on the graph below?

We can see that once we travel to vertex E there is no way to leave without returning to C, so there is no possibility of a Hamiltonian
circuit. If we start at vertex E we can find several Hamiltonian paths, such as ECDAB and ECABD

With Hamiltonian circuits, our focus will not be on existence, but on the question of optimization; given a graph where the edges
have weights, can we find the optimal Hamiltonian circuit; the one with lowest total weight.

This problem is called the Traveling salesman problem (TSP) because the question can be framed like this: Suppose a salesman
needs to give sales pitches in four cities. He looks up the airfares between each city, and puts the costs in a graph. In what order
should he travel to visit each city once then return home with the lowest cost?

To answer this question of how to find the lowest cost Hamiltonian circuit, we will consider some possible approaches. The first
option that might come to mind is to just try all different possible circuits.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Question can be framed like this: Suppose a salesman needs to give sales pitches in four cities. He looks up the airfares between
each city, and puts the costs in a graph. In what order should he travel to visit each city once then return home with the lowest cost?
To answer this question of how to find the lowest cost Hamiltonian circuit, we will consider some possible approaches. The first
option that might come to mind is to just try all different possible circuits.

Brute Force Algorithm (a.k.a. exhaustive search)

1. List all possible Hamiltonian circuits


2. Find the length of each circuit by adding the edge weights
3. Select the circuit with minimal total weight.

Example
Apply the Brute force algorithm to find the minimum cost Hamiltonian circuit on the graph below.

To apply the Brute force algorithm, we list all possible Hamiltonian circuits and calculate their weight:
Circuit Weight

ABCDA 4+13+8+1 = 26

ABDCA 4+9+8+2 = 23

ACBDA 2+13+9+1 = 25
Note: These are the unique circuits on this graph. All other possible circuits are the reverse of the listed ones or start at a different
vertex, but result in the same weights.

From this we can see that the second circuit, ABDCA, is the optimal circuit.

The Brute force algorithm is optimal; it will always produce the Hamiltonian circuit with minimum weight. Is it efficient? To answer
that question, we need to consider how many Hamiltonian circuits a graph could have. For simplicity, let’s look at the worst-case
possibility, where every vertex is connected to every other vertex. This is called a complete graph.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Suppose we had a complete graph with five vertices like the air travel graph above. From Seattle there are four cities we can visit
first. From each of those, there are three choices. From each of those cities, there are two possible cities to visit next. There is then
only one choice for the last city before returning home.
This can be shown visually:

Counting the number of routes, we can see thereare 4⋅3⋅2⋅14⋅3⋅2⋅1 routes. For six cities there would be 5⋅4⋅3⋅2⋅15⋅4⋅3⋅2⋅1 routes.

Number of Possible Circuits

For N vertices in a complete graph, there will be (n−1)!=(n−1)(n−2)(n−3)…3⋅2⋅1(n−1)!=(n−1)(n−2)(n−3)…3⋅2⋅1 routes. Half of these
are duplicates in reverse order, so there are (n−1)!2(n−1)!2 unique circuits.
The exclamation symbol, !, is read “factorial” and is shorthand for the product shown.

Example
How many circuits would a complete graph with 8 vertices have?

A complete graph with 8 vertices would have = 5040 possible Hamiltonian circuits. Half of the circuits are duplicates of other circuits
but in reverse order, leaving 2520 unique routes.

While this is a lot, it doesn’t seem unreasonably huge. But consider what happens as the number of cities increase:
Cities Unique Hamiltonian Circuits

9 8!/2 = 20,160

10 9!/2 = 181,440

11 10!/2 = 1,814,400

15 14!/2 = 43,589,145,600

20 19!/2 = 60,822,550,204,416,000

As you can see the number of circuits is growing extremely quickly. If a computer looked at one billion circuits a second, it would still
take almost two years to examine all the possible circuits with only 20 cities! Certainly Brute Force is not an efficient algorithm.

Nearest Neighbor Algorithm (NNA)

1. Select a starting point.


2. Move to the nearest unvisited vertex (the edge with smallest weight).
3. Repeat until the circuit is complete.

Unfortunately, no one has yet found an efficient and optimal algorithm to solve the TSP, and it is very unlikely anyone ever will. Since
it is not practical to use brute force to solve the problem, we turn instead to heuristic algorithms; efficient algorithms that give
approximate solutions. In other words, heuristic algorithms are fast, but may or may not produce the optimal circuit.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Example

Consider our earlier graph, shown to the right.


Starting at vertex A, the nearest neighbor is vertex D with a weight of 1.
From D, the nearest neighbor is C, with a weight of 8.
From C, our only option is to move to vertex B, the only unvisited vertex, with a cost of 13.
From B we return to A with a weight of 4.

The resulting circuit is ADCBA with a total weight of 1+8+13+4=261+8+13+4=26.


Example
Consider again our salesman. Starting in Seattle, the nearest neighbor (cheapest flight) is to LA, at a cost of $70. From there:

LA to Chicago: $100
Chicago to Atlanta: $75
Atlanta to Dallas: $85
Dallas to Seattle: $120
Total cost: $450

In this case, nearest neighbor did find the optimal circuit.


Going back to our first example, how could we improve the outcome? One option would be to redo the nearest neighbor algorithm
with a different starting point to see if the result changed. Since nearest neighbor is so fast, doing it several times isn’t a big deal.
Example
We will revisit the graph from Example 17.

Starting at vertex A resulted in a circuit with weight 26.


CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Starting at vertex B, the nearest neighbor circuit is BADCB with a weight of 4+1+8+13 = 26. This is the same circuit we found starting
at vertex A. No better.

Starting at vertex C, the nearest neighbor circuit is CADBC with a weight of 2+1+9+13 = 25. Better!

Starting at vertex D, the nearest neighbor circuit is DACBA. Notice that this is actually the same circuit we found starting at C, just
written with a different starting vertex.

The RNNA was able to produce a slightly better circuit with a weight of 25, but still not the optimal circuit in this case. Notice that
even though we found the circuit by starting at vertex C, we could still write the circuit starting at A: ADBCA or ACBDA.

Try It
The table below shows the time, in milliseconds, it takes to send a packet of data between computers on a network. If data needed
to be sent in sequence to each computer, then notification needed to come back to the original computer, we would be solving the
TSP. The computers are labeled A-F for convenience.

A B C D E

A — 44 34 12 40

B 44 — 31 43 24

C 34 31 — 20 39

D 12 43 20 — 11

E 40 24 39 11 —

F 41 50 27 17 42

a. Find the circuit generated by the NNA starting at vertex B.


b. Find the circuit generated by the RNNA.

While certainly better than the basic NNA, unfortunately, the RNNA is still greedy and will produce very bad results for some graphs.
As an alternative, our next approach will step back and look at the “big picture” – it will select first the edges that are shortest, and
then fill in the gaps.

Example
Using the four vertex graph from earlier, we can use the Sorted Edges algorithm.

The cheapest edge is AD, with a cost of 1. We highlight that edge to mark it selected.

The next shortest edge is AC, with a weight of 2, so we highlight that edge.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

For the third edge, we’d like to add AB, but that would give vertex A degree 3, which is not allowed in a Hamiltonian circuit. The next
shortest edge is CD, but that edge would create a circuit ACDA that does not include vertex B, so we reject that edge. The next
shortest edge is BD, so we add that edge to the graph.

BAD

BAD

OK
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

We then add the last edge to complete the circuit: ACBDA with weight 25.

Notice that the algorithm did not produce the optimal circuit in this case; the optimal circuit is ACDBA with weight 23.

While the Sorted Edge algorithm overcomes some of the shortcomings of NNA, it is still only a heuristic algorithm, and does not
guarantee the optimal circuit.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

Quiz # 2. Euler and Hamiltonian Paths & Circuits Quiz

Multiple Choice Questions (1–10)

1. Which of the following is a necessary condition for a graph to have an Euler circuit?
o A) All vertices must have odd degree.
o B) The graph must be connected, and all vertices must have even degree.
o C) The graph must be disconnected, and at least one vertex must have odd degree.
o D) The graph must have at least one vertex with degree 1.
2. What is the maximum number of odd degree vertices a graph can have to have an Euler path?
o A) One
o B) Two
o C) Three
o D) Four
3. Which of the following is NOT a requirement for an Euler circuit?
o A) The graph must be connected.
o B) All vertices must have even degree.
o C) The graph must contain at least one vertex with degree 1.
o D) The graph must have no disconnected components.
4. In a Hamiltonian path, what must be true?
o A) Every vertex must be visited exactly once.
o B) Every edge must be used exactly once.
o C) The path must return to the starting vertex.
o D) The path must visit every vertex at least once, but can repeat edges.
5. Which of the following is NOT a characteristic of a Hamiltonian circuit?
o A) It visits every vertex exactly once.
o B) It uses every edge exactly once.
o C) It starts and ends at the same vertex.
o D) It may or may not be unique.
6. Which of the following algorithms is not used for solving the Traveling Salesman Problem (TSP)?
o A) Nearest Neighbor Algorithm (NNA)
o B) Brute Force Algorithm
o C) Dijkstra’s Algorithm
o D) Sorted Edges Algorithm
7. What is the time complexity of the brute force approach for finding a Hamiltonian circuit in a graph with NNN vertices?
o A) O(N)O(N)O(N)
o B) O(N2)O(N^2)O(N2)
o C) O((N−1)!/2)O((N-1)! / 2)O((N−1)!/2)
o D) O(2N)O(2^N)O(2N)
8. Which of the following is true about the Nearest Neighbor Algorithm (NNA) for solving the TSP?
o A) It always guarantees the optimal solution.
o B) It selects the nearest unvisited vertex based on the smallest edge weight.
o C) It may take a longer time than brute force to find the optimal solution.
o D) It is guaranteed to find the best Hamiltonian path.
9. What is a key difference between an Euler path and a Hamiltonian path?
o A) An Euler path must visit every vertex exactly once, while a Hamiltonian path must visit every edge exactly once.
o B) An Euler path uses every edge exactly once, while a Hamiltonian path uses every vertex exactly once.
o C) A Hamiltonian path returns to the starting vertex, but an Euler path does not.
o D) There is no difference; both terms describe the same thing.
10. Which of the following can be used to create a spanning tree of a graph?
o A) Kruskal’s Algorithm
o B) Dijkstra’s Algorithm
o C) Prim’s Algorithm
o D) Both A and C

True/False Questions (11–15)


11. A graph that has an Euler path but not an Euler circuit must have exactly two vertices of odd degree.
CS221 Class Module – 2nd Quarter
DISCRETE STRUCTURES 2 2ND SEM SY 2024-2025

o True
o False
12. If a graph has an Euler circuit, it must also have an Euler path.
o True
o False
13. A Hamiltonian path can repeat edges but must visit every vertex exactly once.
o True
o False
14. The Brute Force Algorithm is efficient but not guaranteed to find the optimal Hamiltonian circuit.
o True
o False
15. In the Nearest Neighbor Algorithm, the circuit produced may not be optimal, but it is usually faster than the Brute Force
method.
o True
o False

Fill-in-the-Blank Questions (16–20)

16. An Euler circuit exists in a graph if and only if all vertices have an __________ degree.
17. The _________ algorithm starts at an arbitrary vertex and adds the nearest unvisited vertex at each step to form a
Hamiltonian circuit.
18. The __________ algorithm guarantees the optimal solution to the Traveling Salesman Problem, but it becomes
computationally expensive for large graphs.
19. In a complete graph with NNN vertices, the number of unique Hamiltonian circuits is (N−1)!2\frac{(N-1)!}{2}2(N−1)!. This is
because there are (N−1)!(N-1)!(N−1)! possible circuits, but half of them are __________ in reverse order.
20. A graph with an Euler path but not an Euler circuit must have exactly two vertices with __________ degree.

You might also like