Numerical optimization is used to design linear-optical devices that implement a desired quantum gate with perfect fidelity, while maximizing the success rate. For the 2-qubit CS (or CNOT) gate, we provide numerical evidence that the maximum success rate is S = 2/27 using two unentangled ancilla resources; interestingly, additional ancilla resources do not increase the success rate. For the 3-qubit Toffoli gate, we show that perfect fidelity is obtained with only three unentangled ancilla photons -less than in any existing scheme -with a maximum S = 0.00340. This compares well with S = (2/27) 2 /2 ≈ 0.00274, obtainable by combining two CNOT gates and a passive quantum filter [1]. The general optimization approach can easily be applied to other areas of interest, such as quantum error correction, cryptography, and metrology [2,3].PACS numbers: 03.67.Lx, 42.50.Dv Linear optics is considered as a viable method for scalable quantum information processing, due in large part to the seminal work of Knill, Laflamme, and Milburn (KLM) [4]. These authors showed that an elementary quantum logic gate on qubits, encoded in photonic states, can be constructed using a combination of linearoptical elements and quantum measurement. The tradeoff in this measurement-assisted scheme is that the gate is properly implemented only when the measurement yields a positive outcome, i.e., the gate is non-deterministic. Soon after the KLM scheme became a paradigm for linear optical quantum computation (LOQC), it became clear that there is a general unresolved theoretical problem of finding the optimal implementation for a desired quantum transformation [5].For the nonlinear sign (NS) gate, which acts on photons in a single optical mode, α 0 |0 + α 1 |1 + α 2 |2 → α 0 |0 + α 1 |1 − α 2 |2 , the maximum success probability without feed-forward has been theoretically proved to be 1/4 [6]. Here we focus on more complicated gates, taking as examples the two-qubit controlled sign (CS) gate (equivalently, the CNOT gate), and the three-qubit Toffoli gate. For these physically important gates, existing theoretical results are limited to upper or lower bounds on the success probability [1,7,8].A linear-optical quantum gate, or state generator (LO-QSG) [5], can be viewed formally as a device implementing a contraction transformation (for ideal detectors) that converts pure input states into desired pure output states. The goal of the optimization problem is to find a proper linear optical network (see Fig. 1), characterized by a unitary matrix U, that performs the desired transformation [9,10]. The problem is naturally partitioned into two tasks: i) finding a subspace of perfect fidelity within the space of all unitary matrices U, and ii) maximizing the success probability within this subspace. While in this paper we address transformations implemented by linear optics, the method is universal and with minor modifications can be successfully applied to any quantum-information problem involving unitary operations combined with measurements. Origina...