Producing every string of a given length using some range of characters Ever since I was a kid I wanted to understand how brute force programs work. I have not been able to make sense of any of the examples throughout the internet, so it became a personal challenge to make my own. Now that I have a couple Java classes under my belt, I realized I could tackle this problem with a linked list. Any advice about best practices, better algorithms, or how to make the existing one faster are welcome.

The problem to solve is to produce every possible combination of characters for a given range of characters and a given string length. This is purely for the purpose of personal learning.

public class BruteForce {

    final int minASCII = 97;
    final int maxASCII = 122;
    final int stringLength = 4;

    CharNode firstNode = new CharNode(minASCII);

    public BruteForce() {

        CharNode tempNode = firstNode;
        //Create stringLength number of CharNodes as a doubly linked list
        //The last node is used as an end of string marker
        for(int i = 0; i &lt; stringLength; i++) {
            CharNode nextNode = new CharNode(minASCII - 1);
            tempNode.setNextNode(nextNode);
            nextNode.setPreviousNode(tempNode);
            tempNode = nextNode;

            //Link the last node with the first node, and the first node with
            //the last node to make it a circular linked list
            if (i == stringLength - 1) {
                nextNode.setNextNode(firstNode);
                firstNode.setPreviousNode(nextNode);
            }
        }
        //keep printing and incrementing the nodes until the last
        //marker node is incremented
        while (firstNode.getPreviousNode().getData() == (minASCII - 1)) {
            printData();
            firstNode.incrementData();
        }
    }

    private void printData() {

        CharNode tempNode = firstNode;

        while (tempNode.getData() != (minASCII -1)){
            System.out.print((char)tempNode.getData());
            tempNode = tempNode.getNextNode();
        }
        System.out.println();
    }

    /*
     * One CharNode represents one character. Each CharNode links to
     * the next CharNode and to the previous CharNode. Based on the
     * circular doubly linked list data structure.
     */
    private class CharNode {

        private int data = 0;
        private CharNode nextNode = null;
        private CharNode previousNode = null;

        public CharNode(int data) {
            this.data = data;
        }

        public void setData(int data) {
            this.data = data;
        }

        public int getData() {
            return data;
        }

        public void setNextNode(CharNode nextNode) {
            this.nextNode = nextNode;
        }

        public CharNode getNextNode() {
            return nextNode;
        }

        //Automatically increment the next node and reset data to minASCII
        //once maxASCII is reached
        public void incrementData() {
            if (data &gt;= maxASCII) {
                this.getNextNode().incrementData();
                data = minASCII;
            }
            else
                data++;
        }

        public CharNode getPreviousNode() {
            return previousNode;
        }

        public void setPreviousNode(CharNode previousNode) {
            this.previousNode = previousNode;
        }
    }

    public static void main(String[] args) {
        new BruteForce();
    }
}
There is not much to understand about "brute forcing" something. "Brute force" does not mean a particular algorithm.

"Brute force" simply means that instead of using a clever algorithm to simplify a problem (simplify here means reducing the running time) you just test every single possible input to see which one produces the right result.

For example in password cracking, "brute force" means calculating every single possible password and testing them one by one. A smart algorithm would try passwords that are based on names and such first, because we know those are used way too often.

So, first of all, you need to clarify the problem that you are trying to solve through brute force.