0% found this document useful (0 votes)
87 views17 pages

DAA Lab Manual Answers

Uploaded by

goturi sohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views17 pages

DAA Lab Manual Answers

Uploaded by

goturi sohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Course Code: Course Title:

L T P O Total
22CSE304 Design & Analysis of Algorithms
Credits
Lab Manual 2 1 2 0 4

Objectives
This course aims to provide the knowledge and understanding of the complexity issues of algorithms:
1. To introduce algorithms analysis and design techniques
2. To understand and design algorithms used for searching, sorting, and indexing operation

Outcomes
CLO 1: Analyzing complexity issues of algorithms
CLO 2: Ability to use the appropriate algorithm for searching, sorting, and indexing operations
CLO 3: Designing of new algorithms
CLO4: Students will be able to learn NP Class problems
Reference Materials
Textbooks (T) T1 T.H. Cormen, C.E. Leiserson, R.L. Rivest and C. Stein, “Introduction to Algorithms”,
Per availability in the library PHI Pvt. Ltd., 2012.
T2 Anany Levitin, “Introduction to the Design and Analysis of Algorithm”, Pearson
Education Asia, 2003.
T3 M.T.Goodrich and R.Tomassia, Algorithm Design: Foundations, Analysis and Internet
examples, Johnwiley and sons.
R1 R.C.T.Lee, S.S.Tseng, R.C.Chang and T.Tsai, Introduction to Design and Analysis of
Reference Books (R) Algorithms A strategic approach, McGraw-Hill Education (Asia) ,2005
R2 Aho, Ullman and Hopcroft, Design and Analysis of algorithms, Pearson Education India;
1st edition 2002
R3 Ellis Horowitz, Satraj Sahni and Rajasekharam, Fundamentals of Computer Algorithms,
Galgotia publications pvt. Ltd.
Journal Articles (J) J1 NA
provide link only
Case Material/ C1 NA
Whitepaper
provide link only
Any Other Sources O NA
Modules
Experiment Topics Total Contact CLO Mapping
No. Hours
UNIT-1
1. Write a program to implement the following algorithm using an 2
array as a data structure and analyse its time complexity.
a. Bubble sort,
def bubble_sort(arr):
n = len(arr)
for i in range(n):
swapped = False CLO1
for j in range(n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
swapped = True
if not swapped:
break
# Example usage:
my_array = [64, 34, 25, 12, 22, 11, 90]
bubble_sort(my_array)
print("Sorted array using Bubble Sort:", my_array)

b. Selection sort
def selection_sort(arr):
n = len(arr)
for i in range(n):
min_index = i
for j in range(i + 1, n):
if arr[j] < arr[min_index]:
min_index = j
arr[i], arr[min_index] = arr[min_index], arr[i]

# Example usage:
my_array = [64, 34, 25, 12, 22, 11, 90]
selection_sort(my_array)
print("Sorted array using Selection Sort:", my_array)

c. Insertion sort
def insertion_sort(arr):
n = len(arr)
for i in range(1, n):
key = arr[i]
j=i-1
while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key

# Example usage:
my_array = [64, 34, 25, 12, 22, 11, 90]
insertion_sort(my_array)
print("Sorted array using Insertion Sort:", my_array)

2. Write a program to implement Linear search and Binary search and 2 CLO1
analyze its time complexity. (Recursive/ non-recursive)

a. Linear Search (Non-Recursive)


def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1

# Example usage:
my_array = [12, 114, 0, 4, 9]
target_value = 4
result = linear_search(my_array, target_value)
if result != -1:
print(f"Element found at index: {result}")
else:
print("Element not found")
b. Binary Search (Non-Recursive)
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = low + (high - low) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1

# Example usage:
sorted_array = [0, 4, 9, 12, 114]
target_value = 4
result = binary_search(sorted_array, target_value)
if result != -1:
print(f"Element found at index: {result}")
else:
print("Element not found")

3. Write a program to implement the following algorithm using an 2 CLO2


array as a data structure and analyze its time complexity.
a. Merge Sort
def merge(arr, l, m, r):
n1 = m - l + 1
n2 = r - m
L = arr[l : l + n1]
R = arr[m + 1 : m + 1 + n2]

i, j, k = 0, 0, l
while i < n1 and j < n2:
if L[i] <= R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
k += 1

while i < n1:


arr[k] = L[i]
i += 1
k += 1

while j < n2:


arr[k] = R[j]
j += 1
k += 1

def mergeSort(arr, l, r):


if l < r:
m = l + (r - l) // 2
mergeSort(arr, l, m)
mergeSort(arr, m + 1, r)
merge(arr, l, m, r)
# Example usage:
my_array = [12, 11, 13, 5, 6, 7]
mergeSort(my_array, 0, len(my_array) - 1)
print("Sorted array using Merge Sort:", my_array)

b. Quick Sort
def partition(arr, low, high):
pivot = arr[high]
i = low - 1

for j in range(low, high):


if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]

