Unit 2: Analysis of Algorithms and Graphs Flashcards

1
Q

3 Common measures for the efficiency of algorithms

A
  • Run-time
  • Memory usage
  • Problem-specific parameters (e.g. slow memory access, network usage).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Random Access Machine

A
  • There is exactly one CPU
  • All data is in main memory
  • All memory accesses require the same amount of time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

4 Atomic operations

A
  • Assignments: a←b
  • Arithmetic operations: b ⏺ c with ⏺ ∈ { +, -, x, /, mod, ... }
  • Logical operations: , , ¬, . . . .
  • Comparison operations: a b with ∈ {<, ≤, =, 6=, >, ≥}.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Run-time of an algorithm

A

Run-time:
- Is the number of atomic operations executed by the algorithm.
- For simplicity, the run-time T(n) is usually described as a function T of the input size n.

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

Definition of Θ(g(n))

A

For a given (non-negative) function g(n) we denote by Θ(g(n)) the set of functions:

Θ(g(n)) = { f(n) | there exist constants 0 < c₁ ≤ c₂ and n₀ such that
c₁g(n)f(n)c₂g(n) for all n ≥ n₀}

Intuition: f(n) ∈ Θ(g(n)) if f(n) can be “sandwiched” between c₁g(n) and c₂g(n),
for sufficiently large n.

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

Further asymptotic notation: Θ, O,

A
  • Θ expresses tight upper and lower bounds on f(n).
  • O (“big-Oh”) expresses an upper bound (e.g. when talking about worst-case run-time).
  • expresses a lower bound.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Definition of O(g(n)) :

A

O(g(n)) = { f(n) | there exist constants 0 ≤ c and n₀ such that
f(n) ≤ cg(n) for all n ≥ n₀}

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

Definition of Ω(g(n))

A

Ω(g(n)) = {f(n) | there exist constants 0 ≤ c and n₀ such that
cg(n) ≤ f(n) for all n ≥ n₀}

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

2 Properties of Θ

A
  • cf(n)Θ(f(n))
  • f(n) + g(n) ∈ max( Θ(f(n)), Θ(g(n)))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Properties of Θ, O, : “defining smaller order terms”

A

max( Θ(f(n)), Θ(g(n))) =
* Θ(f(n)) if g(n)O(f(n))
* Θ(g(n)) otherwise

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

Dominance between functions

A

f(n) is dominated by g(n), if f(n) = O(g(n)) but not g(n) = O(f(n)).

g(n) dominates f(n), if lim_{n→∞}
f(n)/g(n) = 0

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

Define:

Undirected Graphs

A

G = (V, E)
* V is the set of vertices
* E is the set of edges between pairs of vertices.

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

Define:

Adjacency & Neighbours

A

Let e={v, u} be an edge in E, then
- v and u are adjacent.
- v is a neighbour of v and u is a neighbour of v.

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

Define:

Incident edge

A

Let e={v, u} be an edge in E, then
- v and e are incident

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

Define:

Vertex degree

A

The number of edges incident to v.

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

Define:

Multi-edge

A

More than one edge between the same two vertices.

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

Define:

Loop

A

An edge between a vertex and itself.

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

Define:

Simple graph

A

An undirected graph without multi-edges and loops.

19
Q

Define

Path

A

A path in an undirected graph G = (V, E) is a sequence (v₁, v₂, . . . , vₖ₋₁, vₖ), k ≥ 1, of vertices with the property that each consecutive pair
vᵢ, vᵢ₊₁ is joined by an edge in E.

The length of a path is k − 1.

20
Q

Define

Cycle

A

A cycle is a path (v₁, v₂, . . . , vₖ₋₁, vₖ) for which {v₁, vₖ} is an edge too,
k ≥ 3.
The length of this cycle is k.

21
Q

Define

Path

A

A path in a digraph G = (V, E) is a sequence (v₁, v₂, . . . , vₖ₋₁, vₖ),
k ≥ 1, of vertices with the property that every consecutive pair vᵢ, vᵢ₊₁ is connected by a directed arc from vᵢ to vᵢ₊₁.

22
Q

Define

Trees

A

An undirected graph is a tree, if it is connected and cycle-free (i. e., does not contain a cycle).

23
Q

Define

Rooted tree

a.k.a. arborescence

A

Obtained from a tree by choosing an arbitrary vertex r as the root and
directing all edges away from r.

24
Q

s-t connectivity problem

A

Is there a path between two given vertices s and t?

25
Q

s-t shortest paths

A

The length of a shortest path between s and t (i.e, the distance between s and t)?

26
Q

Define

Connectivity of an undirected graph

A

An undirected graph is connected if there is a path between every pair of nodes in the graph.

27
Q

Define

Disconnected graph

A

If the graph contains a pair of nodes without a path between them, the graph is not connected.

28
Q

Define

Subgraph

A

A graph G₁ = (V₁, E₁) is a subgraph of a graph G₂ = (V₂, E₂), if
V₁ ⊆ V₂ and E₁ ⊆ E₂.

29
Q

Define

Connected Component

A

A maximal connected subgraph of a graph is called a connected component.

A disconnected graph is the disjoint union of its connected components.

30
Q

Define

Strong connectivity

of nodes

A

Two nodes u and v are strongly connected if there is a path from u to v and vice versa.

31
Q

Define

Strong connectivity

of a directed graph

A

A directed graph is strongly connected if every pair of nodes is strongly connected.

32
Q

Define

Weak connectivity

of a directed graph

A

A directed graph is called weakly connected if the underlying undirected graph, i.e., the undirected graph that one obtains by ignoring the direction of edges, is connected.

33
Q

Define

Directed acyclic graph
(DAG)

A

A DAG is a directed graph with no directed cycles.

34
Q

Define

Topological ordering

of a directed graph

A

A topological ordering of a directed graph G = (V, E) is a linear order of its nodes, denoted by v₁, v₂, ..., vₙ, such that i < j for every arc (vᵢ, vⱼ).

35
Q

Algorithm Run-time: Atomic Operations

Which operations are ignored / disregarded?

A
  • Index calculations
  • Type of operands
  • Size of operands
36
Q

2 Examples of algorithms with constant growth Θ(1)

A
  • Addition of two numbers (of constant size)
  • Access to the ith element of an array of size n.
37
Q

Example of Algorithms that run in Logarithmic Time O(log n)

A
  • Binary Search
38
Q

Binary search

A

input: an increasingly sorted array A. And a value V.

calculate the center index s of A;

if A[s] = V then:
> print “found value”

else if V < A[s] then
> apply binary search to the subarray left of s;

else
> apply binary search to the subarray right of s

39
Q

Example of linear growth algorithm O(n)

A
  • Search for a maximum in an unsorted array.
  • Merge two sorted lists
40
Q

An example of an algorithm with superlinear growth O(n log n)

A
  • Mergesort
41
Q

An example of an algorithm with quadratic growth O(n²)

A

Find the closest pair of points in a list of point pairs.

42
Q

An example of an algorithm with cubic growth O(n³)

A

Disjoint sets

Let S₁, …, Sₙ be n subsets of {1…, n}.

Is there a pair of disjoint sets?

43
Q

Induced subgraph

A

(V₁, E₁) is an induced subgraph of (V₂, E₂) if it is a graph where V₁⊆V₂ and E₁ contains all edges of E₂ which are subsets of V₁.