Tag Info

New answers tagged

0

I am assuming that you are indexing elements that are all of about the same size, otherwise life gets complex, or slow, or both…… A Quadtree node does not need to have a fixed capacity. The capacity is used to Allow each tree node to be fixed size in memory or on disk – not required if the tree node contains a variable sized set of elements and you are ...


1

"replacing directory_a with directory_b" is the thing to do, but that doesn't mean you need to use regexes. Standard string manipulation functions will suffice. Depending on how the path is constructed, you may need to confirm that "directory_a" is a prefix of the path, for which there isn't a standard C or POSIX function. It sounds like this won't be ...


-1

I think you're looking for this: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.510.1758&rep=rep1&type=pdf It details how to create an optimal dictionary-representing DAWG.


-2

The main problem here is that now the node type has a state, type inference has either been done or not. This makes it hard to reason about. Only to a person whose brain has been damaged by an overdose of Strict Immutability flavored Kool Aid. The reasoning is actually quite simple: if the value is null, one can clearly deduce that type inference has ...


0

My advise would be to keep tokens as tokens, and if anything, perform a type inference step where you wrap each node in another class or struct that does have state. // Token type struct - immutable struct VarDec: Statement { var varKeyword: Keyword var varName: Id var assignment: Symbol var initializer: Expr } // Type-checked token /w ...


1

I think you are confusing the issue by using lambda expressions in the structure. The expression lambda:5 is neither a list nor a number. It is a function. So the data structure in your example is not a tree of numbers, since one of the leaves is a function rather than a number. But disregarding the lambda, the expression [1, 2, 3, 4] is a list, and also a ...


8

This heavily depends on definition of list and tree. Mathematically list doesn't mean anything and tree is just special subset of a graph. Inferring from your question, your teacher's definition of tree is nested lists. In which case, list of nesting depth of 0 is still a tree. So abc = [1, 2, 3, 4] Is a tree. In this case, the list is subset of tree. ...


1

What is the 'right' way to see it? It is a directed graph. How would I treat this in Excel? You could use an Excel template such as NodeXL. For some further discussion of NodeXL and additional graph libraries for other languages, have a look at What is a good network graph library for language X?


1

The data structure that you're describing is often used in JSON documents where you have a list of objects, each with attributes (keys to dictionaries) and their values (the mapped portion of each dictionary). In the DS that you give, you can think of obj_1_id and obj_2_id as objects and key1 and key2 as those objects' fields.


2

It's neither a pattern nor an anti-pattern. There's no specific name for it. It is exactly what it appears to be and its quality is determined by the program using it. Does it make sense? Not to me, not without context. Could the outer array be removed and the IDs moved into a single object? Maybe, depends on the program. Could the nested objects be ...


1

The best way is to store a version number in each of the persisted files. Then you can read any of them, from any time and if the version is not the current one - send it to a migration routine that updates it to the current format and then continue processing it as if it was always the current format. This allows you to perform the migration on an ...


0

Converting your data files from the "old" formats to your latest and greatest one is probably the best option. Save the reformatted data after converting it. That way, you're data gets upgraded gradually, over time, instead of a "Big Bang". Every time a file is accessed, it gets upgraded to the latest version (whichever that is today) and nobody's any the ...


3

For the numbers you gave, just brute force it. Here's a JavaScript program that brute forces it for 10 ingredients in the DB, 10 recipes in the DB, each recipe needs 2 ingredients, and I have 5 ingredients available: var i, j; var numIngredients = 10; var numRecipes = 10; var numIngredientsPerRecipe = 2; var numIngredientsInQuery = 5; function ...


2

Binary trees why use them? In programming you work a lot with collections of same type data. The two basic ways of storing this data are : linked lists and arrays. They both come with up and downsides: In a linked list it's easy to add elements at any position or remove elements. But access to a specific element is harder, because you have to go through ...


2

Any tree structure, where a node can have unlimited numbers of children, can be implemented using a binary tree. For each node in your tree, replace it with a node with a right and left pointer. The left pointer goes to the first of the node's children. The right node goes to the next sibling of the node. All the children of a given node are in a linked ...


0

One approach I like, to use your own term, is having "complex models" but asking the server how deeply you want the model to be filled. In your example, you might have an API call: GET /project?id=1337 That will return some basic representation of your model with attributes common across all use cases. Now you might be able to call the API with ...


24

No, binary trees are not for storing hierarchical data in the sense you're thinking of. The primary use case for n-ary trees, where n is a fixed number, is fast search capability, not a semantic hierarchy. Remember the old game where one person thinks of a number between 1 and 100, and the other has to guess it in as few guesses as possible, and if you ...



Top 50 recent answers are included