arr[i + 1], arr[high] = arr[high], arr[i + 1]


return i + 1

def quickSort(arr, low, high):


if low < high:
pi = partition(arr, low, high)
quickSort(arr, low, pi - 1)
quickSort(arr, pi + 1, high)

# Example usage:
my_array = [12, 11, 13, 5, 6, 7]
quickSort(my_array, 0, len(my_array) - 1)
print("Sorted array using Quick Sort:", my_array)

c. Heap Sort
def heapify(arr, n, i):
largest = i
left = 2 * i + 1
right = 2 * i + 2

if left < n and arr[i] < arr[left]:


largest = left

if right < n and arr[largest] < arr[right]:


largest = right

if largest != i:
arr[i], arr[largest] = arr[largest], arr[i]
heapify(arr, n, largest)

def heapSort(arr):
n = len(arr)
for i in range(n // 2, -1, -1):
heapify(arr, n, i)

for i in range(n - 1, 0, -1):


arr[i], arr[0] = arr[0], arr[i]
heapify(arr, i, 0)

# Example usage:
my_array = [12, 11, 13, 5, 6, 7]
heapSort(my_array)
print("Sorted array using Heap Sort:", my_array)

4. 1. Write a program for the Implementation of Red-Black Tree 2 CLO2


operations.
import enum

class Color(enum.Enum):
RED = enum.auto()
BLACK = enum.auto()

class RBNode:
def __init__(self, key):
self.color = Color.RED # New nodes are always red
self.key = key
self.leftChild = None
self.rightChild = None
self.parent = None

# Example usage:
root = RBNode(10)
root.color = Color.BLACK # Root is always black

2. Write a program for implementing AVL tree and its


operations.
class AVLNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
self.height = 1

class AVLTree:
def __init__(self):
self.root = None

def insert(self, root, key):


if not root:
return AVLNode(key)
if key < root.key:
root.left = self.insert(root.left, key)
else:
root.right = self.insert(root.right, key)

root.height = 1 + max(self._get_height(root.left),
self._get_height(root.right))
balance = self._get_balance(root)

# Perform rotations to maintain balance


if balance > 1:
if key < root.left.key:
return self._right_rotate(root)
else:
root.left = self._left_rotate(root.left)
return self._right_rotate(root)
if balance < -1:
if key > root.right.key:
return self._left_rotate(root)
else:
root.right = self._right_rotate(root.right)
return self._left_rotate(root)
return root

def _get_height(self, node):


return node.height if node else 0

def _get_balance(self, node):


return self._get_height(node.left) -
self._get_height(node.right)

def _left_rotate(self, z):


y = z.right
T2 = y.left

y.left = z
z.right = T2

z.height = 1 + max(self._get_height(z.left),
self._get_height(z.right))
y.height = 1 + max(self._get_height(y.left),
self._get_height(y.right))

return y

def _right_rotate(self, y):


z = y.left
T3 = z.right

z.right = y
y.left = T3

y.height = 1 + max(self._get_height(y.left),
self._get_height(y.right))
z.height = 1 + max(self._get_height(z.left),
self._get_height(z.right))

return z

# Example usage:
avl_tree = AVLTree()
avl_tree.root = avl_tree.insert(avl_tree.root, 10)
avl_tree.root = avl_tree.insert(avl_tree.root, 20)
avl_tree.root = avl_tree.insert(avl_tree.root, 30)

# Continue inserting more nodes as needed


5. Write programs (Greedy Algorithms) 2 CLO3
a. To implement the Knapsack Problem.
def knapSack(W, wt, val, n):
if n == 0 or W == 0:
return 0
if wt[n - 1] > W:
return knapSack(W, wt, val, n - 1)
else:
return max(
val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1),
knapSack(W, wt, val, n - 1)
)

# Example usage:
profit = [60, 100, 120]
weight = [10, 20, 30]
W = 50
print(knapSack(W, weight, profit, len(profit)))

b. To implement the Activity Selection Problem.


def printMaxActivities(s, f):
n = len(f)
i=0
print(i, end=" ")
for j in range(n):
if s[j] >= f[i]:
print(j, end=" ")
i=j

# Example usage:
start = [1, 3, 0, 5, 8, 5]
finish = [2, 4, 6, 7, 9, 9]
print("The following activities are selected:")
printMaxActivities(start, finish)

c. To implement Huffman Coding and analyze its time


complexity.
import heapq

class Node:
def __init__(self, symbol=None, frequency=None):
self.symbol = symbol
self.frequency = frequency
self.left = None
self.right = None

def __lt__(self, other):


return self.frequency < other.frequency

def build_huffman_tree(chars, freq):


priority_queue = [Node(char, f) for char, f in zip(chars, freq)]
heapq.heapify(priority_queue)

while len(priority_queue) > 1:


left_child = heapq.heappop(priority_queue)
right_child = heapq.heappop(priority_queue)
merged_node = Node(frequency=left_child.frequency +
right_child.frequency)
merged_node.left = left_child
merged_node.right = right_child
heapq.heappush(priority_queue, merged_node)

return priority_queue[0]

def generate_huffman_codes(node, code="",


huffman_codes={}):
if node is not None:
if node.symbol is not None:
huffman_codes[node.symbol] = code
generate_huffman_codes(node.left, code + "0",
huffman_codes)
generate_huffman_codes(node.right, code + "1",
huffman_codes)
return huffman_codes

d. To implement Task Scheduling Problem.


def intervalScheduling(tasks):
tasks.sort(key=lambda x: x[1]) # Sort by end time
count = 0
prev_end = float('-inf')
selected_tasks = []

for start, end in tasks:


if start >= prev_end:
count += 1
selected_tasks.append((start, end))
prev_end = end

print(f"Maximum non-overlapping tasks: {count}")


print("Selected tasks:", selected_tasks)

# Example usage:
tasks = [(1, 3), (2, 5), (4, 6), (5, 7), (7, 8)]
intervalScheduling(tasks)
6. Write programs (Single Source Shortest Path in Graph) 2 CLO3
a. To implement Dijkstra’s Algorithm.

import heapq

class Graph:
def __init__(self, vertices):
self.V = vertices
self.graph = [[] for _ in range(vertices)]

def add_edge(self, u, v, w):


self.graph[u].append((v, w))
self.graph[v].append((u, w))

def dijkstra(self, src):


pq = [] # Priority queue to store vertices being processed
dist = [float('inf')] * self.V
dist[src] = 0

heapq.heappush(pq, (0, src))

while pq:
d, u = heapq.heappop(pq)

for v, weight in self.graph[u]:


if dist[v] > dist[u] + weight:
dist[v] = dist[u] + weight
heapq.heappush(pq, (dist[v], v))
return dist

# Example usage:
g = Graph(5)
g.add_edge(0, 1, 2)
g.add_edge(0, 2, 3)
g.add_edge(1, 2, 1)
g.add_edge(1, 3, 4)
g.add_edge(2, 4, 5)

