CISC 320 Midterm 2

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/110

encourage image

There's no tags or description

Looks like no tags are added yet.

111 Terms

1
New cards

Reccurence Vocab

T(N): Total number of operations for input size N.

a: Number of recursive calls (subproblems), a >=1

b: Factor by which the input size is divided; b> 1

d: Exponent representing the extra work outside recursion, d >= 0

Example:

Here, a=5, b=3, and d=2.

2
New cards

a = bd

o (ndlogn)

3
New cards

a < bd

O (nd)

4
New cards

a > bd

nlogba

5
New cards

Deriving Reccurence Relations From Function

def f(n):
    if n <= 1:
        return
    f(n // 2)
    f(n // 2)
    for i in range(n):
        print(i)

Answer:


6
New cards

Reccurnece Relation Formula

T(N) = aT/(n/b) + f(n)

7
New cards

Graph

A collection of vertices (V) connected by edges (E).

8
New cards

Directed vs. Undirected Graph

Directed edges have a specific direction; undirected edges allow travel in both directions.

9
New cards

Adjacency List

Stores each vertex's neighbors. Space: O(V+E)

10
New cards

Adjacency Matrix

A V x V matrix indicating whether edges exist. Space: O(V2); edge lookup: O(1)

11
New cards

Breadth-First Search (BFS)

Explores vertices level by level using a queue. Finds shortest paths in unweighted graphs.

12
New cards

Depth-First Search (DFS)

Explores as deeply as possible before backtracking. Uses recursion or a stack.

13
New cards

BFS and DFS Runtime

Both take O(V+E) time using adjacency lists.

14
New cards

BFS vs. DFS

BFS uses a queue and explores by level; DFS uses a stack or recursion and explores by depth.

15
New cards

BFS Shortest Path

BFS finds the shortest path by number of edges in an unweighted graph.

16
New cards

Connected Component

A maximal group of vertices where every pair is connected by a path in an undirected graph.

17
New cards

Bipartite Graph

A graph whose vertices can be divided into two sets with no edges within either set. Can be tested using BFS two-coloring.

18
New cards

Cycle Detection

Finding a path that returns to its starting vertex. DFS can detect cycles.

19
New cards

Topological Sort

A linear ordering of vertices in a DAG where every directed edge u → v places before u.

20
New cards

Directed Acyclic Graph (DAG)

A directed graph containing no directed cycles.

21
New cards

DFS Edge Classification

Tree edges discover new vertices; back edges lead to ancestors; forward edges lead to descendants; cross edges connect other DFS branches (in directed graphs).

22
New cards

DFS Entry and Exit Times

Entry time records when DFS discovers a vertex; exit time records when DFS finishes exploring it.

23
New cards

Articulation Vertex

A vertex whose removal increases the number of connected components in an undirected graph.

24
New cards

BFS and DFS Traversal Order

BFS visits vertices by distance from the start; DFS visits deeply before backtracking. Exact order depends on neighbor ordering.

25
New cards

Adjacency list edge lookup

O(deg(v))

26
New cards

Topological sort runtime

O (V + E)

27
New cards

Adjacency matrix edge lookup

O(1)

28
New cards

Connected components runtime

O (V + E)

29
New cards
30
New cards

Weighted Graph

graph in which each edge has a numerical weight representing cost, distance, or another quantity.

31
New cards

Minimum Spanning Tree (MST)

A spanning tree that connects every vertex in a connected, undirected, weighted graph with the minimum possible total edge weight.

32
New cards

Prim's Algorithm

A greedy algorithm that constructs an MST by starting at one vertex and repeatedly adding the minimum-weight edge connecting the current tree to a vertex outside it.

33
New cards

Kruskal's Algorithm

A greedy algorithm that constructs an MST by considering edges in increasing order of weight and adding them unless they create a cycle.


34
New cards

Union-Find (Disjoint Set)

A data structure that maintains disjoint sets using Find to identify a set and Union to combine two sets. Used in Kruskal's algorithm to detect cycles.

35
New cards

Dijkstra's Algorithm

An algorithm that finds the shortest paths from a single source vertex to every reachable vertex in a weighted graph with nonnegative edge weights.


36
New cards

Edge Relaxation

The process of updating the shortest known distance to a vertex when a shorter path is discovered through another vertex.


37
New cards

Maximum Flow

The greatest amount of flow that can travel from a source to a sink in a network without violating edge capacities or flow conservation.

38
New cards

MST vs. Shortest-Path Tree

An MST minimizes the total weight of all selected edges, while a shortest-path tree minimizes the distance from a particular source to every other reachable vertex.

39
New cards

Is an MST path always a shortest path?

No. An MST minimizes the total weight of the tree, not the shortest distance between individual vertices.

40
New cards

How many edges does an MST contain?

An MST always contains V-1 edges, where V is the number of vertices.

41
New cards

When is an MST guaranteed to be unique?

When every edge has a distinct weight, the MST is guaranteed to be unique.

42
New cards

Can a graph have multiple MSTs?

Yes. Different spanning trees can have the same minimum total weight, especially when edges have equal weights.

43
New cards

Maximum Spanning Tree

A spanning tree that connects every vertex while maximizing the total sum of its edge weights.

44
New cards

Adding a Constant to Every Edge Weight

Adding the same constant to every edge does not change which spanning trees are minimum because every spanning tree contains exactly V-1 edges. However, shortest paths may change.

45
New cards

Cut Property

For any cut in a connected weighted graph, a minimum-weight edge crossing that cut belongs to at least one MST.

46
New cards

Cycle Property

If an edge is strictly heavier than every other edge in a cycle, that edge cannot belong to any MST.

47
New cards

Augmenting Path

A path from the source to the sink in a residual graph along which additional flow can be sent.

48
New cards

Max-Flow Min-Cut Theorem

The maximum possible flow from a source to a sink equals the minimum capacity of any cut separating the source from the sink.

49
New cards

Prim's Algo Runtime (binary heap + adjacency list)

O(E log V)

50
New cards

Prim's (adjacency matrix)

O(V2)

51
New cards

Backtracking

A recursive search algorithm that builds a solution one step at a time and returns to earlier decisions to explore alternative choices.

52
New cards

Pruning

Eliminating branches of a search tree that cannot lead to a valid or better solution, reducing unnecessary computation.

53
New cards

State-Space Tree

A tree representing possible decisions, where each node is a partial solution and each branch represents a choice.

54
New cards

Exhaustive Search vs. Backtracking

Exhaustive search considers all possible solutions, while backtracking can avoid exploring branches that cannot produce valid solutions.

55
New cards

construct_candidates()

A function in Skiena's backtracking framework that generates the possible choices for extending the current partial solution.

56
New cards

Permutations vs. Subsets

Permutations are arrangements where order matters (n! possibilities). Subsets are selections where order does not matter 2n possibilities.

57
New cards

Heuristic Algorithm

An algorithm that uses practical strategies to find good solutions efficiently without necessarily guaranteeing an optimal solution.

58
New cards

Local Search

An optimization method that starts with a candidate solution and repeatedly explores neighboring solutions to improve its quality.

59
New cards

Hill Climbing

A local search algorithm that repeatedly moves to a better neighboring solution until no improving move is available.

60
New cards

Local Optimum vs. Global Optimum

A local optimum is best among nearby solutions, while a global optimum is the best across the entire search space.

61
New cards

Simulated Annealing

A randomized optimization algorithm that sometimes accepts worse solutions to escape local optima, gradually reducing this behavior as temperature decreases.

62
New cards

Cooling Schedule

A rule controlling how temperature decreases during simulated annealing, making the algorithm less likely to accept worse solutions over time

63
New cards

How many subsets and permutations exist for n distinct elements?

Subsets = 2n; permutations = n!. For n=4, there are 16 subsets and 24 permutations.

64
New cards

How does backtracking solve the N-Queens problem?

Place queens one row at a time, rejecting placements that share a column or diagonal with previously placed queens. Backtrack when no valid placement remains.

65
New cards

Why can simulated annealing escape local optima while hill climbing cannot?

Simulated annealing can accept worse moves, allowing it to escape local optima. Standard hill climbing only accepts improving moves.

66
New cards

Generate subset choices

O(2n)

67
New cards

Generate permutation choices

O(n!)

68
New cards

Backtracking

Often exponetial or factorial

69
New cards

Binary search tree exploration (depth n) runtime

O(2n)

70
New cards

Brute-force TSP runtime

O(n!) tours

71
New cards

Simulated annealing runtime

Depends on iterations and move cost

72
New cards

Dynamic Programming (DP)

An algorithmic technique that solves overlapping subproblems once and stores their answers to avoid repeated calculations.

73
New cards

Optimal Substructure

A property where an optimal solution can be constructed from optimal solutions to smaller subproblems.

74
New cards

Overlapping Subproblems

When the same smaller problems are solved repeatedly during computation.

75
New cards

Memoization vs. Tabulation

Memoization uses top-down recursion and caching; tabulation uses bottom-up table filling.

76
New cards

Dynamic Programming vs. Greedy

DP evaluates multiple choices using stored results, while greedy chooses the locally best option at each step.

77
New cards

Recurrence Relation

An equation that defines a problem's solution using solutions to smaller subproblems.


78
New cards

Dynamic Programming vs. Divide and Conquer

DP reuses overlapping subproblems, while divide and conquer typically solves independent subproblems.

79
New cards

Base Case

The simplest subproblem with an already-known answer.

80
New cards

Edit Distance

The minimum number of insertions, deletions, and substitutions needed to transform one string into another.

81
New cards

Longest Common Subsequence (LCS)

The longest sequence appearing in two strings in the same order, but not necessarily consecutively.

82
New cards

Longest Increasing Subsequence (LIS)

The longest subsequence of numbers in strictly increasing order.

83
New cards

Partition Problem

Dividing a sequence or set into groups to satisfy an objective, such as balancing their sums.

84
New cards

Fibonacci Runtime — Recursive vs. DP

Naive recursion: O(2n). Dynamic programming: O(n).

85
New cards

Edit Distance and LCS Runtime

Both take O(mn) time for strings of lengths m and n.

86
New cards

Longest Increasing Subsequence Runtime

Basic DP: O(n2). Optimized algorithm: O(n log n).

87
New cards

Edit Distance

Find the edit distance between "cat" and "cut". Answer: 1 substitution.

88
New cards

Practice — LCS

Find the LCS length of "ABCD" and "ACBD". Answer: 3.

89
New cards

Practice — LIS

Find the LIS length of [3,1,4,2,5]. Answer: 3.

90
New cards

DP Runtime

An algorithm fills an n x n table with O(n) work per cell. Runtime:O(n3).

91
New cards

Recursion

A function that calls itself to solve smaller versions of a problem.

92
New cards

Recursive Base Case vs. Recursive Case

The base case stops recursion; the recursive case calls the function on a smaller problem.

93
New cards

When Master Theorem Cannot Be Used

When the recurrence doesn't satisfy its required form or assumptions, such as unequal subproblem sizes.

94
New cards

Direct Proof

Start with known facts and logically derive the conclusion.

95
New cards

Proof by Contradiction

Assume the statement is false and show that this leads to a contradiction.

96
New cards

Proof by Contrapositive

To Prove P → Q, prove ~Q→~P

97
New cards

Proof by Induction

Prove a base case, then show that if the statement holds for k, it also holds for k+1

98
New cards

Inductive Hypothesis

The assumption that the statement is true for k, used to prove it for k+1

99
New cards

Loop Invariant

A property that remains true before and after every iteration and helps prove algorithm correctness.

100
New cards

Walk vs. Trail vs. Path

A walk can repeat vertices and edges; a trail cannot repeat edges; a path cannot repeat vertices.