user2716: Does the Bitcoin protocol guarantee that within a valid block, if transaction B spends the outputs of transaction A, A will always precede B?
Or is it possible to have B before A?

user5406: The Bitcoin protocol requires transactions to appear in topological order in the blockchain. Given two transactions A and B where B spends an output of A: 

Both A and B may be included in the same block.
A must precede B in the transaction list.

Colloquially, a miner will never include a transaction in a block template until the transaction's requirements are met. Since B spends an output of A, B is not valid until A has created said output. To satisfy this dependency, B can only be included after A was included.
Also see: Can multiple transactions transferring the same bitcoin be done in one block?

2716: <p>Does the Bitcoin protocol guarantee that within a valid block, if transaction B spends the outputs of transaction A, A will always precede B?</p>

<p>Or is it possible to have B before A?</p>
 5406: <p>The Bitcoin protocol requires transactions to appear in <strong>topological order</strong> in the blockchain. Given two transactions A and B where B spends an output of A: </p>

<ul>
<li>Both A and B may be included in the same block.</li>
<li>A must precede B in the transaction list.</li>
</ul>

<p>Colloquially, a miner will never include a transaction in a block template until the transaction's requirements are met. Since B spends an output of A, B is not valid until A has created said output. To satisfy this dependency, B can only be included after A was included.</p>

<p>Also see: <a href="https://bitcoin.stackexchange.com/q/1726/5406">Can multiple transactions transferring the same bitcoin be done in one block?</a></p>
