binary-tree

Bin Tree Post Order Traversal, No recursion, no node flag

你离开我真会死。 提交于 2019-12-23 03:35:15
问题 Is there another way to do this? Just spent 2 hours trying to figure it out. I have a solution (see DumpPostOrder below) however, is there is a better or more efficient method? It feels like there may be. Rules are - no recursion, and the nodes cannot have a visited flag. Ie, you can only use left + right members. My approach was to destroy the tree in the process. By setting the children of each side to null you can mark the node as traversed once, but I'm also looking at each node with

construct and print elements of a Binary Tree (unbalanced binary tree), from left to right, and from bottom-up

允我心安 提交于 2019-12-23 02:36:30
问题 please let me know how to achieve the following: I have a binary tree, which is unbalanced, having both the left & right sub trees. I have to print the values of nodes of that unbalanced binary tree in the sequence (i) from left to right, (ii) from bottom to up, and (iii) also the data structure which will be used & its memory management or memory allocation. What initially I thought is that will go for level-order-traversal, en-queue the elements, and then print and de-queue the queue. Your

Non-recursive add function in a binary tree using c++

血红的双手。 提交于 2019-12-23 02:29:24
问题 I am writing an Add function to add nodes to a binary tree non recursively. I have run into the problem of only being able to produce one level deep binary tree. I debugged it and I know where the problem is but can't figure out how to fix it. Maybe fresh pair of eyes will see something i dont... The problem is that my temp node is being reset to the root value every new function call and hence, adding nodes linearly. Anyways, here is the function: void BinaryTreeNonRec::add(int num){

Creating a Binary Tree for a Knockout Tournament

*爱你&永不变心* 提交于 2019-12-22 20:54:04
问题 I am trying to create a binary tree for use in a knockout tournament. The tree consists of TNodes with Left and Right pointers. This is the code that I have come up with (below); however, it runs into difficulties with the pointers in the CreateTree section. Once this creates an empty tree of large enough size, I need to add the names on the Memo1.List to the bottoms of the tree so I can pair them up for matches. How would I do this? Type TNodePtr = ^TNode; TNode = Record Data:String; Left

Creating a Binary Tree for a Knockout Tournament

霸气de小男生 提交于 2019-12-22 20:53:53
问题 I am trying to create a binary tree for use in a knockout tournament. The tree consists of TNodes with Left and Right pointers. This is the code that I have come up with (below); however, it runs into difficulties with the pointers in the CreateTree section. Once this creates an empty tree of large enough size, I need to add the names on the Memo1.List to the bottoms of the tree so I can pair them up for matches. How would I do this? Type TNodePtr = ^TNode; TNode = Record Data:String; Left

Level Order Traversal w/ Binary Trees using Java and Recursion

笑着哭i 提交于 2019-12-22 19:18:12
问题 I am having problems with the level order traversal of my binary tree whilst using recursion. I am inputing the following values: 50,60,70,30,20,10 Here is the code I am using: public void levelOrder(Node localRoot){ if(localRoot != null){ if(localRoot.leftChild != null && localRoot.rightChild != null){ System.out.print(localRoot.iData + " "); System.out.print(localRoot.leftChild.iData + " "); System.out.print(localRoot.rightChild.iData + " "); levelOrder(localRoot.leftChild); levelOrder

Understanding the logic in iterative Postorder traversal implementation on a Binary tree

别说谁变了你拦得住时间么 提交于 2019-12-22 14:51:15
问题 I was trying to understand how it is so intuitive to implement postorder traversal using 2 stacks. How did someone come up with it, is it just an observation or some particular way of thinking which helps one come up with such methods. If yes then please explain how to think in the right direction. 回答1: Let me explain how I stumbled on the solution: You start off with this simple observation: prima facie, the pre-order and post-order traversal differ only in their order of operations :

Binary Process Tree with fork()

时间秒杀一切 提交于 2019-12-22 11:22:04
问题 My first project for my OS class is to create a process tree using fork() that has a depth that the user specifies at the command line. Each leaf level node needs to sort data and pass it back to its parent using named-pipes (FIFOs). I can create an N-depth tree with fork() , each process having 2 children. What I can’t figure out is how to pass a FIFO to each child all the way down the tree and then have this process perform a sort on certain data in the FIFO and then also pass it back up

freeing memory of a binary tree C

£可爱£侵袭症+ 提交于 2019-12-22 08:59:34
问题 I would like to free memory from my allocated binary tree what traversal is the best for doing so? typedef struct Node{ struct Node * right; struct Node * left; void * data; }Node; typedef int (*cmp) (void*,void *); Node* init(void * element){ Node * newNode=(Node*)malloc(sizeof(Node)); newNode->data=element; newNode->left=NULL; newNode->right=NULL; return newNode; } void insert(void * element, Node** root,cmp compareTo){ if(*root==NULL){ *root=init(element); return; } if(compareTo(element,(

File indexing (using Binary trees?) in Python

偶尔善良 提交于 2019-12-22 08:15:54
问题 Background I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). Proposal In particular, one idea that appeals to me is "indexing" the files in some way. Since these files are read-only (and static), I was imagining some persistent files containing binary trees