• Home
  • La Trobe University
  • Computational Intelligence
  • LISP Programming and Search Algorithms

LISP Programming and Search Algorithms

Question 1 [ 2 + 4 + 2 + 2 + 4 = 14 marks ] (a) Write LISP code for a function average, which takes exactly two numbers as input parameters, and returns the average of these numbers. (b) LISP functions are 'first-class objects'. What are the four properties possessed by first class objects? (c) What would be returned by the following? > (mapcar #' (lambda (x) (- x 1) ) ' (0 2 4 6) ) (d) Consider the following LISP function that takes one argument, a-list: (defun function-A (a-list) (cond ( (null a-list) 0) (t (+ (car a-list) (function-A (cdr a-list) ) ) ) ) ) What would the function's output be if it was run as follows: > (function-A ' (3 2 1 0) ) (e) Write a LISP function largest that takes a list of numbers as its argument, and returns the largest element of the list. Page - 2 Page - 3 [ 2 + 2 + 2 + 2 = 8 marks ] Question 2 Below is a tree structure that contains 20 nodes. Node A is the start node. Nodes J and O are goal nodes. A B C D E F G H I J K L M N O P Q R S T Write down the nodes which are visited in sequential order when conducting each of the following searches. Stop the search when either of the two goals is found. (a) depth-first search (b) breadth-first search (c) depth-first search with depth limit of two (d) depth-first search with iterative deepening Question 3 (a) Answer each of the following: [ (1 + 1 + 1 + 1) + 2 + 4 = 10 marks ] Page - 4