How do you implement a max-heap? - data-structures

So I've read up on heaps, and I understand the basic concept,
but not how to actually implement it.
Basically, my issue is
How you know where to put a new node?
How you know which node to replace the root with when you delete?

Related

Im trying my hardest to get a D3 Hierachy tree running. But failed at appending

This is my first post - be gentle, I'm learning (or trying to) D3js.
I have been trying to put together a basic D3js Heirachy tree and have hit an issue.
While I have the basics pretty much covered I am hitting a wall.
I have started with this code as a foundation as its pretty close to what I'm trying to achieve.
http://blockbuilder.org/mattsrinc/16dab5a09aa46ed46975
However, as the original creator had stated - when you ADD/APPEND a new node it removes any and all children to the node you are using.
I've managed to isolate the point at which I think its occuring and replaced
Within the dndtree.js line 398.
if (currentNode[0]._children!=null) {
With
if(!d.children==false ) {
This stops the deletion and then I can add a node to the end and drag it into place - not ideal, but works.
I was wondering if any proper java wizards have a proper solution.
Any pointers appreciated and any help gratefully received.
Thank you for your time.

Arango single tree response using AQL only

I have found several questions that are similar but no solution worked as needed, or used internal functions. This is the most relevant one:
Getting data for d3 from ArangoDB using AQL (or arangojs)
I'm unable to understand how to return a single response with a tree structure of parent + children. Something that D3 can understand. Whatever I do, beyond the first iteration, everything is a mess. I have tried MERGE and MERGE_RECURSIVE but it just did not work as I thought of.
I'm clueless to how I can make it to work. I'm used to Neo4J and for some reason this one is just hard for me to understand.
Any help will do,
Thanks,
DD.
I found a simple solution. I'm just using AQL to get a flat list of results and their edges. After that, I just sort it as I need on my code

Understanding X-Path Expression

I'm trying to get an understanding of XPath in order to parse a diffxml file. I skimmed over the w3schools site. Am I understanding these correctly?
Statement 1: /node()[1]/node()[3]
Selects the third child of the root node
Statement 2: /node()[1]/node()[1]/node()[1]
Selects the child of the first node of the root node
Statement 3: /node()[1]/node()[3]/node()[2]
Selects the second child of the third node under the root node.
Yes, you understand them correctly, but this is not how you'd use XPath. First node() can be anything, not just elements. Then the pure index is arguably the wort way of selecting things, you should really use names, and possibly predicates for filtering the node-sets.
You'll find a lot of criticism of w3schools on this site. Personally I find it a useful resource, but only when I'm trying to remind myself of something I once knew. It's not really designed for teaching yourself things from scratch, and I suggest you need a different learning strategy. Call me old-fashioned, but when I'm learning a new technology I find there's nothing better than a good book.
You've understood your examples correctly as far as I can tell. But have you understood what a "node" is? For example, do you know under what circumstances whitespace text counts as a node? The key to understanding XPath is to understand the data model, and the way in which the data model relates to the lexical (angle-bracket) form of the XML.

Infinispan tree like cache structure

I would like to use Infinispan following a tree like structure for the cache. For example, using the following data structure for ticker symbols:
Exchange (NY stock exchange, AMEX...)
Date
Ticker
I am not sure how to implement this as the only examples that I have found are pretty basic such as:
cache.put("key", "value");
I tried to look up the internet and stackoverflow without any luck... I know that I could flatten the structure in the example above but for illustrative purposes, I would like to know how Infinispan works (and the tutorials don't cover it, which is why I must not be thinking about it correctly since Infinispan is pretty robust).
Any help would be greatly appreciated.
Thanks,
Julien
Did you check the tree module in Infinispan?

Need to create a "choose your own adventure" type guide - best approach to use

Basically need to ask user a set of questions and gather information along the way. Each question could have impacts on different questions down the road. Another example would be turbo tax's web interface, answering yes on some ?s may trigger future questions.
Seems like this would be a fairly common problem in software so I guess I'm asking if there are any existing solutions/Design Patterns out there that could help. Kind of seems like a state machine, but I think that is an oversimplification.
State pattern
Look at this picture which helps with choosing correct fonts which is called So You Need a Typeface (big image there!).
It asks you numerous questions and at some point suggest you one or several answers.
As I understand you want to create something similar but interactive and about another domain.
So, you need to construct similar graph with branching-nodes and leaf-nodes. It can be done very conveniently with the Composite pattern. If you already have (know) all possible questions (or if you know that at some point you will know all of them and will be able to add them manually to the system) then it's the way to go.
If you want something more dynamic and intelligent then the solution can highly vary from case to case.

Resources