Search Results

Search found 4490 results on 180 pages for 'binary trees'.

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

  • What is the usage of Splay Trees in the real world?

    - by Meena
    I decided to learn about balanced search trees, so I picked 2-3-4 and splay trees. What are the examples of splay trees usage in the real world? In this Cornell: http://www.cs.cornell.edu/courses/cs3110/2009fa/recitations/rec-splay.html I read that splay trees are 'A good example is a network router'. But from rest of the explanation seams like network routers use hash tables and not splay trees since the lookup time is constant instead of O(log n).

    Read the article

  • What is the usage of Spaly Trees in the real world?

    - by Meena
    I decided to learn about Balance search trees, so I picked 2-3-4 and splay trees. I'm wondering what are the examples of splay trees usage in the real world? In this Cornell: http://www.cs.cornell.edu/courses/cs3110/2009fa/recitations/rec-splay.html I read that splay trees are 'A good example is a network router'. But from rest of the explanation seams like network routers use hash tables and not splay trees since the lookup time is constant instead of O(log n). thanks!

    Read the article

  • Finding if a Binary Tree is a Binary Search Tree

    - by dharam
    Today I had an interview where I was asked to write a program which takes a Binary Tree and returns true if it is also a Binary Search Tree otherwise false. My Approach1: Perform an inroder traversal and store the elements in O(n) time. Now scan through the array/list of elements and check if element at ith index is greater than element at (i+1)th index. If such a condition is encountered, return false and break out of the loop. (This takes O(n) time). At the end return true. But this gentleman wanted me to provide an efficient solution. I tried but I was unsuccessfult, because to find if it is a BST I have to check each node. Moreover he was pointing me to think over recusrion. My Approach 2: A BT is a BST if for any node N N-left is < N and N-right N , and the INorder successor of left node of N is less than N and the inorder successor of right node of N is greater than N and the left and right subtrees are BSTs. But this is going to be complicated and running time doesn't seem to be good. Please help if you know any optimal solution. Thanks.

    Read the article

  • Design pattern for isomorphic trees

    - by Peregring-lk
    I want to create a data structure to work with isomorphic tree. I don't search for a "algorithms" or methods to check if two or more trees are isomorphic each other. Just to create various trees with the same structure. Example: 2 - - - - - - - 'a' - - - - - - - 3.5 / \ / \ / \ 3 3 'f' 'y' 1.0 3.1 / \ / \ / \ 4 7 'e' 'f' 2.3 7.7 The first "layer" or tree is the "natural tree" (a tree with natural numbers), the second layer is the "character tree" and the third one is the "float tree". The data structure has a method or iterator to traverse the tree and to make diferent operations with its values. These operations could change the value of nodes, but never its structure (first I create the structure and then I configure the tree with its diferent layers). In case of that I add a new node, this would be applied to each layer. Which known design pattern fits with this description or is related with it?

    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

  • Game Trees Conceptual Question

    - by Chris Corbin
    I am struggling to conceptually understand a question in a programming assignment for an algorithms class. The problem is dealing with a fictitious 2 player game, named Easy. The rules of the game are simple; each player may chose one of 4 integers {0-3} after which that integer is not available for the other player. The catch is, a player picks {0} it means they quit. The objective is for Player 1 to get {1} and Player 2 to get {2}, in which case they may win, however if both or neither succeed, then the game ends in a draw. I have been asked to draw the game tree for Easy, showing all nodes, which they explained as 4! = 24. Labeling the edges, which represent moves (selecting a number) and the leaves with who won (1 means Player 1 won, -1 means Player 2 won, and 0 means a tie). I have drawn out a game tree, which I believe is correct, however I am not 100% certain hence I am asking the question. My game tree only has 16 leaves. I am thinking that when a player picks {0}, and then quits, the game tree stops there? I don't see how it is possible to get to 24 leaves? Any help would be greatly appreciate, and if you need more information I would be happy to provide it. Thanks

    Read the article

  • Binary to strings as binary? C #/.NET

    - by acidzombie24
    Redis keys are binary safe. I'd like to mess around and put binary into redis using C#. My client of choice doesn't support writing binary keys it uses keys and it make sense. However i am just fooling around so tell me how i can do this. How do i convert a raw byte[] into a string? At first i was thinking about converting a byte[] to a utf8 string however unicode has some checks to see if its valid or not. So raw binary should fail. Actually i tried it out. Instead of failing i got a strange result. My main question is how do i convert a raw byte[] to the equivalent string? My unimportant question is why did i get a 512 byte string instead of an exception saying this is not a valid UTF8 string? code var rainbow = new byte[256]; for (int i = 0; i < 256; i++) { rainbow[i] = (byte)i; } var sz = Encoding.UTF8.GetString(rainbow); var szarr = Encoding.UTF8.GetBytes(sz); Console.WriteLine("{0} {1} {2}", ByteArraysEqual(szarr, rainbow), szarr.Length, rainbow.Length); Output False 512 256

    Read the article

  • apt-get update error - binary-i386, binary-amd64 [duplicate]

    - by magamig
    This question already has an answer here: How can I fix a 404 Error when updating packages? 5 answers When I run: sudo apt-get update It shows me the following error: W: Failed to fetch http://ppa.launchpad.net/directhex/ppa/ubuntu/dists/trusty/main/binary-amd64/Packages 404 Not Found W: Failed to fetch http://ppa.launchpad.net/directhex/ppa/ubuntu/dists/trusty/main/binary-i386/Packages 404 Not Found E: Some index files failed to download. They have been ignored, or old ones used instead. I have googled for solutions, but none of what I found, have worked for me. Please give me your suggestions

    Read the article

  • How to Serialize Binary Tree

    - by Veljko Skarich
    I went to an interview today where I was asked to serialize a binary tree. I implemented an array-based approach where the children of node i (numbering in level-order traversal) were at the 2*i index for the left child and 2*i + 1 for the right child. The interviewer seemed more or less pleased, but I'm wondering what serialize means exactly? Does it specifically pertain to flattening the tree for writing to disk, or would serializing a tree also include just turning the tree into a linked list, say. Also, how would we go about flattening the tree into a (doubly) linked list, and then reconstructing it? Can you recreate the exact structure of the tree from the linked list? Thank you/

    Read the article

  • Binary Search Tree - Postorder logic

    - by daveb
    I am looking at implementing code to work out binary search tree. Before I do this I was wanting to verify my input data in postorder and preorder. I am having trouble working out what the following numbers would be in postorder and preorder I have the following numbers 4, 3, 14 ,8 ,1, 15, 9, 5, 13, 10, 2, 7, 6, 12, 11, that I am intending to put into an empty binary tree in that order. The order I arrived at for the numbers in POSTORDER is 2, 1, 6, 3, 7, 11, 12, 10, 9, 8, 13, 15, 14, 4. Have I got this right? I was wondering if anyone here would be able to kindly verify if the postorder sequence I came up with is indeed the correct sequence for my input i.e doing left subtree, right subtree and then root. The order I got for pre order (Visit root, do left subtree, do right subtree) is 4, 3, 1, 2, 5, 6, 14 , 8, 7, 9, 10, 12, 11, 15, 13. I can't be certain I got this right. Very grateful for any verification. Many Thanks

    Read the article

  • Find kth smallest element in a binary search tree in Optimum way

    - by Bragaadeesh
    Hi, I need to find the kth smallest element in the binary search tree without using any static/global variable. How to achieve it efficiently? The solution that I have in my mind is doing the operation in O(n), the worst case since I am planning to do an inorder traversal of the entire tree. But deep down I feel that I am not using the BST property here. Is my assumptive solution correct or is there a better one available ?

    Read the article

  • Do dconf use EXI binary XML?

    - by Hibou57
    A question came to my mind reading an answer to the question What are the differences between gconf and dconf?. In an reply to the above question, Oli said: Binary read access is far faster than parsing XML. However, there exist a W3C recommendation for binary XML, since 2010: Efficient XML Interchange (EXI) Format 1.0. Is this what dconf uses? If Yes, where is it confirmed? If No, was there some investigations toward it at some time, and what was the conclusions? Thanks for any tracks, I'm curious to know.

    Read the article

  • Binary on the Coat of Arms of the Governor General of Canada

    - by user132636
    Can you help me further this investigation? Here is about 10% of the work I have done on it. I present it only to see if there are any truly curious people among you. I made a video a few weeks ago showing some strange things about the Governor General's Coat of Arms and the binary on it. Today, I noticed something kinda cool and thought I would share. Here is the binary as it appears on the COA: 110010111001001010100100111010011 As DEC: 6830770643 (this is easily found on the web) Take a close look at that number. What do you notice about it? It has a few interesting features, but here is the one no one has pointed out... Split it down the middle and you have 68307 70643. The first digit is double the value of the last digit. The second digit is double the second last digit. The third digit is half of the third to last digit. And the middle ones are even or neutral. At first, I thought of it as energy. ++-nnnn+-- But actually you can create something else with it using the values. 221000211. See how that works. You may be asking why that is significant. Bare with me. I know 99% are rolling their eyes. 221000211 as base3 gives you this as binary: 100011101000111 100011101000111 as HEX is 4747, which converts to "GG". Initials of Governor General. GG.ca is his website. When you convert to base 33 (there are 33 digits in the original code) you get "GOV" Interesting? :D There is a lot more to it. I'll continue to show some strange coincidences if anyone is interested. Sorry if I am not explaining this correctly. By now you have probably figured out that I have no background in this. Which is why I am here. Thank you.

    Read the article

  • C++ find largest BST in a binary tree

    - by fonjibe
    what is your approach to have the largest BST in a binary tree? I refer to this post where a very good implementation for finding if a tree is BST or not is bool isBinarySearchTree(BinaryTree * n, int min=std::numeric_limits<int>::min(), int max=std::numeric_limits<int>::max()) { return !n || (min < n->value && n->value < max && isBinarySearchTree(n->l, min, n->value) && isBinarySearchTree(n->r, n->value, max)); } It is quite easy to implement a solution to find whether a tree contains a binary search tree. i think that the following method makes it: bool includeSomeBST(BinaryTree* n) { if(!isBinarySearchTree(n)) { if(!isBinarySearchTree(n->left)) return isBinarySearchTree(n->right); } else return true; else return true; } but what if i want the largest BST? this is my first idea, BinaryTree largestBST(BinaryTree* n) { if(isBinarySearchTree(n)) return n; if(!isBinarySearchTree(n->left)) { if(!isBinarySearchTree(n->right)) if(includeSomeBST(n->right)) return largestBST(n->right); else if(includeSomeBST(n->left)) return largestBST(n->left); else return NULL; else return n->right; } else return n->left; } but its not telling the largest actually. i struggle to make the comparison. how should it take place? thanks

    Read the article

  • B- trees, B+ trees difference

    - by dta
    In a B- tree you can store both keys and data in the internal/leaf nodes. But in a B+ tree you have to store the data in the leaf nodes only. Is there any advantage of doing the above in a B+ tree? Why not use B- trees instead of B+ trees everywhere? As intuitively they seem much faster. I mean why do you need to replicate the key(data) in a B+ tree?

    Read the article

  • 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

  • Binary Search Tree in Java

    - by John R
    I want to make a generic BST, that can be made up of any data type, but i'm not sure how I could add things to the tree, if my BST is generic. All of my needed code is below. I want my BST made up of Locations, and sorted by the x variable. Any help is appreciated. Major thanks for looking. public void add(E element) { if (root == null) root = element; if (element < root) add(element, root.leftChild); if (element > root) add(element, root.rightChild); else System.out.println("Element Already Exists"); } private void add(E element, E currLoc) { if (currLoc == null) currLoc = element; if (element < root) add(element, currLoc.leftChild); if (element > root) add(element, currLoc.rightChild); else System.out.println("Element Already Exists); } Other Code public class BinaryNode<E> { E BinaryNode; BinaryNode nextBinaryNode; BinaryNode prevBinaryNode; public BinaryNode() { BinaryNode = null; nextBinaryNode = null; prevBinaryNode = null; } } public class Location<AnyType> extends BinaryNode { String name; int x,y; public Location() { name = null; x = 0; y = 0; } public Location(String newName, int xCord, int yCord) { name = newName; x = xCord; y = yCord; } public int equals(Location otherScene) { return name.compareToIgnoreCase(otherScene.name); } }

    Read the article

  • Understanding binary numbers in terms of real world objects

    - by Kaushik
    When I represent a number in the decimal system, I have an intuitive knowledge of what it amounts to. For example take the number '10': I understand that it means 10 apples or 10 people... i.e I can count in the real world. But as soon as the number is converted to any other system, this understanding no longer applies. For example 10 when converted to binary will be 1010...now what does this represent? Is there a way to understand this number 1010 in terms of counting objects in the real world?

    Read the article

  • Cannot execute binary file

    - by user291727
    I am new to Ubuntu and I'm trying to install Popcorn Time. I downloaded 32 bit version and tried to install it but that's where the problem started showing. I duble clicked the executable file and well, nothing happened. It's a official download from their web-site but it doesn't work. Maybe I'm doing something wrong.....Anyway, I found out that you can insatll it from a script, but people keep talking in ubuntu terms and I don't understand it, so I have a few questions: 1.How to make a script? (witch I'm suppose to run in terminal using bash comand), 2.Is it normal that i cannot run the installer, and if that is an installer or just files for the program. 3.If it is an installer, how do I make it work? 4.What does " Cannot execute binary file" mean? Thank you in advance, hope I'm not asking too many questions(please understand that I'm new to ubuntu) and sorry about my English. xD

    Read the article

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