Giter VIP home page Giter VIP logo

externalsorting's Introduction

ExternalSorting

Definition

A way to sort numbers in a file that has the size bigger than the RAM itself.
If your RAM is 4 GB, then it is impossible to sort numbers in array that has the size bigger than 4 GB.
To solve this issue, we can use External Sorting.
This method works by:

  1. Split the big file to smaller chunks [MUST be smaller than the RAM]
  2. Sort each and every smaller file with any sorting methods
  3. Merge them together in a single file
    Here's the visuals:
    External Sorting Visuals]

Dive into Code

Versions

The Python version I used at the time was Python 3.7.6

Creating the large file

The large file can be created with largefile.py. The range of numbers is from (-2^31) to (2^31-1)

Usage

  1. Change the filename (output is a text file).
  2. Change the size

Compilation

python3 largefile.py

Limitations

Found no way to make a big file just by specifying the file size.
Instead, I used total numbers to make the file. Approximately:

  • 100 million numbers = 1 GB
  • 1 billion numbers = 10 GB

WARNING! This is just an approximation, so at times the file can be bigger or lower than what you want depending on the number of bytes in each and every line of numbers.

externalsorting's People

Contributors

benedictuskent 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.