A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.

learn more… | top users | synonyms (1)

3
votes
1answer
34 views

d-ary heap in C

Now I have this d-ary heap data structure. Note that for d = 2 this is a binary heap. The client programmer specifies the value ...
4
votes
1answer
40 views

Unordered (hash) map for C

I am still working on basic data structures for C. Now I came up with a hash map: unordered_map.h: ...
5
votes
0answers
22 views

Creating a pseudo Pivot Table / Database using a 4-D array

Why am I not just using a Pivot Table / Database? a) I've never ever used either before. And I don't have time to learn how before this project needs to actually be finished. b) The final output ...
1
vote
0answers
11 views

Segment tree with lazy propagation

This is the implementation of segment tree with lazy propagation. Could you please review this code so that I can improve my ...
3
votes
1answer
44 views

Ordered map for C using AVL tree

I was in the mood for some data structures and I decided to code up an ordered map using AVL tree. I will post only map.h and ...
-2
votes
0answers
29 views

Inseting a node in binary search tree [closed]

When I'm inserting a node on the below binary tree,it is giving incorrect answer,although logic seems fine to me. ...
2
votes
1answer
26 views

Menu driven program to represent polynomials as a data structure using arrays

Write a menu-driven program to represent Polynomials as a data structure using arrays and write functions to add, subtract and multiply two polynomials; multiply a polynomial with a constant, ...
6
votes
1answer
21 views

Implementing a van Emde Boas tree in Rust

I wanted to implement a van Emde Boas Tree in Rust, to start learning the language. Much of my implementation is derived from the pseudo-code on wikipedia, with the exception that empty subtrees are ...
4
votes
2answers
53 views

InfixDictionary: Data structure for Infix string lookup

