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)

0
votes
1answer
68 views

Data Structures C# Dictionary<int,user> and user has a property that is a list<numbers>

1st time posting here. I am about to post a question to StackOverflow about how to do a better job adding a Number to the list inside the User class. But I feel if I refactored this I might solve my ...
7
votes
0answers
91 views

C# Treap implementation

I recently developed a simple treap data structure in C#. In the future, I may have the class extend IDictionary. For now, I only expose a public accessor and a ...
1
vote
1answer
46 views

Check if a Binary Tree is full

Problem statement Given a node check whether the sub-tree rooted at given node is full binary tree or not. Definition A full binary tree (sometimes proper binary tree or 2-tree) is a tree in ...
1
vote
1answer
116 views

Binary tree from given Inorder and Preorder traversal

Below is code which builds a Binary Tree from given Inorder and Preorder lists. ...
3
votes
1answer
100 views

N-ary heap implementation

NaryHeap as a generalization of binary heap. Each node has up to N children. A template specialization for N = 2 (BinaryHeap) ...
4
votes
2answers
181 views

Thread-safe inventory system

I have implemented a thread safe inventory system. The Product is bound to a location in a warehouse. I have a Product class and ...
1
vote
1answer
43 views

Reversing a linked list recursively

This appears to work. Are there any edge cases I am missing? What are your thoughts on the algorithm and implementation? ...
3
votes
2answers
59 views

Multiply linked list - implementation

I don't know what is the common name for this data structure I named it like this due to a definition in wikipedia that states the following: In a 'multiply linked list', each node contains two ...
2
votes
3answers
70 views

Reverse part of a linked list

I'm learning data structures. I'm working on linked lists at the moment, and I'd like to have a strong grasp on them. Below is the last problem I solved. I'd like to know what you think of the ...
1
vote
0answers
19 views

First Element not being extracted right in a Max Binary Heap [closed]

I implemented a Max Binary Heap. However, When I extract the values, the first element extracted is wrong and the values after that are extracted correctly. As a matter of fact, the first element ...
4
votes
4answers
90 views

“Tractor” Python implementation

This is the Tractor problem from the Kattis problems archive. Problem Statement Bessie the Cow has stolen Farmer John’s tractor and is running wild on the coordinate plane! She, however, is a ...
3
votes
2answers
74 views

“Cut the sticks” Python implementation

Problem Statement You are given N sticks, where the length of each stick is a positive integer. A cut operation is performed on the sticks such that all of them are reduced by the length of the ...
6
votes
3answers
943 views

“Angry Professor” Python implementation

Problem Statement The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there ...
2
votes
1answer
51 views

Implementing a Trie in Python - follow-up

This is a follow-up of Wikipedia Trie pseudocode in Python Code quality improvements find has been fixed and a regression test ("bana" vs "banana") has been ...
5
votes
1answer
42 views

ADT stack with a dynamic array (revision 1)

Here's the second draft of my ADT stack code which I posted here before after carrying out most of the improvements suggested there. I decided to expose a function called ...
5
votes
4answers
111 views

ADT stack with a dynamic array

I'm starting to learn about data structures and coding in C. The stack is the simplest of all data structures so I'm trying to implement an ADT stack with dynamically allocated array in C. This ...
6
votes
2answers
59 views

Wikipedia Trie pseudocode in Python

I translated the Wikipedia pseudo-code into Python code (little changes only were required), but I do not like the end result, as it looks like C with all those while loops and counters. The fact is ...
7
votes
2answers
70 views

Trie for lowercase words

I need to develop a dictionary program so I used a trie data structure to implement it. I have created a array of object with size of 26 - so each object of class ...
0
votes
0answers
15 views

AccountModel data structure

I need to model simple account data structure. The user should be able: to add a transaction get information about transaction take all transaction of some type sum a transaction and all its ...
6
votes
2answers
235 views

Search on List<Tree-like structure>

I create a data collection system that has a tree-like structure built on the similarity to the pattern of the factory, and I have the difficulty in working with this structure, more stingrays lot of ...
1
vote
0answers
19 views

Counting Bloom filter library in Java - follow-up

This question is the second iteration of Counting Bloom filter library in Java. I did nothing more but fixing the remove method in order to fix an issue mentioned ...
3
votes
1answer
45 views

Stack implemented with a linked list

I have made a basic stack class utilizing a linked list for data storage and \$O(1)\$ push and pop and just want some basic feedback on the class to see if there is anything basic I missed. It seems ...
1
vote
1answer
43 views

Character class for an RPG game

I have an RPG-like program that uses a Character class to specify and return information about an individual player/character. I was curious about a way to best set ...
1
vote
0answers
77 views

Red-Black Tree (2-3-4 node tree) map implementation

Here is an implementation of a red black tree that I made. I am pretty sure it's working fine though I may have overlook something. How can I improve it in any way possible? Interface: ...
7
votes
4answers
396 views

Inserting a node to a given position in a linked list

Given You’re given the pointer to the head node of a linked list, an integer to add to the list and the position at which the integer must be inserted. Create a new node with the given integer, ...
2
votes
0answers
59 views

C++ Finite State Machine - follow-up

This question is a follow-up from Object Oriented Finite State Machine. I vastly improved commenting and followed the suggestions from the answer. Additionally, I improved my tests and did some more ...
5
votes
4answers
151 views

Utility functions for a linked list

I have written code to add a node to the head of the list. Criticisms and feedback are welcome. ...
12
votes
2answers
284 views

The median of the given AVL tree

A long time ago I found this question and asked about an algorithm here. My code is also available on GitHub. Given a self-balancing tree (AVL), code a method that returns the median. ...
2
votes
1answer
67 views

Object Oriented Finite State Machine

I wrote a little library for myself: implementing a generic finite state machine. I will be using this library in class assignments. I clearly have little understanding of C++ templates because most ...
2
votes
2answers
58 views

Doubly linked list implementation in C++

I made this C++ doubly linked list implementation and it seems to work right, handle everything well, and not have any errors. However, I've been working with it for a while and would like some fresh ...
2
votes
1answer
38 views

Doubly circular linked list implementation

I made this C++ doubly circular linked list implementation and it seems to work right, handle everything well, and not have any errors. However, I've been working with it for a while and would like ...
6
votes
0answers
58 views

Improving performance in unique-ifying an image

I'm writing a program that takes an input image, and generates a set of unique colors, and repaints the image using only those colors. It takes a long time, and I'm hoping to improve the running time. ...
1
vote
2answers
72 views

C++ Winsock HTTP Request Library

I'm trying to write a HTTP Request library for practice with Sockets and C++ in general. I created a seperate function to setup the struct needed to Connect() however it is now breaking and I cant ...
8
votes
1answer
148 views

Tuple<int, int> replacement

I use the following structure in a web service where performance is critical. It is used for making joins between domain data objects, the key is made of two integers. The idea is to fit the two 32 ...
5
votes
1answer
101 views

Find maximum element in bitonic array

An array is bitonic if it is composed of an increasing sequence of integers followed immediately by a decreasing sequence of integers. Write a program that, given a bitonic array of N distinct ...
8
votes
2answers
108 views

My own version of a search binary tree

I wrote my own version of a search binary tree in Java. Could someone kindly review it? ...
3
votes
1answer
39 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
43 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: ...
8
votes
0answers
45 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
36 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
47 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
1answer
44 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
39 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
58 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
46 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
456 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
97 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
107 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, ...
3
votes
2answers
39 views

Counting Bloom filter library in Java

See also the next iteration. 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 ...
3
votes
1answer
105 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 ...