Questions tagged [data-structures]

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.

Filter by
Sorted by
Tagged with
3113votes
20answers
3.2mviews

What is the difference between Python's list methods append and extend?

What's the difference between the list methods append() and extend()?
user avatar
  • 215k
2433votes
18answers
1.0mviews

How do I sort a list of dictionaries by a value of the dictionary?

I have a list of dictionaries and want each item to be sorted by a specific value. Take into consideration the list: [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] When sorted by name, it ...
1507votes
19answers
572kviews

Why is Dictionary preferred over Hashtable in C#?

In most programming languages, dictionaries are preferred over hashtables. What are the reasons behind that?
user avatar
1175votes
7answers
190kviews

Ukkonen's suffix tree algorithm in plain English

I feel a bit thick at this point. I've spent days trying to fully wrap my head around suffix tree construction, but because I don't have a mathematical background, many of the explanations elude me as ...
user avatar
866votes
37answers
610kviews

Simplest code for array intersection in javascript

What's the simplest, library-free code for implementing array intersections in javascript? I want to write intersection([1,2,3], [2,3,4,5]) and get [2, 3]
user avatar
  • 120k
860votes
29answers
503kviews

How do you implement a Stack and a Queue in JavaScript?

What is the best way to implement a Stack and a Queue in JavaScript? I'm looking to do the shunting-yard algorithm and I'm going to need these data-structures.
user avatar
794votes
83answers
377kviews

What are the lesser known but useful data structures?

There are some data structures around that are really useful but are unknown to most programmers. Which ones are they? Everybody knows about linked lists, binary trees, and hashes, but what about ...
724votes
8answers
513kviews

How to check if a specific key is present in a hash or not?

I want to check whether the "user" key is present or not in the session hash. How can I do this? Note that I don't want to check whether the key's value is nil or not. I just want to check whether ...
user avatar
  • 41.7k
534votes
25answers
779kviews

How to implement a tree data-structure in Java?

Is there any standard Java library class to represent a tree in Java? Specifically I need to represent the following: The sub-tree at any node can have an arbitrary number of children Each node (...
user avatar
  • 5,359
523votes
5answers
479kviews

Graph visualization library in JavaScript

I have a data structure that represents a directed graph, and I want to render that dynamically on an HTML page. These graphs will usually be just a few nodes, maybe ten at the very upper end, so my ...
520votes
17answers
290kviews

How does a hash table work?

I'm looking for an explanation of how a hash table works - in plain English for a simpleton like me! For example, I know it takes the key, calculates the hash (I am looking for an explanation how) ...
user avatar
  • 59.7k
464votes
27answers
203kviews

How to detect a loop in a linked list?

Say you have a linked list structure in Java. It's made up of Nodes: class Node { Node next; // some user data } and each Node points to the next node, except for the last Node, which has ...
user avatar
  • 20.8k
438votes
21answers
353kviews

How to implement a queue using two stacks?

Suppose we have two stacks and no other temporary variable. Is to possible to "construct" a queue data structure using only the two stacks?
user avatar
  • 14.4k
438votes
15answers
263kviews

When should I use a List vs a LinkedList

When is it better to use a List vs a LinkedList?
user avatar
430votes
34answers
262kviews

Split List into Sublists with LINQ

Is there any way I can separate a List<SomeObject> into several separate lists of SomeObject, using the item index as the delimiter of each split? Let me exemplify: I have a List<SomeObject&...
user avatar
  • 10.1k

15 30 50 per page
1
2 3 4 5
2081