Unit 4
Unit 4
B.TECH V SEM
BY:
Somya Agrawal
Assistant Professor ,CSE
SN Contents Hours
1 Introduction: Objective, scope and outcome of the course. 1
Background: Review of Algorithm, Complexity Order Notations: definitions and calculating complexity.
2 6
Divide And Conquer Method: Binary Search, Merge Sort, Quick sort and Strassen's matrix multiplication algorithms.
Greedy Method: Knapsack Problem, Job Sequencing, Optimal Merge Patterns and Minimal Spanning Trees.
3 10
Dynamic Programming: Matrix Chain Multiplication. Longest CommonSubsequence and 0/1 Knapsack Problem.
Branch And Bound: Traveling Salesman Problem and Lower Bound Theory. Backtracking Algorithms and queens problem.
4 8
Pattern Matching Algorithms: Naïve and Rabin Karp string matching algorithms, KMP Matcher and Boyer Moore Algorithms.
Problem Classes Np, Np-Hard And Np-Complete: Definitions of P, NP-Hard and NP-Complete Problems. Decision Problems.
6 Cook's Theorem. Proving NP-Complete Problems - Satisfiability problem and Vertex Cover Problem. Approximation 8
Algorithms for Vertex Cover and Set Cover Problem.
Branch And Bound: Traveling Salesman Problem and Lower Bound Theory. Backtracking
Algorithms and queens problem. Pattern Matching Algorithms: Naïve and Rabin Karp string
matching algorithms, KMP Matcher and Boyer Moore Algorithms.
• It may be noted that with n facilities and n jobs, there are n! possible assignments.
One way of finding an optimal assignment is to write all the n! possible arrangements, evaluate their total cost, and select the
assignment with minimum cost. But, due to heavy computational burden, this method is not suitable.
This chapter concentrates on an efficient method for solving assignment problems that was developed by a Hungarian
mathematician, D. Konig.
• When each source (resource facility) can be associated with one and only one job/destination (One
job to one machine)
Determinstic Algorithms
• In flow shop, m different machines should process n jobs. Each job contains exactly n operations.
The ith operation of the job must be executed on the ith machine. Operations within one job must be
performed in the specified order.
• The first operation gets executed on the first machine, then the second operation on the second
machine, and so on. Jobs can be executed in any order. The problem is to determine the optimal
such arrangement, i.e. the one with the shortest possible total job execution makespan.
• With two machines, problem can be solved in O(nlogn) time using Johnson’s algorithm. For more
than 2 machines, the problem is NP hard. The goal is to minimize the sum of completion time of
all jobs.
Somya Agrawal ,Assistant Professor ,CSE 27
• The flow shop contains n jobs simultaneously available at time zero and to be processed by two
machines arranged in series with unlimited storage in between them. The processing time of all
jobs are known with certainty.
• It is required to schedule n jobs on machines so as to minimize makespan. The Johnson’s rule for
scheduling jobs in two machine flow shop is given below: In an optimal schedule, job i precedes
job j if min{pi1,pj2} < min{pj1,pi2}. Where as, pi1 is the processing time of job i on machine 1 and
pi2 is the processing time of job i on machine 2. Similarly, p j1 and pj2 are processing times of job j
on machine 1 and machine 2 respectively.
• The SAT problem, k-SAT problem is the problem of examining a given CNF (or k-CNF)
expression and deciding whether or not it has a satisfying assignment.
• ▶ For the formula above, easy to see there is a satisfying assignment (any with x1 = 1, x4 = 0, x2
= 1 would do).
• ▶ The 3-SAT problem, and k-SAT for all k > 3, are all NP-complete.
• Analysis Consider an (unknown so far) satisfying assignment S ∈ {0, 1} n that makes our 2SAT
formula ϕ true (satisfies all the clauses).
• Our “measure of progress” will be the number of indices k such that xk = Sk , (x1, . . . , xn) being
the current assignment.
• We will analyse the expected number of steps before (x1, . . . , xn) becomes S.
• ▶ Note that if ϕ does not have any satisfying assignment, Algorithm 2SATRANDOM always returns
FAILED (as it should).
• ▶ Let’s first assume that the formula ϕ has some satisfying assignment.
• he Ford-Fulkerson algorithm is a widely used algorithm to solve the maximum flow problem in a
flow network. The maximum flow problem involves determining the maximum amount of flow
that can be sent from a source vertex to a sink vertex in a directed weighted graph, subject to
capacity constraints on the edges.
• The algorithm works by iteratively finding an augmenting path, which is a path from the source to
the sink in the residual graph, i.e., the graph obtained by subtracting the current flow from the
capacity of each edge. The algorithm then increases the flow along this path by the maximum
possible amount, which is the minimum capacity of the edges along the path.
Somya Agrawal ,Assistant Professor ,CSE 35
• Problem:
• Given a graph which represents a flow network where every edge has a capacity. Also, given two
vertices source 's' and sink 't' in the graph, find the maximum possible flow from s to t with the
following constraints:
• Incoming flow is equal to outgoing flow for every vertex except s and t.