Algorithm Pseduo Code

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/4

encourage image

There's no tags or description

Looks like no tags are added yet.

5 Terms

1
New cards

BFS

Q ← [s]
visited[s] ← true
while Q not empty:
  u ← dequeue(Q)
  for v in adj[u]:
     if not visited[v]:
        visited[v] ← true
        enqueue(Q,v)

O (V + E)

2
New cards

DFS

explore(u):
    visited[u] ← true
    for v in adj[u]:
        if not visited[v]:
            explore(v)

O (V + E)

3
New cards

Kruskal


sort edges by weight
for (u,v) in sorted edges:
    if Find(u) != Find(v):
        add edge (u,v)
        Union(u,v)

O (E Log E)

4
New cards

Prim

key[s] ← 0
all other keys ← ∞
repeat:
    u ← unvisited vertex with minimum key
    add u to tree
    for unvisited neighbor v:
        key[v] ← min(key[v],weight(u,v))

O ((E + V) log v)

5
New cards

Dijkstra

dist[s] ← 0
all other dist ← ∞
while priority queue not empty:
    u ← extractMin()
    for (u,v,w):
        if dist[u]+w < dist[v]:
            dist[v] ← dist[u]+w

O ((E + V)log v)