How to create multi-user wallet or wallets supporting off-chain transactions I want to implement the wallet to create bitcoin and altcoins exchange and store system. 


Somehow create random or HD wallet that holds and store upto 50 user public keys.But users will not have access to private keys so the user cannot sell coins directly. User A should be able to transfer coins to user B without paying transaction fee using our system.
(Thinking of some kind of HD wallet on which I control all the private keys and only provide users with public address within this wallet for receiving the coins)
Users hold the private keys themselves on mobile/pc using our system. User A should be able to transfer coins to user B without paying transaction fee using our system.(I think its not possible without private key in this case)


How to create wallet for case 1 and different wallet for case 2 ?
The case 1 is easy from a technical perspective: you create a single hierarchical deterministic wallet and take full custody of your users' balances. To do so, you provide distinct addresses to each user whenever they want to deposits or receive coins. You keep track which addresses are associated with which account, but only show them their balance aggregated from what they received and sent. When they send to another user on your service, you only update your database and do not move any coins. To create withdrawals or send transactions, you use whatever coins are convenient to do so. Note that this is simple only from a technical perspective, it is difficult from a legal and regulatory perspective.

Case 2 is impossible: The two requirements of the users holding their own private keys and being able to transfer coins without paying transaction fees are not compatible.
If you want users to hold their own keys, to sign over bitcoins, they need to be transferred to the control of another key. This requires an on-chain transaction and thus requires fees. On the other hand, to transfer balances without a fee, the coins must be under your service's control so that you can unilaterally amend the balances in your database.