Your SlideShare is downloading. ×
0
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
------
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

------

221

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
221
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. ДЕЯКІ КЛАСИЧНІ АЛГОРИТМИ ТА ЇХ РЕАЛІЗАЦІЯ
  • 2. Бінарні дерева пошуку (Корінь (Ліве-піддерево Праве-піддерево))
  • 3. Бінарні дерева пошуку (Корінь Ліве-піддерево Праве-піддерево)
  • 4. Бінарні дерева пошуку (Корінь . (Ліве-піддерево . Праве-піддерево))
  • 5. Бінарні дерева пошуку (defun insel (n tree) (cond ((null tree) (cons n nil)) ((> n (car tree)) (cons (car tree) (cons (cadr tree) (insel n (cddr tree))))) (t (cons (car tree) (cons (insel n (cadr tree)) (cddr tree)))) ))
  • 6. Бінарні дерева пошуку > (setq tr (insel 5 nil)) (5) > (setq tr (insel 3 tr)) (5 (3)) > (setq tr (insel 1 tr)) (5 (3 (1))) > (setq tr (insel 4 tr)) (5 (3 (1) 4)) > (setq tr (insel 7 tr)) (5 (3 (1) 4) 7) > (setq tr (insel 6 tr)) (5 (3 (1) 4) 7 (6)) > (setq tr (insel 13 tr)) (5 (3 (1) 4) 7 (6) 13) > (setq tr (insel 15 tr)) (5 (3 (1) 4) 7 (6) 13 NIL 15) > (setq tr (insel 11 tr)) (5 (3 (1) 4) 7 (6) 13 (11) 15) > (setq tr (insel 17 tr)) (5 (3 (1) 4) 7 (6) 13 (11) 15 NIL 17) 5 3 1 4 7 6 13 15 11 17
  • 7. Бінарні дерева пошуку (defun pud (tree) (cond ((null tree)) (t (format t "~d " (car tree)) (pud (cadr tree)) (pud (cddr tree)) )) ) >(pud tr) 5 3 1 4 7 6 13 11 15 17 T
  • 8. Бінарні дерева пошуку (defun plr (tree) (cond ((null tree)) (t (plr (cadr tree)) (format t "~d " (car tree)) (plr (cddr tree)) )) ) >(plr tr) 1 3 4 5 6 7 11 13 15 17 T
  • 9. Графи G=(V,E) V – множина вершин графу Е – множина ребер графу еі=(vk, vl) – vk та vl Є V Порядок графу Суміжні вершини та ребра Шлях у графі – (v1,v2)(v2,v3)…(vk+1,vk) Довжина Цикл Зв’язаний граф Відстань між вершинами U та V Остове дерево графу
  • 10. Графи + “чи існує ребро з i в j ?”- один крок - розмір пам’яті NxN G граф порядку N, V={1,2,…,N} Матриця суміжності B = [Bij] NxN. Bij =1 або Bij =0
  • 11. Графи               0001 1000 0100 0110 ((0 1 1 0) (0 0 1 0) (0 0 0 1) (1 0 0 0))
  • 12. Графи >(neighbour1 2 '((0 1 1 0)(0 0 1 0)(0 0 0 1)(1 0 0 0))) (3) >(neighbour1 4 '((0 1 1 0)(0 0 1 0)(0 0 0 1)(1 0 0 0))) (1) >(neighbour1 1 '((0 1 1 0)(0 0 1 0)(0 0 0 1)(1 0 0 0))) (2 3) (defun neighbour1 (x graph) (neigb1 1 (nth (- x 1) graph))) (defun neigb1 (i lst) (cond ((null lst) nil) ((eql (car lst) 1) (cons i (neigb1 (+ i 1) (cdr lst)))) (t (neigb1 (+ i 1) (cdr lst))))
  • 13. Графи
  • 14. Графи
  • 15. Графи (defun neighbour2 (x graph) (cond ((null graph) nil ) ((and (eql (caar graph) x) (eql (cdar graph)'false)) nil) ((eql (caar graph) x) (cons (cdar graph) (neighbour2 x (cdr graph))) ) ((eql(cdar graph) x) (cons (caar graph) (neighbour2 x (cdr graph))) ) (t (neighbour2 x (cdr graph)))))
  • 16. Графи >(neighbour2 2 '((1 . 2) (1 . 3) (2 . 3) (5 . false))) (1 3) >(neighbour2 1 '((1 . 2) (1 . 3) (2 . 3) (5 . false))) (2 3) >(neighbour2 5 '((1 . 2) (1 . 3) (2 . 3) (5 . false))) nil
  • 17. Графи (defun main (x graph) (list-set (neighbour2 x graph)) ) (defun list-set (lst) (cond ((null lst) nil ) ((member (car lst) (cdr lst)) (list-set (cdr lst)) ) (t (cons (car lst) (list-set (cdr lst))) ) ))
  • 18. Графи >(main 2 '((1 . 2) (1 . 3) (2 . 3) (2 . 1) (3 . 1) (3 . 2) (5 . false))) (1 3) >(main 1 '((1 . 2) (1 . 3) (2 . 3) (2 . 1) (3 . 1) (3 . 2) (5 . false))) (2 3) >main 5 '((1 . 2) (1 . 3) (2 . 3) (2 . 1) (3 . 1) (3 . 2) (5 . false))) NIL
  • 19. Графи
  • 20. Графи (defun neighbour3 (x graph) (cond ( (null (assoc x graph)) nil ) ( t (cdr (assoc x graph)) ) ) >(neighbour3 2 ' ((1 . (2 3 4)) (2 . (1 3)) (3 . (1 2)) (4 . (1)))) (1 3) >(neighbour3 1 ' ((1 . (2 3 4)) (2 . (1 3)) (3 . (1 2)) (4 . (1)))) (2 3 4) >(neighbour3 3 ' ((1 . (2 3 4)) (2 . (1 3)) (3 . (1 2)) (4 . (1)))) (1 2)
  • 21. Графи (defun depthfirst graph root) (cond ((null graph) nil ) (t (defi graph (list root) (list root))))) (defun defi (graph visited path) (cond ((null path) (reverse visited) ) (t(cond ((null (expnd graph visited (car path))) (defi graph visited(cdr path)) ) (t(defi graph (cons (expnd graph visited(car path))visited) (cons (expnd graph visited(car path)) path)) )) )))
  • 22. Графи (defun expnd (graph visited vertex) (cond ((null (neighbour3 vertex graph)) nil ) (t (firstnotvisited visited (neighbour3 vertex graph)))) (defun firstnotvisited (visited vlist) (cond ((null vlist) nil ) (t(cond ((null (member (car vlist) visited)) (car vlist)) (t (firstnotvisited visited(cdr vlist)) ))))
  • 23. Графи >(depthfirst '((1 . (2 3 4)) (2 . (3)) (3 . (4))) 1) (1 2 3 4) >(depthfirst '((1 . (2 3 4)) (2 . (3)) (3 . (4))) 2) (2 3 4) >(depthfirst '((1 . (2 3 4)) (2 . (3)) (3 . (4))) 3) (3 4) > >(depthfirst '((1 . (2 3 4)) (2 . (3 1)) (3 . (4))) 2) (2 3 4 1)
  • 24. Графи >(depthfirst '((1 . (2 3)) (2 . (4 5)) (3 . (6 7))) 1) (1 2 4 5 3 6 7)
  • 25. Дякую за увагу

×