Answer to Question #157220 in Algorithms for nazia khan

Question #157220

Q: Write the Algorithm of Binary Search using binary search tree. Explain with example .


1
Expert's answer
2021-01-24T11:10:06-0500

It is using the divide and conquer searching technique in which we have to arrange the data in the particular format before the searching operation. After that we find the middle element of the array and then compare with the target element.

If item not found, then we again check the target element. If it is greater than or less than the middle element then we followed the following operations. If it is greater than the middle element then we searching in the right side of the middle element and if it is less than the middle element then we will search into the left side of the middle element.

Algorithm:

  1. "Begin;"
  2. "Set\\ \\ a[5]\\leftarrow \\{10,20,30,40, 50\\}"
  3. "Set \\ l_r\\leftarrow 0, u_p\\leftarrow 4, f\\leftarrow 0"
  4. "Inpuut \\ searching \\ item"
  5. "Repeat \\ 6 \\ to \\ 8 \\ while (\\ l_r<u_p)"
  6. "Set \\ mid\\leftarrow (\\frac{l_r+u_p}{2})"
  7. "if \\ a[mid]=searching \\ item" "\\{Set \\ if=1 \\& \\ break \\ (element\\ found)\\ \\ break \\}"
  8. "if \\ a[mid]<searching\\ item \\ then"

"\\{ Set \\ l_r\\leftarrow mid+1"

"else"

"Set \\ u_p\\leftarrow mid-1"

9 ."If \\ f=1 \\ then"

"print(searching \\ item \\ found, \\ location =mid)"

"else"

"pinrt(element\\ not \\ found)"



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS