Nucleic acids that interact to generate structures in which three or more double helices emanate from a single point are said to form a junction. Such structures arise naturally as intermediates in DNA replication and recombination. It has been proposed that stable junctions can be created by synthesizing sets of oligonucleotides of defined sequence that can associate by maximizing Watson-Crick complementarity (Seeman N. C., 1981, Biomolecular Stereodynamics. Adenine Press, New York. 1: 269-278; Seeman, N. C., 1982, J. Theor. Biol. 99:237-247.) To make it possible to design molecules that will form junctions of specific architecture, we present here an efficient algorithm for generating nucleic acid sequences that optimize two fundamental properties: fidelity and stability. Fidelity refers to the relative probability of forming the junction complex relative to all alternative paired structures. Calculations are described that permit approximate prediction of the melting curves for junction complexes.