Skip to content

Commit d6a78f2

Browse files
committed
chore: working on questions
1 parent 548e844 commit d6a78f2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
- [Trees and Graphs](#trees-and-graphs)
6464
- [Route Between Nodes: Given a directed graph, design an algorithm to find out whether there is a route between two nodes.](#route-between-nodes-given-a-directed-graph-design-an-algorithm-to-find-out-whether-there-is-a-route-between-two-nodes)
6565
- [Minimal Tree: Given a sorted increasing order array with unique integer elements, write an algorithm to create a binary search tree with minimal height](#minimal-tree-given-a-sorted-increasing-order-array-with-unique-integer-elements-write-an-algorithm-to-create-a-binary-search-tree-with-minimal-height)
66+
- [Check if a given binary tree is BST ( Binary Search Tree )](#check-if-a-given-binary-tree-is-bst--binary-search-tree-)
6667
- [Recursion Interview Questions](#recursion-interview-questions)
6768
- [Calculate x to the power n using recursion](#calculate-x-to-the-power-n-using-recursion)
6869
- [Calculate Modular Exponentiation using recursion](#calculate-modular-exponentiation-using-recursion)
@@ -646,6 +647,13 @@ Trade off or invest some memory to improve run time complexity. Suppose use Has-
646647

647648
[Answer for Creating Minimal Tree Interview Question](src/interview-questions/graph/2-minimal-bs-tree.mjs)
648649

650+
651+
#### Check if a given binary tree is BST ( Binary Search Tree )
652+
653+
**Binary Search Tree (BST)**: is a binary tree in which for each node value of all the nodes in the left subtree is lesser or equal to the root node. And the values of all the nodes in the right subtree is greater than the root node.
654+
655+
656+
649657
### Recursion Interview Questions
650658

651659
#### Calculate x to the power n using recursion
@@ -722,7 +730,18 @@ Try `Binary Search`.
722730

723731
#### Reverse linked list
724732

733+
![](https://i.imgur.com/iaJ66fu.png)
734+
735+
Algorithm of Reverse Linked List:
736+
737+
![](https://i.imgur.com/WN6yJBJ.png)
738+
739+
Reverse Linked List simulation:
740+
741+
![](https://i.imgur.com/cTLz2fo.png)
725742

743+
- [Question](https://codepen.io/roopkt/pen/mdWayxv?editors=0010)
744+
- [Answer](https://codepen.io/roopkt/pen/dyvwPej?editors=0011)
726745

727746
## References
728747

src/algorithms/searching/binary-search/binary-search-tree.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ export class Tree {
5252
let temp = start;
5353

5454
while (true) {
55-
if (data >= temp.data) {
55+
if (data > temp.data) {
5656
if (temp.right) {
5757
temp = temp.right;
5858
continue;
5959
} else {
6060
temp.right = node;
6161
break;
6262
}
63-
} else if (data < temp.data) {
63+
} else if (data <= temp.data) {
6464
if (temp.left) {
6565
temp = temp.left;
6666
continue;

0 commit comments

Comments
 (0)