I needed a data structure to quickly find all previously inserted values, that have the given string as key or substring (full text search). At first, I tried out some tree structures (infix ...
2
votes
1answer
39 views

Get K most frequent tokens from a token stream

This is an interview problem: Given a token stream, find the K most frequent tokens in real time (the order of these k tokens does not matter). My approach: Use a hash table (...
5
votes
4answers
295 views

A data structure with push(int x), pop(), min() and max() in O(1)

I have written this Java code for a data structure which includes 3 stacks to supports four operations in \$O(1)\$: push(int x), ...
4
votes
2answers
76 views

Two sum algorithm variant

I need to compute the number of target values \$t\$ in the range: \$-10000 \le t \le 10000\$ (inclusive) such that there are distinct numbers \$x, y\$ in the input file that satisfy \$t= x+y\$. I have ...
4
votes
1answer
106 views

2D Fenwick-tree with combinatorics and modular arithmetic

This is a contest problem; Description: In the winter, children started to build snowmen. The snowmen were becoming adorable, except for a detail: none of them had a nose. The king, touched, ...
2
votes
2answers
23 views

Counting Bloom filter library in Java

This snippet is a counting Bloom filter supporting removal of elements as well. Instead of a bit vector it maintains a vector of "bucket counters". Also, the API supports well taking your customised ...
3
votes
1answer
80 views

Calculating the sum of array elements to the left and right

I am using C++ to code the following logic: An Array is given we have to traverse the array such that sum of array elements to its left must be equal to sum of elements to its right. BTW this is ...
3
votes
2answers
36 views

Skip-List that uses a Singly-Linked-List implementation

I've implemented this skip-list yesterday, and I'd like suggestions on how to improve this code, and my coding practices. ...
5
votes
2answers
119 views

Merge k Sorted Arrays

Please review my answer for this interview question: Merge k sorted arrays, using min heap. ...
11
votes
1answer
132 views

I made an implementation of std::deque, in my own way…?

In fact, entire deque header, though. According to Wikipedia, common implementations of std::deque include: Storing deque contents in a circular buffer, and only resizing when the buffer ...
4
votes
0answers
51 views

Swap items of a linked list in pairs - revision 5

Here is the source of the question. Given a singly linked list, swap the list items in pairs (reconnect the pointers, not simply swap the values). For example: Before: A->B->C->D ...
8
votes
3answers
99 views

Check if all leaves are at same level in a binary tree

I have written this code for checking whether all leaves are in the same level or not, in a binary tree. Any suggestion or improvement is appreciate. ...
-2
votes
5answers
90 views

What is the better way to write such code in PHP?

Is there a better way to write the below code? ...
5
votes
1answer
160 views

Algorithm that tells the user what current “status” they fall under based on their current time in comparison to an array of meeting data times

This is an algorithm that takes in an ArrayList of objects that store information on meeting/event schedules. This algorithm's purpose is to check and see what the ...
2
votes
1answer
36 views

Create a text index of files

This program creates a text index of 3 different files in Python. While this works correctly, I am still a beginner in Python. I used a list of class objects. Can this code be further optimised? ...
2
votes
1answer
72 views

HackerRank Regex Challenge: Detect HTML Tags

Problem Statement In this problem you will use regular expressions to help you detect the various Tags used in an HTML document. Here are a few examples of tags: The "p" tag for ...
3
votes
1answer
26 views

Container supporting PeekMax, PeekMin, Sum, and PeekNextToMax v2.0

This is another part of the update to this question. The interfaces are in this question. To summarize, the class is a generic container similar to MaxHeap, but only needs to support the following ...
1
vote
1answer
36 views

Interfaces & Factory for generic container supporting PeekMax, PeekMin, Sum, and PeekNextToMax

This is a partial update of this question. An implementation of these interfaces is in this question. To summarize, the class is a generic container similar to MaxHeap, but only needs to support the ...
4
votes
1answer
67 views

Matching strings

Basically I solved this question on one of the competitive websites: Given the total n number of String on first input, n input follows: We have to find such pairs of string (i,j) such that ...
0
votes
1answer
62 views

Remove Duplicates from Sorted List — LeetCode Solution in C

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given ...
12
votes
1answer
87 views

Compile-time data structure generator

In response to another recent question I mentioned that one mechanism to avoid runtime overhead for creating a data structure was to create it at compile time and use it directly. Since there was ...
3
votes
1answer
53 views

Priority stack in Java

I have this (simple) data structure that maintains multiple LIFO stacks. Each such stack is assigned a priority. The less is the value of a priority key, the higher the priority. Pushing operation ...
9
votes
2answers
91 views

Simple inventory system - Part 2

I've refactored my previous inventory system, and added a few features like removing items from the Inventory class, easily obtaining the current selected item ...
2
votes
3answers
47 views

Transforming data from an array of objects to a nested array of objects

I have an array of objects where each object has a datetime key/value pair: ...
6
votes
1answer
362 views

Very simple inventory system

To learn F#, I've implemented this very simple inventory system. While I'm proud that that it's my first program, and that it works, there are still a few areas that I'd like tips on, namely these: ...
2
votes
1answer
32 views

Chained hash table implementation to store student's information

This is my implementation of a Hash Table to store information about a student. Everything seems to work as expected, but I'd like some feedback on the following: Is my style good? Is it easy to ...
3
votes
1answer
88 views

Detecting cycles

This is a challenge question from codeeval.com: Given a sequence, write a program to detect cycles within it. Input sample: Your program should accept as its first argument a path to a ...
6
votes
1answer
109 views

Trie data structure in Java

I have implemented a trie data structure in my way, though it is very similar to what major implementations I found but would like to get it reviewed by experts. I don't see the need to store ...
2
votes
0answers
31 views

Inheritance across data in JavaScript

I'm creating a JavaScript app for a esoteric language, Marbelous. One of the features of this language are the devices. Each cell has a device, and each device has certain properties. In order to ...
-6
votes
1answer
75 views

Date Range Tree

...
6
votes
1answer
65 views

Finding most frequent words from Google N-Gram dataset

I have written a program to process Google 1-Gram dataset in order to obtain the list of most frequent words. This is my second more or less working program in Haskell, so I really want to know if it ...
0
votes
1answer
46 views

Implementing find middle element of singly linked list without using 2 pointers

There is a solution floating around about using 2 pointers. But I decide to keep the implementation much simpler by using basic constructs that works use to build basic methods of a singly list list ...
8
votes
5answers
651 views

Find longest lines from a file

This is a challenge question from codeeval.com: Write a program which reads a file and prints to stdout the specified number of the longest lines that are sorted based on their length in ...
7
votes
1answer
48 views

Querying houses similar to a given house

I was given this task as an interview coding challenge and was wondering If the code is well structured and follows python guidelines. I chose to sort the houses based on a similarity metric and then ...
3
votes
5answers
234 views

Making ArrayList.containsAll run faster

Whenever using ArrayList, the method containsAll(collection) runs in time \$\mathcal{O}(mn)\$, where \$n\$ is the size of ...
6
votes
1answer
284 views

Caterpillar uneaten leaves

K caterpillars are eating their way through N leaves, each caterpillar falls from leaf to leaf in a unique sequence, all caterpillars start at a twig at position 0 and falls onto the leaves ...
11
votes
3answers
1k views

Fastest and minimal random access data structure in Java

I have written up a data structure in Java that supports the following features: get(i) set(i, e) ...
1
vote
1answer
37 views

Interface for fixed-size container supporting max, min, sum

I had posted this previously as part of Generic container similar supporting PeekMax, PeekMin, Sum, and PeekNextToMax but I think it was to big a morsel for people to chew on. So I'm splitting it up. ...
3
votes
3answers
78 views

Dynamic resizeable array

How can I improve this code for a dynamic and re-sizable array data structure? Array.h ...
6
votes
1answer
68 views

List querying capabilities in Python 3.x

Either out of boredom, or my odd fascination with LINQ and SQL, this, thing, was created. Essentially, it provides list querying capabilities. At the moment, you can only query lists based on ...
3
votes
2answers
57 views

Linked list insertion

I have written the code below for inserting an element at the position specified by the user. I have seen the code in multiple books, and they have always used two pointers in the function that ...
2
votes
2answers
77 views

Maintaining a single collection subdivided by a value's property

I'm working on a networked game. In this game, the base entity is called an actor. An actor can either be replicated or local, with each instance having a "replicates" field that represents this. ...