Giter Club home page Giter Club logo

linear-time-sorting's Introduction

Sorting algorithms that run in linear time

This repository implements in Rust some algorithms that are known to run in linear time. For a basic understanding of these algorithms, see the References section.

The algorithms are:

  • Count sort: it sorts an array of unsigned 1-byte number, which is u8, in rust.
  • Radix sort: it sorts an array of unsigned 8-byte number, which is u64, in rust.
  • Bucket sort: it sorts an array of floating point numbers, each number must be in the range [0, 1).

Usage example

Count sort

use linear_sort::counting_sort;

fn main() {
    let arr: [u8; 7] = [8, 2, 3, 100, 38, 3, 8];
    let sorted: Vec<u8> = counting_sort::sort(&arr);
    for i in &sorted {
        print!("{} ", i);
    }
    println!("");
}
$ cargo run
2 3 3 8 8 38 100 

Radix sort

use linear_sort::radix_sort;

fn main() {
    let arr: [u64; 7] = [8000, 3000, 38, 100, 38, 3, 3000];
    let sorted: Vec<u64> = radix_sort::sort(&arr);
    for i in sorted {
        print!("{} ", i);
    }
    println!("");
}
$ cargo run
3 38 38 100 3000 3000 8000 

Bucket sort

use linear_sort::bucket_sort;

fn main() {
    let arr: [f64; 7] = [0.6, 0.333, 0.2, 0.8, 0.9, 0.87, 0.65];
    let sorted: Vec<f64> = bucket_sort::sort(&arr);
    for i in &sorted {
        print!("{} ", i);
    }
    println!("");
}
$ cargo run
0.2 0.333 0.6 0.65 0.8 0.87 0.9

References

  • Introduction to algorithms / Thomas H. Cormen / Section 8

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.