Thanks aliashraf, can you elaborate a little about #3 please. In which case Bitcoin client (I assume wallet) have to deal with the block? Is it a special api something like audit?
And how is it possible to work with tree which is not in-memory?
The merkle tree is computed dynamically by full nodes connected to SPV servers and is not cached. The tree is made* when the block itself is fetched.
*Only the leaves of the merkle tree, which are the transactions, are passed as input, and then it computes the hashes of each adjacent pair of transactions, and then the hashes of each adjacent pair of those hashes, until only one hash is left, which is called the root hash.
At any point, there is only one layer of the merkle tree stored in memory, whether it be the set of transactions in a block, an intermediate row of hashes that is made inside
ComputeMerkleRoot() or just the root hash itself.