How to find the level of an n-ary tree

I have a n-ary tree. I traverse this tree using Breadth First and using queues to store the nodes that I encounter.
Can anyone tell me how to find the current level I am in this n-ary tree

How do I do that...My mind is drawing a blank totally
This code does a breadth first traversal
private void processTree(Node node) {
LinkedList queue = new LinkedList();
queue.addLast(node);
while (queue.size() > 0) {
     Node node1 =(Node)queue.removeFirst();
     if (node1 != null) {
          processNode(node1);//Do some processing on this node
          NodeList nodeList = node1.getChildNodes();
          for (int i = 0; i < nodeList.getLength(); i++) {
                    queue.addLast(nodeList.item(i));
Using this how can I determine the level. Since Im visiting each node of a particular level how do I know that a level is over and Im now visitng the next level?

Similar Messages

  • How to find the level of each child table in a relational model?

    Earthlings,
    I need your help and I know that, 'yes, we can change'. Change this thread to a answered question.
    So: How to find the level of each child table in a relational model?
    I have a relacional database (9.2), all right?!
         O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */
        /↑\ Fks
       O"O O" <-- level 2 for first table (circle)
      /↑\ Fks
    "o"o"o" <-- level 1 for middle table (circle)
       ↑ Fk
      "º"Tips:
    - each circle represents a table;
    - red tables no have foreign key
    - the table in first line of tree, for example, has level 3, but when 3 becomes N? How much is N? This's the question.
    I started thinking about the following:
    First I have to know how to take the children:
    select distinct child.table_name child
      from all_cons_columns father
      join all_cons_columns child
    using (owner, position)
      join (select child.owner,
                   child.constraint_name fk,
                   child.table_name child,
                   child.r_constraint_name pk,
                   father.table_name father
              from all_constraints father, all_constraints child
             where child.r_owner = father.owner
               and child.r_constraint_name = father.constraint_name
               and father.constraint_type in ('P', 'U')
               and child.constraint_type = 'R'
               and child.owner = 'OWNER') aux
    using (owner)
    where child.constraint_name = aux.fk
       and child.table_name = aux.child
       and father.constraint_name = aux.pk
       and father.table_name = aux.father;Thinking...
    Let's Share!
    My thanks in advance,
    Philips
    Edited by: BluShadow on 01-Apr-2011 15:08
    formatted the code and the hierarchy for readbility

    Justin,
    Understood.
    Nocycle not work in 9.2 and, even that would work, would not be appropriate.
    With your help, I decided a much simpler way (but there is still a small problem, <font color=red>IN RED</font>):
    -- 1
    declare
      type udt_roles is table of varchar2(30) index by pls_integer;
      cRoles udt_roles;
    begin
      execute immediate 'create user philips
        identified by philips';
      select granted_role bulk collect
        into cRoles
        from user_role_privs
       where username = user;
      for i in cRoles.first .. cRoles.count loop
        execute immediate 'grant ' || cRoles(i) || ' to philips';
      end loop;
    end;
    -- 2
    create table philips.root1(root1_id number,
                               constraint root1_id_pk primary key(root1_id)
                               enable);
    grant all on philips.root1 to philips;
    create or replace trigger philips.tgr_root1
       before delete or insert or update on philips.root1
       begin
         null;
       end;
    create table philips.root2(root2_id number,
                               constraint root2_id_pk primary key(root2_id)
                               enable);
    grant all on philips.root2 to philips;
    create or replace trigger philips.tgr_root2
       before delete or insert or update on philips.root2
       begin
         null;
       end;
    create table philips.node1(node1_id number,
                               root1_id number,
                               node2_id number,
                               node4_id number,
                               constraint node1_id_pk primary key(node1_id)
                               enable,
                               constraint n1_r1_id_fk foreign key(root1_id)
                               references philips.root1(root1_id) enable,
                               constraint n1_n2_id_fk foreign key(node2_id)
                               references philips.node2(node2_id) enable,
                               constraint n1_n4_id_fk foreign key(node4_id)
                               references philips.node4(node4_id) enable);
    grant all on philips.node1 to philips;
    create or replace trigger philips.tgr_node1
       before delete or insert or update on philips.node1
       begin
         null;
       end;
    create table philips.node2(node2_id number,
                               root1_id number,
                               node3_id number,
                               constraint node2_id_pk primary key(node2_id)
                               enable,
                               constraint n2_r1_id_fk foreign key(root1_id)
                               references philips.root1(root1_id) enable,
                               constraint n2_n3_id_fk foreign key(node3_id)
                               references philips.node3(node3_id) enable);
    grant all on philips.node2 to philips;
    create or replace trigger philips.tgr_node2
       before delete or insert or update on philips.node2
       begin
         null;
       end;                          
    create table philips.node3(node3_id number,
                               root2_id number,
                               constraint node3_id_pk primary key(node3_id)
                               enable,
                               constraint n3_r2_id_fk foreign key(root2_id)
                               references philips.root2(root2_id) enable);
    grant all on philips.node3 to philips;
    create or replace trigger philips.tgr_node3
       before delete or insert or update on philips.node3
       begin
         null;
       end;                          
    create table philips.node4(node4_id number,
                               node2_id number,
                               constraint node4_id_pk primary key(node4_id)
                               enable,
                               constraint n4_n2_id_fk foreign key(node2_id)
                               references philips.node2(node2_id) enable);
    grant all on philips.node4 to philips;
    create or replace trigger philips.tgr_node4
       before delete or insert or update on philips.node4
       begin
         null;
       end;                          
    -- out of the relational model
    create table philips.node5(node5_id number,
                               constraint node5_id_pk primary key(node5_id)
                               enable);
    grant all on philips.node5 to philips;
    create or replace trigger philips.tgr_node5
       before delete or insert or update on philips.node5
       begin
         null;
       end;
    -- 3
    create table philips.dictionary(table_name varchar2(30));
    insert into philips.dictionary values ('ROOT1');
    insert into philips.dictionary values ('ROOT2');
    insert into philips.dictionary values ('NODE1');
    insert into philips.dictionary values ('NODE2');
    insert into philips.dictionary values ('NODE3');
    insert into philips.dictionary values ('NODE4');
    insert into philips.dictionary values ('NODE5');
    --4
    create or replace package body philips.pck_restore_philips as
      procedure sp_select_tables is
        aExportTablesPhilips     utl_file.file_type := null; -- file to write DDL of tables   
        aExportReferencesPhilips utl_file.file_type := null; -- file to write DDL of references
        aExportIndexesPhilips    utl_file.file_type := null; -- file to write DDL of indexes
        aExportGrantsPhilips     utl_file.file_type := null; -- file to write DDL of grants
        aExportTriggersPhilips   utl_file.file_type := null; -- file to write DDL of triggers
        sDirectory               varchar2(100) := '/app/oracle/admin/tace/utlfile'; -- directory \\bmduhom01or02 
        cTables                  udt_tables; -- collection to store table names for the relational depth
      begin
        -- omits all referential constraints:
        dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'REF_CONSTRAINTS', false);
        -- omits segment attributes (physical attributes, storage attributes, tablespace, logging):
        dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SEGMENT_ATTRIBUTES', false);
        -- append a SQL terminator (; or /) to each DDL statement:
        dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SQLTERMINATOR', true);
        -- create/open files for export DDL:
        aExportTablesPhilips := utl_file.fopen(sDirectory, 'DDLTablesPhilips.pdc', 'w', 32767);
        aExportReferencesPhilips := utl_file.fopen(sDirectory, 'DDLReferencesPhilips.pdc', 'w', 32767);
        aExportIndexesPhilips := utl_file.fopen(sDirectory, 'DDLIndexesPhilips.pdc', 'w', 32767);
        aExportGrantsPhilips := utl_file.fopen(sDirectory, 'DDLGrantsPhilips.pdc', 'w', 32767);
        aExportTriggersPhilips := utl_file.fopen(sDirectory, 'DDLTriggersPhilips.pdc', 'w', 32767);
        select d.table_name bulk collect
          into cTables -- collection with the names of tables in the schema philips
          from all_tables t, philips.dictionary d
         where owner = 'PHILIPS'
           and t.table_name = d.table_name;
        -- execution
        sp_seeks_ddl(aExportTablesPhilips,
                     aExportReferencesPhilips,
                     aExportIndexesPhilips,
                     aExportGrantsPhilips,
                     aExportTriggersPhilips,
                     cTables);
        -- closes all files
        utl_file.fclose_all;
      end sp_select_tables;
      procedure sp_seeks_ddl(aExportTablesPhilips     in utl_file.file_type,
                             aExportReferencesPhilips in utl_file.file_type,
                             aExportIndexesPhilips    in utl_file.file_type,
                             aExportGrantsPhilips     in utl_file.file_type,
                             aExportTriggersPhilips   in utl_file.file_type,
                             cTables                  in out nocopy udt_tables) is
        cDDL       clob := null; -- colletion to save DDL
        plIndex    pls_integer := null;
        sTableName varchar(30) := null;
      begin
        for i in cTables.first .. cTables.count loop
          plIndex    := i;
          sTableName := cTables(plIndex);
           * Retrieves the DDL and the dependent DDL into cDDL clob       *      
          * for the selected table in the collection, and writes to file.*
          begin
            cDDL := dbms_metadata.get_ddl('TABLE', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportTablesPHILIPS, cDDL);
          exception
            when dbms_metadata.object_not_found then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('REF_CONSTRAINT', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportReferencesPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('INDEX', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportIndexesPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('OBJECT_GRANT', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportGrantsPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
          begin
            cDDL := dbms_metadata.get_dependent_ddl('TRIGGER', sTableName, 'PHILIPS');
            sp_writes_ddl(aExportTriggersPhilips, cDDL);
          exception
            when dbms_metadata.object_not_found2 then
              null;
          end;
        end loop;
      end sp_seeks_ddl;
      procedure sp_writes_ddl(aExport in utl_file.file_type,
                              cDDL    in out nocopy clob) is
        pLengthDDL  pls_integer := length(cDDL);
        plQuotient  pls_integer := null;
        plRemainder pls_integer := null;
      begin
          * Register variables to control the amount of lines needed   *
         * for each DDL and the remaining characters to the last row. *
        select trunc(pLengthDDL / 32766), mod(pLengthDDL, 32766)
          into plQuotient, plRemainder
          from dual;
          * Join DDL in the export file.                            *
         * ps. 32766 characters + 1 character for each line break. *
        -- if the size of the DDL is greater than or equal to limit the line ...
        if plQuotient >= 1 then
          -- loops for substring (lines of 32766 characters + 1 break character):
          for i in 1 .. plQuotient loop
            utl_file.put_line(aExport, substr(cDDL, 1, 32766));
            -- removes the last line, of clob, recorded in the buffer:
            cDDL := substr(cDDL, 32767, length(cDDL) - 32766);
          end loop;
        end if;
          * If any remains or the number of characters is less than the threshold (quotient = 0), *
         * no need to substring.                                                                 *
        if plRemainder > 0 then
          utl_file.put_line(aExport, cDDL);
        end if;
        -- record DDL buffered in the export file:
        utl_file.fflush(aExport);
      end sp_writes_ddl;
    begin
      -- executes main procedure:
      sp_select_tables;
    end pck_restore_philips;<font color="red">The problem is that I still have ...
    When creating the primary key index is created and this is repeated in the file indexes.
    How to avoid?</font>

  • How to find the header and item level status of a CRM contract ?

    Hi,
    Few questions
    A. How to find the header and item level status of a CRM contract ? My req is to select all the contract line items which are in CLOSED status.
    B. How to get the BPs associated with a contract ?
    Anyone have the list of CRM tables and the relation amongst them. Please mail me in [email protected]

    CRMD_ORDERADM_H     Contains the Header Information for a Business Transaction.
    Note:
    1.     It doesn’t store the Business Partner
           responsible for the transaction. To 
           get the Partner No, link it with
           CRM_ORDER_INDEX.
    2.     This table can be used for search
           based on the Object Id(Business
           Transaction No). 
    CRMD_CUSTOMER_H     Additional Site Details at the Header Level of a Business Transaction
    CRMD_LINK     Transaction GUID set for all the Business Transactions
    CRMD_ORDER_INDEX     Contains Header as well as Item details for a Business Transaction.
    Note:
    1.     It doesn’t store the Business 
          Transaction No (Object ID).
          To get the Business Transaction No  
          link the table with
          CRMD_ORDERADM_H
    2.   This table can be used for search
          based on the Partner No
    CRMD_ORDERADM_I     Stores the Item information for a Business Transaction. The scenarios where we have a Contract Header and within contract we have Line Items for the contract, this table can be useful.
    E.g. Service Contracts
    CRMD_CUSTOMER_I     Additional Site Details at the Item Level of a Service Contract
    Pl.reward points.......

  • What is latest bundle patch level for exadata x3-2 machine? how to find the doc?

    We have a exadata x3-2 machine. I have a question: What is latest bundle patch level for exadata x3-2 machine? how to find the doc?
    Thanks in advance.

    Check note id 888828.1
    This has all the infomation you need.

  • How to find the number of users  connected to database from OS level(Linux)

    Hi All,
    Could anyone know , how to find the number of users connected to database without connecting with sql*plus
    is there any command to find it?
    example we have 10 databases in one server, how to find the number of users connected to particular database without connecting to database(v$session)?
    oracle version:- 10g,11g
    Operating System:- OEL4/OEL5/AIX/Solaris
    any help will be appreciated.
    Thanks in advance.
    Thank you.
    Regards,
    Rajesh.

    Excellent.
    Tested, works as long as you set the ORACLE_SID first ( to change databases )
    ps -ef | grep $ORACLE_SID | grep "LOCAL=NO" | awk '{print $2}' | wc -l
    Thanks!
    select OSUSER
        from V$SESSION
    where AUDSID = SYS_CONTEXT('userenv','sessionid')
        and rownum=1;Best Regards
    mseberg

  • HOW TO FIND THE REQUIRED DELIVERY DATE IN VA02

    hi
    HOW TO FIND THE REQUIRED DELIVERY DATE IN VA02.
    i want to display this field in my report. what is the fieldname and in which table it is ?

    Hi Jyothsna,
    There are 2 dates when you say Requested Delivery Date
    1.  Header level in VBAK-VDATU is the field
    2.  At item level it is in the schedule line. VBEP-EDATU.
    The relationship between item (VBAP ) and schedule line ( VBEP )is 1 to many. But there will be mutiple schedule lines only if you are using the scheduling functionality. Also note to check for confirmed quantity (VBEP-BMENG) to be greater than 0 and use that schedule lines EDATU date as Requested delivery date.
    regards,
    Advait Gode.

  • How to find the Semifinished Goods in list of Finished Goods

    Hi
    I have list of Finished Goods. Tell me how to find the Semi finished Goods used in this finished Goods using Table Level.
    Kindly help.
    Regards,
    Rajkumar.C

    Hi,
    Have you created a Material  BOM for finished product ?
    if so all your subcomponents can be semi-finished or finished
    you can check in CS02 or MAST table
    regards,
    santosh

  • How to reduce the level of free text / direct purchasing

    A common problem at all sites is how to reduce the level of free text / direct / non catalogue based purchasing. This is where users enter an account assignment and free text instead of using an existing material number.
    This is often the case because it is too "dificult" for the user to search and find the correct material number.
    How have other sites handled this?
    has anyone found a solution that if a user enters lets say "paper" into the free text box, a pop up appears with a match on possible materials with the word "paper" in the short description? This sounds like a pretty easy function to implement? Does anyone have the code?
    Cheerio

    >
    Ravi.or.raj wrote:
    > The search function you ask for is pretty much a standard functionality.
    > In ME21N , click on  "Personal Settings"    , and select the check box "int search help on"  .
    Yes this works, but you have to tell that the user has to enter the text  in the material number field, then SAP will search thru the database.

  • How to find the id of the node given the path using connect by?

    I have a table like this:
    CREATE TABLE tab1 (Id INTEGER, Name VARCHAR2(100), ParentId INTEGER)
    Let's say I have the following rows:
    Id name ParentId
    1 X NULL
    2 Y 1
    3 Z 2
    4 A 3
    Now, given the path /X/Y/Z/A, I need to return 4
    Is it possible to achieve this using CONNECT BY?
    If it helps, I have over simplified the scenario - that a node has only one child. In reality, a node can have many children.
    Thanks.

    Hi,
    user2888313 wrote:
    Thanks for the suggestions - will follow from now on. Here's one way to post the sample data, given the CREATE TABLE statement you posted earlier:
    -- Basic data:
    INSERT INTO tab1 (id, name, parentid) VALUES (1,  'X', NULL);
    INSERT INTO tab1 (id, name, parentid) VALUES (2,  'Y', 1);
    INSERT INTO tab1 (id, name, parentid) VALUES (3,  'Z', 2);
    INSERT INTO tab1 (id, name, parentid) VALUES (4,  'A', 3);
    -- To test branching (i.e., multiple children for the same parent):
    INSERT INTO tab1 (id, name, parentid) VALUES (11, 'P', 1);
    INSERT INTO tab1 (id, name, parentid) VALUES (12, 'Q', 1);
    INSERT INTO tab1 (id, name, parentid) VALUES (13, 'R', 12);Alternatively, you could post a WITH clause, as someone did above.
    I am not clear how to use the LEVEL pseudo column. Should I just start from the root, find all paths up to the level I am looking for? Could you please give me the syntax? Sorry, I'm still not clear what you want, or why you want it.
    Do you want 4 because 'A' is the 4th generation in this family tree (that is, because 'A' has 3 ancestors), or do you want 4 because id=4 is on the same row as name='A'? In the former case, use LEVEL; in the latter, use the id column.
    This query shows both:
    SELECT  SYS_CONNECT_BY_PATH (name, '/')          AS name_path
    ,     LEVEL                                AS lvl
    ,     id
    FROM     tab1
    START WITH     parentid     IS NULL
    CONNECT BY     parentid     = PRIOR id
    ;Output from the expanded sample data:
    NAME_PATH                   LVL         ID
    /X                            1          1
    /X/Y                          2          2
    /X/Y/Z                        3          3
    /X/Y/Z/A                      4          4
    /X/P                          2         11
    /X/Q                          2         12
    /X/Q/R                        3         13

  • How to determine the level Of FRBs

    Hi All
    Can anybody tell me how to determine the level of profit center ( FRBs)
    in SAP. I mean for example that how will i find out the level the level of
    FRBs in the table BSIS.

    Below query will help
    select Serverproperty('productlevel'),
    Serverproperty('productversion'),
    Serverproperty('edition')
    The last column will show you edition which will confirm whether it is enterprise ,standard,evaluation or express
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • How to find revision level

    hi my requirement is that,
    i have to get the revision level for each material number in a specific plant,
    is there any function module which can get this data,
    actually this revision level has to be brought from table AEOI table,
    but its key fields are
    AENNR
    AETYP
    OBJKT
    i donot know how to get these fields.
    can some one help.
    thanks & rgds.

    hi charlie,
    thanks for the response,
    actually my problem was that the table AEOI had the value to be extracted but i didnot have input fields to retrive that value, what all i had were material number and plant,
    so i was asking how to find the link between matnr, werks and  fields  aennr, aetyp, objkt.
    anyways, i found from sdn that, we can pass matnr as objkt, and aetyp as 41( for material) ,
    and out of the records retieved latest would bare the correct revlv.
    thanks.

  • How to find the business content cubes..

    Hi bw guru's,
       how to find the standard cubes and how to map the fields for our reuirements..can any one help me ..in this scenario..
    thanx in advance..
    uma reddy

    uma,
    help.sap.com is a reasonably good source of information on available business content.  For example, here is an overview of BC for NW2004s:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/3d/5fb13cd0500255e10000000a114084/frameset.htm
    As you drill down you can often (but not always) find information on how the BI infoobjects map back to source system tables/fields.  For instance, this link shows this information for sales order header information under NW2004s:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/3c/63073c52619459e10000000a114084/frameset.htm
    As you navigate you'll want to take care that you're looking at information related your system version and business content level.
    Hope this helps.
    Bob

  • How to find the senior manager

    hi gurus ,
    i am involved in the extension of the standard workflow of leave approval , i want to extend the approval level. in std the is one approval level which identifies  the manger of the employee who requested for leave . my work is to extend to another appoval level to his senior manager . so when manager approves the workitem  , then it should go to senior manger for final approval  .
    for the first approval i got the agent through RULE 0000168 . how to find the senior manager  ?
    Message was edited by:
            arumugam shanmugam

    You can also try Rule AC00000157. In this rule you get the manager by providing the Position Id. This is useful when you know only the Position Id of the user.
    <b>Reward points if useful</b>

  • How to find kernel level

    hi guys
    can anyone tel me how to find the kernel level with out going to os.. i hav to check the kernel level in my portal screen..
    regards
    kamal..

    open the url
    http://<yourportal FQDN>:<portno>/index.html
    click system information
    There you find all the information of the Kernal and many others
    You can find Kernal version and patch level under  Server0.
    Raghu

  • How to find High level water mark

    Hi all,
    How to find high level water mark of a table.
    Thanks,
    Bhanu Chander.

    Probably you mean High Water Mark.
    select blocks from user_segments where segment_name='YOUR TABLE';
    exec dbms_stats.gather_table_stats('YOU','YOUR TABLE')
    select blocks from user_tables where table_name='YOUR TABLE';
    subtract the last number from the first number. That is where your High Water Mark stands.
    Kind regards
    Uwe
    http://uhesse.wordpress.com
    Correction: The last number is where your HWM stands. The difference between the two numbers is the amount of blocks where no row has been yet :-)
    Edited by: Uwe Hesse on 26.06.2009 21:00

Maybe you are looking for

  • Can't name new folders or rename existing folders in Finder

    I can't name new folders or rename existing folders in Finder. I've never had this happen before. I tried both using the new folder icon and choosing "new folder" from the actions icon. The only unusual thing I'm doing now is working with Spaces enab

  • Mouse trapped in second display

    Hi - I have my xorg.conf set up to display on my TV as well, this has worked fine until last upgrade. Now, if I move mouse over to the tv screen I can't get it back! It works fine on the tv but I can't do anything on my laptop screen. I know there ha

  • Its Been asked 1000 times b4 but its just not making sense.......

    I have just completed a track containing about 24 tracks all together. I have just started making a new track, with about 5 audio tracks and 3 midi tracks running, and i keep getting that annoying core audio error msg - Disk is too slow or System Ove

  • Manage permissions for a list sharepoint 2013

    Hey A user, only have permission to contribute on Document Library. He can give permissions for items in this Document Library? This user don't have permission to  Site but just the  Document Library?  Thanks

  • Can I make SQL*Plus output more readable like this ?

    Version : 11.2 Can I make sql results more readbale like below using SqlPlus ? ie. enclosing result columns neatly in a table like structure. +------------+------------+ | department | Avg Salary | +------------+------------+ | Finance    | 63863.247