traversal

Javascript / Jquery Tree Travesal question

Suppose I have the following <ul> <li>Item 1</li> <li>Item 2 <ul> <li>Sub Item</li> </ul> </li> <li>Item 3</li> </ul> This list is auto-generated by some other code (so adding exclusive id's/class' is out of the question. Suppose I have some jquery code that states that if I mouseover an li, it gets a background color. How...

How to find sum of node's value for given depth in binary tree?

I've been scratching my head for several hours for this... problem: Binary Tree (0) depth 0 / \ 10 20 depth 1 / \ / \ 30 40 50 60 depth 2 I am trying to write a function that takes depth as argument and return the sum of values of nodes of the given depth. For instance, if I pass 2, it should return 180 (i.e. ...

find xml element by attribute

Using JQuery or Javascript how would I return 'Mary Boone' from the xml below starting out with the show 'id' attribute of '2'? I'm thinking something along the lines of - var result = xml.getElementByAttribute("2").gallery.text(); the XML: <shows> <show id="1"> <artist>Andreas Gursky</artist> <gallery>Matthew M...

How can you reverse traversal through a c# collection?

Is it possible to have a foreach statement that will traverse through a Collections object in reverse order? If not a foreach statement is there any other way? Thanks. ...

jquery - how to get the html inside a div

I have this html: <div class="portlet-header"> Company Information ... <button> some button here </button> </div> <div class="portlet-content"> <div class="content_regular"> <table style=" width:100%; height:100%;"> ...content </table> </div> </div> how do i get the hmtl after i click the butto...

Jquery tree traversal - Nested Unordered list elements to JSON

Okay, Now I have an unordered list here: <ul id="mycustomid"> <li><a href="url of Item A" title="sometitle">Item A</a> <ul class="children"> <li><a href="url of Child1 of A" title="sometitle">Child1 of A</a> <ul class="children"> <li><a href="url of Grandchild of A" title="sometitle...

JQuery Plugin related. . getting an array element from an object

Right so I'm creating a plugin using jquery what I have thus far is this. . (function ($) { $.fn.AppCompFunctionality = function () { var defaults = { }; var options = $.extend(defaults, options); return this.each(function () { $(this).click(function () { var currentComps = $("#currentComps").get(); $(current...

Algorithms for Directed Cyclic Graph Traversal (JavaScript)

I have a connected, directed, cyclic graph. The task is to discover every single node in the graph without falling into an infinite loop, as a regular tree traversal algorithm will do. You can assume that I already know what node to start at so as to reach all points in the directed graph, and that for each node I have a function that w...

Postorder Traversal

In-order tree traversal obviously has application; getting the contents in order. Preorder traversal seems really useful for creating a copy of the tree. Is there a common use for postorder traversal of a binary tree? ...

Reconstructing binary tree from inorder and preorder traversals.

I have written the following code for constructing a tree from its inorder and preorder traversals. It looks correct to me but the final tree it results in does not have the same inorder output as the one it was built from. Can anyone help me find the flaw in this function? public btree makeTree(int[] preorder, int[] inorder, int left,...

Huffman Tree Encodeing

So i must say that i love this site because its sooooo helpful and now i have another question! my Huffman tree which i had asked about earlier has another problem! here is the code: package huffman; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.PriorityQueue; import java...

Javascript array traversal overwriting key values

Hi, I have a hashmap that I have created to control the events for buttons. It is defined as so: var Signage_Manager = { init: function() { Signage_Manager.buttonActions.set_events(); }, buttonActions: { buttons: { '#add_product': {action: 'navigate', href: '/manager/add_product'}, '.back_to_dashboard': {act...

Building a dynamic tree with session information in Django (template question)

Hi, So I've got a expanding/collapsing tree that I'm keeping track of in session data. I want to be able to render the tree in Django based upon the session data. I am saving the state with something like: request.session['treedata'][item_id] = state # (0 or 1) In my template for rendering, I'm looping through the items and for e...

How to get a parent element's index in jQuery.

Hi. I'm having some trouble writing a jQuery function and could use a little help. Here's what I'd like to accomplish: I have a ul element with 5 li children. Elsewhere on the page, I have a container div with 5 div children. When I click a link in the third li, I'd like to hide the other divs and show only the third one. Currently ev...

Postorder tree traversal with clojure.zip to edit nodes

I have a tree represented as a nested vector. I want to have a generalization of indexed for trees, showing the index of each node like this, (visit 42); => [0 42] (visit [6 7]); => [0 ; [[0 6] ; [1 7]]] The naive implementation would use clojure.zip directly (as already asked here) (defn visit [...

median of BST in o(logn) time complexity

I came across solution given at http://discuss.joelonsoftware.com/default.asp?interview.11.780597.8 using Morris InOrder traversal using which we can find the median in O(n) time. But is it possible to acheive the same using O(logn) time? The same has been asked here - http://www.careercup.com/question?id=192816 ...

Nested Tree Search

Hi, i just followed the answers provided in this question: http://stackoverflow.com/questions/1310649/getting-a-modified-preorder-tree-traversal-model-nested-set-into-a-ul I already built my database and is working properly, printing all the child and parent pages with the correct identation. But, i want to make it like a web search. S...

Algorithm to visit all points in a matrix of N (unknown) dimensions.

I have a multidimensional matrix that can have any number of dimensions greater than one. Looking for an efficient algorithm that can visit every point in the matrix. Some info about the code: The matrix has value accessors like (although these aren't really relevant). object value = matrixInstance.GetValue(int[] point); matrixInsta...

Instant Messaging server on Android behind NAT-router

Hi. I am making an IM application for Android. The application consists of a server and client, both residing on the android. At startup, the applications register with a webserver. If a client wants to send an IM to a server behind a NAT router, how this be done? I heard of stun4j and jstun but found nowhere an example of their usage in...

Traversing weighted graph through all vertecies ending up at the same point

Is there an algorithm that will allow me to traverse a weighted graph in the following manner? Start at a specific node Go through all vertecies in the graph Do this in the least amount of time (weights are times) End up at the starting node ...