Giter Site home page Giter Site logo

stringperm's Introduction

String Permutations

This program takes a string input from stdin and prints all permutations of that string.
Duplicate characters are included.

Getting Started

Prerequisites

  • Java 8

Running

To run the program:

./gradlew run Enter a String to find permutations of:
Then input your string:
>sep The following are permutations of the string "sep" : "sep", "esp", "pse", "spe", "eps", "pes"

Complexity

Time complexity

The algorithm does not visit duplicate permutations. Each permutation is only evaluated once and has no nested loops. The number of permutations calculated is n! - 1 (since first permutation is the input. Therefore, this program runs in O(n!)(not including time to read input, validate input and print output).

Space complexity

Permutations are not stored in memory as they are immediately printed. Otherwise we can risk running out of memory. The largest variables stored is the input character array and the weight index array. Both of which are size of the input. Therefore this program uses O(n) space`

Execution time

Setup: 2015 MacBook Pro, 2.7 GHz Intel Core i5

Input n n! time (ms) time/permuation (ms)
mastercard 10 3628800 19152ms .004737ms
mastercards 11 39916800 147437ms .00369ms

Input criteria

  • Must be valid UTF-16 string
  • Trailing whitespaces will be removed (Internal whitespaces will be permuted).
  • There is no limit on max size of input (see Execution time).

Running the tests

To run the unit tests:
./gradlew test

Built With

  • Gradle
  • Java 8
  • Junit 4
  • IntellJ IDEA CE

Resources

TODO

  • Implement permutation storage without running out of memory. A buffered Collection will mitigate
    running out of memory.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

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.