Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [data-structures]

For challenges involving ways to organize data (data types, arrays, binary trees ...)

24
votes
3answers
526 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 ...
43
votes
76answers
7k 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 ...
16
votes
30answers
1k 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 ...
16
votes
7answers
702 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 ...
6
votes
4answers
262 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 ...
11
votes
10answers
375 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
1answer
295 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 ...
8
votes
10answers
650 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 ...
8
votes
6answers
371 views

Charlie and the evil hyphen

Here's the phonetic alphabet: ...
30
votes
8answers
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 ...
14
votes
6answers
982 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 ...
12
votes
18answers
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. ...
62
votes
47answers
6k 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
17answers
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
2answers
190 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
1answer
256 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 ...
19
votes
4answers
336 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: ...
13
votes
13answers
1k 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-...
19
votes
10answers
522 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 ...
23
votes
1answer
619 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
2answers
351 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
7answers
466 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
7answers
459 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
1answer
652 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
2answers
381 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
2answers
351 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
2answers
528 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
1answer
253 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
11answers
4k 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: <...
0
votes
8answers
745 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
3answers
966 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 ...
-4
votes
2answers
582 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
9answers
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 ...
4
votes
2answers
379 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: ...