Sankait Gupta - Assistant Professor at Govt. P.G. College Rajouri

Sankait Gupta - Assistant Professor at Govt. P.G. College Rajouri
Slide Note
Embed
Share

Sankait Gupta is an Assistant Professor at Govt. P.G. College Rajouri. With expertise in Computer Applications, he brings valuable insights to academic settings. His contributions aid in the growth of students, fostering a dynamic learning environment. Sankait Gupta's dedication and passion for teaching make him a respected figure within the educational community.

  • Sankait Gupta
  • Assistant Professor
  • Computer Applications
  • Education
  • Academic

Uploaded on Feb 20, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Created by : Sankait Gupta Assistant Professor Deptt. Of Computer Applications Govt P.G.College Rajouri

  2. DEFINITION A Binary Tree is called a Binary Search Tree if a node with data element has the following characteristics : Each node with data element in left subtree is less than its root element. i. Each node with data element in right subtree is greater than or equal to its root element. ii. iii. Both left subtree and right subtree will be again the Binary Search Trees. BINARY SEARCH TREE 5/14/2019 2

  3. Some Important Terms The successor nodes of a node are called its children The predecessor node of a node is called its parent The first" node is called the root (has no parent) A node (at last level) without children is called a leaf or terminal node 5/14/2019 BINARY SEARCH TREE 3

  4. REPRESENTATION OF BST Following is a pictorial representation of BST 5/14/2019 BINARY SEARCH TREE 4

  5. As it is clear from the example that the root node E has all the less values on the left subtree and the higher values on the right subtree. I. The value stored at a node is greater than the value stored at its left child and less than the value stored at its right child. II. BST, 5/14/2019 BINARY SEARCH TREE 5

  6. OPERATIONS ON BST Traversal Searching Insertion Deletion Finding Largest element Finding smallest element BINARY SEARCH TREE 5/14/2019 6

  7. SEARCHING IN BST (1) Start at the root (2) Compare the value of the item you are searching for with the value stored at the root (3) If the values are equal, then item found; otherwise, if it is a leaf node, then not found 5/14/2019 BINARY SEARCH TREE 7

  8. (4) If it is less than the value stored at the root, then search the left subtree (5) If it is greater than the value stored at the root, then search the right subtree (6) Repeat steps 2-6 for the root of the subtree chosen in the previous step 4 or 5 5/14/2019 BINARY SEARCH TREE 8

  9. COMPARISON Complexity of BST Searching O(logN) Complexity of Linked List Searching O(N) So it is clear that the BST searching is better one. 5/14/2019 BINARY SEARCH TREE 9

  10. BST SEARCH ALGORITHM Suppose we have a Tree with ROOT and ITEM is the number to be searched. BSTSearch(ROOT,ITEM,POSITION,PARENT) Steps involved in the algorithm : Step 1: If ROOT=NULL, then set Position=NULL and set PARENT=NULL EXIT [End if] 5/14/2019 BINARY SEARCH TREE 10

  11. Step 2: Set Pointer=ROOT and PointerP=NULL Step 3: Repeat step 4 while Pointer!=NULL Step 4: If item=Pointer -> info , then set POSITION=Pointer and set PARENT=PointerP Exit 5/14/2019 BINARY SEARCH TREE 11

  12. Else if item < Pointer -> info , then set PointerP=Pointer and set Pointer=Pointer -> left else set PointerP=Pointer and set Pointer=Pointer -> right [End if] [End of loop] 5/14/2019 BINARY SEARCH TREE 12

  13. Step 5: Set Position=NULL and PARENT=NULL Step 6: Exit. 5/14/2019 BINARY SEARCH TREE 13

  14. Thank You.............. 5/14/2019 BINARY SEARCH TREE 14

Related


More Related Content