Question

Give a decision problem corresponding to each of the search problems given below. (a) • Input: A set of classes to be schedul

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The program below depicts your requirements and for any Query post in comment section and do rate my answer.

The code and output screenshots will be attatched in case of indentation errors.

"""

1.) Input: List of classes to be scheduled , List of tuples (class,class) cannot be scheduled together. Integer k

OUTPUT: Yes --> k classes scheduled together

No --> k classes cannot be scheduled together

"""

def isKschedulePossible(list_classes,tuple_pair,k):

schedule_list = []

# schedule all classes at first

schedule_list.extend(list_classes)

for x in tuple_pair:

# either 1 of the pair of classes can be present

if x[0] in schedule_list:

# removing its pair class from schedule list will give us one from each tuple

schedule_list.remove(x[1])

if len(schedule_list) is k:

return "Yes"

else:

return "No"


"""

2.) Input: Set of classes to be scheduled, List of tuples(class,class) cannot be scheduled together

Output: Schedule of classes with minimum period.

"""

# let a period where classes are scheduled be unit period.

def minSchedulePeriod(list_classes,tuple_pair):

schedule_list = []

# this will contain classes scheduled over a period together

schedule_list.append([])

for x in list_classes:

schedule_list[0].append(x)

# all classes are added in schedule at first.__build_class__

for item in tuple_pair:

# first lets remove one item out of the pair from schedule list

if item[0] in schedule_list[0]:

try:

schedule_list[0].remove(item[1])

schedule_list.append(item[1])

except ValueError:

pass

print("Schedule with minimum period needed is printed as list of list as schedules for classes at same time and a list member if its scheduled after a certain schedule.")

print(schedule_list)

"""

3.) Input: Tuple of items (Item no,Item Weight,Item Value). A Total Weight W. Min Value V.

Output: Yes if V reached with at max weight W or No.

This problem resembles a knapsack problem but is not a knapsack problem

"""

def knapSack(tuple_list, W, V):

# the tuple has all the list for item no. its weight and value

prof_val = 0 # profit or Value

init_weight = 0 # weight of knapsack

for item in tuple_list:

if init_weight<W and prof_val<V:

init_weight += item[1]

prof_val += item[2]

# if both exceed at a given item

if init_weight > W and prof_val >= V:

return "No"

if init_weight <= W and prof_val >=V:

return "Yes"

if init_weight == W and prof_val <V:

return "No"

##### DRIVER PROGRAM#########

list_classes = [1,2,3,4,5,6]

tuple_pair = [(1,6),(2,5)]

k = 5

print(isKschedulePossible(list_classes,tuple_pair,k))

minSchedulePeriod(list_classes,tuple_pair)

item_list = [(1,5,10),(2,6,12),(3,9,25)]

print(knapSack(item_list,11,22))

print(knapSack(item_list,11,45))


####### Screenshot ############

main.py E saved No Schedule with minimum period needed is printed as list of list as schedules for classes at sa me time andmain.py saved 45 3.) Input: Tuple of items (Item no, Item Weight, Item Value). A Total Weight W. Min Value V. Output: Yes if

Add a comment
Know the answer?
Add Answer to:
Give a decision problem corresponding to each of the search problems given below. (a) • Input:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 2. In the Subset-Sum problem the input consists of a set of positive integers X...

    Problem 2. In the Subset-Sum problem the input consists of a set of positive integers X = {x1, . . . , xn}, and some integer k. The answer is YES if and only if there exists some subset of X that sums to k. In the Bipartition problem the input consists of a set of positive integers Y = {y1, . . . , yn}. The answer is YES if and only if there exists some subset of X...

  • 5) (10 pts) Greedy Algorithms The 0-1 Knapsack problem is as follows: you are given a...

    5) (10 pts) Greedy Algorithms The 0-1 Knapsack problem is as follows: you are given a list of items, each item has an integer weight and integer value. The goal of the problem is to choose a subset of the items which have a sum of weights less than or equal to a given W with a maximal sum of values. For example, if we had the following five items (each in the form (weight, value)): 11(6, 13), 2(4, 10),...

  • C++ programing question22 Minimum spanning tree Time limit: 1 second Problem Description For a connected undirected...

    C++ programing question22 Minimum spanning tree Time limit: 1 second Problem Description For a connected undirected graph G = (V, E), edge e corresponds to a weight w, a minimum weight spaning tree can be found on the graph. Into trees. Input file format At the beginning, there will be a positive integer T, which means that there will be T input data. The first line of each input has two positive integers n,m, representing n points and m edges...

  • The decision version of the Knapsack problem is as follows: Given a set of n items...

    The decision version of the Knapsack problem is as follows: Given a set of n items {1, 2, …, n}, where each item j has a value v(j) and a weight w(j), and two numbers V and W, can we find a subset X of {1, 2, …, n} such that Σj∈X v(j) ≥ V and Σj∈X w(j) ≤ W? Prove formally that the Knapsack problem is NP-complete.

  • A problem that can be solved by the Backtracking technique is the 'Sum-of-Subsets' problem. Given n...

    A problem that can be solved by the Backtracking technique is the 'Sum-of-Subsets' problem. Given n distinct positive numbers (usually called weights), we want to find all possible subsets of these numbers whose sum (or weight) is W. A “binary” state space tree (like in the 0/1 Knapsack problem) can be constructed for this problem, where each level represents one of the n numbers. A left branch indicates that the number is included in the subset, and a right branch...

  • 2. In the BACKPACK problem, you are given a collection of books of different costs and...

    2. In the BACKPACK problem, you are given a collection of books of different costs and are tasked with storing as expensive a subset of books as possible so you can sell them at the bookstore in only one trip. Unfortunately, the books are very heavy, and you are limited in how much total weight you can carry. Formally, you are given two arrays C[1.. n] and w[1..n] of positive integers where C[i] is the cost of book i in...

  • 5. The Hitting Set Problem (HS) is the following decision problem. Input. A finite set S,...

    5. The Hitting Set Problem (HS) is the following decision problem. Input. A finite set S, a collection (s1, s2,... , sn) of subsets of S, and a positive integer K. Question. Does there exist a subset t of S such that (a) t has exactly K members and (b) for i 1,..., n, sint6For example, suppose S # {1, 2, 3, 4, 5, 6, 7. the collection of subsets is (2.45), (34).(1,35) and K - 2. Then the answer...

  • Consider the following four problems: Bin Packing: Given n items with positive integer sizes s1,s2,...,sn, a...

    Consider the following four problems: Bin Packing: Given n items with positive integer sizes s1,s2,...,sn, a capacity C for bins and a positive integer k, is it possible to pack the n items using at most k bins? Partition: Given a set S of n integers, is it possible to partition S into two subsets S1 and S2 so that the sum of the integers in S1 is equal to the sum of the integers in S2? Longest Path: Given...

  • Shopping Spree: Acme Super Store is having a contest to give away shopping sprees to lucky...

    Shopping Spree: Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example, one family member can take one television, one watch and one toaster, while another family member can take one television, one camera and...

  • Write a program that first gets a list of integers from input. The input begins with...

    Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, and output all integers less than or equal to that value. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75 The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT