Graphs Flashcards

(25 cards)

1
Q

What are graphs?

A

An ADT comprised of a network of nodes connected by edges used to model complex relationships between entities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a node?

A

Part of a graph that represents objects or entities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an edge?

A

Part of a graph that represents a relationship between entities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a weight in a graph?

A

A data value used to describe/label an edge.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the uses of graphs

A

Modelling and representing:
- Human (social) networks
- Transport networks , including road and rail networks
- Connections between devices on a network
- Planning telecommunications networks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an undirected graph?

A

A graph in which each relationship between nodes is two-way.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a directed graph?

A

A graph where each relationship between nodes can be one-way as shown by arrows on the edges or bidirectional.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a weighted graph?

A

A graph in which each edge is given a weight.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some possible graph operations?

A
  • Adding/Removing a node
  • Adding/Removing an edge between nodes
  • Test if an edge exists between two nodes
  • Getting and updating weights of an edge between two nodes
  • Finding a valid path between two nodes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the two main ways of implementing a graph?

A
  • Adjacency matrix - size of N^2 (N is number of nodes)
  • Adjacency list - size of N + E (N is number of nodes and E is number of edges within graph)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can an adjacency matrix be represented?

A

Static 2D array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can an adjacency list be represented?

A

Dynamically as an array of graph nodes, each containing a pointer to a list of nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the advantages of adjacency matrices?

A
  • Edges between nodes can be quickly identified due to random access of elements within arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the disadvantages of adjacency matrices?

A

-Less memory efficient and can be wasteful with memory
- Almost half of the matrix is repeated data
- Stores every possible edge between nodes, even those that don’t exist - more memory is used, as a value (1, 0, weight) is stored for every combination of nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When are adjacency matrices used?

A
  • “Dense graphs” where there are a lot of edges
  • Graphs where edges need to be frequently created,removed,identified or their weights changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When are adjacency lists used?

A
  • “Sparse graphs” where there are not many edges
  • Graphs where nodes are frequently added/removed
17
Q

What are the advantages of adjacency lists?

A
  • Memory efficient as they only store edges that exist in the graph
18
Q

What are the disadvantages of adjacency lists?

A
  • They are slower to identify edges as the list has to be traversed to see if an edge exists between two nodes
19
Q

What is graph traversal?

A

Visiting every node within the graph to achieve an purpose

20
Q

What are the two different types of graph traversal?

A
  • Depth-First Search
  • Breadth-First Search
21
Q

How does Depth First traversal work?

A
  • Recursively visits nodes that are adjacent to a starting node
  • Until a node is reached with no unvisited adjacent nodes
  • At this point the algorithm backtracks to the previous node and visits any unvisited nodes from there
22
Q

How is a stack used in depth first traversal?

A

Stack is used to keep track of the node being currently visited and the history of nodes required to get there.

23
Q

What are the uses of a depth first traversal algorithm.

A
  • Finding a solution to a maze, where the maze is modelled as a graph
  • Finding the valid path from one node to another
  • Determining the order with which processes that depend on one another should occur
24
Q

How does breadth first traversal work?

A

Adds all adjacent nodes to a queue and uses iteration to repeat the process with the node at the front of the queue.

25
What are some uses of breadth first searches?
- Identifying “friends” and first-degree contacts - Finding immediately connected devices and networks to network hubs - Crawling web pages to build an index of linked pages as used by search engines - Mapping an unknown graph