Professional Documents
Culture Documents
Social Media Influence Analyzer
Social Media Influence Analyzer
Social Media Influence Analyzer
Explanations:
BFS (Breadth-First Search) and DFS (Depth-First Search) are algorithms used to
traverse or search through graphs or trees in different orders.
• Meaning:
• BFS is a graph traversal algorithm that explores all the vertices of a
graph level by level.
• It starts from a source vertex and visits all its neighbors before moving
on to the next level of vertices.
• Implementation in Python:
• Utilizes a queue data structure.
• It is often used to find the shortest path in an unweighted graph.
• Meaning:
• DFS is a graph traversal algorithm that explores as far as possible along
one branch before backtracking.
• It explores deeper into the graph structure before moving to the next
branch.
• Implementation in Python:
• Can be implemented using recursion or an explicit stack.
• Useful for topological sorting, detecting cycles in a graph, and solving
problems on strongly connected components.
FlowChart :
Coding
from collections import defaultdict
class InfluenceAnalyzer:
def __init__(self):
self.graph = defaultdict(list)
def dfs_util(node):
print(node, end=' ')
visited.add(node)
dfs_util(start_node)
# Example usage
ia = InfluenceAnalyzer()
ia.add_edge('Vijay', 'ajith')
ia.add_edge('vijay', 'suresh')
ia.add_edge('ajith', 'dinesh')
ia.add_edge('suresh', 'vivek')
ia.add_edge('dinesh', 'vignesh')
ia.add_edge('vivek', 'vignesh')
print("BFS:")
ia.bfs('Vijay')
print("\nDFS:")
ia.dfs('ajith')
Output:
BFS:
Vijay ajith dinesh vignesh
DFS:
ajith dinesh vignesh