Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with this Breadth- First-Search function. Difference of Pairs on

ID: 3821744 • Letter: P

Question

Please help me with this Breadth- First-Search function.

Difference of Pairs on a BST: Write a method/function that outputs two pointers pointing to two nodes, x and y. in a given BST. where the key values of x and y differ by a given integer k. Recall that we had given the following algorithm in lecture that on an sorted input array A and given value k returns two indices i and j. where A[i] - A[j] = k. or report error if such i and j do not exist: i leftarrow 1; j leftarrow 2 n leftarrow length [A]//assuming indices of A start with 1 while (j lessthanorequalto n and i lessthanorequalto n) d leftarrow A[i] - A[j] if (d==k) return (i, j) if (d

Explanation / Answer

A BST is a tree in which has following details

-The left sub-tree of a node has a key less than or equal to its parent node's key.

-The right sub-tree of a node has a key greater than to its parent node's key.

Basic operations of BST are

Search Searches an element in a tree.

Insert Inserts an element in a tree.

Pre-order Traversal Traverses a tree in a pre-order manner.

In-order Traversal Traverses a tree in an in-order manner.

Post-order Traversal Traverses a tree in a post-order manner.

The solution for the given problem is given below with code.I think it will helps to figure out your problem

static int data(int[] a,int k) {
    int t;
    int l=a.length;
    int d,i,j;
    int c=0;
    while(i<=l){
    t=a[i];
        while(j<=l){
             d=(a[i]-a[j]);
            if(d==k){
                c++;
            }
            elseif(d<k){
                 i++;
            }
            Else
                 j++;
       }
    }
    return i,j;
}