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.
18
votes
5answers
1k views
11
votes
2answers
130 views
Parsing Valve Map Files (VMF) into a tree like structure
I've written a small library of objects for parsing of Valve Map Files (VMF). These files are always generated and exported from either the Hammer World Editor, or a Source engine built in map making ...
10
votes
3answers
1k views
What do you think of this improvement of Linq's GroupBy method?
Linq already has a set of GroupBy methods for enumerable, which returns IEnumerable<IGrouping<TKey, TSource>>. I dislike this return type because it ...
10
votes
3answers
170 views
Please review my C code for a double linked list. Are there memory leaks I'm not seeing?
I've run my code through Valgrind and managed to not get any memory leaks based on the test code in main. I'm looking for things that I may not have thought to check for, and ways to improve my code ...
10
votes
3answers
429 views
Reversing a linked list
I implemented reversing a linked list in iterative way, just by knowing we need 3 pointers and I have never seen a code before, when I coded. I ran this code and tested it, it works fine. Even for ...
10
votes
2answers
153 views
Thread-safe prime number source
I am working on some multi-threaded code that requires a prime-number source.
The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being ...
10
votes
1answer
1k views
Flask-SQLAlchemy models and unit-testing
This is my first time building anything remotely like a robust database. I'm midway through designing it and I would be grateful if you have suggestions or have found any logical errors.
Goal: allow ...
10
votes
1answer
101 views
Binary Tree/ Amorphous Binary Tree Creator
I suppose this is a two-part question. The first part is just a simple implementation of a Binary Tree (BTree), with pre-order, post-order, and in-order searches ...
10
votes
2answers
667 views
Scala: Disjoint-Sets
I would like to get some feedback on the following implementation of disjoint sets, based on disjoint-sets forests (Cormen, et.al., Introduction to Algorithms, 2nd ed., p.505ff). It should have the ...
9
votes
3answers
170 views
Calculating infix expression with no parenthesis
This is my Java implementation (\$O(n)\$) about how to calculate infix expression with no parenthesis.
For example, when we input "3 + 4 * 4 / 8", we will get a double type answer is 5.0. Here to ...
9
votes
3answers
697 views
Checking brackets nesting in a string
I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are {,},(,),[,]. I have written the ...
9
votes
2answers
882 views
Quadtree design
I have an application which is used for displaying and modifying huge volumes of point cloud data from lidar files (up to few gigabytes each, sometimes loaded in simultaneously). In the app the user ...
8
votes
4answers
2k views
Circular Bounded Que using C#
I have implemented a circular bounded que using arrays as the base data structure. I'd appreciate if someone can review it for me.
...
8
votes
2answers
370 views
Which is the most correct pattern for using Stack.Pop?
There at least 2 patterns of using Stack.Pop
...
8
votes
3answers
538 views
Readability and Performance of my Trie implementation
As an interesting exercise in Python 3.3, I implemented a Trie (also known as a Prefix Tree).
Example usages
Create from list of key-value-tuples
...
7
votes
2answers
481 views
Singly Linked List
I am a self taught programmer and, while I understand data structures at a theoretical level (as well as through optimizing my own code), I have never actually taken the time to write my own ...
7
votes
5answers
511 views
Treap implementation in C
I was needed a SET-like data structure written in pure C for some university class, so I've implemented a simple one - the Treap (or cartesian tree).
Please check if everything is okay (actually, I'm ...
7
votes
2answers
606 views
Using bucket sort to rank students based on their marks
Problem:
n students have marks and names. Rank students based on their marks and print their names.
...
7
votes
3answers
2k views
Two Key HashMap
Background
Would like to create a two-key map that is fairly generic. In the existing system, there are a number of ways to name a parameter for a report. Rather than re-writing each report (too much ...
7
votes
2answers
4k views
atomic_queue - thread-safe and lock-free implementation of the FIFO data structure pattern
please review my implementation of a FIFO data structure that guarantees thread-safe access without locking.
I removed the license header block and all Doxygen comments. The original version (along ...
7
votes
1answer
1k views
Implementations of prefix lookup tables in Python
I've got a fairly performance sensitive need for fast prefix lookup, and I've built two different implementations trying to optimize for my use case. The first is built off a Trie implementation, and ...
7
votes
2answers
115 views
Java implementation of spell-checking algorithm
This little program was written for an assignment in a data structures and algorithms class. This is my first post here, and I understand that I shouldn't post the entire assignment, so in lieu of ...
6
votes
2answers
1k views
Find all single elements in an array
I am interested in printing all numbers that do not have a match in an array.
Example: 1,3,4,5,3,4,5,5,6 result 1,5,6
Please ...
6
votes
2answers
152 views
Holding server response header data after parsing it
I'm creating a program to retrieve web content in order to learn how these things work. I would like it to be as correct as possible, ideally fully compliant.
But I'm not sure this is the right ...
6
votes
2answers
544 views
Count frequency of words in a given file
Write a function that takes two parameters:
a String representing a text document
an integer providing the number of items to return
Implement ...
6
votes
1answer
412 views
6
votes
1answer
1k views
Implementation of binary heap in C++
Things I can think of include integer overflow, if the input type is int, etc. But other than that, what do you think is wrong with this code, design-wise, style-wise, and also in terms of other ...
6
votes
3answers
2k views
Check if a binary tree is a subtree of another tree
I am doing a refresher on algorithms.
I tried to solve the problem of determining if you have 2 trees (T1 and T2), one is a subtree of the other.
I came up with the following:
...
6
votes
1answer
482 views
What do you think of my Map implementation?
Just as a refresher I put together a simple Map implementation and I would love to get some feedback on it.
...
6
votes
1answer
2k views
A trie implementation for left to right wild card search
I was working on a task to implement auto suggest from an array of couple of thousands of strings.
Ofcourse the first and the easiest implementable was to go through each element and do ...
6
votes
2answers
130 views
Ring buffer - can I make any improvements?
I was just reading about ring buffer the other day and I was fascinated by how simple yet efficient it is.
I've implemented a ring (circular) buffer in Ruby and I'm just wondering if there's anything ...
6
votes
3answers
129 views
How to extract elements from multiple sorted list efficiently?
Problem Statement:-
I was ask this interview question recently.. I was able to come up with the below code only which runs in O(k log n)-
Given k <= n sorted arrays each of size n, there exists ...
6
votes
2answers
962 views
In Java, how to operate the sublists efficiently?
In my Java program, I need to operate on the sublists a of ArrayList or LinkedList often, like removing a sublist, comparing two ...
5
votes
2answers
523 views
Comparing list elements in an effective way
I have a list of opened nodes, with each step about 3000 nodes are opened and I want to put to the opened list only those nodes that are not already there. For now I'm just comparing each new one to ...
5
votes
4answers
96 views
Array of Objects or Array of arrays?
I build phone apps and I use JSON a lot in my APIs. The problem is sometimes I don't know how to format the JSON data.
For example, an iOS UITableView takes ...
5
votes
2answers
124 views
Conjugation Tables - Efficiently Handling the Data
I'm in the process of structuring a model for conjugation tables for French. There are noun inflections, adverb inflections, and (19) verb conjugations. I'm trying to model the data so that every ...
5
votes
2answers
152 views
Linked list implementation in C
I'm learning C for mainly for fun and to get a better understanding of how things work under the hood (most of my experience lies with high-level languages). I've been following quite a few books and ...
5
votes
1answer
105 views
Duplicate detection and reporting in a BST
For the purpose of this problem, the BST is defined to allow duplicates, and the duplicate values will always follow to the right-side of the parent nodes with the same value. For example, with the ...
5
votes
2answers
102 views
Binary Tree/Knowledge Base design C++
Currently I have a binary tree template setup where my main is using it with strings to make a question/answer game. I'm using a knowledge base that works as an interface to the binary tree that main ...
5
votes
2answers
2k views
Implementation of Dijkstra's algorithm
Please pick my code apart and give me some feedback on how I could make it better or more simple.
...
5
votes
1answer
258 views
Improving a priority queue sketch in Racket/Scheme
I just put together the skeletons for a priority queue using a binary heap in racket/scheme. Using racket/scheme is all about the educational experience and I was wondering if anyone wants to ...
5
votes
2answers
2k views
Reversing a linked list by iteration and recursion
From my original question on Stack Overflow: Is my implementation of reversing a linked list correct?
I'm a beginner at C and I'd like to know about style, and correctness of the reverse algorithms. ...
5
votes
1answer
72 views
Unbalanced binary search tree
I wrote this unbalanced binary tree and would like to know how to improve the code and performance. If you can point out any situations that are not being handled appropriately, that would be great ...
5
votes
1answer
33 views
Microcontroller ringbuffer
I'm pretty new to microcontrollers and C in general, so I thought asking here would be a good way not to get started with bad habits.
...
5
votes
1answer
158 views
Sparse Bitarray Class in Python (or rather frequently having contiguous elements with the same value)
Sparse is probably the wrong word - this is for encoding arrays of booleans where contiguous values tend to be the same. It'd be great to know a proper name for this data structure so I could read ...
5
votes
1answer
1k views
LinkedList and Binary Search Tree in Javascript
I recently decided to make a LinkedList and Binary Search Tree using JavaScript. I wanted to reach out to a wider audience and see how I did, and where could I improve.
Linked List: ...
4
votes
2answers
134 views
fractions data type — when to reduce?
Here is my Python implementation of a simple fractions class:
...
4
votes
3answers
11k views
C linked list implementation
For the following C linked list implementation, please give me some suggestions for improved efficiency, style and design. This implementation is not 100% complete, please give some suggestions for ...
4
votes
1answer
313 views
Queued Employees
The following example shows how to implement a queue in an employee structure. I am looking for a review of the implementation:
...
4
votes
2answers
108 views