data-structures

What's the fastest way to represent and multiply sparse boolean matrices?

So, I'm using boolean matrices whose dimension is usually a couple dozen to a couple hundred, they are usually quite sparse (just some 2-4 non-zeros in most rows and columns) and my runtime is heavily dominated by their multiplication. What datastructure suits best for speeding up multiplication under these circumstances? Currently I'm...

Scala: Using HashMap with a default value

I have a mutable HashMap and would like to use it like a default-dictionary. The obvious method appears to be to use getOrElse and provide the default value each time as a second value. However this seems a little inelegant in my use case since the default value doesn't change. var x = HashMap(1 -> "b", 2 -> "a", 3 -> "c") println(x.ge...

Critique this C# Hashmap Implementation?

I wrote a hashmap in C# as a self study exercise. I wanted to implement chaining as a collision handling technique. At first I thought I'd simply use GetHashCode as my hashing algorithm, but I quickly found that use the numbers returned by GetHashCode would not always be viable (size of the int causes a out of mem if you want to index an...

Quick look up of Data structures.

Hi, can i get the link to Quick look up of data structures.. ...

Priority of learning programming craft and other suggestions

Hello, As I am in my starting career year in software development (C++ & C#) I now see my flaws and what I miss in this sphere. Because of that I came into some conclusions and made myself a plan to fill those gaps and increase my knowledge in software development. But the question I stumbled upon after making a tasks which I need to do...

Array or Database Table?

I could really use some good feedback on best practices / insight on whether it is better to put things in the database, or build an array. Take for example you have the suits of cards: $suits = array('clubs', 'spades', 'hearts', 'diamonds'); The array could change in the future, but not very frequently if at all. Now these suits are ...

Building a suffix tree for a string matching algorithm in large database.

Hi friends, I had an internship interview last week and I was given a question regarding searching for a particular string in a large database. I was totally clueless about it during the interview though I just gave a reply the"multi-level hashing" as that was the only hin I knew which had the best time efficiency, After a bit googling I...

Counting English words in a random string

Suppose I have a randomly generated string s=t&^%JHGgfdteam*&HGEdfg, what is the best approach to count the number of English words in that string? (English words as defined in some dictionary file). Obviously brute-force is not a good idea... would a suffix-tri e work? Binary search? Notice that in the case of s, there are two words: "t...

Datastructure Interview Questions and answers

Hi, please post the possible data structure interview Questions and answers.. it will be helpfull for all who reffers this post. Thanks ...

What would be a sensible way to implement a Trie in .NET?

I get the concept behind a trie. But I get a little confused when it comes to implementation. The most obvious way I could think to structure a Trie type would be to have a Trie maintain an internal Dictionary<char, Trie>. I have in fact written one this way, and it works, but... this seems like overkill. My impression is that a trie sh...

Book to learn advance concepts in Data Structures and Algorithms

Can any one suggest a book on data structures and algorithms that a programmer needs to cover. ...

Incidence matrix instead of adjacency matrix

What kind of problems on graphs is faster (in terms of big-O) to solve using incidence matrix data structures instead of more widespread adjacency matrices? ...

Performance of an AVL Tree in C#

I have implemented an AVL tree in C# whose insertion matrix is as follows Number of Elements Time taken to insert (sec) ------------------------------------------------------ 10 0.067 100 0.073 200 0.112 500 0.388 900 ...

Table data structure for quick searching with wildcards

I am storing a relatively small amount (perhaps may be larger in the future) and then searching it but this is proving to be a bit of a bottleneck in my project. To expand I have up to a few thousand rows and a few columns. I wish to be able search with the ability to specify a simple match with match all wildcards for any element. All ...

Optimized "Multidimensional" Arrays in Ruby

From birth I've always been taught to avoid nested arrays like the plague for performance and internal data structure reasons. So I'm trying to find a good solution for optimized multidimensional data structures in Ruby. The typical solution would involve maybe using a 1D array and accessing each one by x*width + y. Ruby has the abili...

Implementing a Trie in a non-OO way

Any idea how could I implement a Trie in a non-OO way, i.e. only using arrays? The idea is that it would store some good amount of elements, and the OO approach would be too heavy for my case as it is to be used in a J2ME app, where memory is a concern. Thanks! ...

PHP Pagestructure to array

Okey, so this is my problem. I have a page structure saved into a mysql db. Like this: Page 1 - SubPage 1.1 - - SubPage 1.1.1 - - - SubPage 1.1.1.1 - - - SubPage 1.1.1.2 - - SubPage 1.1.2 - SubPage 1.2 - SubPage 1.3 Page 2 Page 3 The structure can have endless pages and sub pages. All pages have a field called "url" and "childof". "ch...

Is there any good known file based key->value datastructure available in c++?

Is there any good file based key->value data-structure available in c++. similar to std::map(template based) with a insert/delete/get of O(logn). ...

Why does this program cause a segfault?

hi guys i am new so i am sure you will help i have some trouble with skip list here is code #include <stdio.h> #include<stdlib.h> #include<time.h> #include <string.h> #define P 0.5 #define MAX_LEVEL 6 struct sn{ int value; struct sn **forward; }; typedef struct sn skipnode; typedef struct{ skipnode *...

Best approach to configurable system structure.

Hi, I need some help with decide what is the best solution and how should be created system that has dynamic structures. The structure look something like this, that we have an process that contain various number of parameters that can be in different type and those parameter are represented in individual test. Whole that can be conf...