trees become unbalanced because of the order in which the data items are inserted if these key values are inserted randomlythe tree will be more or less balanced howeverif an ascending sequence (like and so onor descending sequence is generatedall the values will be right children (if ascendingor left children (if descendingand the tree will be unbalanced the key values in the workshop applet are generated randomlybut of course some short ascending or descending sequences will be created anywaywhich will lead to local imbalances when you learn how to insert items into the tree in the workshop appletyou can try building up tree by inserting such an ordered sequence of items and see what happens if you ask for large number of nodes when you use fill to create treeyou may not get as many nodes as you requested depending on how unbalanced the tree becomessome branches may not be able to hold full number of nodes this is because the depth of the applet' tree is limited to fivethe problem would not arise in real tree if tree is created by data items whose key values arrive in random orderthe problem of unbalanced trees may not be too much of problem for larger trees because the chances of long run of numbers in sequence is small but key values can arrive in strict sequencefor examplewhen data-entry person arranges stack of personnel files into order of ascending employee number before entering the data when this happenstree efficiency can be seriously degraded we'll discuss unbalanced trees and what to do about them in "red-black trees representing the tree in java code let' see how we might implement binary tree in java as with other data structuresthere are several approaches to representing tree in the computer' memory the most common is to store the nodes at unrelated locations in memoryand connect them using references in each node that point to its children you can also represent tree in memory as an arraywith nodes in specific positions stored in corresponding positions in the array we'll return to this possibility at the end of this for our sample java code we'll use the approach of connecting the nodes using references note as we discuss individual operationswe'll show code fragments pertaining to that operation the complete program from which these fragments are extracted can be seen toward the end of this in listing