GRAPHS Flashcards

1
Q

What is graph

A

Mathematically, a graph is a set V of vertices and a set E of edges, such that each edge in E connects two of the vertices in V
We use node as a synonym for vertex

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

Draw unlabeled, labeled and weighted graphs

A

*See notes for graph

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

When are vertices adjacent to each other?

A

One vertex is adjacent to another vertex if there is an edge connecting the two vertices (neighbors)

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

What is a path?

A

Sequence of edges that allows one vertex to be reached from another vertex in a graph

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

What is the length of a path and the degree of a vertex?

A

Length of a path: Number of edges on the path

Degree of a vertex: Number of edges connected to it

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

Define and illustrate simple path and cycles

A

Simple path: Path that does not pass through the same vertex more than once
Cycle: Path that begins and ends at the same vertex

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

When is a graph said to be connected?

A

A graph is connected if there is a path from each vertex to every other vertex
*See notes for pic

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

When is a graph said to be complete?

A

A graph is complete if there is an edge from each vertex to every other vertex

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

What are the two types of graphs? Illustrate each

A

Graphs can be undirected or directed (digraph)

*See notes for pic

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

Define: Directed edges and incident edges

A

A directed edge has a source vertex and a destination vertex

Edges emanating from a given source vertex are called its incident edges

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

How does one convert an undirected graph to a directed graph

A

To convert undirected graph to equivalent directed graph, replace each edge in undirected graph with a pair of edges pointing in opposite directions

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

What is a DAG?

A

A special case of digraph that contains no cycles is known as a directed acyclic graph, or DAG

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

Give examples of graph applications?

A

A roadmap
A map of airline routes
A schematic of the computers and connections that make up the Internet
The links between pages on the Web
The relationship between students and courses i.e courses and their pre-requisites
A diagram of the flow capacities in a communications or transportation network

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

What are the common ways to represent graphs?

A

The adjacency matrix

The adjacency list

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

What is an adjacency list?

A

The adjacency list for the graph is an array of N linked lists
Each individual list shows what vertices a given vertex is adjacent to.
Adjacency list shows which vertices are adjacent to—that is, one edge away from—a given vertex, not paths from vertex to vertex.

*See notes for illustration

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

What are the different types of graph traversal

A

A depth-first search (DFS), uses a stack

A breadth-first search (BFS), uses a queue

17
Q

List the rules of Depth First Search

A

RULE 1: If possible, visit an adjacent unvisited vertex, mark it, and push it on the stack
RULE 2: If you can’t follow Rule 1, then, if possible, pop a vertex off the stack.
RULE 3: If you can’t follow Rule 1 or Rule 2, you’re done

18
Q

List the rules of Breadth First Search

A

1: Visit the next unvisited vertex(if there is one) that’s adjacent to the current vertex, mark it and insert it into the que
2: If you can’t carry out rule 1 because there are no more unvisited vertices remove a vertex from the queue(if possible) and make it the current vertex
3: If you can’t follow Rule 1 or Rule 2, you’re done

19
Q

Describe the minimum spanning tree

A

Subset of edges whose sum of edge weights is as small as possible
In a weighted graph, you can sum the weights for all edges in a spanning tree and attempt to find a spanning tree that minimizes this sum
There are several algorithms for finding a minimum spanning tree for a component.
For example, to determine how an airline can service all cities, while minimizing the total length of the routes it needs to support

20
Q

Describe the topological sort

A

A directed acyclic graph (DAG) has an order among the vertices
A topological order assigns a rank to each vertex such that the edges go from lower- to higher- ranked vertices
Topological sort: process of finding and returning a topological order of vertices in a graph
*See notes for examples

21
Q

What is a subgraph?

A

A subgraph consists of a subset of a graph’s vertices and a subset of its edges

22
Q

Write down java code to create a graph

A

*See notes for code

23
Q

Discuss two types of algorithms that have been used by taxi hailing applications to improve the customer experience today

A

Dijkstra’s search algorithm to find out the best route

DFS to find shortest route