Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

NATIONAL INSTITUTE OF TECHNOLOGY KURUKSHETRA

DEPARTMENT OF COMPUTER APPLICATIONS

ARTIFICIAL INTELLIGENCE PRACTICAL

SUBMITTED BY: SUBMITTED TO:

NAME – Tushar Sachdeva Dr. Anshu Parashar

ROLL NO - 52212215

SEMESTER - 4th
1) To implement Depth First Search Algorithm Problems:
a)https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/
practiceproblems/algorithm/minimum-nodes-e023e51e/

b)https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/
practiceproblems/algorithm/minimize-the-magic-05a3986c/
2) To implement Breadth First Search Algorithm Problems:
a)https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/
practiceproblems/algorithm/cloudy-days-82a872ec/
b)https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/
practiceproblems/algorithm/dhoom-4/
3) To implement A* Search Algorithm Problems: https://leetcode.com/problems/shortest-path-in-
a-grid-with-obstacles-elimination/description/
4) To implement Best First Search Algorithm Problems:

A) https://leetcode.com/problems/cheapest-flights-within-k-stops/description/
B) https://leetcode.com/problems/possible-bipartition/description/
5) To implement Min-Max Problems:

https://www.hackerearth.com/practice/basic-programming/implementation/basics-
ofimplementation/practice-problems/algorithm/min-max-3/
https://www.hackerearth.com/problem/algorithm/sherlock-and-minimax/
6) To implement Alpha-Beta Pruning Algorithm Problems: https://leetcode.com/problems/stone-
game/description/ https://leetcode.com/problems/predict-the-winner/description/
7) To implement Travelling Salesperson Problem Problems:
https://www.hackerearth.com/problem/algorithm/a-travelling-salesman-problem/
https://leetcode.com/problems/find-the-shortest-superstring/description/
8) To implement LISP Iterative Functions (If construct, Do times loop, for loop, do list)

If Construct

(defun check-number (x)

(if (> x 0)

(format t "Positive number.~%")

(format t "Non-positive number.~%")))

Do Times Loop

(defun print-numbers (n)

(do ((i 0 (+ i 1)))

((>= i n))

(format t "~A~%" i)))

For Loop
(defun print-list-elements (lst)

(for (elem lst)

(format t "~A~%" elem)))

Do List

(defun square-list (lst)

(do ((l lst (cdr l)))

((null l))

(format t "~A~%" (* (car l) (car l)))))

9) To implement Recursion using LISP

Factorial Function

(defun factorial (n)

(if (= n 0)

(* n (factorial (- n 1)))))

Fibonacci Sequence

(defun fibonacci (n)

(cond ((= n 0) 0)

((= n 1) 1)

(t (+ (fibonacci (- n 1))

(fibonacci (- n 2))))))

10) To implement Array using LISP

Creating an Array

(defun create-array (size &optional (initial-value nil))


(make-list size initial-value))

Accessing an Element

(defun get-element (array index)

(nth index array))

Setting an Element

(defun set-element (array index value)

(setf (nth index array) value))

Getting the Length (Size) of the Array

(defun array-length (array)

(length array))

Printing the Array

(defun print-array (array)

(format t "~A~%" array))

11) To implement Backward/Forward Reasoning

In the context of expert systems and artificial intelligence, backward chaining (backward
reasoning) and forward chaining (forward reasoning) are two common inference methods used
in rule-based systems. These methods are used to determine the sequence of steps needed to
reach a conclusion based on a set of rules and facts.

Forward Chaining (Forward Reasoning)

Forward chaining starts with the available data (facts) and uses a set of rules to derive new
information until a goal or conclusion is reached.
Backward Chaining (Backward Reasoning)

Backward chaining starts with a goal and works backward through the rules to find a sequence
of rules and facts that support the goal.

Here's an example of implementing backward chaining in Lisp:


12) Prolog – To define Facts, apply rules then Infer Queries using Prolog.
In this Prolog example:

Facts are used to define relationships between entities. For example, father(john, sarah)
indicates that John is the father of Sarah.

Rules are defined using predicates to derive new relationships or facts from existing ones. For
example, grandparent(X, Z) :- parent(X, Y), parent(Y, Z). defines a rule to infer the relationship
between X (grandparent) and Z (grandchild) through an intermediate parent Y.

Queries are used to infer or ask about relationships between entities based on the defined facts
and rules. For example, ?- father(X, sarah). is a query that asks Prolog to find the value of X
(father) when Y is Sarah.

You might also like