11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

tree 479Some applications process transactions in batches. Forexample, a company may run a program once a month thatgenerates paychecks <strong>and</strong> withholding stubs from employeerecords that include hours worked, number <strong>of</strong> dependentsclaimed, <strong>and</strong> so on. Indeed, in the ATM example, theaccount balance is typically not updated during the on-linetransaction, but instead a batch transaction is stored. Overnightthat transaction will be processed together with othertransactions affecting that account (such as checks), <strong>and</strong>the balance will then be <strong>of</strong>ficially updated. (The programmodule that keeps track <strong>of</strong> the progress <strong>of</strong> transactions iscalled a transaction monitor.)There are several considerations that are important indesigning transaction systems. While some transactionsmay simply involve a request for information <strong>and</strong> do notupdate any files, many transactions may require that severalfiles or database records be updated. For example, a transfer<strong>of</strong> funds from a saving account to a checking account willrequire that both accounts be updated: the first with a debit<strong>and</strong> the second with a credit. What happens if the computerperforms the savings debit but then goes down before thechecking account can be credited? The result would be anupset customer whose money seems to have disappeared.The solution to this problem is to design a process wherethe various updates are done not to the actual databasesbut to associated temporary databases. Once these potentialtransactions are posted, the system issues a “commit” comm<strong>and</strong>to the databases. Each database must send a replyacknowledging that it’s ready to perform the actual update.Only if all databases reply affirmatively is the commit comm<strong>and</strong>given, which updates all the databases simultaneously.stored in a binary tree, a program can use two pointers, oneto the current node’s left child <strong>and</strong> one to its right child(see pointers <strong>and</strong> indirection). The pointers can then beused to trace the paths through the nodes. If the tree representsa file that has been sorted (see sorting <strong>and</strong> searching),comparing nodes to the desired value <strong>and</strong> branchingaccordingly quickly leads to the desired record.Alternatively, the data can be stored directly in contiguousmemory locations corresponding to the successivenumbers <strong>of</strong> the nodes. This method is faster than havingto trace through successive pointers, <strong>and</strong> a binary searchalgorithm can be applied directly to the stored data. On theother h<strong>and</strong> it is easier to insert new items into a linked list(see list processing).A common solution is to combine the two structures,storing the linked list in a contiguous range <strong>of</strong> memory bystoring its root in the middle <strong>of</strong> the range, its left child atthe beginning <strong>of</strong> the range, its right child at the end, <strong>and</strong>then repeatedly splitting each portion <strong>of</strong> the range to storeeach level <strong>of</strong> children. Intuitively, one can see that algorithmsfor processing such stored trees will take a recursiveapproach (see recursion).Further ReadingLewis, Philip M., Arthur Bernstein, <strong>and</strong> Michael Kifer. Databases<strong>and</strong> Transaction Processing: An Application-Oriented Approach.Upper Saddle River, N.J.: Addison-Wesley, 2002.Little, Mark, Jon Maron, <strong>and</strong> Greg Pavlik. Java Transaction Processing:Design <strong>and</strong> Implementation. Upper Saddle River, N.J.:Prentice Hall PTR, 2004.treeThe tree is a data structure that consists <strong>of</strong> individual intersectionscalled nodes. The tree normally starts with a singleroot node. (Unlike real trees, data trees have their root atthe top <strong>and</strong> branch downward.) The root connects to oneor more nodes, which in turn branch into additional nodes,<strong>of</strong>ten through a number <strong>of</strong> levels. (A node that branchesdownward from another node is called that node’s childnode.) A node at the bottom that does not branch any furtheris called a terminal node or sometimes a leaf.Trees are useful for expressing many sorts <strong>of</strong> hierarchicalstructures such as file systems where the root <strong>of</strong> a diskholds folders that in turn can hold files or additional folders,<strong>and</strong> so on down many levels. (A corporate organizationchart is a noncomputer example <strong>of</strong> a hierarchical tree.)The most common type <strong>of</strong> tree used as a data structureis the binary tree. A binary tree is a tree in which nonode has more than two child nodes. To move through dataIn a binary tree each node either has two branch (child) nodes oris a terminal node. Here a binary tree is shown with the equivalentrepresentation in an array <strong>of</strong> memory locations. Notice that thenumbers are stored level by level (50 in the top level, 25 <strong>and</strong> 75 inthe second level, <strong>and</strong> so on.) Null would be a special value (suchas -1) representing an empty node.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!