Thread: how can a breadth-first-search-tree include every node have ancestor list

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    4

    how can a breadth-first-search-tree include every node have ancestor list

    how can a breadth-first-search-tree include every node have ancestor list. every node have multiple ancestor list(because every node may be multiple parents)
    input: undirected graph
    Last edited by cmsamota; 03-22-2014 at 09:52 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think that you need to explain more clearly what you are trying to do and what problems you are facing doing it. Just writing "input: undirected graph" tells me nothing about how does that relate in your case to a "breadth-first-search-tree", and how "include every node have ancestor list" is a problem.

    (Also, I don't think there is such a thing as a breadth-first search tree: you can apply breadth-first search on a tree, but that doesn't make it a "breadth-first-search-tree" since you can apply depth-first search on the same tree.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    ^_^

    I'm so pleased that I'm not the only one...

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  4. #4
    Registered User
    Join Date
    Mar 2014
    Posts
    4

    how can a breadth-first-search-tree include every node have ancestor list

    thank you laserlight
    i want to make ancestor list at every node in the bfs spanning tree but bfs spanning tree every node does not contain more then one parent. in my case every node have multiple parent and every node maintain own ancestor list(if single parent then single ancestor list else multiple parent then multiple ancestor list). ancestor list are stored at corresponding node.
    example:
    input graph
    node connected_with_node
    0 -> 1,2,5
    1 ->0,3
    2 ->0,3,4
    3 ->1,2
    4 ->2,5
    5 ->0,4
    desire output :
    node ancestor_list
    0 -(no any parent so no list)
    1 ->0-1
    2 ->0-2
    3 ->0-1-3
    ->0-2-3(node 2 have two parent so make two list)
    4 ->0-2-4
    ->0-5-4(same as node 2,node 4 have two parent)
    5 ->0-5


    and using BFS only for making ancestor list in graph.

    thank you laserlight
    Last edited by cmsamota; 03-23-2014 at 12:11 AM.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    I'm not sure I understand, but if I do, you have only to use normal "DFS" traversal of your graph with an recursive phase to reset "visited" for each parent followed by reducing the set.

    That said, having the list isn't the same as having valuable information about the list. If you are trying to find the "nearest" ancestor for each node or similar property you should search for specific algorithms related to what property you require.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  6. #6
    Registered User
    Join Date
    Mar 2014
    Posts
    4
    thank you sir
    Last edited by cmsamota; 03-23-2014 at 10:59 AM.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by cmsamota View Post
    thank you sir
    i'm beginner in c++ so please help me in code. please give me source code
    Please read the rules. At least this one.
    Announcements - General Programming Boards
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Breadth-first search
    By jordanguyoflove in forum C Programming
    Replies: 9
    Last Post: 03-31-2009, 08:01 AM
  2. Using Breadth First Search
    By neandrake in forum C++ Programming
    Replies: 4
    Last Post: 05-06-2005, 05:13 PM
  3. Help me about the Breadth-First-Search??
    By john_tran in forum C++ Programming
    Replies: 1
    Last Post: 04-09-2005, 02:33 AM
  4. Breadth-First Search
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 11-13-2003, 11:39 AM
  5. Binary Search Tree, Inserting node
    By cheryl_li in forum C Programming
    Replies: 1
    Last Post: 09-13-2003, 03:53 AM