Mente

algorithms_anki.htm

Analysis of Algorithms

What's the order of growth of common algorithms?

Alt text

Stacks and Queues

Sorting

Priority Queues

Symbol Tables (Hash Tables)

Graphs

DFS

What is the pseudocode for DFS?

def dfs(graph, start):
    visited = set()

    def dfs_recursive(current):
        if current in visited:
            return

        visited.add(current)

        for neighbor in graph[current]:
            dfs_recursive(neighbor)

    dfs_recursive(start)

What is the pseudocode for BFS?

def bfs(graph, start):
    visited = set()
    queue = [start]

    while queue:
        current = queue.pop(0)
        if current in visited:
            continue

        visited.add(current)

        for neighbor in graph[current]:
            if neighbor not in visited:
                queue.append(neighbor)

How do we do a topological sort of appointments? Give an example?