data-structures

Data structure for fast filtering (Delphi)?

I am optimizing a part of a Delphi application where lists of objects are frequently filtered using different criteria. The objects are kept in TObjectList structures and it is common to select a very small percentage (ex. 1%) of the entire set with each filter. The total number of objects can be in the 100k range and during computations...

How can I declare a thousand separator in read.csv?

The dataset I want to read in contains numbers with and without a comma as thousand separator: "Sudan", "15,276,000", "14,098,000", "13,509,000" "Chad", 209000, 196000, 190000 and I am looking for a way to read this data in. Any hint appreciated! ...

Merging two sorted lists

Hi, This is one of the programming questions asked during written test from Microsoft. I am giving the question and the answer that I came up with. Thing is my answer although looks comprehensive (at least to me), I feel that the number of lines can be reduced. It was asked in C and I am a Java person but I managed to code it (my answer...

Efficient way to analyze large amounts of data?

I need to analyze tens of thousands of lines of data. The data is imported from a text file. Each line of data has eight variables. Currently, I use a class to define the data structure. As I read through the text file, I store each line object in a generic list, List. I am wondering if I should switch to using a relational database (SQ...

Difference in performance between map and unordered_map in c++

I have a simple requirement, i need a map of type . however i need fastest theoretically possible retrieval time. i used both map and the new proposed unordered_map from tr1 i found that at least while parsing a file and creating the map, by inserting an element at at time. map took only 2 minutes while unordered_map took 5 mins. As...

Which Data Structure? LinkedList or Any Other in Java?

I have specific requirements for the data structure to be used in my program in Java. It (Data Structure) should be able to hold large amounts of data (not fixed), my main operations would be to add at the end, and delete/read from the beginning (LinkedLists look good soo far). But occasionally, I need to delete from the middle also and ...

How to simplify creating huge data structures in Python

I am writing some and I need to pass a complicated data structure to some function. The data structure goes like this: { 'animals': [ 'cows', 'moose', { 'properties': [ 9, 26 ] } ] 'fruits': { 'land': [ 'strawberries', 'other berries' ], 'space': [ 'apples', 'cherries' ] } } This structure looks pretty ugly to me. Can you...

Are there any classes that can be queried / modified like a DB but is entirely local and internal to the program?

Are there any classes that can be queried / modified like a SQL DB but is entirely local and internal to the program? I am aiming to write a program that needs to have a local data source with all data saved in a file, but I would like to be able to query this information store just as I would a DB; LINQ compatibility would be a huge pl...

How can I implement a tree in Python? Are there any built in data structures in Python like in Java?

I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree? ...

Storing Content with Complex Structure using Django

Is there a recommended best-practice for storing content that has a complex structure. For example, suppose a typical "article" I am trying to serve may have the following hierarchy: Header #1 Subheader #1.a) Text content Image content Text Content Subheader #1.b) Text Content Other complex content ty...

R: Applying nlminb to subsets of data (by index or label) and store what the program returns as a new data frame

I was wondering if anyone could kindly help me on this seemingly easy task. I'm using nlminb to conduct optimization and compute some statistics by index. Here's an example from nlminb help. > x <- rnbinom(100, mu = 10, size = 10) > hdev <- function(par) { + -sum(dnbinom(x, mu = par[1], size = par[2], log = TRUE)) + } > nlminb(c(9,...

Linked List Implementation In Java and Garbage Collection

If I have a linked list structure, and I implement the clear() method as follows: public void clear() { firstNode = null; size = 0; } will it still get correctly garbage collected, or would I want to walk through each node, setting nextNode to null? None of the nodes can be directly referenced from outside the linked list, so...

How to represent this "tree" data?

Ive got some data (not that the data actually exists until after I solved this...) I need to be able to manipulate within my program. However I cant work out a suitable structure for storing this in. The data represents a set of paths and nodes. There is one input (which may in some cases no be present) then a number of paths between no...

How to build a game entity list custom data structure

I'm writing a game in Flash (player 10) and need to come up with a good way to manage the list of objects/entities/actors in the game (player character, obstacles, enemies, etc.). It has these requirements: Iterable Objects addable and removable while iterating. Argument to remove() function would be the object to remove, not an index...

Modular data structure in C with dynamic data type

Hi, For my upcoming university C project, I'm requested to have modular code as C allows it. Basically, I'll have .c file and a corresponding .h file for some data structure, like a linked list, binary tree, hash table, whatever... Using a linked list as an example, I have this: typedef struct sLinkedList { int value; struct s...

Inserting a new value in binary search tree

Using an algorithm Tree-Insert(T, v) that inserts a new value v into a binary search tree T, the following algorithm grows a binary search tree by repeatedly inserting each value in a given section of an array into the tree: Tree-Grow(A, first, last, T) 1 for i ← first to last 2 do Tree-Insert(T, A[i]) If the tree is i...

Why are hash table expansions usually done by doubling the size?

I've done a little research on hash tables, and I keep running across the rule of thumb that when there are a certain number of entries (either max or via a load factor like 75%) the hash table should be expanded. Almost always, the recommendation is to double (or double plus 1, i.e., 2n+1) the size of the hash table. However, I haven'...

find the position of a string in another string

Possible Duplicate: substring algorithm Given two strings, A and B, how to find the first position of B in A? For instance, A = " ab123cdefgcde"; B= "cde" Then the first position of B in A is 5. Is there any trick to solve this problem or just search A from the start? ...

Java ORM related question - SQL Vs Google DB (Big Table?) GAE

I was wondering about the following two options when one is not using SQL tables but ORM based DBs (Example - when you are using GAE) Would the second option be less efficient? Requirement: There is an object. The object has a collection of similar items. I need to store this object. Example, say the object is a tree and it has a co...

Recursive Splay Tree

I am trying to implement a recursive splay tree, bottom up. I recurse down to the node I am need to splay up, and I find the parent and grandparent of that node. Then I am able to either zig zag or zig zig depending on the situation just fine. The problem is after this is done, I return the node which has been splayed once to the previou...