ics 46: graphs

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

20 Terms

1
New cards

graph definition

Set of vertices V connected by edges E

2
New cards

Difference between tree vs graph

  • Tree CANT have cycles 

  • Graphs can have cycles

3
New cards

What's the max amount of nodes a graph can have?

  • n(n-1)/2

  • n=total number of notes

  • n-1=each node has this total max 

  • /2=avoid counting duplicates

4
New cards

Whats the min amount of nodes a graph can have?

0

5
New cards

directed vs undirected graph

  • Directed: has 1 specific direction of the edges 

  • Undirected: can go both directions from edges

6
New cards

Adjacency matrix Space complexity

  • v^2

  • bc v rows x v cols 

7
New cards

adjacency matrix Time complexity of lookup of edge

  • O(1)

  • always constant time for lookups in 2d arrays

8
New cards

adjacency matrix time complexity for adding edge

  • O(1)

  • always constant time adding in 2d arrays

9
New cards

adjacency matrix time complexity for iterating over vertices adjacent to v

  • O(V)

  • need to iterate thru that corresponding vertex’s row to find the 1’s/the vertices that are adjacent to v  

10
New cards

adjacency list space complexity

  • Array holding vertices: v

  • Linked lists holding edges: e

  • O(v + e)

11
New cards

adjacency list time complexity of lookup of edge

  • Based on the number of children of the vertex ur looking up an edge for (basically degree of the vertex)

  • Once ur in linked list, searching in a linked list is always O(n)

  • O(degree(v))

12
New cards

adjacency list time complexity for adding edge

  • O(1): inserting to the head of linked list (not checking for duplicate edges)

  • If checking for duplicate edges, must traverse thru the linked list first, so O(degree(v))

13
New cards

adjacency list time complexity for iterating over vertices adjacent to v

O(degree(v))

14
New cards
15
New cards
16
New cards
17
New cards
18
New cards
19
New cards
20
New cards