• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
មេរៀនៈ Data Structure and Algorithm in C/C++
 

មេរៀនៈ Data Structure and Algorithm in C/C++

on

  • 3,661 views

នេះជាមេរៀនទាំងអស់នៃមុខវិជ្ជា Data Structure and Algorithm in C/C++

នេះជាមេរៀនទាំងអស់នៃមុខវិជ្ជា Data Structure and Algorithm in C/C++

Statistics

Views

Total Views
3,661
Views on SlideShare
3,565
Embed Views
96

Actions

Likes
0
Downloads
139
Comments
2

3 Embeds 96

http://ngeamsoly.wordpress.com 92
http://www.virtualians.pk 2
http://virtualian.ning.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • @hongsignin គ្រាន់តែចុចប៊ូតុង Save វានឹងធ្វើការ Download ហើយ ។
    Are you sure you want to
    Your message goes here
    Processing…
  • How to download?
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Give an example, such as database of a company. Or more examples, sound, video games, …..
  • Give an example, such as database of a company. Or more examples, sound, video games, …..
  • But, unlike a linked list, the connections between the nodes are more than a simple one-to-another progression. An example can illustrate the connections in a binary tree.
  • This is an example of a binary tree with nine nodes. Presumably each node contains information about one of the 50 states. In this example, the states are not arranged in any particular order, except insofar as I need to illustrate the different special kinds of nodes and connections in a binary tree.
  • Each node in a binary tree is permitted to have two links downward to other nodes, called the left child and the right child .
  • Some nodes have no children, and those nodes are called leaves . In this example, there are four leaves: Massachusetts, Oklahoma, New Hampshire (or is that Vermont?) and Nebraska. (Yes, that really is Nebraska. Either the author ran out of room on the slide and had to shrink it, or the author is from rival state Colorado.)
  • There are two rules about parents in any tree: 1. The root never has a parent. 2. Every other node has exactly one parent. There is also a related rule which is not written here, but is part of the definition of a tree: If you start at the root, there is always one way to get from the root to any particular node by following a sequence of downward links (from a parent to its child).
  • Two nodes that have the same parent are called siblings , as shown here. In a binary tree, a node has at most one sibling.
  • When a complete binary tree is built, its nodes are generally added one at a time. As with any tree, the first node must be the root.
  • The next node must be the right child of the root.
  • A quick summary . . .
  • The first node of a complete binary tree is always the root...
  • ...then the right child of the root...
  • So, a heap is a complete binary tree. Each node in a heap contains a key, and these keys must be organized in a particular manner. Notice that this is not a binary search tree, but the keys do follow some semblance of order. Can you see what rule is being enforced here?
  • We can add new elements to a heap whenever we like. Because the heap is a complete binary search tree, we must add the new element at the next available location, filling in the levels from left-to-right. In this example, I have just added the new element with a key of 42. Of course, we now have a problem: The heap property is no longer valid. The 42 is bigger than its parent 27. To fix the problem, we will push the new node upwards until it reaches an acceptable location.
  • In general, there are two conditions that can stop the pushing upward: 1. We reach a spot where the parent is >= the new node, or 2. We reach the root. This process is called reheapification upward (I didn't just make up that name, really).
  • We'll fix the problem by pushing the out-of-place node downward. Perhaps you can guess what the downward pushing is called.... reheapification downward .
  • Reheapification downward can stop under two circumstances: 1. The children all have keys that are <= the out-of-place node. 2. The out-of-place node reaches a leaf.
  • Following the usual technique for implementing a complete binary tree, the data from the root is stored in the first entry of the array.
  • As with any partially-filled array, we are only concerned with the front part of the array. If the tree has five nodes, then we are only concerned with the entries in the first five components of the array.
  • A quick summary . . .

មេរៀនៈ Data Structure and Algorithm in C/C++ មេរៀនៈ Data Structure and Algorithm in C/C++ Presentation Transcript