Search Results

Search found 4232 results on 170 pages for 'tree traversal'.

Page 10/170 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Count function on tree structure (non-binary)

    - by Spevy
    I am implementing a tree Data structure in c# based (largely on Dan Vanderboom's Generic implementation). I am now considering approach on handling a Count property which Dan does not implement. The obvious and easy way would be to use a recursive call which Traverses the tree happily adding up nodes (or iteratively traversing the tree with a Queue and counting nodes if you prefer). It just seems expensive. (I also may want to lazy load some of my nodes down the road). I could maintain a count at the root node. All children would traverse up to and/or hold a reference to the root, and update a internally settable count property on changes. This would push the iteration problem to when ever I want to break off a branch or clear all children below a given node. Generally less expensive, and puts the heavy lifting what I think will be less frequently called functions. Seems a little brute force, and that usually means exception cases I haven't thought of yet, or bugs if you prefer. Does anyone have an example of an implementation which keeps a count for an Unbalanced and/or non-binary tree structure rather than counting on the fly? Don't worry about the lazy load, or language. I am sure I can adjust the example to fit my specific needs. EDIT: I am curious about an example, rather than instructions or discussion. I know this is not technically difficult...

    Read the article

  • How to Create tree type CVL in Content server(UCM)

    - by rajeev.y.ranjan-oracle
    Steps to create tree choice list:1)Create a table "tblStates" with column "stateID" and "stateName". Click on "ADD Recommended".2) Create another table "tblCities with columns "cityID", "stateID" and "cityName".3)Then create two views on these tables namely "tblstateview" and "tblcityview".3)In "StateView" added two rows with values as JH and MH in stateID column.Jharkhand and Maharastra in stateName.4)Similarly in tblcityview added two rows with values as:BO and RA in cityID column.JH and MH in stateID columnBokaro and Mumbai in cityname column.5)Created relationship with Parentinfo "tblStates" and stateID and  childinfo with tblCities and stateID.6)Created metadata by name "Newtest"Enable option list,go to the configure ,Select use tree,Click on go edit definition 7)Tree Definition at level 1: a)Choose" tblstateView"b)Choose relation "newstatecity"At Level2:a)Choose cityView.Log out of the NativeUI and ContentUI and test the tree created by name "Newtest".

    Read the article

  • FIlling a Java Bean tree structure from a csv flat file

    - by Clem
    Hi, I'm currently trying to construct a list of bean classes in Java from a flat description file formatted in csv. Concretely : Here is the structure of the csv file : MES_ID;GRP_PARENT_ID;GRP_ID;ATTR_ID M1 ; ;G1 ;A1 M1 ; ;G1 ;A2 M1 ;G1 ;G2 ;A3 M1 ;G1 ;G2 ;A4 M1 ;G2 ;G3 ;A5 M1 ; ;G4 ;A6 M1 ; ;G4 ;A7 M1 ; ;G4 ;A8 M2 ; ;G1 ;A1 M2 ; ;G1 ;A2 M2 ; ;G2 ;A3 M2 ; ;G2 ;A4 It corresponds to the hierarchical data structure : M1 ---G1 ------A1 ------A2 ------G2 ---------A3 ---------A4 ---------G3 ------------A5 ------G4 ---------A7 ---------A8 M2 ---G1 ------A1 ------A2 ---G2 ------A3 ------A4 Remarks : A message M can have an infinite number of groups G and attributes A A group G can have an infinite number of attributes and an infinite number of under-groups each of them having under-groups too That beeing said, I'm trying to read this flat csv decription to store it in this structure of beans : Map<String, MBean> messages = new HashMap<String, Mbean>(); == public class MBean { private String mes_id; private Map<String, GBean> groups; } public class GBean { private String grp_id; private Map<String, ABean> attributes; private Map<String, GBean> underGroups; } public class ABean { private String attr_id; } Reading the csv file sequentially is ok and I've been investigating how to use recursion to store the description data, but couldn't find a way. Thanks in advance for any of your algorithmic ideas. I hope it will put you in the mood of thinking about this ... I've to admit that I'm out of ideas :s

    Read the article

  • Implementing the tree with reference to the root for each leaf

    - by AntonAL
    Hi, i implementing a products catalog, that looks, like this: group 1 subgroup 1 subgroup 2 item 1 item 2 ... item n ... subgroup n group 2 subgroup 1 ... subgroup n group 3 ... group n The Models: class CatalogGroup < ActiveRecord::Base has_many: catalog_items has_many :catalog_items_all, :class_name => "CatalogItem", :foreign_key => "catalog_root_group_id" end class CatalogItem < ActiveRecord::Base belongs_to :catalog_group belongs_to :catalog_root_group, :class_name => "CatalogGroup" end Migrations: class CreateCatalogItems < ActiveRecord::Migration def self.up create_table :catalog_items do |t| t.integer :catalog_group_id t.integer :catalog_root_group_id t.string :code t.timestamps end end For convenience, i referenced each CatalogItem to it's top-most CatalogGroup and named this association "catalog_root_group". This will give us the simple implementation of search request, like "show me all items in group 1". We will have a deal only with CatalogModel.catalog_root_group The problem is - this association does't work. I always get "catalog_root_group" equals to nil Also, i have tried to overcome the using of reference to root group ("catalog_root_group"), but i cannot construct appropriate search request in ruby ... Do you know, how to do it ?

    Read the article

  • Parse tree and grammars information

    - by fuzzylogikk
    Do anyone know where to find good online resources with examples how to make grammars and parsetrees? Preferebly introductary materials. Info that is n00b friendly, haven't found anything good with google myself. edit: I'm thinking about theory, not a specific parser software.

    Read the article

  • Need algorithm to add Node in binary tree

    - by m.qayyum
    •if your new element is less or equal than the current node, you go to the left subtree, otherwise to the right subtree and continue traversing •if you arrived at a node, where you can not go any deeper, because there is no subtree, this is the place to insert your new element (5)Root (3)-------^--------(7) (2)---^----(5) ^-----(8) (5)--^ i want to add this last node with data 5...but i can't figure it out...I need a algorithm to do that or in java language

    Read the article

  • A two way minimum spanning tree of a directed graph

    - by mvid
    Given a directed graph with weighted edges, what algorithm can be used to give a sub-graph that has minimum weight, but allows movement from any vertex to any other vertex in the graph (under the assumption that paths between any two vertices always exist). Does such an algorithm exist?

    Read the article

  • Acts as Tree with Multiple Models

    - by Joe
    I've got several models that I'd like to relate together hierarchically. For simplicity's sake, let's say I've got these three: class Group < ActiveRecord::Base acts_as_tree has_many :users end class User < ActiveRecord::Base acts_as_tree belongs_to :group has_many :posts end class Post < ActiveRecord::Base acts_as_tree belongs_to :user end Under the current acts_as_tree, each node can individually can relate hierarchically to other nodes provided they are of the same type. What I'd like is to remove this restriction on type identity, so that SomePost.parent could have a User or a Post as its' parent, and that SomeUser.parent could have another user or a group as its parent. Any thoughts?

    Read the article

  • PHP Moving mySQL Tree Node

    - by TK
    I am having trouble trying to move sub nodes or parent nodes up or down... not that good at math. CREATE TABLE IF NOT EXISTS `pages` ( page-id mediumint(8) unsigned NOT NULL AUTO_INCREMENT, page-left mediumint(8) unsigned NOT NULL, page-right smallint(8) unsigned NOT NULL, page-title text NOT NULL, page-content text NOT NULL, page-time int(11) unsigned NOT NULL, page-slug text NOT NULL, page-template text NOT NULL, page-parent mediumint(8) unsigned NOT NULL, page-type text NOT NULL, PRIMARY KEY (page-id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; INSERT INTO pages (page-id, page-left, page-right, page-title, page-content, page-time, page-slug, page-template, page-parent, page-type) VALUES (17, 1, 6, '1', '', 0, 'PARENT', '', 0, ''), (18, 2, 5, '2', '', 0, 'SUB', '', 17, ''), (19, 3, 4, '3', '', 0, 'SUB-SUB', '', 18, ''), (20, 7, 8, '5', '', 0, 'TEST', '', 0, ''); As example how would I move TEST up above PARENT and say move SUB down below SUB-SUB by playing with the page-left/page-right IDs? Code is not required just help with the SQL concept or math for it, would help me understand how to move it better...

    Read the article

  • How to modify preorder tree traversal algorithm to handle nodes with multiple parents?

    - by poldo
    I've been searching for a while now and can't seem to find an alternative solution. I need the tree traversal algorithm in such a way that a node can have more than 1 parent, if it's possible (found a great article here: Storing Hierarchical Data in a Database). Are there any algorithms so that, starting from a root node, we can determine the sequence and dependencies of nodes (currently reading topological sorting)?

    Read the article

  • magento category tree menu query being called on every page

    - by user1173309
    I have this query being called on every page in Magento CE 1.6.2, to find out where is it being called from, I have disabled all modules, removed the customizations done but it's still being called, this query is slowing up the page loading time and am at my wit's end trying to find out how can I stop it from being executed. The query is given below, for simplcitiy, I have removed lot of category id' to keep the sql short, it would be great if I could get solutions or hints to stop this query being called. SELECT e.*, IF(at_is_active.value_id 0, at_is_active.value, at_is_active_default.value) AS is_active, IF(at_include_in_menu.value_id 0, at_include_in_menu.value, at_include_in_menu_default.value) AS include_in_menu, core_url_rewrite.request_path FROM catalog_category_entity AS e INNER JOIN catalog_category_entity_int AS at_is_active_default ON (at_is_active_default.entity_id = e.entity_id) AND (at_is_active_default.attribute_id = '119') AND at_is_active_default.store_id = 0 LEFT JOIN catalog_category_entity_int AS at_is_active ON (at_is_active.entity_id = e.entity_id) AND (at_is_active.attribute_id = '119') AND (at_is_active.store_id = 1) INNER JOIN catalog_category_entity_int AS at_include_in_menu_default ON (at_include_in_menu_default.entity_id = e.entity_id) AND (at_include_in_menu_default.attribute_id = '934') AND at_include_in_menu_default.store_id = 0 LEFT JOIN catalog_category_entity_int AS at_include_in_menu ON (at_include_in_menu.entity_id = e.entity_id) AND (at_include_in_menu.attribute_id = '934') AND (at_include_in_menu.store_id = 1) LEFT JOIN core_url_rewrite ON (core_url_rewrite.category_id=e.entity_id) AND (core_url_rewrite.is_system=1 AND core_url_rewrite.product_id IS NULL AND core_url_rewrite.store_id='1' AND id_path LIKE 'category/%') WHERE (e.entity_type_id = '9') AND (e.entity_id IN('105', '125', '284', '285', '286', '288', '289', '185', '463', '464', '465', '625')) AND (e.entity_id NOT IN('140', '145', '530', '531', '775')) AND (IF(at_is_active.value_id 0, at_is_active.value, at_is_active_default.value) = '1') AND (IF(at_include_in_menu.value_id 0, at_include_in_menu.value, at_include_in_menu_default.value) = '1') Cheers Arjun

    Read the article

  • A balanced binary search tree which is also a heap

    - by saeedn
    I'm looking for a data structure where each element in it has two keys. With one of them the structure is a BST and looking at the other one, data structure is a heap. With a little search, I found a structure called Treap. It uses the heap property with a random distribution on heap keys to make the BST balanced! What I want is a Balanced BST, which can be also a heap. The BST in Treap could be unbalanced if I insert elements with heap Key in the order of my choice. Is there such a data structure?

    Read the article

  • looping through an object (tree)

    - by Val
    Is there a way (in jquery or javascript) to loop through each object and it's children and gandchildren and so on. if so... can i also read their name? example foo :{ bar:'', child:{ grand:{ greatgrand: { //and so on } } } } so the loop should do something like this... loop start if(nameof == 'child'){ //do something } if(nameof == 'bar'){ //do something } if(nameof =='grand'){ //do something } loop end I know this is stupid code but i tried to make it understandable :) btw this is for a jquery UI, as i am clueless how to go on about this. thanks

    Read the article

  • Error inserting data in binary tree

    - by chepe263
    I copied this code (in spanish) http://www.elrincondelc.com/nuevorincon/index.php?pag=codigos&id=4 and wrote a new one. This is my code: #include <cstdlib> #include <conio.h> #include <iostream> using namespace std; struct nodoarbol { int dato; struct nodoarbol *izq; struct nodoarbol *der; }; typedef nodoarbol Nodo; typedef Nodo *Arbol; void insertar(Arbol *, int); void inorden(Arbol); void postorden(Arbol); void preorden(Arbol); void insertar(Arbol *raiz, int nuevo){ if (*raiz==NULL){ *raiz = (Nodo *)malloc(sizeof(Nodo)); if (*raiz != NULL){ (*raiz)->dato=nuevo; (*raiz)->der=NULL; (*raiz)->izq=NULL; } else{ cout<<"No hay memoria suficiente u ocurrio un error"; } } else{ if (nuevo < (*raiz)->dato) insertar( &((*raiz)->izq), nuevo ); else if (nuevo > (*raiz)->dato) insertar(&((*raiz)->der), nuevo); } }//inseertar void inorden(Arbol raiz){ if (raiz != NULL){ inorden(raiz->izq); cout << raiz->dato << " "; inorden(raiz->der); } } void preorden(Arbol raiz){ if (raiz != NULL){ cout<< raiz->dato << " "; preorden(raiz->izq); preorden(raiz->der); } } void postorden(Arbol raiz){ if (raiz!=NULL){ postorden(raiz->izq); postorden(raiz->der); cout<<raiz->dato<<" "; } } int main() { int i; i=0; int val; Arbol raiz = NULL; for (i=0; i<10; i++){ cout<<"Inserte un numero"; cin>>val; insertar( (raiz), val); } cout<<"\nPreorden\n"; preorden(raiz); cout<<"\nIneorden\n"; inorden(raiz); cout<<"\nPostorden\n"; postorden(raiz); return 0; } I'm using netbeans 7.1.1, mingw32 compiler This is the output: make[2]: Leaving directory `/q/netbeans c++/NetBeansProjects/treek' make[1]: Leaving directory `/q/netbeans c++/NetBeansProjects/treek' main.cpp: In function 'int main()': main.cpp:110:30: error: cannot convert 'Arbol {aka nodoarbol*}' to 'Nodo** {aka nodoarbol**}' for argument '1' to 'void insertar(Nodo**, int)' make[2]: *** [build/Release/MinGW-Windows/main.o] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 BUILD FAILED (exit value 2, total time: 11s) I don't understand what's wrong since i just copied the code (and rewrite it to my own code). I'm really good in php, asp.net (vb) and other languages but c is a headche for me. I've been struggling with this problem for about an hour. Could somebody tell me what could it be?

    Read the article

  • Binary Search Tree can't delete the root

    - by Ali Zahr
    Everything is working fine in this function, but the problem is that I can't delete the root, I couldn't figure out what's the bug here.I've traced the "else part" it works fine until the return, it returns the old value I don't know why. Plz Help! node *removeNode(node *Root, int key) { node *tmp = new node; if(key > Root->value) Root->right = removeNode(Root->right,key); else if(key < Root->value) Root->left = removeNode(Root->left, key); else if(Root->left != NULL && Root->right != NULL) { node *minNode = findNode(Root->right); Root->value = minNode->value; Root->right = removeNode(Root->right,Root->value); } else { tmp = Root; if(Root->left == NULL) Root = Root->right; else if(Root->right == NULL) Root = Root->left; delete tmp; } return Root; }

    Read the article

  • mysql category tree search

    - by ffffff
    I have the following schema on MySQL 5.1 CREATE TABLE `mytest` ( `category` varchar(32) , `item_name` varchar(255) KEY `key1` (`category`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; category column is filled with like that [:parent_parent_cat_id][:parent_cat_id][:leaf_cat_id] "10000200003000" if you can search all of the under categories :parent_parent_category_id SELECT * FROM mytest WHERE category LIKE "10000%"; it's using index key1; but How to use index when I wanna search :parent_cat_id? SELECT * FROM mytest WHERE category LIKE "%20000%"; Do you have a better solutions?

    Read the article

  • Express XPath as an expression tree

    - by 47d_
    If I have an XPath query like NodeA/NodeB[@WIDTH and not(@WIDTH="20")] | NodeC[@WIDTH and not(@WIDTH="20")]/NodeD Is there any API available to visualize this XPath query as a stack of atomic expressions, something like (following is generic) Get results of NodeA, call it "first set" Get results of NodeB from "first set" Filter where [@WIDTH and not(@WIDTH="20")] Filter NodeD, call this "node d for B" Get results of NodeC from "first set" Filter where [@WIDTH and not(@WIDTH="20")] Filter NodeD, call this "node d for C" Combine "node d for B" and "node d for C" I am trying to see if we can convert the XPath expression into custom expression which is close to english and vice versa. If no API is available, what would be the best approach? Thanks in advance.

    Read the article

  • transform file/directory structure into 'tree' in javascript

    - by dave
    I have an array of objects that looks like this: [{ name: 'test', size: 0, type: 'directory', path: '/storage/test' }, { name: 'asdf', size: 170, type: 'directory', path: '/storage/test/asdf' }, { name: '2.txt', size: 0, type: 'file', path: '/storage/test/asdf/2.txt' }] There could be any number of arbitrary path's, this is the result of iterating through files and folders within a directory. What I'm trying to do is determine the 'root' node of these. Ultimately, this will be stored in mongodb and use materialized path to determine it's relationships. In this example, /storage/test is a root with no parent. /storage/test/asdf has the parent of /storage/test which is the parent to /storage/test/asdf/2.txt. My question is, how would you go about iterating through this array, to determine the parent's and associated children? Any help in the right direction would be great! Thank you

    Read the article

  • How to find Sub-trees in non-binary tree

    - by kenny
    I have a non-binary tree. I want to find all "sub-trees" that are connected to root. Sub-tree is a a link group of tree nodes. every group is colored in it's own color. What would be be the best approach? Run recursion down and up for every node? The data structure of every treenode is a list of children, list of parents. (the type of children and parents are treenodes) Clarification: Group defined if there is a kind of "closure" between nodes where root itself is not part of the closure. As you can see from the graph you can't travel from pink to other nodes (you CAN NOT use root). From brown node you can travel to it's child so this form another group. Finally you can travel from any cyan node to other cyan nodes so the form another group

    Read the article

  • GUI question : representing large tree

    - by Peter
    I have a tree-like datastructure of some six levels deep, that I would like to represent on a single webpage (can be tabs, trees; ....) In each level both childnodes and content are possible. Presenting it like a real tree would be not very usable (too big). I was thinking in the lines of hiding parts of the tree when you drill down and presenting a breadcrumbs or the like to keep you informed as to where you are... I guess my question boils down to : any ideas / examples ? Tx!

    Read the article

  • How to find siblings of a tree?

    - by smallB
    On my interview for an internship, I was asked following question: On a whiteboard write the simplest algorithm with use of recursion which would take a root of a so called binary tree (so called because it is not strictly speaking binary tree) and make every child in this tree connected with its sibling. So if I have: 1 / \ 2 3 / \ \ 4 5 6 / \ 7 8 then the sibling to 2 would be 3, to four five, to five six and to seven eight. I didn't do this, although I was heading in the right direction. Later (next day) at home I did it, but with the use of a debugger. It took me better part of two hours and 50 lines of code. I personally think that this was very difficult question, almost impossible to do correctly on a whiteboard. How would you solve it on a whiteboard? How to apprehend this question without using a debugger?

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >