Part 6 Flashcards
How would the expression (a+7)*b be represented in a tree?
times
/ \
plus id(b)
/ \
id (a) number(7)
What is a parser?
A program that converts text into parse trees
What two pieces of information does a node in a parse tree need to hold?
Type of node, i.e. number, identifier, Operator etc.
Value, e.g. 7, myId or +
What are the two approaches for parse tree nodes in Java?
Use Object to store the data
write an abstract class and subclasses for each kind of node
What is a graph?
A collection of vertices and edges where each edge connects two of the vertices
What is the difference between a directed and undirected graph?
Directed - edges have direction so (u, v) is not the same as (v, u)
Undirected - edge has no direction so (u,v)==(v,u)
What is a path from vertex v1 to vk?
A sequence of edges, e.g.
(v1, v2), (v2, v3), …, (vk-1, vk)
What is a connected graph?
Every pair of vertices u and v has a path from u to v
I.e. you can go from any vertex to any vertex, somehow
What is a cycle (in graphs)?
A non-empty path from a vertex to itself comprising distinct edges
What is an acyclic graph?
A graph that contains no cycles
What is a weighted graph?
A graph where each edge has some numeric value associated with it, i.e. as a measure of distance, cost or capacity
Which letters denote the number of vertices and edges in graphs?
n = number vertices
e = number edges
For any graph, what is e less than?
n^2
For any undirected graph, what is e less than?
n^2 / 2
For a connected graph, what is e greater than or equal to?
n-1