正在加载图片...
6.001, Spring Semester, 2005--Pro ject 3 (define (DFS-simple start goal? graph) earch start goal? find-node-children (lambda (new old)(append new old) graph)) And here is an example of using it (lambda (node)(eq? node 1)) est-graph) In this case, we are searching a particular graph test-graph, st arting from a no de wit h name a We are looking for a node named 1(hence our second argument ) We use our graph abstraction to extract the children of a node(i.e. find-node-children). The key element is how we choose to order the set of nodes to be explored. Note the fourt h argument. We can see that this will basically t ake the list of nodes to be explored, and add the new children to the end of the list. This should give us a dept h first search (you should think carefully about why This simple met hod does not work in general, but it does work for the graph in Figure 2.(See arm Up Exercise 2 for some thoughts on why this algorit hm does not work on all graphs. An index abstraction We will also be interested in constructing an index of web pages. To do this, we will first construct a general purpose index abstract ion, and then use it for our purpose of web indexing An Index enables us to associate values wit h keys, and to retrieve those values later on given the key. Here we will assume that a key is a Scheme sy mbol (i.e. Key symbol), and that a value is also a symbol (i.e. Val sy mbol). Our index will be a mutable data struct ure A concrete implement ation for an index is as follows. An Index will be a tagged dat a object holds a list of Index-Entries. Each Index-Entry asso ciates a key wit h a list of values for K ex Pair<Index-Tag, list<Index-Entry>> ex-Entry Pair <Key, Pair <list<val>, null>> Thus our index implement at ion is shown(partially) below. You will be asked in the exercises to complete the implement at ion. The index implement ation makes use of the Scheme procedure assv; you will find it helpful to consult the Scheme manual as to what t his procedure does (define (make-index) void -> Index (define (index? index) anytype -> boolean (and (pair? index)(eq? 'index (car index))))￾         L ￾ ￾2/3    (  ￾    (   ￾  ￾   ￾      + %  .  %  ￾2/3  ' ￾  ￾ ￾)(  '     +% %& 1  %+   +  # ￾& %    1+  ! 3  4     8+  % 9! 3 %  + ,%  . + +    8!!   ￾  9! + 4*  % +1 1 +%   + %  %  , .!  + + ! 3  % + +% 1 ,%* 4 + %  %  , .&   + 1 +  +   + %! +% %+ 2 %  + >% %+ 8* %+ +4 * , 1+*9! +% % + %  14  & ,  % 14  + +   '! 8 3 5 .% '  % ++%  1+* +% + %  14   +%!9       3 1 % , %  %  .  1, %!   +%& 1 1 >% %   % . ,%&  + %    %  1, .!  ,  ,% %  %% 2% 1+ 4*%&   2 +% 2%   2 + 4*!  1 1 %% +  4* %  + %*, 8!! - % ! % $ 9&  +  2 % %  %*, 8!! . ! % $ 9!  . 1 ,  ,  %!       % % 1%!  ,  1 ,    , - + +%  %  ,  ! + , % %%%  - % 1+  %  2%  + - %& !!  4 ! 5%46  %4"&&  4" ! 5%7" 5%  %8 &  && +%  .  % %+1 8*9 ,1!  1 , %4  + .%%   + ! + .  4% %  + +  /F * 1 >  +  % + +  %  1+ +%  %! ￾ ￾   . & 4 ￾   ' ￾ ￾(   "" &   ￾ ￾(  ￾)( ' ￾ 
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有