Questions tagged [data-structures]
For challenges involving ways to organize data (hash maps, arrays, binary trees ...)
45
questions
11
votes
5
answers
496
views
Double dequer sort
In this challenge Bubbler describes sorting a list by inserting its elements left to right into a double ended queue or "deque".
Take a number from the front of the array, and push it into ...
24
votes
16
answers
2k
views
Sorting with a deque
You're given an array of positive integers. Your job is to sort them using an initially empty deque (double-ended queue) by the following procedure:
Take a number from the front of the array, and ...
25
votes
22
answers
2k
views
Implement a bag without replacement
Intro
The Tetris Guidelines specify what RNG is needed for the piece selection to be called a Tetris game, called the Random Generator.
Yes, that's the actual name ("Random Generator").
In ...
8
votes
33
answers
1k
views
Keep elements in sequence that have a letter repeated at least 3 times
Challenge:
Given the input array l with a list of strings, only keep the elements in the sequence that have a letter that's repeated at least 3 times. Like ...
14
votes
10
answers
424
views
CGAC2022 Day 17: Present Heap
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Inspired by https://xkcd.com/835
In the midst of his mid-life crisis, Santa has impulsively purchased a Sports ...
13
votes
10
answers
673
views
CGAC2022 Day 8: Fen The Wicked, Part 2
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Fen is a magician Elf. He can cast spells on an array of numbers to produce another number or array of numbers.
One ...
20
votes
25
answers
1k
views
CGAC2022 Day 7: Fen The Wicked
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Fen is a magician Elf. He can cast spells on an array of numbers to produce another number or array of numbers.
One ...
12
votes
4
answers
285
views
Is it a heapable sequence?
A binary max heap is a rooted tree with integer labeled nodes such that:
No node has more than 2 children.
The label of every node is greater than all of its children.
We say a sequence of integers ...
2
votes
1
answer
1k
views
An Scalable Event Scheduler That Can Handle Billions of Events [closed]
The event scheduler is a recurrent theme in event-driven architectures: something triggers an event that needs to be checked in the future one or more times. I has particular use in trading where you ...
41
votes
51
answers
2k
views
Follow a linked list
For this challenge, a linked list looks like this:
[1, 2, 4, 0, 6, 1, 3, 1]
You'll notice there's no data; each item in the list is just a reference to the index ...
1
vote
1
answer
160
views
Building a Structured Outline [closed]
In a fictional document management system, input documents are structured with weighted headings. Lowest weighted headings are the most important.
This is a sample document:
H1 All About Birds
H2 ...
25
votes
3
answers
736
views
Drawing a tree from an array
Given a possibly nested, non-empty array of single-digit positive integers (not guaranteed unique), output the ASCII-art representation as a tree, using the box-drawing characters ...
48
votes
85
answers
8k
views
Implementing a stack
I can't believe we don't have this already.. It's one of the most important data-structures in programming, yet still simple enough to implement it in a code-golf:
Challenge
Your task is to ...
17
votes
31
answers
2k
views
Search text for a prefix and list all its suffixes in the text
I use "suffix" loosely here to mean "any sub-string that follows the prefix".
"Prefix" here means the START of a word, where a word's start is defined as either after a space or from the first ...
17
votes
7
answers
962
views
Binary tree rotations
Balanced binary search trees are essential to guarantee O(log n) lookups (or similar operations). In a dynamic environment where a lot of keys are randomly inserted and/or deleted, trees might ...
7
votes
4
answers
306
views
Regrowing trees
Background
Here you have another work-inspired challenge, but from my wife's work in this case. Imagine you have a service that returns the list of nodes in a tree structure (much like the files and ...
12
votes
10
answers
447
views
Disentangle doubly linked data
A doubly linked list is a data structure in which each node has a value as well as "links" to both the previous and next ...
5
votes
1
answer
920
views
Decode my I2C Stream!
From the sandbox!
I2c or TWI, is a 2 way stream that uses 2 signal lines: SDA and SCK. This is used in sensors to communicate ...
9
votes
11
answers
814
views
Squaring Off (fit to smallest possible square)
Intro
More complex than A square of text since this requires padding and input has unknown data type.
Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code....
8
votes
6
answers
415
views
Charlie and the evil hyphen
Here's the phonetic alphabet:
...
29
votes
8
answers
5k
views
Should we be friends?
Note this is a question primarily focusing on data-structures
Introduction
Bacefook wants people to be friendlier! As such, they are implementing a new system to suggest friends! Your task is to help ...
15
votes
6
answers
1k
views
Evaluate a simple spreadsheet
Rules
No cell range references (A2:B3).
Maximum 9 rows and 9 columns.
No circular references or formula errors.
Empty cells evaluate to ...
14
votes
20
answers
1k
views
Simple CSV/DSV importer
Slightly more than an inverse of this.
In: Multi-line DSV data and a single delimiter character. The DSV may be taken as a file, a filename, line-break separated string, list of strings, etc. ...
69
votes
61
answers
7k
views
N-dimensional N^N array filled with N
In: Enough memory and a positive integer N
Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by...
Examples:
1: [1] ...
22
votes
17
answers
2k
views
Neutralize data
To neutralize data, recursively replace all numbers (not digits!) with zeros and all characters (not strings!) with spaces.
You must accept any single number, character, or string, or possibly ...
9
votes
2
answers
382
views
Compute the height of a radix tree
Introduction
A radix tree, also known as compressed trie or compressed prefix tree, is a tree-like data structure for storing a set of strings.
The edges of the tree are labeled by nonempty strings, ...
9
votes
1
answer
437
views
Flexagonal flexagation
Being programmers, watching us flex aren't very interesting. Today we change that! In this challenge you will lex and flex hexaflexagons.
About
For a video introduction, watch viharts video(s) on ...
20
votes
4
answers
391
views
Validate a stem-and-leaf plot
A stem and leaf plot displays a bunch of numerical values in groups, which are determined by all but the last digit. For example, suppose we have this set of data:
...
15
votes
15
answers
3k
views
Is it a max-heap?
A heap, also known as a priority-queue, is an abstract data type. Conceptually, it's a binary tree where the children of every node are smaller than or equal to the node itself. (Assuming it's a max-...
21
votes
11
answers
784
views
Implement bag operations
A bag, also called a multiset, is an unordered collection. You can call it a set that allows duplicates, or a list (or an array) that is not ordered/indexed. In this challenge, you are asked to ...
24
votes
1
answer
718
views
Stack Exchanging
Problem
Say you have N stacks named S1 through SN, where each Sk (k = 1 to N) contains N copies of the number k.
For example, when N = 3 the stacks looks like this:
...
6
votes
3
answers
534
views
Shortest class to implement Perl hash-of-hashes
At some point, I bumped into an SO question asking how to implement Perl's trivial hash-of-hashes data structure in Java.
For those who don't know Perl, the hash value can be a scalar or another ...
13
votes
7
answers
649
views
Prefix Tree Traversal
Write a program that takes in (via stdin or command line) a string with the recursive form
PREFIX[SUFFIXES]
where
PREFIX may ...
18
votes
7
answers
512
views
Numbering Hierarchical Outlines
Write a program that takes in a string where every line consists of the character 0 indented by some number of spaces. The top line is not indented and every other ...
5
votes
1
answer
700
views
Most efficient table storage for determining recurrence
The goal of this challenge is to implement a storage and retrieval pattern that will most quickly determine if a set of recurrence definitions fall within a date range.
Consider the schema: ...
19
votes
2
answers
424
views
Turn over a new leaf
You're given a tree, which in computer science tradition, has the root at the top and leaves at the bottom. The leaf nodes are labelled with numbers. Your goal is to take the special leaf marked ...
5
votes
2
answers
380
views
Heaps of trouble
Challenge
You must, in the least bytes possible, implement the Binary Heap data structure and each of the following methods that operate on it:
A function which takes no arguments and returns an ...
6
votes
2
answers
1k
views
Collatz Graph Plotting [closed]
Write a program that outputs a graph of the collatz sequence any way you want (ASCII Image Video etc). You have to implement it that way that you can adjust the size of the graph by either the maximum ...
2
votes
1
answer
326
views
Immutable dictionaries in Haskell [closed]
You need to implement immutable dictionaries using only functions without any other data types (custom or built-in).
The dictionary must be indexed by any data type of class Eq and contain values of ...
6
votes
11
answers
5k
views
Generate the python dictionary of phone keypresses for any letter
In the fewest bytes, generate the dictionary of keypresses for any letter (as described in https://code.google.com/codejam/contest/351101/dashboard#s=p2)
In Python, the dictionary literal itself:
<...
1
vote
8
answers
815
views
Build a numerical library without using any primitive data type
The task is to build a numerical library for working with arbitrarily large integers that supports the following operations:
addition
subtraction
multiplication
division
modulo operation
However, ...
5
votes
4
answers
1k
views
Shortest implementation of a linked list, stack and queue
Challenge
Write the shortest program that implements the minimum requirements for a linked list, stack and queue.
Minimum requirements
Functions that allow the user to add and remove elements from ...
-5
votes
2
answers
600
views
Strings: Microsoft interview
You are given an array of strings , you have to construct a single array containing all of them so that the same array of strings can be reconstructed from the large array. The strings may contain any ...
21
votes
9
answers
2k
views
Implement lazy lists, preferably in a language you don't know well [closed]
This is a nice exercise for becoming more fluent in that programming language you've been meaning to learn, but have only tinkered with lightly. This involves working with objects, using or ...
3
votes
2
answers
407
views
Implement cdbmake
Write the shortest program to build a cdb database, using the following syntax for input:
+klen,dlen:key->data
followed by a newline. Example:
...