Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Initialize sibling pointers in a tree

Posted on 2007-03-24
5
Medium Priority
?
419 Views
Last Modified: 2008-02-01
I need an algorithm or pseudo code for the following problem:

Initialize sibling pointers of a tree level by level starting with the root.

This is the tree representation before:

Level 1: A (no sibling pointers)
Level 2: B, C (children of A) (no sibling pointers)
Level 3: D (children of B), F, G (children of C) (no sibling pointers)

and after:

Level 1: A
Level 2: B -> C
Level 3: D -> F -> G

Traversal result would be ABCDEFG.

Thanks
0
Comment
Question by:gromul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18787555
Isn't F a cousin of D rather than a sibling?
0
 

Author Comment

by:gromul
ID: 18787560
Ok, the problem is linking cousins.
0
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 18787584
traverse as in http:/Q_22470611.html keeping track of depth, and start a new pointer chan when the depth changes
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 18808589
Yep.  Breadth first search will visit the nodes in the proper order.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 18808928
I wonder what's the difference between http:/Q_22470611.html and the current question.

Here you said: "Initialize sibling pointers of a tree level" while the other question was "Traverse a complete tree level by level".

Above you said that you mean cousins rather than siblings. Then you said "This is the tree representation before".  Ok, that means that *currently* children pointers and cousin pointers were well defined, right?

But if so  I don't know what "initialization of cousin pointers means". "Initialization" normally means that you set the pointers to NULL. But if you do so, the tree information was lost and you can't traverse to cousins? Or do you mean by "initialization" that you have an empty tree and wants to build a tree like the one above?

Do you have already some code? E. g. a node struct/class ?

Regards, Alex
 
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question