Module 12: Graphs Final Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What are the different graph traversals?

Breadth First Traversal Depth First Traversal

adjacent vertices

IN AN UNDIRECTED GRAPH: vertices are adjacent if they are joined by an edge IN AN DIRECTED GRAPH: vertex A is adjacent to vertex B if a directed edge begins at B and ends at A - Adjacent vertices are called neighbors

Is MCQ a path or cycle?

No, cycle because it is open ended

Is ABCADEA a cycle?

No, false it is not, bc we revisit A again in the middle (only start and end can be the same node)

Whats is the Big Oh for BFS

O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used,

What is the time complexity expressed as in BFS?

O(|V| + |E|) -Every vertex and edge will be explored in the worst case

What do matrix and list represent?

They represent edges

Connected graph

a graph that has a path between every pair of distinct vertices

Complete graph

a graph that has an edge between every pair of disticnt vertices - a complete graph is ALWAYS a connected graph

Path

a sequence of vertices, p₀, p₁,..., such that each adjacent pair of vertices are connected by an edge

Cycle

a simple path with no repeated vertices or edges other than the starting and ending vertices. a cycle in a directed graph is called a directed cycle -simple path with no repeated vertices or edges other than the starting and ending vertices( cycle in directed graph = directed cycle)

What is an adjacency matrix?

a square grid of true/false values that represent the edges of a graph

What is the difference between a tree and a graph?

a tree is a special type of graph without a cycle

What is the graph implemented list?

adjacency list

What happens once the adjacent matrix has been set?

an application can examine locations of the matrix to determine which edges are present and which are missing

Loop

an edge that connects a vertex to itself

Why do we use graphs?

are used to address real-world problems in which it represents the problem area as a network like telephone networks, circuit networks, and social networks

What are the two common implementations of a graph?

array or list

What are Depth First Traversals used for?

can be used to detect cycles in a graph

What can undirected graphs be like?

connected, complete or disconnected

What is a directed graph?

each edge is associated with two vertices, called source and target. -the order of the two connected vertices are important

In what type of graph does the BFS give shortest path?

in unweighted graphs, BFS gives the shorotest path between two nodes u and v, where the path length is measured by number of edges.

What is a weighted graph?

it has values on its edges, values are called either weights or costs (values = weights / costs)

Breadth-First Traversal

level order, queue, visits the origin and the origins neighbors -then it considers each of these neighbors and visits their neighbors this traversal uses queues to hold the visited vertices. -BFS can find the shortest path between origin and any node

What's the difference between loop and cycle?

loop is with itself and cycle is going back to source node

If a DIRECTED grpah has n vertices, What is the maximum number of edges that the directed graph can have?

n (n-1) edges if the graph is directed

If and UNDIRECTED graph has n vertices, What is the maximum number of edges that the undirected graph can have?

n(n-1)/ 2 edges if the graph is undirected

Whats a recursive implementation of DFS

procedure DFS(G,v): label v as discovered for all edges from v to w in G.adjacentEdges(v) do if vertex w is not labeled as discovered then recursively call DFS(G,w)

What happens if a graph contains n vertices?

the grid then contains n rows and n columns

What is a graph?

the most general data structure, most commonly used data structures, non-linear consisting of nodes and edges between nodes - G =(V,E) - where V is a set of vertices (nodes) and E is a set of edges

What is an undirected graph?

think of it as a set of nodes and a set of links between the nodes. as a directed graph with two edges

If two vertex numbers i and j, are component at row i and column j , is there an edge from vertex i to vertex j?

true, yes otherwise the component is false

What is the graph implmented array?

two-dimensional array called an adjacency matrix

What are the dif types of graphs

undirected, directed

What is the origin vertex?

vertex that a graph traversal starts from

Depth First Traversal

visits the origin, then a neighbor of the origin, and a neighbor of the neighbor. it continues in this fashion until it finds no unvisited neighbor -backing up by one vertex, it considers another neighbor -uses stack, can implement recursively to expand deepest unvisited nodes

What happened to the matric is a graph is UNDIRECTED

we can say the matrix is symmetrical

What can we use to store an adjacent matrix?

we can use a two-dimensional array, boolean[][] adjacent = new boolean [4][4];

How do we represent a graph with adjacency list?

•A directed graph with n vertices can be represented by n different linked lists. •List number i provides the connections for vertex i. •For each entry j in list number i, there is an edge from i to j.


संबंधित स्टडी सेट्स

Chapter 2: Psychological Research

View Set

Exam 1 Study Guide Fundamental of Business Finance

View Set

Macro Economics Practice Chapter

View Set

Pre-Class Review Questions Sec 10.2

View Set

Life Insurance Underwriting and Policy Issue Ch. 5

View Set