Beginning Programming All-In-One Desk Reference for Dummies (ISBN by 0470108541)
Author:0470108541)
Language: eng
Format: mobi
Tags: &NEW
Published: 2011-07-01T01:27:23+00:00
• • •
Z
alpha-
betically by
last name.
Bally, David
Burkins, John
To save the name David Bally, the computer stores the name under the B
node. To save the name John Burkins, the computer also stores this name under the B node. To determine whether to store this new name before or after any existing data, the computer examines the data and sorts it alphabetically. In this way, the tree data structure not only stores data, but sorts and organizes it as well.
If you had a long list of names stored in an array or a collection, finding a name would require searching through the entire array or collection. However, if that same list of names is stored in a tree, a name would be much simpler to find because you’d only need to look at the first letter of a person’s last name to find where it might be stored.
So if you want to find the name John Bally, start at the B node and ignore any data stored under the other nodes. This makes searching and retrieving data much faster than other types of data structures, which is why trees are so commonly used in databases.
Binary trees
A variation of an ordered tree is a binary tree. Unlike an ordinary tree, every node in a binary tree has at the most two nodes connected underneath. To sort data, the left node contains values less than its parent node whereas the right node contains values greater than its parent node, as shown in Figure 5-8.
By limiting each node to a maximum of two connected nodes, binary trees make searching and sorting data fast and efficient.
10
Figure 5-8:
Binary trees
8
12
store and
sort data
by value.
4
9
11
19
26_108543-bk03ch05.qxp 4/30/08 8:27 PM Page 383
Creating Trees
383
For example, an ordinary tree allows each node to have multiple nodes underneath. As a result, the more data an ordinary tree stores, the more nodes that can appear directly underneath a single node, as shown in Figure 5-9.
10
10
8
12
12
9
4
Figure 5-9:
An ordinary
tree is more
4
9
11
19
8
19
11
difficult to
search than
To find the number 11 in a sorted
To find the number 11 in an unordered,
a binary
binary tree, you have to search three
non-binary tree means having to search
tree.
nodes.
every node.
To find the number 11 in an ordered binary tree is simple. Start with the root (top) node and compare the number 11 to the root node value (10). Because the number you want to find is greater than the root node, you’d branch to the right. At this next node (12), the computer repeats the process and Book III
determines that 11 is less than 12, so it branches to the left node, which is Chapter 5
where it finds the number 11.
Graphs and T
Searching through a sorted binary tree is simple, especially when compared to an unordered tree. Because an unordered tree can scatter data anywhere, searching an unordered tree means methodically searching each node, one by one, until you find the data you want. In a large unordered tree, this rees
search time can be slow and inefficient.
Ordered binary trees are one of the most common tree data structures used in many types of programs, such as databases.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12698)
Hello! Python by Anthony Briggs(10007)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9874)
The Mikado Method by Ola Ellnestam Daniel Brolund(9870)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(9776)
Dependency Injection in .NET by Mark Seemann(9421)
Hit Refresh by Satya Nadella(8864)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8384)
The Kubernetes Operator Framework Book by Michael Dame(7976)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7836)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7808)
Exploring Deepfakes by Bryan Lyon and Matt Tora(7772)
Grails in Action by Glen Smith Peter Ledbrook(7771)
Practical Computer Architecture with Python and ARM by Alan Clements(7713)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(7679)
Robo-Advisor with Python by Aki Ranin(7664)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7653)
Building Low Latency Applications with C++ by Sourav Ghosh(7560)
Svelte with Test-Driven Development by Daniel Irvine(7540)
