<jupyter_start><jupyter_text>BFS -->- O(V+E)<jupyter_code>class Node(object):
    def __init__(self, name):
        self.name = name
        self.adjacentList = []
        self.visited = False
        self.predecssor = None
        

class BreadthFirstSearch(object):
    def bfs(self, startNode):
        queue = []
        queue.append(startNode)
        startNode.visited = True
        
        while queue:
            actualNode = queue.pop(0)
            print("%s " % actualNode.name)
            
            for n in actualNode.adjacentList:
                if not n.visited:
                    n.visited = True
                    queue.append(n)
node1 = Node("A")
node2 = Node("B")
node3 = Node("C")
node4 = Node("D")
node5 = Node("E")

node1.adjacentList.append(node2)
node1.adjacentList.append(node3)
node2.adjacentList.append(node4)
node4.adjacentList.append(node5)

bfs = BreadthFirstSearch()
bfs.bfs(node1)<jupyter_output>A 
B 
C 
D 
E<jupyter_text>DFS- O(V+E)<jupyter_code>class Node(object):
    def __init__(self, name):
        self.name = name
        self.adjacentList = []
        self.visited = False
        self.predecssor = None

class DepthFirstSearch(object):
    def dfs(self, node):
        node.visited = True
        print("%s " % node.name)
        
        for n in node.adjacentList:
            if not n.visited:
                self.dfs(n)
node1 = Node("A")
node2 = Node("B")
node3 = Node("C")
node4 = Node("D")
node5 = Node("E")

node1.adjacentList.append(node2)
node1.adjacentList.append(node3)
node2.adjacentList.append(node4)
node4.adjacentList.append(node5)

dfs = DepthFirstSearch()
dfs.dfs(node1)<jupyter_output>A 
B 
D 
E 
C
{'fraction_non_alphanumeric': 0.12679425837320574, 'fraction_numerical': 0.017344497607655503, 'mean_word_length': 2.3797979797979796, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '62158', 'license': 'MIT', 'n_tokens_mistral': 616, 'n_tokens_neox': 605, 'n_words': 109, 'path': 'CODING/Graph.ipynb', 'repo_name': '44aayush/Placement_Q-A', 'size': '1672'}