Search Results

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

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

  • Algorithm to Render a Horizontal Binary-ish Tree in Text/ASCII form

    - by Justin L.
    It's a pretty normal binary tree, except for the fact that one of the nodes may be empty. I'd like to find a way to output it in a horizontal way (that is, the root node is on the left and expands to the right). I've had some experience expanding trees vertically (root node at the top, expanding downwards), but I'm not sure where to start, in this case. Preferably, it would follow these couple of rules: If a node has only one child, it can be skipped as redundant (an "end node", with no children, is always displayed) All nodes of the same depth must be aligned vertically; all nodes must be to the right of all less-deep nodes and to the left of all deeper nodes. Nodes have a string representation which includes their depth. Each "end node" has its own unique line; that is, the number of lines is the number of end nodes in the tree, and when an end node is on a line, there may be nothing else on that line after that end node. As a consequence of the last rule, the root node should be in either the top left or the bottom left corner; top left is preferred. For example, this is a valid tree, with six end nodes (node is represented by a name, and its depth): [a0]------------[b3]------[c5]------[d8] \ \ \----------[e9] \ \----[f5] \--[g1]--------[h4]------[i6] \ \--------------------[j10] \-[k3] Which represents the horizontal, explicit binary tree: 0 a / \ 1 g * / \ \ 2 * * * / \ \ 3 k * b / / \ 4 h * * / \ \ \ 5 * * f c / \ / \ 6 * i * * / / \ 7 * * * / / \ 8 * * d / / 9 * e / 10 j (branches folded for compactness; * representing redundant, one-child nodes; note that *'s are actual nodes, storing one child each, just with names omitted here for presentation sake) (also, to clarify, I'd like to generate the first, horizontal tree; not this vertical tree) I say language-agnostic because I'm just looking for an algorithm; I say ruby because I'm eventually going to have to implement it in ruby anyway. Assume that each Node data structure stores only its id, a left node, and a right node. A master Tree class keeps tracks of all nodes and has adequate algorithms to find: A node's nth ancestor A node's nth descendant The generation of a node The lowest common ancestor of two given nodes Anyone have any ideas of where I could start? Should I go for the recursive approach? Iterative?

    Read the article

  • Maintaing list order in binary tree.

    - by TheBigO
    Given a sequence of numbers, I want to insert the numbers into a balanced binary tree such that when I do a preorder traversal on the tree, it gives me the sequence back. How can I construct the insert method corresponding to this requirement? Remember that the tree must be balanced, so there isn't a completely trivial solution. I was trying to do this with a modified version of an AVL tree, but I'm not sure if this can work out.

    Read the article

  • Balancing a Binary Tree (AVL)

    - by Gustavo Carreno
    Ok, this is another one in the theory realm for the CS guys around. In the 90's I did fairly well in implementing BST's. The only thing I could bever get my head around was the intricacy of the algorithm to balance a Binary Tree (AVL). Can you guys help me on this?

    Read the article

  • How to create Binary Tree in a image(.jpeg)

    - by abc
    I have data structured in Binary tree format, i want to represent it into an image(*. jpeg) then i need to display that image on web page and all the data will come @ runtime, so image processing should be done @ runtime, how to do this ? This is what my thought solution any other suitable solution are also welcomed, web site is in .NET , i am thinking to produce image using java api then integrate it to .NET wither through WEB-SERVICE call or any other solutions are also welcomed.

    Read the article

  • Convert a post-order binary tree traversal index to an level-order (breadth-first) index

    - by strfry
    Assuming a complete binary tree, each node can be adressed with the position it appears in a given tree traversal algorithm. For example, the node indices of a simple complete tree with height 3 would look like this: breadth first (aka level-order): 0 / \ 1 2 / \ / \ 3 4 5 6 post-order dept first: 6 / \ 2 5 / \ / \ 0 1 3 4 The height of the tree and an index in the post-order traversal is given. How can i calculate the breadth first index from this information?

    Read the article

  • Haskell Binary Tree Function (map)

    - by Bizarro
    How can i define a Haskell function which will apply a function to every value in a binary tree? So i know that it is similar to the map function - and that its type would be: mapT :: (a - b) - Tree a - Tree b but thats about it...

    Read the article

  • Read half precision float (float16 IEEE 754r) binary data in matlab

    - by Michael
    you have been a great help last time, i hope you can give me some advise this time, too. I read a binary file into matlab with bit16 (format = bitn) and i get a string of ones and zeros. bin = '1 00011 1111111111' (16 bits: 1. sign, 2-6. exponent, 7-16. mantissa) According to ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf it can be 'converted' like out = (-1)^bin(1) * 2^(bin(2:6)-15) * 1.bin(7:16) [are exponent and mantissa still binary?] Can someone help me out and tell me how to deal with the 'eeeee' and '1.mmmmmmmmmm' as mentioned in the pdf, please. Thanks a lot! Michael

    Read the article

  • Convert IP address string to binary in Python

    - by pizzim13
    As part of a larger application, I am trying to convert an IP address to binary. Purpose being to later calculate the broadcast address for Wake on LAN traffic. I am assuming that there is a much more efficient way to do this then the way I am thinking. Which is breaking up the IP address by octet, adding 0's to the beginning of each octet where necessary, converting each octet to binary, then combining the results. Should I be looking at netaddr, sockets, or something completely different? Example: From 192.168.1.1 to 11000000.10101000.00000001.00000001

    Read the article

  • binary sed replacement

    - by Ryan
    Hello, I was attempting to do a sed replacement in a binary file however I am beginning to believe that is not possible. Essentially what I wanted to do was similar to the following: sed -bi "s/\(\xFF\xD8[[:xdigit:]]\{1,\}\xFF\xD9\)/\1/" file.jpg Or more notably... scan through a binary file until the hex code FFD8, continue reading until FFD9, and only save what was between them (discards the junk before and after, but saves FFD8 and FFD9 as part of the file still) Is there a good way to do this? Even if not using sed?

    Read the article

  • Help Reading Binary Image Data from SQL Server into PHP

    - by Joe Majewski
    I cannot seem to figure out a way to read binary data from SQL server into PHP. I am working on a project where I need to be able to store the image directly in the SQL table, not on the file system. Currently, I have been using a query like this one: INSERT INTO myTable(Document) SELECT * FROM OPENROWSET(BULK N'C:\image.jpg', SINGLE_BLOB) as BLAH This works fine to actually insert the image into the table, but I haven't yet figured a way to retrieve it and get my image back. I am doing this with PHP, and ultimately will have to make a stored procedure out of it, but can anyone enlighten me on a way to get that binary data (varbinary(MAX)) and generate an image on the fly. I expected it to be simple to use a SELECT statement and add a content-type to the headers that indicated it was an image, but it's simply not working. Instead, the page will just display the name of the file, which I have encountered in the past and understand it to be an error with the image data.

    Read the article

  • Constructing a Binary Tree from its traversals

    - by user991710
    I'm trying to construct a binary tree (unbalanced), given its traversals. I'm currently doing preorder + inorder but when I figure this out postorder will be no issue at all. I realize there are some question on the topic already but none of them seemed to answer my question. I've got a recursive method that takes the Preorder and the Inorder of a binary tree to reconstruct it, but is for some reason failing to link the root node with the subsequent children. Note: I don't want a solution. I've been trying to figure this out for a few hours now and even jotted down the recursion on paper and everything seems fine... so I must be missing something subtle. Here's the code: public static <T> BinaryNode<T> prePlusIn( T[] pre, T[] in) { if(pre.length != in.length) throw new IllegalArgumentException(); BinaryNode<T> base = new BinaryNode(); base.element = pre[0]; // * Get root from the preorder traversal. int indexOfRoot = 0; if(pre.length == 0 && in.length == 0) return null; if(pre.length == 1 && in.length == 1 && pre[0].equals(in[0])) return base; // * If both arrays are of size 1, element is a leaf. for(int i = 0; i < in.length -1; i++){ if(in[i].equals(base.element)){ // * Get the index of the root indexOfRoot = i; // in the inorder traversal. break; } // * If we cannot, the tree cannot be constructed as the traversals differ. else throw new IllegalArgumentException(); } // * Now, we recursively set the left and right subtrees of // the above "base" root node to whatever the new preorder // and inorder traversals end up constructing. T[] preleft = Arrays.copyOfRange(pre, 1, indexOfRoot + 1); T[] preright = Arrays.copyOfRange(pre, indexOfRoot + 1, pre.length); T[] inleft = Arrays.copyOfRange(in, 0, indexOfRoot); T[] inright = Arrays.copyOfRange(in, indexOfRoot + 1, in.length); base.left = prePlusIn( preleft, inleft); // * Construct left subtree. base.right = prePlusIn( preright, inright); // * Construc right subtree. return base; // * Return fully constructed tree } Basically, I construct additional arrays that house the pre- and inorder traversals of the left and right subtree (this seems terribly inefficient but I could not think of a better way with no helpers methods). Any ideas would be quite appreciated. Side note: While debugging it seems that the root note never receives the connections to the additional nodes (they remain null). From what I can see though, that should not happen... EDIT: To clarify, the method is throwing the IllegalArgumentException @ line 21 (else branch of the for loop, which should only be thrown if the traversals contain different elements.

    Read the article

  • Ruby GraphViz Binary Tree Record

    - by Jason M
    I'm using the ruby-graphviz gem and I'm trying to draw binary trees. I'd like to use the record shape so that each node can have a left, middle, and right field and, thus, if there are two edges leaving a node, the left and right edges can be distinguished. I tried specifying the field by concatenating the field name like this: @node1.name + ":left" But that did not work. What is the correct way of specifying the field? require 'rubygems' require 'graphviz' @graph = GraphViz.new( :G, :type => :digraph ) @node1 = @graph.add_node("1", "shape" => "record", "label" => "<left>|<f1> 1|<right>" ) @node2 = @graph.add_node("2", "shape" => "record", "label" => "<left>|<f1> 2|<right>" ) @graph.add_edge(@node1.name + ":left", @node2) # generate a random filename filename = "/tmp/#{(0...8).map{65.+(rand(25)).chr}.join}.png" @graph.output( :png => filename ) exec "open #{filename}"

    Read the article

  • How change Subversion's default binary mime-type?

    - by lamcro
    Subversion sets a binary file's svn:mime-type property to application/octet-stream by default. I need to change this default to some other mime-type. When I import for the first time this code, I would like Subversion to set mime-type to the one I choose. The reason is that my code base contains code in binary files (proprietary format), and I have the applications necessary to emulate diff and diff3 for these. But Subversion does not let me due to their default mime-type. Please note: There is no default extension (*.jar, *.py, etc) for these code files. Some files don't even have an extension. So configuring mime-type by file extension is not possible.

    Read the article

  • binary file formats: need for error correction?

    - by Jason S
    I need to serialize some data in a binary format for efficiency (datalog where 10-100MB files are typical), and I'm working out the formatting details. I'm wondering if realistically I need to worry about file corruption / error correction / etc. What are circumstances where file corruption can happen? Should I be building robustness to corruption into my binary format? Or should I wrap my nonrobust-to-corruption stream of bytes with some kind of error correcting code? (any suggestions? I'm using Java) Or should I just not worry about this?

    Read the article

  • Manipulating binary data in Python

    - by Dominic Bou-Samra
    I am opening up a binary file like so: file = open("test/test.x", 'rb') and reading in lines to a list. Each line looks a little like: '\xbe\x00\xc8d\xf8d\x08\xe4.\x07~\x03\x9e\x07\xbe\x03\xde\x07\xfe\n' I am having a hard time manipulating this data. If I try and print each line, python freezes, and emits beeping noises (I think there's a binary beep code in there somewhere). How do I go about using this data safely? How can I convert each hex number to decimal?

    Read the article

  • How to analyse contents of binary serialization stream?

    - by Tao
    I'm using binary serialization (BinaryFormatter) as a temporary mechanism to store state information in a file for a relatively complex (game) object structure; the files are coming out much larger than I expect, and my data structure includes recursive references - so I'm wondering whether the BinaryFormatter is actually storing multiple copies of the same objects, or whether my basic "number of objects and values I should have" arithmentic is way off-base, or where else the excessive size is coming from. Searching on stack overflow I was able to find the specification for Microsoft's binary remoting format: http://msdn.microsoft.com/en-us/library/cc236844(PROT.10).aspx What I can't find is any existing viewer that enables you to "peek" into the contents of a binaryformatter output file - get object counts and total bytes for different object types in the file, etc; I feel like this must be my "google-fu" failing me (what little I have) - can anyone help? This must have been done before, right??

    Read the article

  • Appropriate high level language to deal with binary data

    - by fortran
    Hi, I need to write a small tool that parses a textual input and generates some binary encoded data. I would prefer to stay away from C and the like, in favour of a higher level, (optionally) safer, more expressive and faster to develop language. My language of choice for this kind of tasks usually is Python, but for this case dealing with binary raw data can be problematic if one isn't very careful with the numbers being promoted to bignums, sign extensions and such. Ideally I would like to have records with named bitfields that are portable to be serialised in a consistent manner. (I know that there's a strong point in doing it in a language I already master, although it isn't optimal, but I think this could be a good opportunity to learn something new). Thanks.

    Read the article

  • File in binary form

    - by Abhi
    Dear All I want to write data into the file in binary form. I was trying using the mentioned below FILE *fp = fopen("binaryoutput.rgb888", "ab+"); for(int m=0; m<height; m++) { for (int n=0; n< width; n++) { temp = (pOutputImg+m*3+n*3); // here temp is a pointer to a unsigned char fprintf(fp,"%u",*temp); } } fclose(fp); I am able to get data which is strored at pOutputImg but not in binary form. Can anyone guide me the correct step.. Thanks in advance

    Read the article

  • reading binary code of a file...in PHP

    - by Val
    How can I read the binary code(to get the 1s and 0s) of a file. $filename = "something.mp3"; $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); I tried this but it shows some strange characters... i presume that this is the formated binary...? I was hoping to get the 1's and 0's instead.... also i am not looking only .mp3 files it could be anything .e.g: .txt , .doc , .mp4, .php .jpg,.png etc.... Thanks

    Read the article

  • Binary Search Tree node removal

    - by doc
    I've been trying to implement a delete function for a Binary Search Tree but haven't been able to get it to work in all cases. This is my latest attempt: if(t->get_left() == empty) *t = *t->get_left(); else if(t->get_right() == empty) *t = *t->get_right(); else if((t->get_left() != empty) && (t->get_right() != empty)) { Node* node = new Node(t->get_data(), t->get_parent(), t->get_colour(), t->get_left(), t->get_right()); *t = *node; } t is a node and empty is just a node with nothing in it. I'm just trying to swap the values but I'm getting a runtime error. Any ideas? Thanks

    Read the article

  • Finding height in Binary Search Tree

    - by mike
    Hey I was wondering if anybody could help me rework this method to find the height of a binary search tree. So far my code looks like this however the answer im getting is larger than the actual height by 1, but when I remove the +1 from my return statements its less than the actual height by 1? I'm still trying to wrap my head around recursion with these BST any help would be much appreciated. public int findHeight(){ if(this.isEmpty()){ return 0; } else{ TreeNode<T> node = root; return findHeight(node); } } private int findHeight(TreeNode<T> aNode){ int heightLeft = 0; int heightRight = 0; if(aNode.left!=null) heightLeft = findHeight(aNode.left); if(aNode.right!=null) heightRight = findHeight(aNode.right); if(heightLeft > heightRight){ return heightLeft+1; } else{ return heightRight+1; } }

    Read the article

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