Search Results

Search found 25747 results on 1030 pages for 'tree view'.

Page 2/1030 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Proper 'cleartool mkview' for ClearCase Snapshot view creation

    - by Jörg Battermann
    Good afternoon, seems like I am somewhat stuck in CC-land these days, but I have one (hopefully) final question regarding proper CC-handling: When using the CC View Creation Wizard with the two steps / details below, I can create a proper Snapshot view on my machine perfectly fine, however when trying to do the same with the mkview command, it fails... Here are the screenshots of the view creation wizard: Now that results into the (working) following view: cleartool> lsview battjo6r_view2 battjo6r_view2 \\Eh40yd4c\Views\battjo6r_view2.vws cleartool> lsview -long battjo6r_view2 Tag: battjo6r_view2 Global path: \\Eh40yd4c\Views\battjo6r_view2.vws Server host: Eh40yd4c Region: CT_WORK Active: NO View tag uuid:f34cf43f.b4d048df.845d.ed:21:a2:9c:45:ff View on host: Eh40yd4c View server access path: D:\Views\battjo6r_view2.vws View uuid: f34cf43f.b4d048df.845d.ed:21:a2:9c:45:ff View attributes: snapshot View owner: WW005\battjo6r However, when trying to create the view manually via mkview -snapshot -tag battjo6r_view2 -vws \\Eh40yd4c\Views\battjo6r_view2.vws -host Eh40yd4c -hpath D:\Views\battjo6r_view2.vws -gpath \\Eh40yd4c\Views\battjo6r_view2.vws battjo6r_view2 ... I get the following error: cleartool> mkview -snapshot -tag battjo6r_view2 -vws \\Eh40yd4c\Views\battjo6r_view2.vws -host Eh40yd4c -hpath D:\Views\battjo6r_view2.vws -gpath \\Eh40yd4c\Views\battjo6r_view2.vws battjo6r_view2 Created view. Host-local path: Eh40yd4c:D:\Views\battjo6r_view2.vws Global path: \\Eh40yd4c\Views\battjo6r_view2.vws cleartool: Error: Unable to find view by uuid:6f99f7ae.6a5d40e4.ba32.37:8e:e5:a4:ed:18, last known at "<viewhost>:<stg_path>". cleartool: Error: Unable to establish connection to snapshot view "6f99f7ae.6a5d40e4.ba32.37:8e:e5:a4:ed:18": ClearCase object not found cleartool: Warning: Unable to open snapshot view "D:\SnapShotViews\battjo6r_view2". cleartool: Error: Unable to create snapshot view "battjo6r_view2". Removing the view ... Any idea why this is happening? Am I missing something?

    Read the article

  • Event Driven Behavior Tree: deterministic traversal order with parallel

    - by Heisenbug
    I've studied several articles and listen some talks about behavior trees (mostly the resources available on AIGameDev by Alex J. Champandard). I'm particularly interested on event driven behavior trees, but I have still some doubts on how to implement them correctly using a scheduler. Just a quick recap: Standard Behavior Tree Each execution tick the tree is traversed from the root in depth-first order The execution order is implicitly expressed by the tree structure. So in the case of behaviors parented to a parallel node, even if both children are executed during the same traversing, the first leaf is always evaluated first. Event Driven BT During the first traversal the nodes (tasks) are enqueued using a scheduler which is responsible for updating only running ones every update The first traversal implicitly produce a depth-first ordered queue in the scheduler Non leaf nodes stays suspended mostly of the time. When a leaf node terminate(either with success or fail status) the parent (observer) is waked up allowing the tree traversing to continue and new tasks will be enqueued in the scheduler Without parallel nodes in the tree there will be up to 1 task running in the scheduler Without parallel nodes, the tasks in the queue(excluding dynamic priority implementation) will be always ordered in a depth-first order (is this right?) Now, from what is my understanding of a possible implementation, there are 2 requirements I think must be respected(I'm not sure though): Now, some requirements I think needs to be guaranteed by a correct implementation are: The result of the traversing should be independent from which implementation strategy is used. The traversing result must be deterministic. I'm struggling trying to guarantee both in the case of parallel nodes. Here's an example: Parallel_1 -->Sequence_1 ---->leaf_A ---->leaf_B -->leaf_C Considering a FIFO policy of the scheduler, before leaf_A node terminates the tasks in the scheduler are: P1(suspended),S1(suspended),leaf_A(running),leaf_C(running) When leaf_A terminate leaf_B will be scheduled (at the end of the queue), so the queue will become: P1(suspended),S1(suspended),leaf_C(running),leaf_B(running) In this case leaf_B will be executed after leaf_C at every update, meanwhile with a non event-driven traversing from the root node, the leaf_B will always be evaluated before leaf_A. So I have a couple of question: do I have understand correctly how event driven BT work? How can I guarantee the depth first order is respected with such an implementation? is this a common issue or am I missing something?

    Read the article

  • What is the kd tree intersection logic?

    - by bobobobo
    I'm trying to figure out how to implement a KD tree. On page 322 of "Real time collision detection" by Ericson The text section is included below in case Google book preview doesn't let you see it the time you click the link text section Relevant section: The basic idea behind intersecting a ray or directed line segment with a k-d tree is straightforward. The line is intersected against the node's splitting plane, and the t value of intersection is computed. If t is within the interval of the line, 0 <= t <= tmax, the line straddles the plane and both children of the tree are recursively descended. If not, only the side containing the segment origin is recursively visited. So here's what I have: (open image in new tab if you can't see the lettering) The logical tree Here the orange ray is going thru the 3d scene. The x's represent intersection with a plane. From the LEFT, the ray hits: The front face of the scene's enclosing cube, The (1) splitting plane The (2.2) splitting plane The right side of the scene's enclosing cube But here's what would happen, naively following Ericson's basic description above: Test against splitting plane (1). Ray hits splitting plane (1), so left and right children of splitting plane (1) are included in next test. Test against splitting plane (2.1). Ray actually hits that plane, (way off to the right) so both children are included in next level of tests. (This is counter-intuitive - shouldn't only the bottom node be included in subsequent tests) Can some one describe what happens when the orange ray goes through the scene correctly?

    Read the article

  • Algorithm for parsing a flat tree into a non-flat tree

    - by Chad Johnson
    I have the following flat tree: id name parent_id is_directory =========================================================== 50 app 0 1 31 controllers 50 1 11 application_controller.rb 31 0 46 models 50 1 12 test_controller.rb 31 0 31 test.rb 46 0 and I am trying to figure out an algorithm for getting this into the following tree structuree: [{ id: 50, name: app, is_directory: true children: [{ id: 31, name: controllers, is_directory: true, children: [{ id: 11, name: application_controller.rb is_directory: false },{ id: 12, name: test_controller.rb, is_directory: false }], },{ id: 46, name: models, is_directory: true, children: [{ id: 31, name: test.rb, is_directory: false }] }] }] Can someone point me in the right direction? I'm looking for steps (eg. build an associative array; loop through the array looking for x; etc.).

    Read the article

  • Implementation of Race Game Tree

    - by Mert Toka
    I build a racing game right in OpenGL using Glut, and I'm a bit lost in all the details. First of all, any suggestions as a road map would be more than great. So far what I thought is this: Tree implementation for transformations. Simulated dynamics.(*) Octree implementation for collusion detection. Actual collusion detection.(*) Modelling in Maya and export them as .OBJs. Polishing the game with GLSL or something like that for graphics quality. (*): I am not sure the order of these two. So I started with the simulated dynamics without tree, and it turned out to be a huge chaos for me. Is there any way you can think of such that could help me to build such tree to use in racing game? I thought something like this but I have no idea how to implement it. Reds are static, yellows are dynamic nodes

    Read the article

  • Programmatically disclosing a node in af:tree and af:treeTable

    - by Frank Nimphius
    A common developer requirement when working with af:tree or af:treeTable components is to programmatically disclose (expand) a specific node in the tree. If the node to disclose is not a top level node, like a location in a LocationsView -> DepartmentsView -> EmployeesView hierarchy, you need to also disclose the node's parent node hierarchy for application users to see the fully expanded tree node structure. Working on ADF Code Corner sample #101, I wrote the following code lines that show a generic option for disclosing a tree node starting from a handle to the node to disclose. The use case in ADF Coder Corner sample #101 is a drag and drop operation from a table component to a tree to relocate employees to a new department. The tree node that receives the drop is a department node contained in a location. In theory the location could be part of a country and so on to indicate the depth the tree may have. Based on this structure, the code below provides a generic solution to parse the current node parent nodes and its child nodes. The drop event provided a rowKey for the tree node that received the drop. Like in af:table, the tree row key is not of type oracle.jbo.domain.Key but an implementation of java.util.List that contains the row keys. The JUCtrlHierBinding class in the ADF Binding layer that represents the ADF tree binding at runtime provides a method named findNodeByKeyPath that allows you to get a handle to the JUCtrlHierNodeBinding instance that represents a tree node in the binding layer. CollectionModel model = (CollectionModel) your_af_tree_reference.getValue(); JUCtrlHierBinding treeBinding = (JUCtrlHierBinding ) model.getWrappedData(); JUCtrlHierNodeBinding treeDropNode = treeBinding.findNodeByKeyPath(dropRowKey); To disclose the tree node, you need to create a RowKeySet, which you do using the RowKeySetImpl class. Because the RowKeySet replaces any existing row key set in the tree, all other nodes are automatically closed. RowKeySetImpl rksImpl = new RowKeySetImpl(); //the first key to add is the node that received the drop //operation (departments).            rksImpl.add(dropRowKey);    Similar, from the tree binding, the root node can be obtained. The root node is the end of all parent node iteration and therefore important. JUCtrlHierNodeBinding rootNode = treeBinding.getRootNodeBinding(); The following code obtains a reference to the hierarchy of parent nodes until the root node is found. JUCtrlHierNodeBinding dropNodeParent = treeDropNode.getParent(); //walk up the tree to expand all parent nodes while(dropNodeParent != null && dropNodeParent != rootNode){    //add the node's keyPath (remember its a List) to the row key set    rksImpl.add(dropNodeParent.getKeyPath());      dropNodeParent = dropNodeParent.getParent(); } Next, you disclose the drop node immediate child nodes as otherwise all you see is the department node. Its not quite exactly "dinner for one", but the procedure is very similar to the one handling the parent node keys ArrayList<JUCtrlHierNodeBinding> childList = (ArrayList<JUCtrlHierNodeBinding>) treeDropNode.getChildren();                     for(JUCtrlHierNodeBinding nb : childList){   rksImpl.add(nb.getKeyPath()); } Next, the row key set is defined as the disclosed row keys on the tree so when you refresh (PPR) the tree, the new disclosed state shows tree.setDisclosedRowKeys(rksImpl); AdfFacesContext.getCurrentInstance().addPartialTarget(tree.getParent()); The refresh in my use case is on the tree parent component (a layout container), which usually shows the best effect for refreshing the tree component. 

    Read the article

  • Find the minimum gap between two numbers in an AVL tree

    - by user1656647
    I have a data structures homework, that in addition to the regular AVL tree functions, I have to add a function that returns the minimum gap between any two numbers in the AVL tree (the nodes in the AVL actually represent numbers.) Lets say we have the numbers (as nodes) 1 5 12 20 23 21 in the AVL tree, the function should return the minimum gap between any two numbers. In this situation it should return "1" which is |20-21| or |21-20|. It should be done in O(1). Tried to think alot about it, and I know there is a trick but just couldn't find it, I have spent hours on this. There was another task which is to find the maximum gap, which is easy, it is the difference between the minimal and maximal number.

    Read the article

  • Can a binary tree or tree be always represented in a Database as 1 table and self-referencing?

    - by Jian Lin
    I didn't feel this rule before, but it seems that a binary tree or any tree (each node can have many children but children cannot point back to any parent), then this data structure can be represented as 1 table in a database, with each row having an ID for itself and a parentID that points back to the parent node. That is in fact the classical Employee - Manager diagram: one boss can have many people under him... and each person can have n people under him, etc. This is a tree structure and is represented in database books as a common example as a single table Employee.

    Read the article

  • Can a binary tree or tree be always represented in a Database table as 1 table and self-referencing?

    - by Jian Lin
    I didn't feel this rule before, but it seems that a binary tree or any tree (each node can have many children but children cannot point back to any parent), then this data structure can be represented as 1 table in a database, with each row having an ID for itself and a parentID that points back to the parent node. That is in fact the classical Employee - Manager diagram: one boss can have many people under him... and each person under him can have n people under him, etc. This is a tree structure and is represented in database books as a common example as a single table Employee.

    Read the article

  • Inorder tree traversal in binary tree in C

    - by srk
    In the below code, I'am creating a binary tree using insert function and trying to display the inserted elements using inorder function which follows the logic of In-order traversal.When I run it, numbers are getting inserted but when I try the inorder function( input 3), the program continues for next input without displaying anything. I guess there might be a logical error.Please help me clear it. Thanks in advance... #include<stdio.h> #include<stdlib.h> int i; typedef struct ll { int data; struct ll *left; struct ll *right; } node; node *root1=NULL; // the root node void insert(node *root,int n) { if(root==NULL) //for the first(root) node { root=(node *)malloc(sizeof(node)); root->data=n; root->right=NULL; root->left=NULL; } else { if(n<(root->data)) { root->left=(node *)malloc(sizeof(node)); insert(root->left,n); } else if(n>(root->data)) { root->right=(node *)malloc(sizeof(node)); insert(root->right,n); } else { root->data=n; } } } void inorder(node *root) { if(root!=NULL) { inorder(root->left); printf("%d ",root->data); inorder(root->right); } } main() { int n,choice=1; while(choice!=0) { printf("Enter choice--- 1 for insert, 3 for inorder and 0 for exit\n"); scanf("%d",&choice); switch(choice) { case 1: printf("Enter number to be inserted\n"); scanf("%d",&n); insert(root1,n); break; case 3: inorder(root1); break; default: break; } } }

    Read the article

  • AVL tree in C language

    - by I_S_W
    Hey all; i am currently doing a project that requires the use of AVL trees , the insert function i wrote for the avl does not seem to be working , it works for 3 or 4 nodes at maximum ; i would really appreciate your help The attempt is below enter code here Tree insert(Tree t,char name[80],int num) { if(t==NULL) { t=(Tree)malloc(sizeof(struct node)); if(t!=NULL) { strcpy(t->name,name); t->num=num; t->left=NULL; t->right=NULL; t->height=0; } } else if(strcmp(name,t->name)<0) { t->left=insert(t->left,name,num); if((height(t->left)-height(t->right))==2) if(strcmp(name,t->left->name)<0) { t=s_rotate_left(t);} else{ t=d_rotate_left(t);} } else if(strcmp(name,t-name)0) { t-right=insert(t-right,name,num); if((height(t-right)-height(t-left))==2) if(strcmp(name,t-right-name)0){ t=s_rotate_right(t); } else{ t=d_rotate_right(t);} } t-height=max(height(t-left),height(t-right))+1; return t; }

    Read the article

  • Truly understand the threshold for document set in document library in SharePoint

    - by ybbest
    Recently, I am working on an issue with threshold. The problem is that when the user navigates to a view of the document library, it displays the error message “list view threshold is exceeded”. However, in the view, it has no data. The list view threshold limit is 5000 by default for the non-admin user. This limit is not the number of items returned by your query; it is the total number of items the database needs to read to calculate the returned result set. So although the view does not return any result but to calculate the result (no data to show), it needs to access more than 5000 items in the database. To fix the issue, you need to create an index for the column that you use in the filter for the view. Let’s look at the problem in details. You can download a solution to replicate this issue here. 1. Go to Central Admin ==> Web Application Management ==>General Settings==> Click on Resource Throttling 2. Change the list view threshold in web application from 5000 to 2000 so that I can show the problem without loading more than 5000 items into the list. FROM TO 3. Go to the page that displays the approved view of the Loan application document set. It displays the message as shown below although I do not have any data returned for this view. 4. To get around this, you need to create an index column. Go to list settings and click on the Index columns. 5. Click on the “Create a new index” link. 6. Select the LoanStatus field as I use this filed as the filter to create the view. 7. After the index is created now I can access the approved view, as you can see it does not return any data. Notes: List View Threshold: Specify the maximum number of items that a database operation can involve at one time. Operations that exceed this limit are prohibited. References: SharePoint lists V: Techniques for managing large lists Manage large SharePoint lists for better performance http://blogs.technet.com/b/speschka/archive/2009/10/27/working-with-large-lists-in-sharepoint-2010-list-throttling.aspx

    Read the article

  • New to AVL tree implementation.

    - by nn
    I am writing a sliding window compression algorithm (LZ77) that searches for phrases in a "moving" dictionary. So far I have written a BST where each node is stored in an array and it's index in the array is also the value of the starting position in the window itself. I am now looking at transforming the BST to an AVL tree. I am a little confused at the sample implementations I have seen. Some only appear to store the balance factors whereas others store the height of each tree. Are there any performance advantage/disadvantages of storing the height and/or balance factor for each node? Apologies if this is a very simple question, but I'm still not visualizing how I want to restructure my BST to implement height balancing. Thanks.

    Read the article

  • Convert a binary tree to linked list, breadth first, constant storage/destructive

    - by Merlyn Morgan-Graham
    This is not homework, and I don't need to answer it, but now I have become obsessed :) The problem is: Design an algorithm to destructively flatten a binary tree to a linked list, breadth-first. Okay, easy enough. Just build a queue, and do what you have to. That was the warm-up. Now, implement it with constant storage (recursion, if you can figure out an answer using it, is logarithmic storage, not constant). I found a solution to this problem on the Internet about a year back, but now I've forgotten it, and I want to know :) The trick, as far as I remember, involved using the tree to implement the queue, taking advantage of the destructive nature of the algorithm. When you are linking the list, you are also pushing an item into the queue. Each time I try to solve this, I lose nodes (such as each time I link the next node/add to the queue), I require extra storage, or I can't figure out the convoluted method I need to get back to a node that has the pointer I need. Even the link to that original article/post would be useful to me :) Google is giving me no joy. Edit: Jérémie pointed out that there is a fairly simple (and well known answer) if you have a parent pointer. While I now think he is correct about the original solution containing a parent pointer, I really wanted to solve the problem without it :) The refined requirements use this definition for the node: struct tree_node { int value; tree_node* left; tree_node* right; };

    Read the article

  • How to functionally generate a tree breadth-first. (With Haskell)

    - by Dennetik
    Say I have the following Haskell tree type, where "State" is a simple wrapper: data Tree a = Branch (State a) [Tree a] | Leaf (State a) deriving (Eq, Show) I also have a function "expand :: Tree a - Tree a" which takes a leaf node, and expands it into a branch, or takes a branch and returns it unaltered. This tree type represents an N-ary search-tree. Searching depth-first is a waste, as the search-space is obviously infinite, as I can easily keep on expanding the search-space with the use of expand on all the tree's leaf nodes, and the chances of accidentally missing the goal-state is huge... thus the only solution is a breadth-first search, implemented pretty decent over here, which will find the solution if it's there. What I want to generate, though, is the tree traversed up to finding the solution. This is a problem because I only know how to do this depth-first, which could be done by simply called the "expand" function again and again upon the first child node... until a goal-state is found. (This would really not generate anything other then a really uncomfortable list.) Could anyone give me any hints on how to do this (or an entire algorithm), or a verdict on whether or not it's possible with a decent complexity? (Or any sources on this, because I found rather few.)

    Read the article

  • Spanning-tree setup with incompatible switches

    - by wfaulk
    I have a set of eight HP ProCurve 2910al-48G Ethernet switches at my datacenter that are set up in a star topology with no physical loops. I want to partially mesh the switches for redundancy and manage the loops with a spanning-tree protocol. However, our connection to the datacenter is provided by two uplinks, each to a Cisco 3750. The datacenter's switches are handling the redundant connection using PVST spanning-tree, which is a Cisco-proprietary spanning-tree implementation that my HP switches do not support. It appears that my switches are not participating in the datacenter's spanning-tree domain, but are blindly passing the BPDUs between the two switchports on my side, which enables the datacenter's switches to recognize the loop and put one of the uplinks into the Blocking state. This is somewhat supposition, but I can confirm that, while my switches say that both of the uplink ports are forwarding, only one is passing any real quantity of data. (I am assuming that I cannot get the datacenter to move away from PVST. I don't know that I'd want them to make that significant of a change anyway.) The datacenter has also sent me this output from their switches (which I have expurgated of any identifiable info): 3750G-1#sh spanning-tree vlan nnn VLAN0nnn Spanning tree enabled protocol ieee Root ID Priority 10 Address 00d0.0114.xxxx Cost 4 Port 5 (GigabitEthernet1/0/5) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32mmm (priority 32768 sys-id-ext nnn) Address 0018.73d3.yyyy Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 300 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi1/0/5 Root FWD 4 128.5 P2p Gi1/0/6 Altn BLK 4 128.6 P2p Gi1/0/8 Altn BLK 4 128.8 P2p and: 3750G-2#sh spanning-tree vlan nnn VLAN0nnn Spanning tree enabled protocol ieee Root ID Priority 10 Address 00d0.0114.xxxx Cost 4 Port 6 (GigabitEthernet1/0/6) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32mmm (priority 32768 sys-id-ext nnn) Address 000f.f71e.zzzz Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 300 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi1/0/1 Desg FWD 4 128.1 P2p Gi1/0/5 Altn BLK 4 128.5 P2p Gi1/0/6 Root FWD 4 128.6 P2p Gi1/0/8 Desg FWD 4 128.8 P2p The uplinks to my switches are on Gi1/0/8 on both of their switches. The uplink ports are configured with a single tagged VLAN. I am also using a number of other tagged VLANs in my switch infrastructure. And, to be clear, I am passing the tagged VLAN I'm receiving from the datacenter to other ports on other switches in my infrastructure. My question is: how do I configure my switches so that I can use a spanning tree protocol inside my switch infrastructure without breaking the datacenter's spanning tree that I cannot participate in?

    Read the article

  • PHP MVC error handling, view display and user permissions

    - by cen
    I am building a moderation panel from scratch in a MVC approach and a lot of questions cropped up during development. I would like to hear from others how they handle these situations. Error handling Should you handle an error inside the class method or should the method return something anyway and you handle the error in controller? What about PDO exceptions, how to handle them? For example, let's say we have a method that returns true if the user exists in a table and false if he does not exist. What do you return in the catch statement? You can't just return false because then the controller assumes that everything is alright while the truth is that something must be seriously broken. Displaying the error from the method completely breaks the whole design. Maybe a page redirect inside the method? The proper way to show a view The controller right now looks something like this: include('view/header.php'); if ($_GET['m']=='something') include('view/something.php'); elseif ($_GET['m']=='somethingelse') include('view/somethingelse.php'); include('view/foter.php'); Each view also checks if it was included from the index page to prevent it being accessed directly. There is a view file for each different document body. Is this way of including different views ok or is there a more proper way? Managing user rights Each user has his own rights, what he can see and what he can do. Which part of the system should verify that user has the permission to see the view, controller or view itself? Right now I do permission checks directly in the view because each view can contain several forms that require different permissions and I would need to make a seperate file for each of them if it was put in the controller. I also have to re-check for the permissions everytime a form is submitted because form data can be easily forged. The truth is, all this permission checking and validating the inputs just turns the controller into a huge if/then/else cluster. I feel like 90% of the time I am doing error checks/permissions/validations and very little of the actual logic. Is this normal even for popular frameworks?

    Read the article

  • Tree View in c# with recursive

    - by user188886
    hi there i have table in DB with 3 column = ParentId , Id , Text i wanna make Tree in C# by the Records that we have saved in this table i dont know how should i write my recursive method in c# please help me thanks

    Read the article

  • What is the difference between an Abstract Syntax Tree and a Concrete Syntax Tree?

    - by Jason Baker
    I've been reading a bit about how interpreters/compilers work, and one area where I'm getting confused is the difference between an AST and a CST. My understanding is that the parser makes a CST, hands it to the semantic analyzer which turns it into an AST. However, my understanding is that the semantic analyzer simply ensures that rules are followed. I don't really understand why it would actually make any changes to make it abstract rather than concrete. Is there something that I'm missing about the semantic analyzer, or is the difference between an AST and CST somewhat artificial?

    Read the article

  • Deletion procedure for a Binary Search Tree

    - by Metz
    Consider the deletion procedure on a BST, when the node to delete has two children. Let's say i always replace it with the node holding the minimum key in its right subtree. The question is: is this procedure commutative? That is, deleting x and then y has the same result than deleting first y and then x? I think the answer is no, but i can't find a counterexample, nor figure out any valid reasoning. EDIT: Maybe i've got to be clearer. Consider the transplant(node x, node y) procedure: it replace x with y (and its subtree). So, if i want to delete a node (say x) which has two children i replace it with the node holding the minimum key in its right subtree: y = minimum(x.right) transplant(y, y.right) // extracts the minimum (it doesn't have left child) y.right = x.right y.left = x.left transplant(x,y) The question was how to prove the procedure above is not commutative.

    Read the article

  • Return parent of node in Binary Tree

    - by user188995
    I'm writing a code to return the parent of any node, but I'm getting stuck. I don't want to use any predefined ADTs. //Assume that nodes are represented by numbers from 1...n where 1=root and even //nos.=left child and odd nos=right child. public int parent(Node node){ if (node % 2 == 0){ if (root.left==node) return root; else return parent(root.left); } //same case for right } But this program is not working and giving wrong results. My basic algorithm is that the program starts from the root checks if it is on left or on the right. If it's the child or if the node that was queried else, recurses it with the child.

    Read the article

  • Problems in Binary Search Tree

    - by user2782324
    This is my first ever trial at implementing the BST, and I am unable to get it done. Please help The problem is that When I delete the node if the node is in the right subtree from the root or if its a right child in the left subtree, then it works fine. But if the node is in the left subtree from root and its any left child, then it does not get deleted. Can someone show me what mistake am I doing?? the markedNode here gets allocated to the parent node of the node to be deleted. the minValueNode here gets allocated to a node whose left value child is the smallest value and it will be used to replace the value to be deleted. package DataStructures; class Node { int value; Node rightNode; Node leftNode; } class BST { Node rootOfTree = null; public void insertintoBST(int value) { Node markedNode = rootOfTree; if (rootOfTree == null) { Node newNode = new Node(); newNode.value = value; rootOfTree = newNode; newNode.rightNode = null; newNode.leftNode = null; } else { while (true) { if (value >= markedNode.value) { if (markedNode.rightNode != null) { markedNode = markedNode.rightNode; } else { Node newNode = new Node(); newNode.value = value; markedNode.rightNode = newNode; newNode.rightNode = null; newNode.leftNode = null; break; } } if (value < markedNode.value) { if (markedNode.leftNode != null) { markedNode = markedNode.leftNode; } else { Node newNode = new Node(); newNode.value = value; markedNode.leftNode = newNode; newNode.rightNode = null; newNode.leftNode = null; break; } } } } } public void searchBST(int value) { Node markedNode = rootOfTree; if (rootOfTree == null) { System.out.println("Element Not Found"); } else { while (true) { if (value > markedNode.value) { if (markedNode.rightNode != null) { markedNode = markedNode.rightNode; } else { System.out.println("Element Not Found"); break; } } if (value < markedNode.value) { if (markedNode.leftNode != null) { markedNode = markedNode.leftNode; } else { System.out.println("Element Not Found"); break; } } if (value == markedNode.value) { System.out.println("Element Found"); break; } } } } public void deleteFromBST(int value) { Node markedNode = rootOfTree; Node minValueNode = null; if (rootOfTree == null) { System.out.println("Element Not Found"); return; } if (rootOfTree.value == value) { if (rootOfTree.leftNode == null && rootOfTree.rightNode == null) { rootOfTree = null; return; } else if (rootOfTree.leftNode == null ^ rootOfTree.rightNode == null) { if (rootOfTree.rightNode != null) { rootOfTree = rootOfTree.rightNode; return; } else { rootOfTree = rootOfTree.leftNode; return; } } else { minValueNode = rootOfTree.rightNode; if (minValueNode.leftNode == null) { rootOfTree.rightNode.leftNode = rootOfTree.leftNode; rootOfTree = rootOfTree.rightNode; } else { while (true) { if (minValueNode.leftNode.leftNode != null) { minValueNode = minValueNode.leftNode; } else { break; } } // Minvalue to the left of minvalue node rootOfTree.value = minValueNode.leftNode.value; // The value has been swapped if (minValueNode.leftNode.leftNode == null && minValueNode.leftNode.rightNode == null) { minValueNode.leftNode = null; } else { if (minValueNode.leftNode.leftNode != null) { minValueNode.leftNode = minValueNode.leftNode.leftNode; } else { minValueNode.leftNode = minValueNode.leftNode.rightNode; } // Minvalue deleted } } } } else { while (true) { if (value > markedNode.value) { if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { break; } else { markedNode = markedNode.rightNode; } } else { System.out.println("Element Not Found"); return; } } if (value < markedNode.value) { if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { break; } else { markedNode = markedNode.leftNode; } } else { System.out.println("Element Not Found"); return; } } } // Parent of the required element found // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { if (markedNode.rightNode.rightNode == null && markedNode.rightNode.leftNode == null) { markedNode.rightNode = null; return; } else if (markedNode.rightNode.rightNode == null ^ markedNode.rightNode.leftNode == null) { if (markedNode.rightNode.rightNode != null) { markedNode.rightNode = markedNode.rightNode.rightNode; return; } else { markedNode.rightNode = markedNode.rightNode.leftNode; return; } } else { if (markedNode.rightNode.value == value) { minValueNode = markedNode.rightNode.rightNode; } else { minValueNode = markedNode.leftNode.rightNode; } if (minValueNode.leftNode == null) { // MinNode has no left value markedNode.rightNode = minValueNode; return; } else { while (true) { if (minValueNode.leftNode.leftNode != null) { minValueNode = minValueNode.leftNode; } else { break; } } // Minvalue to the left of minvalue node if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { markedNode.leftNode.value = minValueNode.leftNode.value; } } if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { markedNode.rightNode.value = minValueNode.leftNode.value; } } // MarkedNode exchanged if (minValueNode.leftNode.leftNode == null && minValueNode.leftNode.rightNode == null) { minValueNode.leftNode = null; } else { if (minValueNode.leftNode.leftNode != null) { minValueNode.leftNode = minValueNode.leftNode.leftNode; } else { minValueNode.leftNode = minValueNode.leftNode.rightNode; } // Minvalue deleted } } } // //////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { if (markedNode.leftNode.rightNode == null && markedNode.leftNode.leftNode == null) { markedNode.leftNode = null; return; } else if (markedNode.leftNode.rightNode == null ^ markedNode.leftNode.leftNode == null) { if (markedNode.leftNode.rightNode != null) { markedNode.leftNode = markedNode.leftNode.rightNode; return; } else { markedNode.leftNode = markedNode.leftNode.leftNode; return; } } else { if (markedNode.rightNode.value == value) { minValueNode = markedNode.rightNode.rightNode; } else { minValueNode = markedNode.leftNode.rightNode; } if (minValueNode.leftNode == null) { // MinNode has no left value markedNode.leftNode = minValueNode; return; } else { while (true) { if (minValueNode.leftNode.leftNode != null) { minValueNode = minValueNode.leftNode; } else { break; } } // Minvalue to the left of minvalue node if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { markedNode.leftNode.value = minValueNode.leftNode.value; } } if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { markedNode.rightNode.value = minValueNode.leftNode.value; } } // MarkedNode exchanged if (minValueNode.leftNode.leftNode == null && minValueNode.leftNode.rightNode == null) { minValueNode.leftNode = null; } else { if (minValueNode.leftNode.leftNode != null) { minValueNode.leftNode = minValueNode.leftNode.leftNode; } else { minValueNode.leftNode = minValueNode.leftNode.rightNode; } // Minvalue deleted } } } } // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } } } } } } public class BSTImplementation { public static void main(String[] args) { BST newBst = new BST(); newBst.insertintoBST(19); newBst.insertintoBST(13); newBst.insertintoBST(10); newBst.insertintoBST(20); newBst.insertintoBST(5); newBst.insertintoBST(23); newBst.insertintoBST(28); newBst.insertintoBST(16); newBst.insertintoBST(27); newBst.insertintoBST(9); newBst.insertintoBST(4); newBst.insertintoBST(22); newBst.insertintoBST(17); newBst.insertintoBST(30); newBst.insertintoBST(40); newBst.deleteFromBST(5); newBst.deleteFromBST(4); newBst.deleteFromBST(9); newBst.deleteFromBST(10); newBst.deleteFromBST(13); newBst.deleteFromBST(16); newBst.deleteFromBST(17); newBst.searchBST(5); newBst.searchBST(4); newBst.searchBST(9); newBst.searchBST(10); newBst.searchBST(13); newBst.searchBST(16); newBst.searchBST(17); System.out.println(); newBst.deleteFromBST(20); newBst.deleteFromBST(23); newBst.deleteFromBST(27); newBst.deleteFromBST(28); newBst.deleteFromBST(30); newBst.deleteFromBST(40); newBst.searchBST(20); newBst.searchBST(23); newBst.searchBST(27); newBst.searchBST(28); newBst.searchBST(30); newBst.searchBST(40); } }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >