How exactly does one go about serializing a BST? What is the correct way to do it in the most efficient way? Now, this is way too general, so let me explain what I mean.

Here is some pseudo-pseudocode : 

```
public int[] serialize(root){
    preorder traversal 
    convert node to binary representation
    add the binary representation to an array
    send array via stream
}

```

Or

```
public int serialize(root){
    preorder traversal 
    convert node to binary representation
    send the binary representation via stream
}

```

My question is -- creating an array and sending it full of bits, is this efficient? Or should I skip the whole array idea and every time a node is converted, send it out to deserialize it? Perhaps both of these implementations are stupid. Any help would be appreciated.