data-structures

Implementation issues in 2-Satisfiability problem

I want to implement 2-SAT problem for 100000 literals. So there would be 200000 vertices. So I am stuck on having a array of all reachable vertices from each vertex, space complexity of O(200000^2) which is infeasible So please suggest a solution for this. And please throw some light on efficient implementation of 2-SAT problem. ...

Link list algorithm to find pairs adding up to 10

Can you suggest an algorithm that find all pairs of nodes in a link list that add up to 10. I came up with the following. Algorithm: Compare each node, starting with the second node, with each node starting from the head node till the previous node (previous to the current node being compared) and report all such pairs. I think thi...

How can I restrict the children of nodes in a tree structure.

I'm creating a tree structure that is based on an AbstractNode class. The AbstractNode class has a generic collection property that contain its child nodes. See the code example below. Is there some way, possibly using generics, that I can restrict a concrete version of AbstractNode to only allow one type of child node? See the code bel...

Delphi data structures

I maybe need to do a project in Delphi and are a beginner in that field. Currently, I am searching the net for ressources and get confused because there are so few resource sites. First of: can you give me some good websites with resources for Delphi I missed so far? I was also searching for data structures in Delphi and was wondering ...

Tree like data structure

Hi i am working on a problem and could do with some help, i am working in C#. What i'm trying to do is create a data structure as follows: I need to layout out item with x and y co-ordinates on a page. Now the actual laying out is not a problem is more about having a valid set of co-ordinates. Each item in my list can have multiple pa...

typedef struct vs struct definitions

I'm a beginner with C programming, but I was wondering what the difference was between the using typedef when defining a structure versus not using typedef. It seems to my like there's really no difference, they accomplish the same. struct myStruct{ int one; int two; }; vs. typedef struct{ int one; int two; }myStruct;...

C++ Data Member Alignment and Array Packing

During a code review I've come across some code that defines a simple structure as follows: class foo { unsigned char a; unsigned char b; unsigned char c; } Elsewhere, an array of these objects is defined: foo listOfFoos[SOME_NUM]; Later, the structures are raw-copied into a buffer: memcpy(pBuff,listOfFoos,3*SOME_NUM); ...

When converting to a red-black tree, is there any reason to choose one form over another?

I have a library of linked list/binary tree methods for use when standard containers don't fit - e.g. when there are different types of nodes, or when I need to convert from binary tree to list and back again. It includes red-black tree handling. One of the methods converts from a double-linked list to a perfectly balanced simple binary...

Data-structure that stores unique elements but answers queries for another ordering in C++

Hi, is there a data structure, which stores its elements uniquely (for a given compare-Functor) but answers queries for the highest element in that data structure with respect to another compare-Function ? For Example: I have a class with two properties : 1) the size 2) the value I'd like to have a data structure which stores all elem...

Spaghetti stack in C

Does anybody know where I can find an example of a Spaghetti stack written in C? ...

Does PHP copy variables when retrieving from shared memory?

If I run an shm_get_var(), will it return a "reference", keeping the data in shared memory? I'm wanting to keep an array about 50MB in size in shared memory so that it can be used by multiple processes without having to keep multiple copies of this 50MB array hanging around. If shared memory isn't the answer, does anyone have another id...

File backed Trie (or Prefix Tree) implementation

I have to store lot of strings in c++ map to keep unique strings and when ever duplicate string occurs I just need to increment the counter (pair.second). I've used c++ map and it well fits to this situation. Since the file that processing is gone now upto 30gig I am trying to keep this in a file instead of memory. I also came across ...

What type of struct/container would you use in this instance?

I am trying to figure out what type of structure or container I should use for a quick project. I need to have an unknown number of sets that will be entered from the GUI (each one will have a name, description, unique ID, priority, and boolean for included). Each set will have an unknown number of strings added to it (also from the GU...

What Is The Structure Of a XPS File

As I think, XPS files are like PDF files, but what is the structure od a XPS file? It's like PDF files? ...

Building Interpreter Of a Document Format

I'm going to start the development of my own document format(like PDF, XPS, DOC, RTF...), but I want to know where I can read some tutorials, how-to's...? I don't want code, this is a project that I want to learn how to build it, not use the experience of someone other. PS: I want to make it like a XML file: [Command Argument="Define i...

Create a sorted array out of 2 arrays

There are 2 arrays given for ex. A = [20,4,21,6,3] B = [748,32,48,92,23......] assuming B is very large and can hold all the elements of array A. Find the way in which array B is in (containing all the elements of array A as well) sorted order. Design an algorithm in the most efficient way. ...

Templates and nested classes/structures

I have a simple container : template <class nodeType> list { public: struct node { nodeType info; node* next; }; //... }; Now, there is a function called _search which searches the list and returns a reference to the node which matched. Now, when I am referring to the return-type of the...

How to implement connected rooms?

This may be a duplicate question as I don't know to phrase the search query. I'm creating a Zork-like text based game in Java where the character moves to different rooms which are connected to each other. I want to be able to list all options a player has available for this room. For example, Room A is connected east to B, and B is con...

How can I rebuild my base of algorithms/data structures knowledge?

I recently graduated from UMass Amherst with a B.S. in Computer Science. I maintained a 4.00 GPA, and I feel like I received a very solid education in most areas of the discipline. In my junior year, I took the Data Structures and Algorithms course. I feel that it was poorly taught. I breezed through it and understood the majority of th...

negative number in the stack

Hello everyone, I am a new student in the compilers world ^_^ and I want to know is legal represent negative number in the stack. For example: infix: 1-5=-4 postfix: 15- The statements are: push(1) push(5) x=pop() y=pop() t=sub(y,x) push(t) The final result in the stack will be (-4) How can i represent this if it is legal?? ...