Question: Write the C language program code . You are given an integer N representing the number of nodes in the graph . The graph is

Write the C language program code . You are given an integer N representing the number of nodes in the graph . The graph is represented
by adjacency list .The next N lines represent an adjacency list where first integer is node itself and
next integers are the nodes adjacent to it in ascending order . The goal is to implement the following
using a Depth-First Search (DFS) traversal algorithm:
All path(Node1,Node2): Print all paths from a given source to a destination vertex. Sep-
arate each path with a new line , otherwise print -1 if no path exists between nodes.
NOTE - paths are printed in sorted order
valid tree():This function checks if the given graph is a tree or not. A valid tree has the
following properties:
(a) There are no cycles (loops) in the graph.
(b) Every vertex is reachable from the root vertex.
(c) There are no isolated vertices (vertices not connected to the rest of the graph).
function prints 1 if the given graph is a tree else -1
Input format:
The first line contains an integer N specifying the number of nodes in the graph.
Next N lines are sequence of integers where first integer is node itself and next integers in
that line are representing nodes which are adjacent to that node.
Each line of input is a character from the menu list [a,t,x].
Input a calls the function All path(Node1,Node2).
Input t calls the function valid tree()
Input x terminates the execution of the program.
All the inputs in a line are separated by space.
Output format:
A line may contain -1 or 1.
The output of the result of any menu is printed in a new line.
Sample Input 1:
6
0135
1025
2134
302
42
501
t
a 14
a 01
x
Sample Output 1 :
-1
10324
124
15032
01
0321
051
Sample Input 2:
8
017
102
213456
32
42
52
62
70
a 67
a 06
t
x
Sample Output 2 :
62107
0126
1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!