-1

Suppose as a computer programmer, you have been assigned a task to develop a program to store the sorted data in ascending order. Initially, you have used linked list data structure to store the data but search operation was time consuming then you decided to use BST (Binary Search Tree) but retrieval efficiency is not improved. In such situation, How can you improve the efficiency of the search operation for BST? Justify your answer with solid reason.

NutCracker
  • 9,614
  • 2
  • 36
  • 62
  • What have you tried, where are you stuck? – enhzflep Feb 01 '20 at 08:56
  • I am stuck in this assignment which assigns by my instructor. I am new in codding. – Farhan Bashir Seyal Feb 01 '20 at 09:08
  • 1
    Okay, then in that case I'll make a suggestion. Adding the numbers 1-10 to a BST in ascending order will lead to an awful tree. A _much_, *much* better one would have had 5 added first. Consider reviewing the features of these data structures that make searching them fast. With a single search method, the exact form of the tree will affect search times. ;) – enhzflep Feb 01 '20 at 09:17
  • 2
    *"How can you improve the efficiency of the search operation for BST?"* - ensure the tree is *balanced* with each insertion or removal, thereby alleviating the potential performance degradation accompanying a O(n) sequential scan search, and promoting search complexity of O(logN). Simpler said than done, but that's your answer, including a reason. – WhozCraig Feb 01 '20 at 10:31

1 Answers1

0

For such type of data which is in ascending order, You can convert the given BST into a height Balanced binary tree or Self balancing binary tree. That will improve the search operation on the new BST. Infact, Self Balancing binary trees are used to construct and maintain ordered lists such as priority queues.

aman kapoor
  • 122
  • 6