(1 - 1) AIandMLFinalAssignment

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Instructions

➔ Please write all the programs on a document file and upload it for evaluation.
➔ Please do not write any type of source code in the description box.
➔ The system will automatically check your submission against the predefined plagiarism
detection criteria. Plagiarized answers will cause you to fail the assignment.
➔ You can submit your assignment in the form of a doc, text, or pdf file.
➔ Corrupted files will cause you to fail the assignment.
➔ Please ensure that you have written your name and email address on the answer
document you have submitted.
____________________________________________________________________________

Question on Variables and Lists


____________________________________________________________________________

Q1) Write a Prolog program that takes in a sequence of integers as input and calculates the
average of all even numbers provided.
Q2) Write a Prolog program that takes a sequence of strings as input and returns the number of
strings starting with a vowel.
Q3) Write a Prolog program that takes in a sequence of words as input and returns the length of
the longest word in the sequence.

____________________________________________________

Question on Search and Backtracking


____________________________________________________________________________

Q1) Suppose you have a binary tree represented as a Prolog term. Can you write a Prolog
program that recursively traverses the tree and returns a list of all the leaf nodes?

Q2) Suppose you have a directed graph represented as a list of edges, where each edge is a
pair of vertices (e.g. [2,3]). Can you write a Prolog program that uses search to find all paths of
length N between two given vertices in the graph?
Q3) Suppose you have a list of 5 integers [1, 2, 3, 4, 5], and you want to generate all possible
combinations of 3 elements from this list using Prolog. Write a program that finds all valid
combinations by considering all possible options for each element until a valid combination is
found.

____________________________________________________

Questions on Cut and Fail


____________________________________________________________________________

Q1) Write a Prolog program that takes in two lists, List1 and List2. It should return the first
element of the List2 that is not present in the List1. If all elements of the second list are present
in the first list, then nothing should be returned.

Q2) Write a Prolog program that takes in a list of integers and returns the second smallest
element in the list. If the list has less than two distinct elements, the program should not return
anything.

Q3) Suppose you are a teacher and want to assign grades to your students based on their
performance in the class. You want to assign an "A" grade to students who score an average of
90 or above, a "B" grade to students who score an average of 80 to 89, a "C" grade to students
who score an average of 70 to 79, and a "D" grade to students who score an average of 60 to
69. Write a Prolog program that takes in a list of student names and their scores on
assignments and exams, and assigns a grade to each student. If a student's average score falls
below 60, the program should not assign a grade to that student.

____________________________________________________

General Question to use all topics


____________________________________________________________________________

Q1) Suppose you have a list of animals in a zoo, along with their species, age, and feeding
schedule. Write a Prolog program that allows the zookeeper to determine which animal to feed
next, based on the following rules:

→ Animals that are "carnivores" and are over 10 years old should be fed first.
→ If no such animals exist, then feed animals that are "herbivores" and are over 5 years old.
→ If no such animals exist, then the youngest animal in the zoo, regardless of species or
feeding schedule, should be fed.

Assume that the list of animals is represented as a Prolog fact, with each animal represented as
a term of the form animal(Name, Species, Age, Diet) and the feeding schedule
represented as a Prolog rule, with each diet represented as a predicate of the form
diet(Diet).

Q2) Suppose you are developing a movie recommendation system for a streaming service. You
have a database of movies with information on their genre, rating, and release year. Create a
Prolog program that takes in a user's preferences and returns a list of recommended movies.
The recommendations should be based on the user's preferred genre, desired rating, and
preferred release year range. The program should optimize its performance by filtering out
movies that don't meet the user's preferences. If the program is unable to find suitable
recommendations, then it should notify the user.

You might also like