src_vertex = 0
shortest_distances = g.dijkstra(src_vertex)
print(f"Shortest distances from vertex {src_vertex}:
{shortest_distances}")
b. To Implement Bellman-ford Algorithm
class Graph:
def __init__(self, vertices):
self.V = vertices
self.graph = []

def add_edge(self, u, v, w):


self.graph.append((u, v, w))

def bellman_ford(self, src):


dist = [float('inf')] * self.V
dist[src] = 0

for _ in range(self.V - 1):


for u, v, weight in self.graph:
if dist[u] != float('inf') and dist[u] + weight < dist[v]:
dist[v] = dist[u] + weight

# Check for negative weight cycles


for u, v, weight in self.graph:
if dist[u] != float('inf') and dist[u] + weight < dist[v]:
print("Graph contains negative weight cycle")
return

return dist

# Example usage:
g = Graph(5)
g.add_edge(0, 1, 2)
g.add_edge(0, 2, 3)
g.add_edge(1, 2, 1)
g.add_edge(1, 3, 4)
g.add_edge(2, 4, 5)

src_vertex = 0
shortest_distances = g.bellman_ford(src_vertex)
print(f"Shortest distances from vertex {src_vertex}:
{shortest_distances}")
7. Write programs (Minimum Spanning Tree) 2 CLO3
a. To implement Prim’s Algorithm.
class Graph:
def __init__(self, vertices):
self.V = vertices
self.graph = []

def add_edge(self, u, v, w):


self.graph.append((u, v, w))

def prim_mst(self):
pq = [] # Priority queue to store vertices being processed
src = 0 # Starting vertex (can be any)

# Create a list for keys and initialize all keys as infinite


key = [float('inf')] * self.V
key[src] = 0

# To keep track of vertices included in MST


in_mst = [False] * self.V

# Insert source itself into the priority queue


heapq.heappush(pq, (0, src))

while pq:
u = heapq.heappop(pq)[1]
in_mst[u] = True

for v, weight in self.graph:


if not in_mst[v] and weight < key[v]:
key[v] = weight
heapq.heappush(pq, (key[v], v))

# Print edges of MST


for i in range(1, self.V):
print(f"{i} - {key[i]}")

# Example usage:
g = Graph(5)
g.add_edge(0, 1, 2)
g.add_edge(0, 2, 3)
g.add_edge(1, 2, 1)
g.add_edge(1, 3, 4)
g.add_edge(2, 4, 5)
g.prim_mst()

b. To implement Kruskal’s Algorithm.


class Graph:
def __init__(self, vertices):
self.V = vertices
self.graph = []

def add_edge(self, u, v, w):


self.graph.append((u, v, w))

def find(self, parent, i):


if parent[i] != i:
parent[i] = self.find(parent, parent[i])
return parent[i]

def union(self, parent, rank, x, y):


if rank[x] < rank[y]:
parent[x] = y
elif rank[x] > rank[y]:
parent[y] = x
else:
parent[y] = x
rank[x] += 1

def kruskal_mst(self):
result = []
self.graph.sort(key=lambda item: item[2])
parent = [i for i in range(self.V)]
rank = [0] * self.V

for u, v, weight in self.graph:


x = self.find(parent, u)
y = self.find(parent, v)
if x != y:
result.append((u, v, weight))
self.union(parent, rank, x, y)

for u, v, weight in result:


print(f"{u} - {v} : {weight}")

# Example usage:
g = Graph(4)
g.add_edge(0, 1, 10)
g.add_edge(0, 2, 6)
g.add_edge(0, 3, 5)
g.add_edge(1, 3, 15)
g.add_edge(2, 3, 4)
g.kruskal_mst()

8. Write programs (Dynamic Programming) 2 CLO3


a. To Implement Matrix Chain Multiplication.
def matrix_chain_multiplication(matrices):
n = len(matrices)
# Create a table to store intermediate results
dp = [[float('inf')] * n for _ in range(n)]

# Base case: single matrix has zero cost


for i in range(n):
dp[i][i] = 0

# Chain length varies from 2 to n


for chain_len in range(2, n):
for i in range(n - chain_len + 1):
j = i + chain_len - 1
for k in range(i, j):
cost = dp[i][k] + dp[k + 1][j] + matrices[i][0] *
matrices[k][1] * matrices[j][1]
dp[i][j] = min(dp[i][j], cost)

return dp[0][n - 1]

# Example usage:
matrices = [(10, 20), (20, 30), (30, 40), (40, 30)]
min_scalar_multiplications =
matrix_chain_multiplication(matrices)
print(f"Minimum scalar multiplications:
{min_scalar_multiplications}")

b. To Implement the Largest Common Subsequence.


def longest_common_subsequence(X, Y):
m, n = len(X), len(Y)
# Initialize a table to store LCS lengths
dp = [[0] * (n + 1) for _ in range(m + 1)]

# Fill the table using dynamic programming


for i in range(1, m + 1):
for j in range(1, n + 1):
if X[i - 1] == Y[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])

# Backtrack to find the LCS


lcs = []
i, j = m, n
while i > 0 and j > 0:
if X[i - 1] == Y[j - 1]:
lcs.append(X[i - 1])
i -= 1
j -= 1
elif dp[i - 1][j] > dp[i][j - 1]:
i -= 1
else:
j -= 1

return ''.join(reversed(lcs))

# Example usage:
X = "AGGTAB"
Y = "GXTXAYB"
print("Longest Common Subsequence:",
longest_common_subsequence(X, Y))
9. a. Write a program to implement a backtracking 2 CLO4
algorithm for the N-queens problem.
def is_safe(board, row, col):
# Check if no queen attacks in the same column
for i in range(row):
if board[i][col] == 1:
return False

# Check upper left diagonal


for i, j in zip(range(row, -1, -1), range(col, -1, -1)):
if board[i][j] == 1:
return False

# Check upper right diagonal


for i, j in zip(range(row, -1, -1), range(col, 8)):
if board[i][j] == 1:
return False
return True

def solve_queens(board, row):


if row == 8:
# Print the solution
for i in range(8):
print(board[i])
print()
return

for col in range(8):


if is_safe(board, row, col):
board[row][col] = 1
solve_queens(board, row + 1)
board[row][col] = 0

# Initialize an empty 8x8 chessboard


chessboard = [[0] * 8 for _ in range(8)]

# Solve the 8-Queens problem


solve_queens(chessboard, 0)

b. Write a program to solve the Sum of subsets problem


for a given set of distinct numbers.
def subsetSumMemo(arr, n, target_sum, memo):
if target_sum == 0:
return True
if n == 0:
return False
if memo[n][target_sum] != -1:
return memo[n][target_sum]
if arr[n - 1] > target_sum:
memo[n][target_sum] = subsetSumMemo(arr, n - 1,
target_sum, memo)
else:
memo[n][target_sum] = subsetSumMemo(arr, n - 1,
target_sum, memo) or subsetSumMemo(arr, n - 1, target_sum -
arr[n - 1], memo)
return memo[n][target_sum]

# Example usage:
my_set = [3, 34, 4, 12, 5, 2]
sum_to_find = 9
memo = [[-1] * (sum_to_find + 1) for _ in range(len(my_set) +
1)]
if subsetSumMemo(my_set, len(my_set), sum_to_find, memo):
print("Found a subset with the given sum")
else:
print("No subset with the given sum")

10. 3-SAT Problem & reductions 2 CLO4

import random
from typing import List, Tuple
def generate_3SAT(num_vars: int, num_clauses: int) ->
List[Tuple[int, int, int]]:
problem = []
for _ in range(num_clauses):
clause = random.sample(range(1, num_vars + 1), 3)
clause = [random.choice([var, -var]) for var in clause]
problem.append(clause)
return problem

def count_satisfied(clauses, assignment):

satisfied = 0
for clause in clauses:
for var in clause:
if (var > 0 and assignment[abs(var)-1]) or (var < 0 and not
assignment[abs(var)-1]):
satisfied += 1
break
return satisfied

def GSAT(problem, maxTries, maxFlips):

for i in range(maxTries):
assignment = [random.choice([True, False]) for _ in
range(len(problem))]

for j in range(maxFlips):
if count_satisfied(problem, assignment) == len(problem):
return assignment
else:
best_var = None
best_satisfied = -1
for var in range(len(problem)):
flipped_assignment = assignment[:]
flipped_assignment[var] = not flipped_assignment[var]
num_satisfied = count_satisfied(problem,
flipped_assignment)
if num_satisfied > best_satisfied:
best_var = var
best_satisfied = num_satisfied

assignment[best_var] = not assignment[best_var]

return None

def GSAT_RW(problem, maxTries, maxFlips, p):

for i in range(maxTries):

assignment = [random.choice([True, False]) for _ in


range(len(problem))]

for j in range(maxFlips):
if count_satisfied(problem, assignment) == len(problem):
return assignment
else:
best_var = None
best_satisfied = -1
false_clauses = []
for clause in problem:
if all([(var > 0 and not assignment[abs(var)-1]) or (var
< 0 and assignment[abs(var)-1]) for var in clause]):
false_clauses.extend(clause)
for var in range(len(problem)):
flipped_assignment = assignment[:]
flipped_assignment[var] = not flipped_assignment[var]
num_satisfied = count_satisfied(problem,
flipped_assignment)
if num_satisfied > best_satisfied:
best_var = var
best_satisfied = num_satisfied
if random.random() < p:
var = random.choice(false_clauses)
else:
var = best_var
assignment[var] = not assignment[var]
return None

def WSAT(problem, maxTries, maxFlips, p):

def heuristic(clause, assignment):

var_counts = [0 for _ in range(len(assignment))]


for c in problem:
if all([(var > 0 and not assignment[abs(var)-1]) or (var < 0
and assignment[abs(var)-1]) for var in c]):
for var in c:
var_counts[abs(var)-1] += 1
return var_counts.index(max(var_counts))

for i in range(maxTries):
assignment = [random.choice([True, False]) for _ in
range(len(problem))]

for j in range(maxFlips):
if count_satisfied(problem, assignment) == len(problem):
return assignment
else:

unsatisfied_clauses = [clause for clause in problem if


all([(var > 0 and not assignment[abs(var)-1]) or (var < 0 and
assignment[abs(var)-1]) for var in clause])]
c = random.choice(unsatisfied_clauses)
if random.random() < p:
x = random.choice(c)
else:
x = heuristic(c, assignment)

assignment[abs(x)-1] = not assignment[abs(x)-1]


return None

def semi_greedy(problem, maxTries, maxFlips, k):

def count_satisfied(clauses, assignment):


satisfied = 0
for clause in clauses:
for var in clause:
if (var > 0 and assignment[abs(var)-1]) or (var < 0 and not
assignment[abs(var)-1]):
satisfied += 1
break
return satisfied

def heuristic(clause, assignment):

var_counts = [0 for _ in range(len(assignment))]


for c in problem:
if all([(var > 0 and not assignment[abs(var)-1]) or (var < 0
and assignment[abs(var)-1]) for var in c]):
for var in c:
var_counts[abs(var)-1] += 1
return var_counts.index(max(var_counts))

best_assignment = None
best_satisfied = -1
for i in range(maxTries):
population = [[random.choice([True, False]) for _ in
range(len(problem))] for _ in range(k)]
for j in range(maxFlips):
for assignment in population:
if count_satisfied(problem, assignment) == len(problem):
return assignment
else:
unsatisfied_clauses = [clause for clause in problem if
all([(var > 0 and not assignment[abs(var)-1]) or (var < 0 and
assignment[abs(var)-1]) for var in clause])]
c = random.choice(unsatisfied_clauses)
x = heuristic(c, assignment)
assignment[x] = not assignment[x]

population.sort(key=lambda x: count_satisfied(problem, x),


reverse=True)
population = population[:k]
if count_satisfied(problem, population[0]) > best_satisfied:
best_assignment = population[0]
best_satisfied = count_satisfied(problem, population[0])

return best_assignment

if __name__=='__main__':
num_problems = 10
num_vars = 50
num_clauses = 50
maxTries = 100
maxFlips = 100
p = 0.5
k=5

for i in range(num_problems):
problem = generate_3SAT(num_vars, num_clauses)
print("Solving problem ", i+1)
print("GSAT: ")
gsat_assignment = GSAT(problem[:], maxTries, maxFlips)
if gsat_assignment:
print("Solution found: ", gsat_assignment)
else:
print("No solution found!")
print("\n")
print("GSAT_RW: ")
gsat_rw_assignment = GSAT_RW(problem[:], maxTries,
maxFlips, p)
if gsat_rw_assignment:
print("Solution found: ", gsat_rw_assignment)
else:
print("No solution found.")
print("\n")
print("WSAT:")
wsat_assignment = WSAT(problem[:], maxTries, maxFlips, p)
if wsat_assignment:
print("Solution found: ", wsat_assignment)
else:
print("No solution found.")
print("\n")
print("Semi-greedy: ")
semi_greedy_assignment = semi_greedy(problem[:],
maxTries, maxFlips, k)
if semi_greedy_assignment:
print("Solution found: ", semi_greedy_assignment)
else:
print("No solution found.")
print("\n")
input()
Total Contact Hours 20
Guest lecture / Expert sessions:
Sl.No Name of Resource Person Module/Topics Total Hours
1 Prof. Soubhagya Ranjan Mallick 1,2,3,4,5 20

Total Hours: 20 Hours


Recommended by Board of studies
Approved by Academic Council on No: / /

Copyright: The content provided by the faculty in the class is copyrighted. Students are instructed not to distribute
or share content used during courses with external entities.

Disclaimer :The Syllabus and the Course Outline is indicative of the body of knowledge a student should possess.
It does not anyway be construed as a to be covered in class in as-is condition. Faculty may add, delete and modify
content based on updated information or context.

You might also like