Time complexity analysis
Set up(MySQL):

    create table inRelation(
    	party1 integer unsigned NOT NULL,
    	party2 integer unsigned NOT NULL,
    	unique (party1,party2)
    );
    
    insert into inRelation(party1,party2) values(1,2),(1,3),(2,3),(1,4),(2,5),(3,5),(1,6),(1,7),(2,7),(5,7);

    mysql> select * from inRelation a
        -> join inRelation b on a.party2=b.party1
        -> join inRelation c on b.party2=c.party1
        -> where a.party1 and c.party2=7;
    +--------+--------+--------+--------+--------+--------+
    | party1 | party2 | party1 | party2 | party1 | party2 |
    +--------+--------+--------+--------+--------+--------+
    |      1 |      2 |      2 |      5 |      5 |      7 |
    |      1 |      3 |      3 |      5 |      5 |      7 |
    |      2 |      3 |      3 |      5 |      5 |      7 |
    +--------+--------+--------+--------+--------+--------+
    3 rows in set (0.00 sec)
    
    mysql> explain select * from inRelation a
        -> join inRelation b on a.party2=b.party1
        -> join inRelation c on b.party2=c.party1
        -> where a.party1 and c.party2=7;
    +----+-------------+-------+--------+---------------+--------+---------+---------------------+------+---------------------------------------------+
    | id | select_type | table | type   | possible_keys | key    | key_len | ref                 | rows | Extra                                       |
    +----+-------------+-------+--------+---------------+--------+---------+---------------------+------+---------------------------------------------+
    |  1 | SIMPLE      | b     | index  | party1        | party1 | 8       | NULL                |   10 | Using index                                 |
    |  1 | SIMPLE      | a     | index  | NULL          | party1 | 8       | NULL                |   10 | Using where; Using index; Using join buffer |
    |  1 | SIMPLE      | c     | eq_ref | party1        | party1 | 8       | news.b.party2,const |    1 | Using index                                 |
    +----+-------------+-------+--------+---------------+--------+---------+---------------------+------+---------------------------------------------+
    3 rows in set (0.00 sec)


This is a BFS solution for my previous post:

http://stackoverflow.com/questions/2076715/challenge-how-to-implement-an-algorithm-for-six-degree-of-separation

But what's the complexity of it?Suppose there are totally `n` records .
Time complexity analysis
===

Set up(MySQL):

    create table inRelation(
    	party1 integer unsigned NOT NULL,
    	party2 integer unsigned NOT NULL,
    	unique (party1,party2)
    );
    
    insert into inRelation(party1,party2) values(1,2),(1,3),(2,3),(1,4),(2,5),(3,5),(1,6),(1,7),(2,7),(5,7);

    mysql> select * from inRelation a
        -> join inRelation b on a.party2=b.party1
        -> join inRelation c on b.party2=c.party1
        -> where a.party1 and c.party2=7;
    +--------+--------+--------+--------+--------+--------+
    | party1 | party2 | party1 | party2 | party1 | party2 |
    +--------+--------+--------+--------+--------+--------+
    |      1 |      2 |      2 |      5 |      5 |      7 |
    |      1 |      3 |      3 |      5 |      5 |      7 |
    |      2 |      3 |      3 |      5 |      5 |      7 |
    +--------+--------+--------+--------+--------+--------+
    3 rows in set (0.00 sec)
    
    mysql> explain select * from inRelation a
        -> join inRelation b on a.party2=b.party1
        -> join inRelation c on b.party2=c.party1
        -> where a.party1 and c.party2=7;
    +----+-------------+-------+--------+---------------+--------+---------+---------------------+------+---------------------------------------------+
    | id | select_type | table | type   | possible_keys | key    | key_len | ref                 | rows | Extra                                       |
    +----+-------------+-------+--------+---------------+--------+---------+---------------------+------+---------------------------------------------+
    |  1 | SIMPLE      | b     | index  | party1        | party1 | 8       | NULL                |   10 | Using index                                 |
    |  1 | SIMPLE      | a     | index  | NULL          | party1 | 8       | NULL                |   10 | Using where; Using index; Using join buffer |
    |  1 | SIMPLE      | c     | eq_ref | party1        | party1 | 8       | news.b.party2,const |    1 | Using index                                 |
    +----+-------------+-------+--------+---------------+--------+---------+---------------------+------+---------------------------------------------+
    3 rows in set (0.00 sec)


This is a BFS solution for my previous post:

http://stackoverflow.com/questions/2076715/challenge-how-to-implement-an-algorithm-for-six-degree-of-separation

But what's the complexity of it?Suppose there are totally `n` records .