cs126 graphs

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/51

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.

52 Terms

1
New cards

What is a graph?

  • G = (V,E) where

  • V is a set of nodes (vertices)

  • E is a collection of pairs of vertices (edges)

2
New cards

Define directed edge.

  • An ordered pair of vertices (u,v)

  • u is the origin 

  • v is the destination

3
New cards

Define undirected graph.

A graph of unordered pairs of vertices.

4
New cards

What are some applications of graphs?

  • Electronic circuits

  • Highway and Flight networks

  • Computer networks (LAN, Internet, Web)

  • Entity-relationship diagrams

5
New cards

Define endpoint / end vertex.

Vertices with incoming edges.

6
New cards

Define incident.

An edge incoming or outgoing from a vertex.

7
New cards

Define adjacent.

Vertices connected by an edge.

8
New cards

Define degree.

  • The number of edges from a vertex

  • Denoted deg(v)

9
New cards

Define parallel.

Edges that connect the same vertices.

10
New cards

Define self-loop.

An edge that connects a vertex to itself.

11
New cards

Define path.

  • A sequence of alternating edges and vertices

  • Starts and ends with a vertex

12
New cards

Define simple path.

A path such that all its vertices and edges are distinct.

13
New cards

Define cycle.

A path that starts and ends at the same vertex.

14
New cards

Define simple cycle.

A cycle such that all its vertices and edges are distinct.

15
New cards

What is Euler’s handshaking lemma?

Sum of the degrees of all vertices is 2 x the number of edges.

16
New cards

What is the rule about the number of edges in a tree?

If G is a tree with n vertices and m edges, m = n-1.

17
New cards

Define complete graph.

A simple and undirected graph where every pair of vertices is connected by a unique edge.

18
New cards

What is the number of edges in a complete graph of n nodes?

O(n2)

19
New cards

Name the (4) ways a graph can be implemented.

  • Edge list

  • Adjacency list

  • Adjacency map

  • Adjacency matrix

20
New cards

Describe how an edge list can be used to represent a graph.

  • Vertex and Edge objects are stored in distinct, unordered lists

  • Each vertex object contains:

    • element

    • reference to position in vertex sequence

  • Each edge object contains:

    • element

    • origin vertex object

    • destination vertex object

    • reference to position in edge sequence

21
New cards

Describe how an adjacency list can be used to represent a graph.

  • A vertex is mapped to a list of its adjacent vertices

  • Two separate collections are kept for incoming and outgoing edges

22
New cards

Describe how an adjacency map can be used to represent a graph.

  • A vertex is mapped to a hash-map of its adjacent vertices

  • This means retrieving and removing edges can be done in (expected) O(1)

23
New cards

Describe how an adjacency matrix can be used to represent a graph.

  • An n x n 2D array is used

  • An integer key is associated with each vertex

  • Each element stores the Edge object that connects the vertices, or null if no edge connects them

24
New cards

What are the advantages and disadvantages of using an adjacency matrix?

  • Any edge can be accessed in O(1)

  • It is inefficient for sparse graphs

25
New cards

What is the worst-case space cost for an edge list?

O(n+m)

26
New cards

What is the worst-case time cost of performing incidentEdges(v) on an edge list?

O(m)

27
New cards

What is the worst-case time cost of performing getEdge(u,v) on an edge list?

O(m)

28
New cards

What is the worst-case time cost of performing insertVertex(o) on an edge list?

O(1)

29
New cards

What is the worst-case time cost of performing insertEdge(v,w,o) on an edge list?

O(1)

30
New cards

What is the worst-case time cost of performing removeVertex(v) on an edge list?

O(m)

31
New cards

What is the worst-case time cost of performing removeEdge(e) on an edge list?

O(1)

32
New cards

What is the worst-case space cost for an adjacency list?

O(n+m)

33
New cards

What is the worst-case time cost of performing incidentEdges(v) on an adjacency list?

O(deg(v))

34
New cards

What is the worst-case time cost of performing getEdge(u,v) on an adjacency list?

O(min(deg(u), deg(v)))

35
New cards

What is the worst-case time cost of performing insertVertex(o) on an adjacency list?

O(1)

36
New cards

What is the worst-case time cost of performing insertEdge(v,w,o) on an adjacency list?

O(1)

37
New cards

What is the worst-case time cost of performing removeVertex(v) on an adjacency list?

O(deg(v))

38
New cards

What is the worst-case time cost of performing removeEdge(e) on an adjacency list?

O(1)

39
New cards

What is the worst-case space cost for an adjacency map?

O(n+m)

40
New cards

What is the worst-case time cost of performing incidentEdges(v) on an adjacency map?

expected O(1)

41
New cards

What is the worst-case time cost of performing getEdge(u,v) on an adjacency map?

O(1)

42
New cards

What is the worst-case time cost of performing insertVertex(o) on an adjacency map?

O(1)

43
New cards

What is the worst-case time cost of performing insertEdge(v,w,o) on an adjacency map?

O(1)

44
New cards

What is the worst-case time cost of performing removeVertex(v) on an  adjacency map?

O(deg(v))

45
New cards

What is the worst-case time cost of performing removeEdge(e) on an adjacency map?

expected O(1)

46
New cards

What is the worst-case space cost for an adjacency matrix?

O(n2)

47
New cards

What is the worst-case time cost of performing incidentEdges(v) on an  adjacency matrix?

O(n)

48
New cards

What is the worst-case time cost of performing getEdge(u,v) on an  adjacency matrix?

O(1)

49
New cards

What is the worst-case time cost of performing insertVertex(o) on an  adjacency matrix?

O(n2)

50
New cards

What is the worst-case time cost of performing insertEdge(v,w,o) on an  adjacency matrix?

O(1)

51
New cards

What is the worst-case time cost of performing removeVertex(v) on an  adjacency matrix?

O(n2)

52
New cards

What is the worst-case time cost of performing removeEdge(e) on an  adjacency matrix?

O(1)