Unit6 - Subjective Questions
CSE408 • Practice Questions with Detailed Answers
Define Modular Arithmetic. Explain the properties of modular addition and multiplication with examples.
Modular Arithmetic is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value, called the modulus.
Let be a positive integer. Two integers and are said to be congruent modulo , written as , if their difference is an integer multiple of .
Properties of Modular Arithmetic:
If and , then:
- Addition:
- Multiplication:
- Subtraction:
Example: Let .
- and .
- Addition: . Also, .
- Multiplication: . Also, .
Explain the concept of Modular Exponentiation. Write an algorithm to compute efficiently.
Modular Exponentiation is a type of exponentiation performed over a modulus. It is used extensively in cryptography. Computing directly by finding first is computationally infeasible for large because grows exponentially.
The efficient way is the Right-to-Left Binary Method (Repeated Squaring), which reduces the time complexity to .
Algorithm:
text
Modular_Exponentiation(a, b, n):
result = 1
a = a % n
while b > 0:
// If b is odd, multiply a with result
if (b % 2 == 1):
result = (result a) % n
// b must be even now
b = b >> 1 // Divide b by 2
a = (a a) % n // Square a
return result
This algorithm uses the property that , keeping intermediate values small.
What is a modular multiplicative inverse? Under what conditions does it exist?
Modular Multiplicative Inverse:
In modular arithmetic, the modular multiplicative inverse of an integer modulo is an integer such that:
This is analogous to the reciprocal in standard arithmetic.
Condition for Existence:
The modular multiplicative inverse of modulo exists if and only if and are coprime (i.e., their Greatest Common Divisor is 1, ).
Finding the Inverse:
If , the Extended Euclidean Algorithm can be used to find coefficients and such that:
Taking modulo on both sides yields , making the modular inverse.
State and explain the Euclidean Algorithm for finding the Greatest Common Divisor (GCD) of two numbers.
Euclidean Algorithm is an efficient method for computing the greatest common divisor (GCD) of two integers, the largest number that divides them both without a remainder.
Principle:
The algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. More efficiently, it uses the modulo operation:
with the base case .
Algorithm:
text
Euclid(a, b):
if b == 0:
return a
else:
return Euclid(b, a % b)
Example: Find
- Return 21. Thus, .
Describe the Extended Euclidean Algorithm and its significance in number-theoretic algorithms.
The Extended Euclidean Algorithm not only finds the greatest common divisor of two integers and , but also finds integers and (called Bézout coefficients) such that:
Significance:
- Modular Multiplicative Inverse: If , then . Taking modulo gives . Here, is the multiplicative inverse of modulo . This is crucial in cryptography (like RSA).
- Solving Linear Diophantine Equations: It helps solve equations of the form , which has integer solutions if and only if divides .
Algorithm Idea:
It maintains variables to compute and iteratively as it computes the sequences of remainders in the standard Euclidean algorithm, effectively working backwards or parallel to the GCD computation.
Analyze the time complexity of the Euclidean Algorithm.
Time Complexity of Euclidean Algorithm:
The time complexity is determined by the number of modulo operations performed.
Let the algorithm be computing where .
In each step, and are replaced by and .
It can be shown that after two consecutive steps, the value of the first argument is reduced to at least half of its original value. Specifically, .
Because the numbers are halved at least every two steps, the number of steps is at most .
Thus, the number of divisions is .
If we consider the bit-length of the numbers, say bits, the time complexity is divisions. If standard long division is used, each division takes bit operations, leading to an overall bit complexity of .
Worst-case scenario: The worst-case occurs when and are consecutive Fibonacci numbers, known as Lamé's Theorem.
State the Chinese Remainder Theorem (CRT).
Chinese Remainder Theorem (CRT):
The Chinese Remainder Theorem states that if one knows the remainders of the Euclidean division of an integer by several pairwise coprime integers, then one can determine uniquely the remainder of the division of by the product of these integers.
Formal Statement:
Let be pairwise coprime positive integers (i.e., for all ).
Let be any integers.
Then the system of simultaneous congruences:
has a unique solution modulo .
This means any two solutions and will satisfy .
Explain the formula used to construct the solution in the Chinese Remainder Theorem.
To construct the unique solution modulo for the system of congruences :
-
Compute the total product:
-
Compute partial products:
For each from 1 to , compute .
Notice that is the product of all moduli except . Thus, . -
Compute modular inverses:
For each , find such that .
is the modular multiplicative inverse of modulo . -
Construct the solution:
Calculate . -
Final step:
The unique solution modulo is .
This works because for any modulus , all terms in the sum where contain as a factor (since includes ) and thus become 0 modulo . The remaining term is .
Find the smallest positive integer that satisfies: , , and .
Given:
Step 1:
Step 2: Compute
Step 3: Compute inverses such that
Step 4: Compute
Step 5: Reduce modulo
So, .
The smallest positive integer is 23.
Distinguish between Optimization Problems and Decision Problems with suitable examples.
1. Optimization Problems:
An optimization problem asks for the best (maximum or minimum) solution among all feasible solutions. The output is a value or a specific configuration that achieves that value.
- Example (Traveling Salesman Problem - TSP): Given a set of cities and distances between them, find the shortest possible route that visits each city exactly once and returns to the origin city.
- Example (0/1 Knapsack): Find the combination of items that maximizes the total value without exceeding the weight capacity.
2. Decision Problems:
A decision problem is a problem that requires a simple "Yes" or "No" answer based on a specific given condition.
- Example (TSP Decision Variant): Given a set of cities, distances between them, and a limit , is there a route that visits each city exactly once and returns to the origin with a total distance less than or equal to ?
- Example (0/1 Knapsack Decision Variant): Is there a combination of items weighing at most that yields a value of at least ?
Relationship:
In complexity theory, optimization problems are often cast as decision problems because if the decision problem is hard, the optimization problem is at least as hard.
Define the complexity class P. Give examples of problems that belong to P.
Complexity Class P:
The class P (Polynomial time) consists of all decision problems that can be solved by a deterministic Turing machine in polynomial time.
In simpler terms, a problem is in P if there exists an algorithm to solve it such that the number of steps required is bounded by a polynomial function of the input size (e.g., ).
Problems in P are generally considered "tractable" or efficiently solvable.
Examples of problems in P:
- Searching: Finding an element in a sorted array (Binary Search, ).
- Sorting: Sorting an array of numbers (Merge Sort, ).
- Shortest Path: Finding the shortest path from a single source in a graph with non-negative edge weights (Dijkstra's Algorithm, polynomial time).
- Primality Testing: Determining if a number is prime (AKS primality test).
- Greatest Common Divisor: Finding the GCD of two numbers (Euclidean Algorithm).
Define the complexity class NP. How does it relate to non-deterministic algorithms?
Complexity Class NP:
NP stands for "Nondeterministic Polynomial time". It is the class of decision problems for which, if the answer is "Yes", there exists a proof (or certificate) that can be verified by a deterministic Turing machine in polynomial time.
Equivalently, NP is the set of decision problems that can be solved in polynomial time by a Non-deterministic Turing Machine (NDTM).
Relation to Non-deterministic Algorithms:
A non-deterministic algorithm operates in two stages:
- Guessing Stage (Non-deterministic): Given an instance of the problem, it "guesses" a solution (certificate). This step is purely non-deterministic.
- Verification Stage (Deterministic): It takes the guessed solution and verifies whether it is a valid solution to the problem in polynomial time.
If the verification stage returns "True" in polynomial time for at least one guess, the problem belongs to NP. Therefore, NP problems are those whose solutions are easy to check, even if they might be hard to find.
What is meant by Polynomial-Time Reduction? Explain its significance in complexity theory.
Polynomial-Time Reduction:
A polynomial-time reduction from a decision problem to a decision problem (denoted as ) is an algorithm that transforms instances of problem into instances of problem such that:
- The transformation function computes the instance of in polynomial time: .
- The answer to instance of problem is "Yes" if and only if the answer to instance of problem is "Yes".
Significance:
- Relative Hardness: If , it means problem is at least as hard as problem . If we have an efficient (polynomial) algorithm for , we can use it to solve efficiently.
- Proving NP-Completeness: Reductions are the primary tool for proving that problems are NP-complete. To prove a new problem is NP-complete, one must show that and that a known NP-complete problem reduces to in polynomial time ().
Define NP-Hard and NP-Complete complexity classes. How do they differ?
NP-Hard:
A problem is NP-hard if every problem in NP can be reduced to in polynomial time ( for all ). NP-hard problems are at least as hard as the hardest problems in NP. They do not have to be in NP themselves (e.g., they could be optimization problems or undecidable problems).
NP-Complete (NPC):
A problem is NP-complete if it satisfies two conditions:
- is in NP ().
- is NP-hard (every problem in NP reduces to in polynomial time).
NP-complete problems are the hardest problems within the class NP.
Differences:
- Membership in NP: NP-complete problems must be in NP (their solutions must be verifiable in polynomial time). NP-hard problems do not have to be in NP.
- Problem Type: NP-complete strictly refers to decision problems. NP-hard can refer to optimization problems (like the optimization version of TSP) or search problems.
- Relationship: The set of NP-Complete problems is the intersection of NP and NP-Hard.
Explain the significance of the Cook-Levin Theorem.
The Cook-Levin Theorem states that the Boolean Satisfiability Problem (SAT) is NP-complete. It was proven independently by Stephen Cook (1971) and Leonid Levin (1973).
Significance:
- First NP-Complete Problem: Before this theorem, the concept of NP-completeness existed in theory, but it was unknown if any such problem actually existed. The theorem provided the very first problem proven to be NP-complete.
- Foundation for Reductions: By proving that SAT is NP-complete, Cook and Levin provided a starting point for proving other problems are NP-complete. To prove a new problem is NP-complete, one no longer needs to reduce every problem in NP to . Instead, one only needs to reduce SAT (or another known NP-complete problem) to .
- P vs NP connection: It established that if a deterministic polynomial-time algorithm can be found for SAT, then , fundamentally shaping theoretical computer science.
What is the Satisfiability (SAT) problem? Why is it historically important in the analysis of algorithms?
The Satisfiability (SAT) Problem:
SAT is a decision problem in Boolean logic. Given a Boolean formula consisting of variables (like ), logical ANDs, ORs, and NOTs, the SAT problem asks whether there exists an assignment of truth values (True/False) to the variables that makes the entire formula evaluate to True.
Example: . Is there an assignment to that makes this True? (Yes, e.g., ).
Historical Importance:
- Cook-Levin Theorem: SAT was the very first problem proven to be NP-complete.
- Benchmark for Hardness: It serves as the root of the NP-completeness tree. Thousands of problems in various domains (graph theory, scheduling, game theory) have been proven NP-complete by demonstrating a polynomial-time reduction from SAT (or 3-SAT) to the target problem.
- Practical Solvers: Despite being NP-complete, modern SAT solvers use advanced heuristics to solve massive real-world instances efficiently, making SAT practically important in hardware verification and AI.
Describe the P vs NP problem. Why is it considered one of the most important open problems in computer science?
The P vs NP Problem:
The P vs NP problem asks whether every problem whose solution can be quickly verified by a computer can also be quickly solved by a computer.
- P is the class of problems that can be solved in polynomial time.
- NP is the class of problems whose solutions can be verified in polynomial time.
The question is whether . Since is trivially true, the real question is whether .
Why it is important:
- Fundamental limit of computation: It addresses the absolute limits of what computers can do efficiently. If , it means that for any problem where a solution is easily checkable, there is an efficient way to find that solution.
- Impact on Cryptography: Modern cryptography (like RSA) relies on the assumption that (specifically, that factoring large numbers or discrete logs are hard). If , public-key cryptography would break.
- Everyday Optimization: Many real-world problems in logistics, scheduling, manufacturing, and AI are NP-complete. A proof that (with a constructive algorithm) would revolutionize how the world optimizes resources.
Explain the Traveling Salesman Problem (TSP). Formulate both its optimization and decision versions.
Traveling Salesman Problem (TSP):
TSP is a classic algorithmic problem focused on optimization. Given a list of cities and the distances between each pair of cities, a salesperson must find the shortest possible route that visits each city exactly once and returns to the origin city.
1. Optimization Version:
- Input: A complete weighted graph where is a set of vertices (cities) and is a set of edges with non-negative weights (distances).
- Output: A Hamiltonian cycle (a cycle that visits every vertex exactly once) such that the sum of the edge weights of the cycle is minimized.
- Complexity: This version is NP-hard.
2. Decision Version:
- Input: A complete weighted graph , and a threshold value .
- Output: "Yes" if there exists a Hamiltonian cycle in with a total weight . "No" otherwise.
- Complexity: This version is NP-complete. If we guess a path, we can verify in polynomial time if it is a valid Hamiltonian cycle and if its total weight is .
What is the Clique Problem? Show that the Clique decision problem is in NP.
The Clique Problem:
In graph theory, a clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent (i.e., its induced subgraph is complete).
The Clique Decision Problem asks: Given an undirected graph and an integer , does contain a clique of size at least ?
Showing Clique is in NP:
To show a problem is in NP, we must show that a proposed solution (certificate) can be verified in polynomial time.
- Certificate: The certificate is a subset of vertices such that .
- Verification Algorithm:
- Check if the number of vertices in is exactly . This takes if the size is known, or to count.
- Check if every pair of vertices has an edge in . There are pairs to check.
- For each pair, checking adjacency takes in an adjacency matrix or in an adjacency list.
- Time Complexity: The verification process takes at most time. Since , the verification takes time, which is polynomial relative to the input size.
Since a valid certificate can be verified in polynomial time, the Clique problem is in NP.
Define the Vertex Cover problem. How does it relate to the Clique problem?
Vertex Cover Problem:
A vertex cover of an undirected graph is a subset of vertices such that for every edge , at least one of or is in .
The decision problem asks: Given a graph and an integer , does have a vertex cover of size at most ?
Relation to the Clique Problem:
The Vertex Cover problem is closely related to the Clique problem through the concept of a complement graph. The complement of a graph is , where if and only if .
The fundamental relationship is:
A subset is a clique in if and only if is a vertex cover in .
Proof sketch:
If is a clique in , then there are no edges between vertices of in the complement graph . Therefore, any edge in must have at least one endpoint in . This exactly means is a vertex cover for .
This exact relationship provides a simple polynomial-time reduction between Clique and Vertex Cover, proving that since Clique is NP-complete, Vertex Cover is also NP-complete.