data-structures

Dictionary of Primes

I was trying to create this helper function in C# that returns the first n prime numbers. I decided to store the numbers in a dictionary in the <int,bool> format. The key is the number in question and the bool represents whether the int is a prime or not. There are a ton of resources out there calculating/generating the prime numbers(SO ...

What are some well coded examples of standard data structures in PHP?

I'd like to see some well done PHP code samples of some standard data structures. Do you know of any code samples of Classes like Linear Linked Lists, Stacks, Queues, Binary Search Trees, etc? ...

Most memory-efficient way of holding base64 data in Python?

Suppose you have a MD5 hash encoded in base64. Then each character needs only 6 bits to store each character in the resultant 22-byte string (excluding the ending '=='). Thus, each base64 md5 hash can shrink down to 6*22 = 132 bits, which requires 25% less memory space compared to the original 8*22=176 bits string. Is there any Python...

How to create a 2 way map in java

I need a data structure to store string-int value pairs in an 1:1 relationship, and being able too look up from either way their counterpart. I wrote a class with a Hashtable and a String array and stored the data 2 times and used the built in functions for lookup. My question is that is there a nicer way to accomplish this? And by nic...

Sample problems to improve knowledge of data structures

I have seen majority of web programmers (writing some script with sql to make CRUD applicationg) do not know how to build a business logic in relatively complex situations like, using Stack, or Queue or write recursive algorithm. These programmers have habit of simply searching code on google and paste it, but dont understand which data ...

Game Design: Data structures for Stackable Attributes (DFP, HP, MP, etc) in an RPG (VB.Net)

I'm wrangling with issues regarding how character equipment and attributes are stored within my game. My characters and equippable items have 22 different total attributes (HP, MP, ATP, DFP). A character has their base-statistics and can equip up to four items at one time. For example: BASE ATP: 55 WEAPON ATP: 45 ARMOR1 ATP: -10...

array datastructure php problem

i want to make a new data structure using arrays for this query it will be like : will start with a query and a code example i want to make a new data structure using arrays for this query it will be like : //this is for the first headline [46] => Array ( [headline_name] => headline 1 [score] => 50 ...

modified depth first traversal of tree

I got this question in an interview with amazon. I was asked to perform a depth first traversal of a tree, without using recursion or stack. I could use a parent pointer for each node, as a part of the structure, but nothing else other than that.(for ex, a "visited" variable" or anything). Please suggest me an algorithm. ...

insert, delete, max in O(1)

Can someone tell me which data structure supports insert/delete/maximum operation in O(1) ? Thanks Ram ...

What's an efficient and simple way to store a data structure?

I want to write a parser for NBT (Named Binary Tags) structures. The format is represented like this: TAG_Compound("hello world"): 1 entries { TAG_String("name"): Bananrama } And in memory (or the file it's stored in) as hexadecimal view: 0000000: 0a 00 0b 68 65 6c 6c 6f 20 77 6f 72 6c 64 08 00 ...hello world.. 0000010: 04 6e 61...

Zipper like data structure with more then one cursor

The Zipper data structure is great when one wants to traverse a tree and keep the current position, but what data structure one should use if they want to track more then one position? Let me explain with examples: Someone on the #haskell channel has told me that zippers are used in yi editor to represent the cursor position. This is...

Library/data structure for handling huge data

I have some huge binary driver logs (around 2-5GB each, and probably around 10x as much after converting them to a readable form) and I need to write a tool that would allow me to sequentially browse, sort, search and filter them effectively (in order to find and resolve bugs). Each log entry has few attributes like: time-stamp, type, m...

Graphs - find common data

Hi! I've just started to read upon graph-teory and data structures. I'm building an example application which should be able to find the xpath for the most common links. Imagine a Google serp, my application should be able to find the xpath for all links pointing to a result. Imagine that theese xpaths were found: /html/body/h2/a /ht...

Kind share a site which gives upto date algorithms.

Kind share a site which gives upto date algorithms. ...

What will be the complexity of the operation to remove an element from the end of the singly linked list ?

What will be the complexity of the operation to remove an element from the end of the singly linked list ? I have implemented linked-list in C. Here is the code for removing a element from the end of linked-list. Now my query is that how to calculate the complexity of this snippet. What are the factors involved. There are other operation...

Overlapping polygons on 2D plane

i would like to build a dynamic data structure that can hold a list of polygons and return a list of polygons that overlaps a specified rectangle. i looked into bst trees (and quad trees) but these dont seem to work too well when the polygons overlap heavily. any good ideas i should check out before i roll my own nonsense? edit lets ...

Algorithms for biased spawning of items

In my game, I would like to spawn N items, not necessarily at the same time. Some of the items are dependent on what was spawned before (Markov chain-esque), so the probability of spawning two rocket launchers in a row is low, but there's a reasonable probability of spawning a rocket launcher followed by rockets. What would be the most e...

How to avoid lots of checks for null when using get() on a Java Collection???

Hi, I have a statement as follows getLD().get(cam.getName()).getAGS().get(aG.getName()) getLD(), getAGS() return Java collections I would not consider it to be an error if getAGS() were empty, nor if the result of getAGS().get(aG.getName()) were empty. However it is rather messy and somewhat of a pain checking for these null conditi...

Can __attribute__((packed)) affect the performance of a program?

I have a structure called log that has 13 chars in it. after doing a sizeof(log) I see that the size is not 13 but 16. I can use the __attribute__((packed)) to get it to the actual size of 13 but I wonder if this will affect the performance of the program. It is a structure that is used quite frequently. I would like to be able to rea...

Name For Stack With Unique Values

I'm using .NET 3.5 to create an application that requires a Stack<T> with unique values. I realize I could call Contains() before every Push(), but it makes sense semantically that I roll my own "unique stack" (UniqueStack<T> or maybe HashStack<T>?). I'm having a hard time to determine a strong name for this data structure. I hate the ...