public void writeBlocks(DAWG graph) throws IOException {

		// use heuristic to estimate number of blocks
		// estimated overhead of 15 and 25KB / block target size
		int blockNumber = graph.text.length() / 1000 * 15 / 25;

		if (blockNumber < 100) {
			blockNumber = 100;
		}

		int threshhold = (graph.size() / blockNumber) + 1;

		LinkedList<Integer> blockNumbers = new LinkedList<Integer>();

		for (int i = 1; i <= blockNumber; i++) {
			blockNumbers.add(i);
		}
		Collections.shuffle(blockNumbers, new SecureRandom());

		// important: Graph needs to implements a depth-first iterator!
		int nodesInBlock = threshhold;
		ArrayList<Block> blockList = new ArrayList<Block>();
		int block = -1;

		for (Node n : graph) {

			if (n != graph.source) {
				if (nodesInBlock == threshhold) {
					// draw new block number and write blockArray
					if (block != -1) {
						// this is the first run, dont write anything
						backend.writeBlockArray(blockList, block);
						blockList.clear();
					}

					block = blockNumbers.pop();

					nodesInBlock = 0;

				}

				Block b = new Block(n.getNumOccurs());
				n.setBlock(block);
				n.setIndex(nodesInBlock);
				for (char c : n.getEdges()) {
					int targetBlock = n.getEdge(c).getBlock();
					int targetIndex = n.getEdge(c).getIndex();
					b.addEdge(new Edge(c, targetBlock, targetIndex));
				}
				if (n == graph.source) {
					// make sure that the root node is always on position 0
					blockList.add(0, b);
				} else {
					blockList.add(b);
				}
				nodesInBlock++;
			}
		}

		// write last block
		backend.writeBlockArray(blockList, block);

		// write source node to block 0
		Block b = new Block(0);
		for (char c : graph.source.getEdges()) {
			b.addEdge(new Edge(c, graph.source.getEdge(c).getBlock(),
					graph.source.getEdge(c).getIndex()));
		}
		backend.writeBlock(b, 0);
	}