SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Binary Search Tree
- Exact match
Illustrated walk through
Node structure
public class Node
{
public int Value;
public Node Left;
public Node Right;
}

Value

Left

Right
Sample tree
5

3

1

10

4

7

12
Find Exact Match
public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

Base Case:
return when beyond a leaf
return a node found

Recursively search left or
right subtree
node

target

5
3

1

10

4

7

12

public Node FindExact( Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

7
node

target

5
3

node == null
is false

1

10

4

7

12

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

7
node

target

5
3

5 == 7
is false

1

10

4

7

12

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

7
node

target

5
3

5<7
is true

1

10

4

7

12

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

7
node

target

5
3

1

7

10

4

7

12

Call Stack for 5
public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5
node

3

1

7

10

4

7

12
Call Stack for 10
Call Stack for 5

public Node FindExact( Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5
node

3

node == null
is false

1

7

10

4

7

12
Call Stack for 10
Call Stack for 5

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5
node

3

1

10 == 7
is false

7

10

4

7

12
Call Stack for 10
Call Stack for 5

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5
node

3

1

10 < 7
is false

7

10

4

7

12
Call Stack for 10
Call Stack for 5

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5
node

3

else (10 > 7)
is true

1

7

10

4

7

12
Call Stack for 10
Call Stack for 5

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5
3

1

node

7

10

4

7

12
Call Stack for 7
Call Stack for 10
Call Stack for 5

public Node FindExact( Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
node == null
is false

target

5
3

1

node

7

10

4

7

12
Call Stack for 7
Call Stack for 10
Call Stack for 5

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
7 == 7
is true
3

1

node

7

target

5
10

4

7

12
Call Stack for 7
Call Stack for 10
Call Stack for 5

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}

We found an
exact match!

if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5
3

7

10
Call Stack for 7

1

node

4

7

12
Call Stack for 10
Call Stack for 5

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

7
target

5
node

3

1

7

10

4

7

12
Call Stack for 10

7
Call Stack for 5
public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
target

5

node
3

1

7

10

4

7

12

Call Stack for 5
public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

7
target

5
3

1

7

10

4

7

12

public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}

The caller of the
if (node.Value ==
FindExactreturn node;
receives
node 7}

target) {

if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}

7

Contenu connexe

Tendances

重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1Chris Huang
 
Pragmatic metaprogramming
Pragmatic metaprogrammingPragmatic metaprogramming
Pragmatic metaprogrammingMårten Rånge
 
Monadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsMonadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsChris Eargle
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...ssuserd6b1fd
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. StreamsDEVTYPE
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Lecture 2: arrays and pointers
Lecture 2: arrays and pointersLecture 2: arrays and pointers
Lecture 2: arrays and pointersVivek Bhargav
 
Tai lieu ky thuat lap trinh
Tai lieu ky thuat lap trinhTai lieu ky thuat lap trinh
Tai lieu ky thuat lap trinhHồ Trường
 
Mutation Testing at BzhJUG
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUGSTAMP Project
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189Mahmoud Samir Fayed
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)Chris Huang
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 

Tendances (20)

重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1
 
Pragmatic metaprogramming
Pragmatic metaprogrammingPragmatic metaprogramming
Pragmatic metaprogramming
 
Monadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsMonadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query Expressions
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Prog
ProgProg
Prog
 
c programming
c programmingc programming
c programming
 
Lecture 2: arrays and pointers
Lecture 2: arrays and pointersLecture 2: arrays and pointers
Lecture 2: arrays and pointers
 
Qno 1 (d)
Qno 1 (d)Qno 1 (d)
Qno 1 (d)
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
Tai lieu ky thuat lap trinh
Tai lieu ky thuat lap trinhTai lieu ky thuat lap trinh
Tai lieu ky thuat lap trinh
 
Mutation Testing at BzhJUG
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUG
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
c programming
c programmingc programming
c programming
 
FSOFT - Test Java Exam
FSOFT - Test Java ExamFSOFT - Test Java Exam
FSOFT - Test Java Exam
 

Similaire à Binary search tree exact match - illustrated walkthrough

Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfFootageetoffe16
 
How to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdfHow to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdffeelingcomputors
 
Hello- the following code- In LeftRotaate and RightRotate methods for.pdf
Hello- the following code- In LeftRotaate and RightRotate methods for.pdfHello- the following code- In LeftRotaate and RightRotate methods for.pdf
Hello- the following code- In LeftRotaate and RightRotate methods for.pdfa2zmobiles
 
Using the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxUsing the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxslyndon
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfarchiesgallery
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfStewart29UReesa
 
Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfhadpadrrajeshh
 
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
package edu-ser222-m03_02-   ---  - A binary search tree based impleme.docxpackage edu-ser222-m03_02-   ---  - A binary search tree based impleme.docx
package edu-ser222-m03_02- --- - A binary search tree based impleme.docxfarrahkur54
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfmail931892
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)진성 오
 
Please change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdfPlease change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdfpallavi953613
 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docxajoy21
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfmichardsonkhaicarr37
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Lucas Witold Adamus
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Write a program that displays an AVL tree along with its balance fact.docx
 Write a program that displays an AVL tree along with its balance fact.docx Write a program that displays an AVL tree along with its balance fact.docx
