|
Binary trees in live!
|
|
07-14-2010, 06:04 AM
Post: #1
|
|||
|
|||
|
Binary trees in live!
On other forum I found .bat game, guessing of numbers
Code: @echo offThe winner is the person who is less mistaken... The most effective way to solve this game is using binary tree algorithm
Read rules ![]()
|
|||
|
07-14-2010, 07:07 AM
Post: #2
|
|||
|
|||
|
RE: Binary trees in live!
eww batch games
this would be much better in C But could you explain the binary tree algorithm? Perhaps in Pascal
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
07-14-2010, 08:44 PM
Post: #3
|
|||
|
|||
|
RE: Binary trees in live!
Basically this is a simple game. You can see the source. You just need to make a loop using goto and that's it.
And about "binary trees", well you need to know pointers very good and than you can start learning binary trees. In C you need to learn pointers on structures and structures that have pointers, and than you can pass on "binary trees" !! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
07-14-2010, 09:02 PM
(This post was last modified: 07-15-2010 12:29 AM by l3g1sl4tor.)
Post: #4
|
|||
|
|||
|
RE: Binary trees in live!
It is not so hard
Imagine that we have 1 array of 100 numbers and we need to find one random which is etc. generated with something as rand() function in php... How that will be done with binary tree search method?Look at the picture. ![]() Lets say that circles that are drawn are the data with which we are operating. On first input we have, as I say just one array of 100 numbers (excluding random number which program will generate on the very beginning of program). In this kind of searching program will divide existing data on half, n times, until it got the solution. So in this our case array 1 (see picture up) will be parted on half on double smaller arrays 2 and 3, then if searched value is not found, arrays 2 and 3 (two halves of array 1) will be parted each on 2 smaller arrays (2 on 4,5 and 3 on 6,7) which will be quarter of our very first array of 100 numbers. This operation will be repeated until random number is found. What this have with binary so it is called binary tree? This was my very first question when I first time heard this upper mentioned story Lets back to our arrays... you see how number of little (parted) arrays is increasing? first we had 1 then 2, then 4, then we would have 8 in next step. You will notice that all that numbers, (starting from two ) are extents of number 2. 2=2^1, 4=2^2, 8=2^3, 16=2^4 ... So you see, binary tree in fact is connected with binary system and method! ![]() Methods implementing in Pascal: First we need to make appropriate type for using binary trees. This type can be made using pointers : Code: typeNOTE : Empty binary tree is marked with nil pointer. Making empty binary search tree, in which we will later on, insert data : Code: function MakeEmptyBinarySearchTree: BinarySearchTree;Inserting data in a search tree : Code: procedure InsertIntoBinarySearchTree (Elm: Element; var B: BinarySearchTree);Searching binary tree: Code: function SearchBinarySearchTree (Sought: KeyType; B: BinarySearchTree;Write data of binary tree: Code: procedure PrintBinarySearchTreeData (B: BinarySearchTree);That's only some basic operations with binary trees, for whole story of interacting with it (in pascal), you can visit this link from where I also learned about pointers and binary trees for my past competitions (which was unsuccessful btw ). Enjoy in searching with this method!
Read rules ![]()
|
|||
|
07-15-2010, 12:23 AM
Post: #5
|
|||
|
|||
|
RE: Binary trees in live!
I must say that you gave a very good explanation Legislator !!!
Binary tree is a very important part when we talk about graph theory in programming. Binary tree is just the beginning and we have ternary tree, and n-ary tree. They are used in many algorithms, such as sorting, searching etc. People avoid trees because of two issues : -Pointers -Recursions You need to know pointers and recursions and to understand basics of graph theory mathematically in order to understand trees and how they work. Also knowledge about Data Structures always goes with algorithms, another fact is a programming language. There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
10-04-2010, 09:31 PM
Post: #6
|
|||
|
|||
|
RE: Binary trees in live!
nice mathematics techniques are share in this post
chicago real estate |
|||
|
10-05-2010, 03:42 AM
Post: #7
|
|||
|
|||
RE: Binary trees in live!
(10-04-2010 09:31 PM)tommy Wrote: nice mathematics techniques are share in this postYeah it has elements of Discrete mathematics ! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
« Next Oldest | Next Newest »
|






this would be much better in C 
![[Image: 69335_binarytree.png]](http://myph.us/pics/69335_binarytree.png)