Tag Info

New answers tagged

5

There are a couple things to think about here - the structure of a card and the structure of the collection of cards... and all the while keeping in mind that this is Java and should be written with proper attention to object oriented principles. A card is a thing. Representing it entirely as a bit in a BitSet, or worse... doing your own bit manipulation ...


1

I would use built-in lists for any lists (uniform variable-length sequences of objects). I would use namedtuple-derived classes to store data with known fixed sets of named fields. It's like objects, but immutable. So you'd have your text.tokens[3].part_of_speech == NOUN, but won't have text.tokens[3].part_of_speech = NOUN. Immutability is often useful at ...


3

Siri typically doesn't "generate" sentences. She parses what you say and 'recognizes' certain keywords, sure, and for common responses, she will use a template, such as I found [N] restaurants fairly close to you or I couldn't find [X] in your music, [Username]. But most of her responses are canned, depending on her interpretation of your speech, in ...


2

I don't know that there is one answer that everyone would agree with, but personally I would just use the built in Python classes. Reading JSON to python dictionaries and lists is a very standard thing to do, it maps very well. I'm all and for OO programming, but I don't see the point in writing a tiny class to be a thin wrapper over existing powerful data ...


9

In Scala, this is called a sliding window: Seq(1, 2, 3, 4, 5).sliding(2).foreach(println) // List(1, 2) // List(2, 3) // List(3, 4) // List(4, 5) As opposed to grouped when the elements don't overlap: Seq(1, 2, 3, 4, 5).grouped(2).foreach(println) // List(1, 2) // List(3, 4) // List(5) In Ruby, it is called cons: [1, 2, 3, 4, 5].each_cons(2).to_a # ...


5

A tuple is a finite sequence (ordered list) of elements. It's true in mathematics, relational databases and many languages (e.g. C++, Prolog, Python...). So tuple could be a good name. node is an alternative since an object of the form {prev, curr, next} remembers of a node of a doubly linked list.


17

Apart from triple (which only means "we have three values") and node (which has been suggested by manlio), I can suggest the following alternatives: Sliding window It looks like you always have a window of three consecutives elements in the list. This is the most appropriate name IMHO according to your situation. That structure does not allow to easily ...


-3

Well this seems like a theory question on algorithms and datastructures. As for the datastructure, if you want to return the three results at once, of course you need to put them into one datastructure, and of course that would make it a triple. Without a given syntax it's hard to give an answer and the question seems not properly stated, I feel the ...


0

Have you considered Sphinx? http://sphinxsearch.com if you can use a 3rd party tool this would be ideal for what your're trying to achieve, its much more efficient at full text search than any RDBMS that I have personally used.


0

I think it would be rare in practice to actually have the option. The decision will likely be made for you simply by the requirements of the application. The semantics of your two examples are very different. It's a typical by-value or by-reference decision. I think you just need to ask Content myContent; myContent.Value = "Some content"; Node myNode; ...


0

I think your intuition is right: use a graph for the data. Maybe you are better off adding nodes that represent bindings in addition to nodes that represent atoms. I agree with @Stephen that a common approach to searching patterns are regular expressions. The important thing is that strings aren't specifically tailored towards being searched, yet searching ...


6

(Biochemistry graduate with 30 years software development experience) Non-organic molecules are "relatively" simple. The interesting ones are the ones that can bond with themselves e.g. C, N, O, Si because you can get some really funky combinations. The Benzene ring is a very simple example. Some variations substitute a Nitrogen for one of the Carbons ...


3

The first temptation with modelling this is to use a quad-tree style data structure. Each carbon atom has four connections, each oxygen two and each hydrogen one. I don't think that this is the proper solution though. I think that the proper solution has already been invented. The data structure to use is a string. Think about this. Chemists have been ...


0

You can see how I did it here: https://bitbucket.org/sventevit/rubiks, see the RubiksCore assembly. Over engineered? Sure! But I was/am still learning :) For solving the cube you would need a database, if there is some interest I could redo parts of the projects so that you won't need a database.


1

Since you already received great answers, let me add just a detail. Irrespective of your concrete representation, note that lenses are a very fine tool for "zooming in" on the various parts of a cube. For instance, look at the function cycleLeft in this Haskell code. It is a generic function which cyclically permutes any list of length 4. The code for ...


2

Using a binary tree for collision handling in a hash table isn't just possible - it has been done. Walter Bright is best known as the inventor of the D programming language, but also wrote an ECMAScript variant called DMDScript. In the past, a headline claim of DMDScript (or possibly an ancestor - I seem to remember the name DScript) was that its hashtables ...


5

What you are asking for is possible given your constraints. Analysis A hash table's strength is its fast lookup and insertion speed. To get that speed, one must forsake any semblance of order in the table: i.e. entries are all jumbled up. A list is acceptable to use as a table entry because while traversal is O(n), the lists tend to be short assuming the ...


0

I don't remember i ever encountered a real life situation when a heap was the best solution. It sounds to me that what you need is a self balancing Self-balancing binary search tree . You should probably look into AVL trees, and Red-Black Trees. Binary Search Trees have very similar performance characteristics to a Heap, but they are much more useful, and ...


4

For the max stuff I'd use a heap, for the min a simple variable (to be potentially updated when the decrease operation lets the previous maximum fall all the way to the bottom of the heap).


0

We were told numbers could be up to about 10^12 and about 20% of numbers would be used. That is 2 * 10^11 numbers actually used. With these numbers, the best you can do is a bitmap of about 125 GBytes, and if you can't afford the RAM, an SSD drive and virtual memory will have to do. You should probably measure whether "normal" file access is faster than ...


-3

Just to add a suggestion to the other solutions. In the biomedical world we often search for specific strings of data (ie genetic patterns). Research has shown that attacking the parent string in the reverse direction, the last entry to the first, is faster that going forward through the string. I guess this is some how related to slurping in all the data ...


1

I would try to go for the bitfield too, but if the data is sparse and the range too great to make this work, a splay tree might be a good data structure to use. Splay trees are modified on each access (so they are not thread-safe, which could be an exclusion reason for you) to optimize repeated access to the same element. Often-used elements bubble to the ...


2

You could generate a binary tree (radix tree aka trie). To prepare for the search, for each number in your array, starting with the least significant bit, if it is 0, you look to the left node. If it is 1, you look to the right node. You follow the tree until you find no more nodes, and from there you create the tree one node at a time. To search, ...


8

If there is a known maximum N, you can use a Bit array for really fast lookup time. Simply keep an array of size N/8 (rounded up) around, with each bit corresponding to a number, 1 if it is in the set, 0 if it isn't. Lookup the relevant bit to check whether a number is in the set. If this is too slow, and you have the megabytes ("millions" doesn't sound ...


3

The AST should only represent the syntax tree of your language. The objects making up the AST would generally not have any further functionality. Nice things like evaluating the AST or prettyprinting it can be implemented outside. I generally use the Visitor Pattern for these external methods – given that I implement an accept_visitor method for each AST ...


1

In the Boo language, which encourages playing around with ASTs via its metaprogramming facilities, there's an AST node class called CompileUnit that lies at the root of a compile tree. Its children are Module nodes, which represent a single source file, and each Module contains tree nodes corresponding to the AST of the code in that file. You could do ...



Top 50 recent answers are included