DFS in Complete Tree

 

DFS in Complete Tree

 "DFD" typically stands for "Data Flow Diagram." It's a graphical representation used in software engineering and systems analysis to illustrate how data moves through a system. However, it's not an algorithm like BFS or DFS.

  • Completeness: DFDs depict data flow in a system but might not cover every detail, depending on the diagram's level of abstraction.

  • Time & Space Complexity: the time complexity of both DFS and BFS is O(V + E), where V represents the number of vertices and E represents the number of edges in the graph. And, the space complexity of DFS and BFS is O(V), in the worst case

  • Optimality: DFDs are design tools; their value lies in effectively illustrating data flow for system understanding and analysis, rather than being inherently optimal or non-optimal.

Tree: 

 

Code:

class Node:
def __init__(self, value):
self.data = value
self.left = None
self.right = None

def Insert(root, val):
if root is None:
return Node(val)
queue = [root]
while queue:
current = queue.pop(0)
if current.left is None:
current.left = Node(val)
return
elif current.right is None:
current.right = Node(val)
return
else:
queue.append(current.left)
queue.append(current.right)

def Inorder(root):
if root:
Inorder(root.left)
print(root.data, end=" ")
Inorder(root.right)

def DFS(root):
if root:
print(root.data, end=" ")
DFS(root.left)
DFS(root.right)


root = Node(1)
Insert(root, 2)
Insert(root, 3)
Insert(root, 4)
Insert(root, 5)
Insert(root, 6)
Insert(root, 7)
print(end="Inorder: ")
Inorder(root)
print()
print(end="DFS: ")
DFS(root)
print()

Explanation: 

 

Sample input and output:

.....Thank you ......



 

 

Comments

Popular posts from this blog

Convert binary to decimal in c using built in function

Install nodeJs in linux