MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS
description
Transcript of MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS
![Page 1: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/1.jpg)
![Page 2: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/2.jpg)
No existe información sobre la cantidad de
estados intermedios o el costo de ruta para
pasar del estado actual a la meta.
Sólo se sabe distinguir si estamos en el
estado meta o no.
A esta búsqueda se le conoce también como
búsqueda ciega.
![Page 3: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/3.jpg)
Existen varios métodos:
a)Búsqueda preferente por amplitud
b)Búsqueda preferente por profundidad
c)Búsqueda de costo uniforme
d)Búsqueda limitada por profundidad
e)Búsqueda por profundización iterativa
f) Búsqueda bidireccional
![Page 4: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/4.jpg)
La búsqueda en amplitud, consiste en recorrer el árbol por niveles; es decir,
primero se recorre el padre, luego los hijos de este(de izquierda a derecha),
luego los nietos… y así sucesivamente hasta encontrar el elemento buscado.
Para nuestro algoritmo hemos definido las funciones padre, hd y hi que
devuelven(si es que existen) respectivamente el nodo-padre, el hijo izquierdo y
el hijo derecho. Estas funciones han sido usadas dentro nuestro algoritmo
principal bpa que es iterativo, y consiste en comparar los elementos hasta que la
lista ingresada este vacía. Primero verifica si el padre es elemento buscado y
hace lo mismo con los hijos de este, luego envía como la lista a evaluar todo el
hijo izquierdo y todo el hijo derecho para hacer lo mismo.
![Page 5: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/5.jpg)
![Page 6: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/6.jpg)
![Page 7: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/7.jpg)
![Page 8: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/8.jpg)
![Page 9: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/9.jpg)
![Page 10: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/10.jpg)
CL-USER 1> (defun bpa(elm lst)
(cond ((null lst) nil)((equal nil(padre lst))nil)
(t(if(equal elm(padre lst))t
(if (equal elm (hi lst)) t
(if (equal elm (hd lst)) t
(or (bpa elm (second lst)) (bpa elm(third lst)))))))))
BPA
CL-USER 2> (defun padre(lst))
(if (atom lst) nil
(first lst)))
PADRE
CL-USER 3> (defun hd(lst)
(if (equal nil (third lst)) nil
(if (atom (third lst)) (third lst)
(first (third lst)))))
HD
![Page 11: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/11.jpg)
CL-USER 4> (defun hi(lst)
(if (equal nil (second lst)) nil
(if (atom (second lst)) (second lst)
(first (second lst)))))
HI
CL-USER 5> bpa ‘e’(a(b c d)(e f))
T
CL-USER 6> bpa ‘d’(a(b c d)(e f))
T
![Page 12: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/12.jpg)
La búsqueda por profundidad, consiste en recorrer los nodos de un árbol de la siguiente manera:
Padre- Hijo Izquierdo-Hijo Derecho, es decir primero observa si el «padre» es el elemento
buscado, luego observa a su «hijo izquierdo» y luego su «hijo derecho»; recursivamente a cado
uno de sus hijos, en otras palabras recorre todos los hijos izquierdos y luego los hijos derechos
hasta encontrar el elemento buscado.
En nuestro algoritmo; cuando un árbol se expresa en lista, todos los nodos se ingresan en pre-
orden (Padre- H Izq- H Der), entonces sólo tendremos que recorrer de elemento en elemento de
la «lista» (árbol) ingresada hasta encontrar nuestro elemento.
Se define una función principal «Buscar»; que recibe 2 parámetros, el primero el elemento a
buscar y el segundo el árbol donde se buscara dicho elemento. Luego pasa a la función
«Busq_Prof»; que recibe 3 parámetros, el primero el elemento a buscar, el segundo el primero
(átomo o lista) del árbol y por último el resto del árbol, y así buscara el elemento recursivamente.
![Page 13: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/13.jpg)
![Page 14: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/14.jpg)
![Page 15: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/15.jpg)
![Page 16: MÉTODOS DE BÚSQUEDA EN UN ESPACIO DE ESTADOS](https://reader036.fdocuments.co/reader036/viewer/2022062422/56813956550346895da0f634/html5/thumbnails/16.jpg)
CL-USER 1> (defun Busq_Porf(n P R)
(if (atom P) (if (null P) (if (null R) 100 (Busq_Prof n (first R)(rest R)))
(if (equal n P) 1 (if (null R) 100 (+ 1 (Busq_Prof n (first R)(rest R))))))
(Busq_Prof n (first P)(if (null(rest P)) R (cons (rest P) R)))))
BUSQ_PROF
CL-USER 2> (defun Buscar(x A)
(setq Canti_Nod (Busq_Prof x (first A)(rest A)))
(if (> Canti_Nod 100)(format t «No se encontro el elemento ~d» x)
(format t «Se recorrio ~d nodos para habllar el elemento ~d» Canti_Nod x)))
BUSCAR
CL-USER 3> Buscar ‘4’(1(2 4 5)(3 6))
Se recorrió 3 nodos para hallar el elemento 4
CL-USER 4> Buscar ‘10’(1(2 4 5)(3 6))
No se encontró el elemento 10