Write a program that displays an AVL tree along with its balance fact.docxajoy21
 
Java code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdfJava code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdffashioncollection2
 
public class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfpublic class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfannaipowerelectronic
 

Similaire à Binary search tree exact match - illustrated walkthrough (20)

Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
 
How to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdfHow to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdf
 
Hello- the following code- In LeftRotaate and RightRotate methods for.pdf
Hello- the following code- In LeftRotaate and RightRotate methods for.pdfHello- the following code- In LeftRotaate and RightRotate methods for.pdf
Hello- the following code- In LeftRotaate and RightRotate methods for.pdf
 
Using the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxUsing the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docx
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdf
 
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
package edu-ser222-m03_02-   ---  - A binary search tree based impleme.docxpackage edu-ser222-m03_02-   ---  - A binary search tree based impleme.docx
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)
 
Materi Searching
Materi Searching Materi Searching
Materi Searching
 
Please change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdfPlease change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdf
 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdf
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Binary tree in java
Binary tree in javaBinary tree in java
Binary tree in java
 
Write a program that displays an AVL tree along with its balance fact.docx
 Write a program that displays an AVL tree along with its balance fact.docx Write a program that displays an AVL tree along with its balance fact.docx
Write a program that displays an AVL tree along with its balance fact.docx
 
Java code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdfJava code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdf
 
public class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfpublic class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdf
 

Plus de Yoshi Watanabe

Create images with AI models.pptx
Create images with AI models.pptxCreate images with AI models.pptx
Create images with AI models.pptxYoshi Watanabe
 
Git コンフリクト
Git コンフリクトGit コンフリクト
Git コンフリクトYoshi Watanabe
 
Find n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthroughFind n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthroughYoshi Watanabe
 
Binary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk throughBinary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk throughYoshi Watanabe
 
Quicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk throughQuicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk throughYoshi Watanabe
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughYoshi Watanabe
 

Plus de Yoshi Watanabe (8)

Create images with AI models.pptx
Create images with AI models.pptxCreate images with AI models.pptx
Create images with AI models.pptx
 
Git フェッチ
Git フェッチGit フェッチ
Git フェッチ
 
Git リベース
Git リベースGit リベース
Git リベース
 
Git コンフリクト
Git コンフリクトGit コンフリクト
Git コンフリクト
 
Find n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthroughFind n th fibonacci iteratively - illustrated walkthrough
Find n th fibonacci iteratively - illustrated walkthrough
 
Binary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk throughBinary search: illustrated step-by-step walk through
Binary search: illustrated step-by-step walk through
 
Quicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk throughQuicksort: illustrated step-by-step walk through
Quicksort: illustrated step-by-step walk through
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk through
 

Dernier

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Binary search tree exact match - illustrated walkthrough

  • 1. Binary Search Tree - Exact match Illustrated walk through
  • 2. Node structure public class Node { public int Value; public Node Left; public Node Right; } Value Left Right
  • 4. Find Exact Match public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } Base Case: return when beyond a leaf return a node found Recursively search left or right subtree
  • 5. node target 5 3 1 10 4 7 12 public Node FindExact( Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } 7
  • 6. node target 5 3 node == null is false 1 10 4 7 12 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } 7
  • 7. node target 5 3 5 == 7 is false 1 10 4 7 12 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } 7
  • 8. node target 5 3 5<7 is true 1 10 4 7 12 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } 7
  • 9. node target 5 3 1 7 10 4 7 12 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 10. target 5 node 3 1 7 10 4 7 12 Call Stack for 10 Call Stack for 5 public Node FindExact( Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 11. target 5 node 3 node == null is false 1 7 10 4 7 12 Call Stack for 10 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 12. target 5 node 3 1 10 == 7 is false 7 10 4 7 12 Call Stack for 10 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 13. target 5 node 3 1 10 < 7 is false 7 10 4 7 12 Call Stack for 10 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 14. target 5 node 3 else (10 > 7) is true 1 7 10 4 7 12 Call Stack for 10 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 15. target 5 3 1 node 7 10 4 7 12 Call Stack for 7 Call Stack for 10 Call Stack for 5 public Node FindExact( Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 16. node == null is false target 5 3 1 node 7 10 4 7 12 Call Stack for 7 Call Stack for 10 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 17. 7 == 7 is true 3 1 node 7 target 5 10 4 7 12 Call Stack for 7 Call Stack for 10 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } We found an exact match! if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 18. target 5 3 7 10 Call Stack for 7 1 node 4 7 12 Call Stack for 10 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } 7
  • 19. target 5 node 3 1 7 10 4 7 12 Call Stack for 10 7 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } }
  • 20. target 5 node 3 1 7 10 4 7 12 Call Stack for 5 public Node FindExact(Node node, int target) { if (node == null) { return null; } if (node.Value == target) { return node; } if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } 7
  • 21. target 5 3 1 7 10 4 7 12 public Node FindExact(Node node, int target) { if (node == null) { return null; } The caller of the if (node.Value == FindExactreturn node; receives node 7} target) { if (node.Value < target) { return FindExact(node.Right, target); } else { return FindExact(node.Left, target); } } 7