Uploaded by nazirdipalpur

Fall 2023 CS607P 1 (1)

advertisement
Artificial Intelligence Practical (CS607P)
Assignment # 01
Fall 2023
Mc210401348
Total marks = 10
Deadline
th
15 of November
2023
Please carefully read the following instructions before attempting the assignment.
RULES FOR MARKING
It should be clear that your assignment would not get any credit if:
 The assignment is submitted after the due date.
 Strict action will be taken if the submitted solution is copied from any other student or the internet.
You should consult the recommended books to clarify your concepts as handouts are not sufficient.
UPLOADING INLINE ASSIGNMENT INSTRUCTION
Follow the given instructions to submit Inline assignments:
Microsoft Word (doc/docx) and Adobe Acrobat (pdf) file uploading options will not be available in inline
assignment submission.
 Students can submit HTML, Images, and plain text only in this inline Mode. You may also insert an image
file/table.
 Students can insert the images or snapshots in the following formats.

Images and tables can be inserted using the following highlighted option in the interface.
OBJECTIVE
The objective of this assignment is to:
 Learn and practice basic concepts of Graphs and Trees
NOTE
No assignment will be accepted after the due date via email in any case (whether it is the case of load shedding
or internet malfunctioning etc.). Hence refrain from uploading assignments in the last hour of the deadline. It is
recommended to upload the solution at least two days before its closing date.
If you people find any mistake or confusion in the assignment (Question statement), please consult with your
instructor before the deadline. After the deadline, no queries will be entertained in this regard.
For any query, feel free to email me at:
cs607p@vu.edu.pk
Questions No. 01
10 Marks
Graph traversal means visiting every vertex and edge at most once in an order. While using certain graph
algorithms, it must be ensured that each vertex of the graph is visited exactly once. The order of vertices as
visited depends upon the algorithm complexity. You are required to write a Pseudo-code of DFS traversal of
the tree as in accordance with the given DF based Tree.
Given Data:
 3 levels
 8 Nodes in Total
 Root Node and target Node is Defined
Root Node (Layer 1)
A
B
E
C
F
G
Layer 2
D
H
Layer 3
Answer:
function dfsTraversal(node):
if node is null:
return
# Assuming the graph is represented as an adjacency list
visited[node] = true
processNode(node) # Process the current node
for each neighbor in adjacencyList[node]:
if neighbor is not visited:
dfsTraversal(neighbor) # Recursively traverse the neighbor nodes
# Given data
totalNodes = 8
graph = {} # Assuming an adjacency list representation
# Adding edges to the graph
# You need to define the actual structure based on your tree
graph[1] = [2, 3]
graph[2] = [4, 5]
graph[3] = [6, 7]
graph[4] = [8]
# Mark all nodes as not visited
visited = {}
for node in range(1, totalNodes + 1):
visited[node] = False
# Start DFS traversal from the root node
rootNode = 1 # Assuming the root node is 1
dfsTraversal(rootNode)
Note: You are required to email to cs607p@vu.edu.pk for any kind of queries related to assignment understanding.
Download