CMSC 204 REVIEWER (FROM Google Classroom)
CMSC 204 REVIEWER (FROM Google Classroom)
Output - An algorithm produces at least one • Hashing algorithm - Hashing algorithms work
output. similarly to the searching algorithm. But they
contain an index with a key ID. In hashing, a key
Definiteness - All instructions in an algorithm
is assigned to specific data.
must be unambiguous, precise, and easy to
interpret. • Divide and Conquer Algorithm -This
algorithm breaks a problem into sub-
Finiteness - An algorithm must terminate after
problems, solves a single sub-problem, and
a finite number of steps in all test cases.
merges the solutions to get the final solution.
Effectiveness - An algorithm must be It consists of the following steps;
developed by using very basic, simple, and
• Divide
feasible operations so that one can trace it out
• Solve
by using just paper and pencil.
• Conquer
Types of algorithms
Space Complexity
• Solutions:
9. Coding an Algorithm
• Challenges:
• Opportunities:
• •
CSMC 204 REVIEWER
• Time Complexity:
• Applications: Computational
geometry, clustering, database
CSMC 204 REVIEWER
Convex-Hull Problem
Key Takeaways
• Finds the smallest convex polygon
• Closest Pair: Brute-force checks all
enclosing all points in a set.
pairs (O(n²)).
• Applications: Collision detection,
• Convex Hull: Checks all pairs and
path planning, accessibility maps, and
validates the remaining points (O(n³)).
outlier detection.
• These algorithms are inefficient for
Convex Set Definition
large datasets, making optimized
• A set is convex if, for any two points p methods (e.g., divide-and-conquer,
and q, the entire segment pq lies Graham scan) preferable.
within the set.
queue.enqueue(neighbor)
CSMC 204 REVIEWER
ASSIGNMENT PROBLEM
OPTIMIZATION PROBLEMS
Problem Definition
Knapsack Problem
• Assign nn workers to nn jobs where:
• Problem Statement: Given nn items
o Each worker has a different
with:
cost for each job (given in a
o Weights: w1,w2,...,wnw_1, cost matrix C[i,j]C[i,j]).
w_2, ..., w_n
o Each worker must be assigned
o Values: v1,v2,...,vnv_1, v_2, ..., exactly one job.
v_n
o The goal is to minimize the
o A knapsack of capacity WW, total assignment cost.
find the most valuable subset
Brute-Force Solution
such that: ∑wj≤W\sum w_j \leq
W • Generate all permutations of n!n!
possible assignments.
• Types of Knapsack Problems:
• Compute the cost for each
o 0/1 Knapsack: Each item can
permutation.
either be taken completely or
not at all. • Select the assignment with the
minimum cost.
o Fractional Knapsack: Items
can be divided into smaller
CSMC 204 REVIEWER
Optimized Approach
Exhaustive Search
Problem
Complexity
Traveling Salesman
O(n!)O(n!)
(TSP)
Assignment
O(n!)O(n!)
Problem
Takeaways