State Space TreesUP

download State Space TreesUP

of 103

Transcript of State Space TreesUP

  • 7/29/2019 State Space TreesUP

    1/103

    Msc. Jorge Espinosa

    [email protected]

    Horas y correo de contactoLunes y Martes 10-12 m

    P19 211 C Ext 492

    Medelln 2013

    INGENIERA DEL CONOCIMIENTO

  • 7/29/2019 State Space TreesUP

    2/103

    Vision of the Future

    Motivation

    http://localhost/var/www/apps/conversion/tmp/scratch_4/video/BBC.Visions.of.the.Future.1of3.The.Intelligence.Revolution.2007.DVBC.XviD.MP3.www.mvgroup.org.avi
  • 7/29/2019 State Space TreesUP

    3/103

    Que es el test de Turing!!!

  • 7/29/2019 State Space TreesUP

    4/103

    4

    The mind beaten

    by the machine?

    Is chess playing a proof of intelligent behaviour?

  • 7/29/2019 State Space TreesUP

    5/103

    MARIANAhttp://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ing

    resantes/ingreso-buenos-aires/

    http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/http://www.uca.edu.ar/uca/index.php/ingreso/index/es/universidad/ingresantes/ingreso-buenos-aires/
  • 7/29/2019 State Space TreesUP

    6/103

    6

    Other examples of success:

    Chatbot - Alice: http://www.alicebot.org/

  • 7/29/2019 State Space TreesUP

    7/103

    Clever Bothttp://www.cleverbot.com/

    http://www.cleverbot.com/http://www.cleverbot.com/
  • 7/29/2019 State Space TreesUP

    8/103

    Siri

    http://www.youtube.com/watch?v=0ubSbju9u68&feature=watch_response

    http://www.youtube.com/watch?v=0ubSbju9u68&feature=watch_responsehttp://www.youtube.com/watch?v=0ubSbju9u68&feature=watch_response
  • 7/29/2019 State Space TreesUP

    9/103

    Existor

    www.existor.com

    http://www.existor.com/http://www.existor.com/
  • 7/29/2019 State Space TreesUP

    10/103

    10

    Are Mariana/Alice/Clever

    Bot/Siri/Existor intelligent?

    ABSOLUTELY NOT ! ~ 50000 fairly trivial input-response rules.

    + some pattern matching

    + some knowledge

    + some randomness

    NO reasoning component

    BUT: demonstrates human-like behaviour.

    Won the turing award

  • 7/29/2019 State Space TreesUP

    11/103

    11

    Data mining:

    An application of Machine Learningtechniques

    It solves problems that humans can not solve,because the data involved is too large ..

    Detecting cancer

    risk molecules is

    one example.

  • 7/29/2019 State Space TreesUP

    12/103

  • 7/29/2019 State Space TreesUP

    13/103

    EE.UU. inicia prueba de un ao con

    "automviles inteligentes"

  • 7/29/2019 State Space TreesUP

    14/103

    14

    Many other applications:

    In language and speech processing:

    In robotics:

    Computervision:

  • 7/29/2019 State Space TreesUP

    15/103

    15

    About intelligence ...

    When would we consider a program

    intelligent ?When do we consider a creative activity of humans to

    require intelligence ?

    Default answers : Never? / Always?

  • 7/29/2019 State Space TreesUP

    16/103

    What is Turing test!!!

  • 7/29/2019 State Space TreesUP

    17/103

    17

    The Turing Test

    The long term goal:

  • 7/29/2019 State Space TreesUP

    18/103

    18

    The meta-Turing test

    The meta-Turing test counts a thing as intelligentifit seeks to devise and apply Turing tests

    to objects of its own creation.-- Lew Mammel, Jr.

  • 7/29/2019 State Space TreesUP

    19/103

    19

    Artificial Intelligence vs.

    Natural Flight

  • 7/29/2019 State Space TreesUP

    20/103

    20

    To some extent, we DO simulate:

    Artificial Neural Nets:

    A VERY ROUGH imitation of a brain structure

    Work very well for learning, classifying and pattern

    matching.

    Very robust and noise-resistant.

  • 7/29/2019 State Space TreesUP

    21/103

    21

    Which applications are easy ?

    For very specialized, specific tasks: AI

    Example:ECG-diagnosis

    For tasks requiring common sense: AI

  • 7/29/2019 State Space TreesUP

    22/103

    22

    Modeling Knowledge

    and managing it .

    The LENAT experiment:

    15 years of work by 15 to 30 people, trying to model

    the common knowledge in the word !!!!

    Knowledge should be learned, not engineered.

    AI: are we only dreaming ????

  • 7/29/2019 State Space TreesUP

    23/103

    23

    But at the end What is Artificial Intelligence?

    In Engineering and Computer Science: The development and the study of advanced computer

    applications, aimed at solving tasks that - for themoment - are still better preformed by humans.

    Well, Artificial Intelligence is ...

  • 7/29/2019 State Space TreesUP

    24/103

    Msc. Jorge Espinosa

    [email protected]

    Horas y correo de contactoLunes y Martes 10-12 m

    P19 211 C Ext 492

    Medelln 2013

    INGENIERA DEL CONOCIMIENTO

  • 7/29/2019 State Space TreesUP

    25/103

    25

    State-Space representation

    and Production Systems

    Introduction: what is State-space representation?

    What are the important trade-offs?

    (E.Rich, Chapt.2)

    Basis search methods.

    (Winston, Chapt.4 + Russel&Norvig)

    Optimal-path search methods.

    (Winston, Chapt.5 + Russel&Norvig)

    Advanced properties and variants.

    (Rich, Chapt.3 + Russel&Norvig + Nilsson)Game Playing

    (Winston, Chapt.6 + Rich + Russel&Norvig )

  • 7/29/2019 State Space TreesUP

    26/103

    26

  • 7/29/2019 State Space TreesUP

    27/103

    State-space representation:

    Introduction and trade-offs

    What is state-space representation?

    Which are the technical issues that arise in thatcontext?

    What are the alternatives that the paradigm offersto solve a problem in the state-spacerepresentation?

  • 7/29/2019 State Space TreesUP

    28/103

    Example: the 8-puzzle.

    Given: a board situation for the 8-puzzle:

    1 3 8

    2 7

    5 4 6

    1 2 3

    567

    48

    Problem: find a sequence of moves (allowed under the rules of the

    8-puzzle game) that transform this board situation in a desired goal

    situation:

  • 7/29/2019 State Space TreesUP

    29/103

    http://mypuzzle.org/sliding

    http://www.permadi.com/java/puzzle8/puzzle8a.html

    http://mypuzzle.org/slidinghttp://www.permadi.com/java/puzzle8/puzzle8a.htmlhttp://www.permadi.com/java/puzzle8/puzzle8a.htmlhttp://mypuzzle.org/sliding
  • 7/29/2019 State Space TreesUP

    30/103

    State-space representation:

    general outline:

    Select some way to represent states in the problem in

    an unambiguous way.

    Formulate all actions that can be performed in states:

    including their preconditions and effects== PRODUCTION RULES

    Represent the initial state (s).

    Formulate precisely when a state satisfies the goal of our

    problem. Activate the production rules on the initial state and its

    descendants, until a goal state is reached.

  • 7/29/2019 State Space TreesUP

    31/103

    Initial issues to solve:

    1 3 82 75 4 6

    How to represent states? (repr.1)

    Ex.: using a 3 X 3 matrix

    How to formulate production rules? (repr. 2) Ex.:

    express how/when squares may be moved?

    Or: express how/when the blank space is moved?

    When is a rule applicable to a state? (matching) How to formulate when the goal criterion is satified and

    how to verify that it is?

    How/which rules to activate? (control)

  • 7/29/2019 State Space TreesUP

    32/103

    The (implicit) search tree

    1 3 8

    2 7

    5 4 6

    1 3 8

    2 7

    5 4 6

    1 3 8

    2 7

    5 4 6

    13

    8

    2 7

    5 4 6

    1 3 8

    2 7

    5

    4

    6

    9!/2

    nodes!

    goal

    Each state-space representation defines a search tree:

    8 puzzle= 181.444

    15 Puzzle = 650.000.000

    24 Puzzle = 5000.000.000.000.000.000.0000.000

  • 7/29/2019 State Space TreesUP

    33/103

    The (implicit) search tree

    1 3 8

    2 7

    5 4 6

    1 3 8

    2 7

    5 4 6

    1 3 8

    2 7

    5 4 6

    13

    8

    2 7

    5 4 6

    1 3 8

    2 7

    5

    4

    6

    9!/2

    nodes!

    goal But this tree is only IMPLICITLY available !!

    Each state-space representation defines a

    search tree:

  • 7/29/2019 State Space TreesUP

    34/103

    A second example: Chess

    Problem: develop a program that plays chess (well).

    341

    23

    45

    678

    A B C D E F G H

    1. A way to represent board situations in an

    unambiguous way:

    Ex.:

    List:

    (( king_black, 8, C),

    ( knight_black, 7, B),

    ( pawn_black, 7, G),

    ( pawn_black, 5, F),

    ( pawn_white, 2, H),( king_white, 1, E))

  • 7/29/2019 State Space TreesUP

    35/103

    35

    1

    23

    4

    A B C D E F G H

    ( (pawn_white,2,x) , (blank, 3, x), (blank, 4, x) )

    add( ( pawn_white, 4, x) ),

    remove( (pawn_white, 2, x) )

    Chess (2):

    2. Describe the rules that represent allowedmoves:

    Ex.:

  • 7/29/2019 State Space TreesUP

    36/103

    Chess (3):

    ( (pawn_white,2,x) , (blank, 3, x), (blank, 4, x) )

    add( ( pawn_white, 4, x) ),

    remove( (pawn_white, 2, x) )

    List:

    (( king_black, 8, C),

    ( knight_black, 7, B),

    ( pawn_black, 7, G),( pawn_black, 5, F),

    ( pawn_white, 2, H),

    ( king_white, 1, E))12345

    678

    A B C D E F G H

    Matching mechanism !!

    3. Provide a way to check whether a rule isapplicable to some state:

    Ex.:

  • 7/29/2019 State Space TreesUP

    37/103

    Chess (4):

    37

    win( black ) attacked( king_white ) and

    no_legal_move( king_white )

    + similar definitions for:

    attacked( Piece )

    no_legal_move( Piece ) ...

    4. How to specify a state in which the goal isreached (= a winning state):

    Ex.:

  • 7/29/2019 State Space TreesUP

    38/103

    Chess (5):

    ?- win( black ).

    win( black ) attacked( king_white ) and

    no_legal_move( king_white )

    Need a theorem prover ( e.g. Prolog) to verify

    that the state is a winning one.

    5. A way to verify whether a winning state isreached.

    Ex.:

  • 7/29/2019 State Space TreesUP

    39/103

    Chess (6).

    A program that is ABLE to play chess.

    The control problem !

    Main focus of this entire

    chapter of the course !!

    7. A mechanism that selects in each state an appropriate rule to

    apply.

    6. The initial state.

    Chess (7)

  • 7/29/2019 State Space TreesUP

    40/103

    Chess (7).

    Move 1

    Move 2

    Move 3

    Implicit search tree

    ~15

    ~ (15)2

    ~ (15)3

    Need very efficient search techniques to find good

    paths in such combinatorial trees.

    Very many issues

  • 7/29/2019 State Space TreesUP

    41/103

    Very many issues

    and trade-offs:

    41

    1. How to choose the rules?2. Should we search through the implicit tree or through an

    implicit graph?

    3. Do we need an optimal solution, or just any solution?

    optimal path problems

    4. Can we decompose states into components on which

    simple rules can in an independent way?

    Problem reduction or decomposability

    5. Should we search forwards from the initial state, or

    backwards from a goal state?

    1 Ch i f th l

  • 7/29/2019 State Space TreesUP

    42/103

    1. Choice of the rules

    Example: The water jugs problem:

    Given: 2 jugs:

    Problem: fill the 4 l jug with 2 l of water.

    42

    4 l 3 l

    Representation:

    a state:

    [content of large jug, content of small jug]

    initial state:

    [ 0, 0 ]

    goal state:

    [ 2, x ]

  • 7/29/2019 State Space TreesUP

    43/103

    Rules for the jugs example:

    Fill large:

    [ x, y ]and x d> 0 [ x - d, y ]

    f

  • 7/29/2019 State Space TreesUP

    44/103

    Rules for the jugs

    example (2):

    44

    Fill large from small:

    [ x, y ] and x + y 4 and y > 0[ 4, y-(4-x)]Empty Small in large.

    [ x, y ] and x + y 4 and y > 0 [ x + y , 0 ]

    Part of the state space:

  • 7/29/2019 State Space TreesUP

    45/103

    45

    [ 0, 0 ]

    [ 0, 3 ]

    Fill small

    [ 3, 0 ]

    Empty small

    in large

    [ 3, 3 ]

    Fill small

    [ 4, 2 ]Fill large

    from small

    Part of the state space:

    [ 4, 0 ] [ 0, 0 ]

    [ 0, 3-d1]

    [ 4, 3][ 0, 0]

    [ 0, 3-d1-d2]

    [ 3-d1, 0]

    [ 4, 3-d1]Redundant

    subspace !

    *

    *

    [ 2, 0 ]Empty small in large

    [ 0, 2 ] Empty large

    R l f th j l

  • 7/29/2019 State Space TreesUP

    46/103

    Rules for the jugs example:

    Fill large:[ x, y ] and x d> 0 [ x - d, y ] Empty (remove some from) small.

    *

  • 7/29/2019 State Space TreesUP

    47/103

    Part of the state space:

    47

    [ 0, 0 ]

    [ 0, 3 ]

    [ 3, 0 ]

    [ 3, 3 ]

    [ 4, 2 ]

    [ 0, 2 ]

    [ 2, 0 ]

    Fill small

    Empty small

    in large

    Fill small

    Fill large

    from small

    Empty large

    Empty small in large

    [ 0, 0 ]

    [ 0, 3 ]

    [ 0, 0 ]

    LOOP !

  • 7/29/2019 State Space TreesUP

    48/103

    2. Avoiding loops:

    search in trees or graphs ?

    48

    [ 0, 0 ]

    [ 0, 3 ][ 4, 0 ]

    Avoids generating loops: but needs to keep track

    of ALL the nodes.

    [ 1, 3 ] [ 4, 3 ] [ 3, 0 ]

    [ 1, 0 ] [ 3, 3 ]

    ...

    3 Any path versus shortest

  • 7/29/2019 State Space TreesUP

    49/103

    3. Any path, versus shortest

    path, versus best path:

    Ex.: 8-puzzle: any or shortest path problem.Ex.: Traveling salesperson problem:

    Find a sequence of cities ABCDEA such thatthe total distance is MINIMAL.

    Boston

    Miami

    NewYork

    SanFrancisco

    Dallas

    3000

    250

    1450

    1200 1700

    33002900

    1500

    1600

    1700

    Best path problem

    State space

  • 7/29/2019 State Space TreesUP

    50/103

    State space

    representation: State:

    the list of cities that are already visited

    Ex.: ( NewYork, Boston)

    Initial state:

    Ex.: ( NewYork )

    Rules: add 1 city to the list that is not yet a member

    add the first city if you already have 5 members

    Goal criterion:

    first and last city are equal

    50

    Boston

    Miami

    NewYork

    SanFrancisco

    Dallas

    0

  • 7/29/2019 State Space TreesUP

    51/103

    51

    ( NewYork )

    ( NewYork,

    Boston )

    ( NewYork,

    Miami )

    ( NewYork,

    Dallas )

    ( NewYork,

    Frisco )

    ( NewYork,

    Boston,

    Miami )

    ( NewYork,

    Frisco,

    Miami )

    250 1200 15002900

    0

    250 1200 1500 2900

    1450 3300

    1700 6200

    Keep track ofaccumulated costs in each state if you want

    to be sure to get the best path.

    4. Problem reduction

  • 7/29/2019 State Space TreesUP

    52/103

    or problem decomposition:

    Ex.: Computing symbolic integrals:

    State: the integral to compute Rules: integration reduction rules

    Goal: all integrals have been eliminated

    AND-OR-tree search

    x2 + 3x + sin2x . cos2x dxx2 dx 3xdx sin2x . cos2x dx

    x3/3 3 xdx((sin2x)/2)2dx (1 - cos2x).cos2x dx

    AND

    ... ... ... ...

    Necessary for decomposition:

  • 7/29/2019 State Space TreesUP

    53/103

    Necessary for decomposition:

    independence of states:

    Ex.: Blocks world problem.

    Initially: C is on A and B is on the table.

    Rules: to move any free block to another or to the table

    Goal: A is on B and B is on C.

    53

    A

    C

    B

    Goal: A on B and B on C

    A

    C

    B

    Goal: A on B

    A

    C

    B

    Goal: B on C

    AND-OR-tree?

    AND

  • 7/29/2019 State Space TreesUP

    54/103

    54

    A

    C

    B

    Goal: A on B

    A

    C

    B

    Goal: B on C

    AND

    AC B

    Goal: A on BA

    C

    B

    A

    C B

    But: branches cannot be

    combined

    5. Forward versus

  • 7/29/2019 State Space TreesUP

    55/103

    backward reasoning:

    55

    Initial states

    Goal states

    Forward reasoning (or forward chaining): from initial states to goal states.

    5. Forward versus

  • 7/29/2019 State Space TreesUP

    56/103

    backward reasoning:

    Initial states

    Goal states

    Backward reasoning (or backward chaining): from goal states to initial

    states.

    Criteria:

  • 7/29/2019 State Space TreesUP

    57/103

    Criteria:

    57

    1 3 8

    2 7

    5 4 6

    1 2 3

    567

    48

    In this case: even the same rules !!

    Sometimes equivalent: (Ex.: 8-puzzle:)

    Branching factor (Ex.: see previous slide)

    Sometimes: no way to start from the goal states

    because there are too many (Ex.: chess)

    because you cant (easily) formulate the rules in2 directions.

    Criteria (2):

  • 7/29/2019 State Space TreesUP

    58/103

    Other possibility: middle-out reasoning.58

    The ratio of initial states versus goal states:

    Ex.: finding your way to some destination

    Backward reasoning!

    Providing explanation facilities:

    (Ex.: expert systems with user interaction)

  • 7/29/2019 State Space TreesUP

    59/103

    Definition:Programs that implement approaches to search

    problems using the state space representation.

    Production-rule systems:

    Consist of:

    A rule base,

    a working memory, containing the state(s) that have currently

    been reached,

    a control strategy for selecting the rules to apply next to the

    states in the working memory (including techniques for

    matching, verifying preconditions and whether a goal state hasbeen reached)

  • 7/29/2019 State Space TreesUP

    60/103

    Msc. Jorge Espinosa

    [email protected]

    Horas y correo de contactoMircoles de 9 a 11 a.m.

    y Jueves de 8 a 9 a.m.

    P19 211 C Ext 492

    Medelln 2013

    INGENIERA DEL CONOCIMIENTO

    Intro to Graph and trees

  • 7/29/2019 State Space TreesUP

    61/103

    Aim of these slides

    Introduce the technical language of graphsand trees.

    Motivation:

    divide and conquer:

    become familiar with the jargon of graphs before

    trying to learn about search

  • 7/29/2019 State Space TreesUP

    62/103

    Graphs

    Graphs are the mathematical and computerscience abstraction that capture many shared andcommon concepts of real-life objects such as

    networks, e.g. water

    electricity

    internet

    mazes road maps

    timetabling

    IA Games Theory

  • 7/29/2019 State Space TreesUP

    63/103

    Graphs

    Many problems in CS/AI can be reduced toproblems in graph theory, gives a good way to share results, methods &

    implementations across many areas Graph Theory has its own jargon; but it is worth

    becoming familiar with it e.g. in discussions of network topology, social

    networks,

  • 7/29/2019 State Space TreesUP

    64/103

    Terminology of Graphs

    Just giving the ideas. Exact mathematical definitions notneeded for this course, and are available in many textbooks,wikipedia, etc.

    A Graph consists of a set V of nodes, and a set E ofedges

    Node has a unique label for identification

    Edge connects two nodes any two nodes have at most one edge between them

    usually forbid self-edges : edges from a node back to itself can be a

    directed edge: e.g. from A to B a one-way street undirected edge: e.g. between A and B a standard street

  • 7/29/2019 State Space TreesUP

    65/103

    Graph Example

    This is not a map!

    The positions of thenodes do not matter,

    only theirinterconnections

    E.g. LondonUnderground Mapgives

    interconnections, butnot true locations

    B

    C

    D

    E

    F

    G

    A

  • 7/29/2019 State Space TreesUP

    66/103

    Mapas

  • 7/29/2019 State Space TreesUP

    67/103

    Mapas

  • 7/29/2019 State Space TreesUP

    68/103

  • 7/29/2019 State Space TreesUP

    69/103

    Mapa

  • 7/29/2019 State Space TreesUP

    70/103

    Graph Example

    Crossing of edges(arcos,aristas) hasno meaning

    A-D and B-E crossin the picture butthey do notinterconnect

    These two

    pictures are thesame graph

    B

    CD

    E

    F G

    A

    B

    CD

    E

    F

    G

    A

  • 7/29/2019 State Space TreesUP

    71/103

    Terminology of Graphs

    Path

    connected sequence of edges (arcos-aristas):

    e.g. A to B to F to C to G

    usually not allowed to use the same node (or edge)twice

    if the edges are directed then the path has to followthe directions of the edges. E.g. follow the one-waystreets on a map

    B

    CD

    E

    F

    G

    A

  • 7/29/2019 State Space TreesUP

    72/103

    Reachable

    Node B is said to be reachable from node Aif and only if

    there is a path from A to B

    Relevance to real-world: many search problems are questions about whether or

    not some goal is reachablefrom some start node part of maintaining the internet topology is ensuring

    that any node (site) is reachable from any other site a design factor in the internet was that nodes stayreachable even if some links are broken

    e.g. in the event of nuclear war

  • 7/29/2019 State Space TreesUP

    73/103

    Connected Graphs

    Connected Graph. Definition: for any two nodes there is a path between them

    i.e. any node is reachable from any other node

    E.g. this graph is connected

    B

    CD

    E

    F

    G

    A

  • 7/29/2019 State Space TreesUP

    74/103

    Connected Graphs

    E.g. this graph is disconnected

    There is no path from A to B

    B

    CD

    E

    F

    G

    A

  • 7/29/2019 State Space TreesUP

    75/103

    Cycles

    Definition: a cycle is a path that goes in a loopfrom a node back to itself, and without usingthe same node twice

    E.g. A-B-E-A in

    B

    CD

    E

    F

    G

    A

  • 7/29/2019 State Space TreesUP

    76/103

    Tree

    A tree is a graph that is connected

    but becomes disconnected if you remove any

    edge (cut the edge) Matches nature

    real trees are connected

    cut any branch then the tree falls into two pieces

  • 7/29/2019 State Space TreesUP

    77/103

    Tree: Example

    This is a tree

    B

    CD

    E

    F

    G

    A

    H

    I

    J

  • 7/29/2019 State Space TreesUP

    78/103

    Acyclic Graphs

    Defn: An acyclic graph has no cycles

    Alternative definition:

    A tree is a graph that is

    connected, and

    acyclic

  • 7/29/2019 State Space TreesUP

    79/103

    Trees

    Question: Why is a acyclic equivalent tobecomes disconnected on any cut?

    B

    CD

    E

    F

    G

    A

    Suppose we cut edge A-B

    Graph stays connected

  • 7/29/2019 State Space TreesUP

    80/103

    Trees

    A Tree is connected: given any two nodes A and B there exists at least one pathbetween them Question: Given a tree, and any two nodes A and B, is the path between them

    unique? or might there be pairs of nodes that have more than one path betweenthem?

    Suppose nodes E and F have two distinct paths P1 and P2 between them: Using P1 followed by reverse(P2), we would be able to construct a cycle. But trees are acyclic, hence, paths between nodes of a tree must be unique

    B

    D

    E

    FA

    P1(E,F)

    B

    D

    E

    FA

    P2(E,F)

    B

    D

    E

    FA

    P1(E,F) U P2(F,E)

  • 7/29/2019 State Space TreesUP

    81/103

    Trees

    A tree is a graph that:1. is connected but becomes disconnected on removing

    any edge

    2. is connected and acyclic

    3. has precisely one path between any two nodes

    The above 3 definitions are equivalent

    Suggestion: become comfortable enough with the

    definitions for this equivalence to be self-evident

    R d T

  • 7/29/2019 State Space TreesUP

    82/103

    Rooted Trees

    Often in trees have a special node called theroot

    E.g.

    J

    B

    CD

    E

    F

    G

    A

    H

    I

    R d T

  • 7/29/2019 State Space TreesUP

    83/103

    Rooted Trees

    Often in trees have a special node called the root Usually also give edges a direction away from the root

    e.g.

    J

    B

    CD

    E

    F

    G

    A

    H

    I

    R d T

  • 7/29/2019 State Space TreesUP

    84/103

    Rooted Trees

    Often, on making a picture of a tree Pick up the tree by the root

    let it hang, and shake it a bit

    JB C

    D

    E

    F

    G

    A

    H

    I

    J

    B

    CD

    E

    F

    G

    A

    H

    I

    But in practice

    you dont usually get the pretty version

    programs have to use messy representations

    R t d T J

  • 7/29/2019 State Space TreesUP

    85/103

    Rooted Trees: Jargon

    The nodes directly below a node arecalled its children e.g. H and E are children of B B is the parent of H H and E are siblings

    Children, children of children, etc aredescendents D is a descendent of B

    Parents,parents of parents, etc areancestors B is an ancestor of D

    A node without children is called aleaf node (or terminal node) e.g. G is a leaf node

    JB C

    D

    E

    F

    G

    A

    H

    I

    R t d T E l

  • 7/29/2019 State Space TreesUP

    86/103

    Rooted Tree : Example

    File systems are rooted trees (Suggestion: When thinking/studying search and it becomes

    too abstract, then filesystems provide a concrete example thatmight make it easier to understand)

    DOS/Windows C:\ is the root (of the C drive)

    Unix / is the root there is even a root user the one that has enough privileges to

    modify the root directory (and all others)

    R t d T E l

  • 7/29/2019 State Space TreesUP

    87/103

    Rooted Tree : Example

    File systems are rootedtrees

    nodes = files or folders

    (a.k.a. directories)

    edges = links from a folderto the files/folders that itcontains

    links are addresses on the

    hard drive

    \J

    \B

    \B\E

    \

    \B\E\A

    \B\H

    \B\E\I

    R t d T E l

  • 7/29/2019 State Space TreesUP

    88/103

    Rooted Tree : Example

    Actual layout on hard drive will be a mess

    \J \B \B\E\ \B\E\A\B\H \B\E\I

    R t d T E l

  • 7/29/2019 State Space TreesUP

    89/103

    Rooted Tree : Example

    Note: there might be a lot of data on the hard drivethat has no valid link to it

    removing a file means just remove the link to it

    can still be on the hard-drive but you cannot reach it byfollowing links from the root directory

    scanning the hard drive for a string does not tell youwhether the string occurs in the filesystem

    E.g. del \B\E\A (or unix rm /B/E/A) gives

    \J \B \B\E\ \B\E\A\B\H \B\E\I

    S ft f R

  • 7/29/2019 State Space TreesUP

    90/103

    Software for Recovery

    T B hi f t

  • 7/29/2019 State Space TreesUP

    91/103

    Trees: Branching factor

    The branching factor of a node is just the number ofbranches emerging from it its number of children

    Branching factor of the tree itself is (usually): largest

    branching factor of any node

    (Might also read about an effective branchingfactor some form of average over the nodes)

    Trees b 2

  • 7/29/2019 State Space TreesUP

    92/103

    Trees: b=2

    If the largest branchingfactor is two then wehave a binary tree

    JB

    E

    F

    A

    H

    I

    Trees b 1

  • 7/29/2019 State Space TreesUP

    93/103

    Trees: b=1

    If the largest branchingfactor is one then we havea linked list

    These are often used inprogramming as acontainer: a way to

    store a collection of

    objects

    B

    E

    F

    A

    Aside: Doubly Linked Lists

  • 7/29/2019 State Space TreesUP

    94/103

    Aside: Doubly Linked Lists

    Take a linked list and alsoadd edges from each(non-root) node to itsparent

    Used in programming as acontainer:

    can easily walk in both

    directions

    B

    E

    F

    A

    Trees: Depth

  • 7/29/2019 State Space TreesUP

    95/103

    Trees: Depth

    The depth, d, of a node isjust the number of edgesit is away from the rootnode

    The depth of a tree is thedepth of the deepestnode

    in this case, depth=4

    JB C

    D

    E

    F

    G

    A

    H

    I

    d=0

    d=1

    d=2

    d=3

    d=4

    Tree Sizes

  • 7/29/2019 State Space TreesUP

    96/103

    Tree Sizes

    Suppose we have a tree with branching factor b

    depth d

    What is the maximum number of nodes doesit can have?

    Sizes of Trees: Branching Factor

  • 7/29/2019 State Space TreesUP

    97/103

    Sizes of Trees: Branching Factor

    Increasing b rapidly increases the tree size:

    d nodes at d, b=2, 2d nodes at d, b=3, 3d

    0 1 11 2 3

    2 4 9

    3 8 27

    4 16 81

    5 32 243

    6 64 729

    Sizes of Trees

  • 7/29/2019 State Space TreesUP

    98/103

    Sizes of Trees

    Pattern seen in binary tree:nodes at d or less = nodes at d+1 1

    = 2d+1-1 = O(2d)

    The number of nodes grows exponentially Another manifestation of the Combinatorial Explosion

    Similarly, for a general tree number of nodes is O(bd)

    but, remember big O gives an upper bound,

    real trees might have a lot fewer nodes

    Trees are generally very leaf-heavy a large fraction of thenodes are leaves e.g. on your file system you probably have far more files

    than folders

    Effects of Tree Sizes

  • 7/29/2019 State Space TreesUP

    99/103

    Effects of Tree Sizes

    If possible try to work with trees with smaller branching factor

    smaller depth

    Be careful when programming that yourmemory requirements do not explode

    Summary

  • 7/29/2019 State Space TreesUP

    100/103

    Summary

    Definitions of graphs

    path

    connected cycles, and acyclic

    tree, and rooted tree

    Trees grow exponentially with depth

    Exercise

  • 7/29/2019 State Space TreesUP

    101/103

    Exercise

    Given a tree with Branching factor of 4, howmany nodes are acumulated at level 5(d=5)?

    If the b= 5, how many nodes are acumulatedat level 6 (d=6)??

    Questions?

  • 7/29/2019 State Space TreesUP

    102/103

    Questions?

  • 7/29/2019 State Space TreesUP

    103/103

    Puuufff!!

    Then See U Next Week

    Be Nice!!!