Daa Record 1 To 5
Daa Record 1 To 5
Daa Record 1 To 5
(LINEAR SEARCH)
PROGRAM:
import time
import matplotlib.pyplot as plt
list_sizes.append(size)
times_taken.append(time_taken)
PROGRAM:
import time
import matplotlib.pyplot as plt
list_sizes.append(size)
times_taken.append(time_taken)
PROGRAM:
import time
import math
import matplotlib.pyplot as plt
list_sizes.append(size)
times_taken.append(time_taken)
PROGRAM:
return A, B
# Main function
if __name__ == "__main__":
A, B = get_input()
PROGRAM:
top_order = []
while zero_in_degree_queue:
# Remove a vertex from the queue
vertex = zero_in_degree_queue.popleft()
top_order.append(vertex)
# Main function
if __name__ == "__main__":
vertices, graph = get_input()
try:
# Perform Topological Sort
top_order = topological_sort(vertices, graph)
except ValueError as e:
print(e)
OUTPUT:
PROGRAM:
import time
import matplotlib.pyplot as plt
start_time = time.time()
heap_sort(arr)
end_time = time.time()
# Main function
if __name__ == "__main__":
# Option 1: Heap sort with user input
arr = get_input()
print(f"Original Array: {arr}")
heap_sort(arr)
print(f"Sorted Array: {arr}")
PROGRAM:
# Function to find the minimum number of coins needed to make the given amount
def coin_change(coins, amount):
# Create a dp array to store the minimum coins required for each amount up to the target
amount
dp = [float('inf')] * (amount + 1)
dp[0] = 0 # Base case: 0 coins are needed to make 0 amount
# If dp[amount] is still infinity, return -1, meaning it's not possible to form that amount
return dp[amount] if dp[amount] != float('inf') else -1
# Main function
if __name__ == "__main__":
# Get user input for coins and amount
coins, amount = get_input()
PROGRAM:
# Set distance to 0 for all diagonal elements (distance from a vertex to itself)
for i in range(V):
dist[i][i] = 0
return dist
# Function to take input for graph
def get_input_floyd():
V = int(input("Enter the number of vertices in the graph: "))
graph = [[] for _ in range(V)]
return graph, V
PROBLEM:
return dp[n][W]
# Main function
if __name__ == "__main__":
weights, values, W, n = get_input()