Coder Social home page Coder Social logo

data-structures's Introduction

Data Structures

A data structure is a particular pattern for organizing information in order to make interacting with that information in the ways we want less expensive. If this sounds abstract, let's consider some examples.

The Rules

The only rule is that you can't use any built-in Ruby data structures. That means no Array, no Hash, and no Set. You can use built-in Ruby primitives, though, like Fixnum, String, nil, true, and false.

Examples

  1. Phone books are organized alphabetically by last name, which makes it easy to find the phone number if we know someone's last name.

    What if they were organized alphabetically by first name? Or numerically by phone number? Or by street name and number? These are all valid ways of organizing a phone book, but they all make it harder to interact with the information in the way we care about.

  2. How do you organize your clothes? Most people fall into two buckets:

    • They fold their clothes as soon as they do laundry and put them away neatly
    • They toss their clothes into a pile and deal with how to find what to wear each morning.

    The first method of organizing requires more up-front work, but makes it much easier to find our clothes in the morning. The second method of organizing requires almost no up-front work, but makes it more challenging to find our clothes in the morning.

    This is a classic trade-off between write performance (putting our clean clothes away) and read performance (finding our clothes in the morning). In the first case, "writing" is expensive but "reading" is cheap, and in the second case, "reading" is expensive but "writing" is cheap.

    How we organize

  3. Imagine we have a collection of financial transactions, e.g., stock trades. How might we want to interact with this list?

    • Adding a new transaction to the list
    • Removing an existing transaction from the list
    • Finding a specific transaction in the list
    • Finding all transactions in a certain price range, e.g., all transactions between $15USD and $20USD.
    • Finding all transactions that occurred within a certain range of time

    Depending on our situation, we might care about some of these more than others.

data-structures's People

Contributors

alagram avatar jfarmer avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.