SlideShare a Scribd company logo
1 of 27
BINARY SEARCH TREE
(BST)
Algoritma dan Struktur
Data
Dr. Achmad Solichin,
S.Kom, M.T.I
REMEMBER: TREE TERMINOLOGY
2
A
E
B
D F
C
G
IH
LJ MK N
Node / Vertex
Edges
Root
Leaves
Left subtree
Right subtree
EXAMPLE TREE CALCULATIONS
3
A
E
B
D F
C
G
IH
LJ MK N
A
Recall: Height of a tree is the
maximum number of edges from
the root to a leaf.
Height =
0
A
B Height =
1
What is the height of this tree?
What is the depth of node G?
What is the depth of node L?
Depth =
2
Depth =
4
Height =
4
BINARY TREE
4
• Binary tree: Each node has at most 2 children (branching
factor 2)
• Binary tree is
• A root (with data)
• A left subtree (may be empty)
• A right subtree (may be empty)
• Special Cases
BINARY SEARCH TREE (BST) DATA
STRUCTURE
4
121062
115
8
14
13
7 9
Structure property (binary tree)
 Each node has  2 children
 Result: keeps operations simple
Order property
 All keys in left subtree smaller
than node’s key
 All keys in right subtree larger
than node’s key
 Result: easy to find any given key
5
A binary search tree is a type of binary tree
(but not all binary trees are binary search trees!)
ARE THESE BST ?
3
1171
84
5
4
181062
115
8
20
21
7
15
6
ARE THESE BST ?
INSERTION IN BST
2092
155
12
307 17
insert(13)
insert(8)
insert(31)
(New) insertions happen
only at leaves – easy!
10
8 31
13
8
Again… worst case running time is O(n),
which may happen if the tree is not
balanced.
INSERTION IN BST
SEARCHING IN BST
Find “4” !
Start with root Go to left, because 4 < 8 Go to right, because 4 > 3Go to left, because 4 < 6
and we found it
SEARCHING IN BST: ALGORITHM
OTHER BST “FINDING”
OPERATIONS
FindMin: Find minimum node
 Left-most node
FindMax: Find maximum node
 Right-most node
2092
155
12
307 1710
12
DELETION IN BST
2092
155
12
307 17
Why might deletion be harder than insertion?
10
13
DELETION IN BST
Basic idea: find the node to be removed,
then
“fix” the tree so that it is still a binary
search tree
Three potential cases to fix:
 Node has no children (leaf)
 Node has one child
 Node has two children
14
DELETION – THE LEAF CASE
2092
155
12
307 17
delete(17)
10
15
DELETION – THE ONE CHILD
CASE
2092
155
12
307 10
16
delete(15)
DELETION – THE ONE CHILD
CASE
2092
5
12
307 10
17
delete(15)
DELETION – THE TWO CHILD
CASE
3092
205
12
7
What can we replace 5 with?
10
18
delete(5)
4
DELETION – THE TWO CHILD
CASE
What can we replace the node with?
Options:
successor minimum node from right subtree
findMin(node.right)
predecessor maximum node from left subtree
findMax(node.left)
19
DELETION: THE TWO CHILD CASE
(EXAMPLE)
3092
235
12
7 10
18
1915 3225
delete(23)
DELETION: THE TWO CHILD CASE
(EXAMPLE)
3092
235
12
7 10
18
1915 3225
delete(23)
DELETION: THE TWO CHILD CASE
(EXAMPLE)
22
3092
195
12
7 10
18
1915 3225
delete(23)
DELETION: THE TWO CHILD CASE
(EXAMPLE)
3092
195
12
7 10
18
15 3225
Success! 
delete(23)
DELETION: ALGORITHM
BST PERFORMANCE
REFERENSI
 Slide by Lauren Milne, entitled “Lecture 6: Binary Search Trees”,
University of Washington
 Slide from King Abdulaziz University, entitled “Binary Search
Tree”.
 https://www.programiz.com/dsa/binary-search-tree
 https://en.wikipedia.org/wiki/Binary_search_tree
THANK YOU
Dr. Achmad Solichin, S.Kom. M.T.I.
Universitas Budi Luhur
achmad.solichin@budiluhur.ac.id |
http://achmatim.net

More Related Content

What's hot

What's hot (20)

Jaringan Syaraf Tiruan (JST)
Jaringan Syaraf Tiruan (JST)Jaringan Syaraf Tiruan (JST)
Jaringan Syaraf Tiruan (JST)
 
Efisiensi algoritma
Efisiensi algoritmaEfisiensi algoritma
Efisiensi algoritma
 
Artificial Intelligence - A Star
Artificial Intelligence - A StarArtificial Intelligence - A Star
Artificial Intelligence - A Star
 
Algoritma brute force
Algoritma brute forceAlgoritma brute force
Algoritma brute force
 
Matematika Diskrit - 09 graf - 08
Matematika Diskrit - 09 graf - 08Matematika Diskrit - 09 graf - 08
Matematika Diskrit - 09 graf - 08
 
Jaringan syaraf tiruan
Jaringan syaraf tiruanJaringan syaraf tiruan
Jaringan syaraf tiruan
 
Algoritma pencarian lintasan jalur terpendek
Algoritma pencarian lintasan jalur terpendekAlgoritma pencarian lintasan jalur terpendek
Algoritma pencarian lintasan jalur terpendek
 
Materi 6. perulangan
Materi 6. perulanganMateri 6. perulangan
Materi 6. perulangan
 
Soal uas struktur data
Soal uas struktur dataSoal uas struktur data
Soal uas struktur data
 
Ppt pengenalan dan pemrograman java
Ppt pengenalan dan pemrograman javaPpt pengenalan dan pemrograman java
Ppt pengenalan dan pemrograman java
 
Materi 3 Finite State Automata
Materi 3   Finite State AutomataMateri 3   Finite State Automata
Materi 3 Finite State Automata
 
Data Base Tiket Pesawat
Data Base Tiket PesawatData Base Tiket Pesawat
Data Base Tiket Pesawat
 
Depth First Search (DFS) pada Graph
Depth First Search (DFS) pada GraphDepth First Search (DFS) pada Graph
Depth First Search (DFS) pada Graph
 
Bahan ajar pertemuan 1 Class & Object
Bahan ajar pertemuan 1 Class & ObjectBahan ajar pertemuan 1 Class & Object
Bahan ajar pertemuan 1 Class & Object
 
Array dan Contoh
Array dan ContohArray dan Contoh
Array dan Contoh
 
Iterasi gauss seidel
Iterasi gauss seidelIterasi gauss seidel
Iterasi gauss seidel
 
Laporan praktikum modul 5 (normalisasi)
Laporan praktikum modul 5 (normalisasi)Laporan praktikum modul 5 (normalisasi)
Laporan praktikum modul 5 (normalisasi)
 
Aplikasi loop
Aplikasi loop Aplikasi loop
Aplikasi loop
 
Analisis algoritma
Analisis algoritmaAnalisis algoritma
Analisis algoritma
 
Merge sort
Merge sortMerge sort
Merge sort
 

Similar to Binary Search Tree (BST) - Algoritma dan Struktur Data

Lecture 09 - Binary Search Trees.pptx mission Sk it
Lecture 09 - Binary Search Trees.pptx mission Sk itLecture 09 - Binary Search Trees.pptx mission Sk it
Lecture 09 - Binary Search Trees.pptx mission Sk itAmazingWorld37
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureMeghaj Mallick
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search treeKrish_ver2
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in indiaEdhole.com
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.pptSuneel61
 
5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docxfredharris32
 
mitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.pptmitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.pptAMMAD45
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
1.2 operations of tree representations
1.2 operations of tree representations 1.2 operations of tree representations
1.2 operations of tree representations Krish_ver2
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeINAM352782
 

Similar to Binary Search Tree (BST) - Algoritma dan Struktur Data (20)

Lecture 09 - Binary Search Trees.pptx mission Sk it
Lecture 09 - Binary Search Trees.pptx mission Sk itLecture 09 - Binary Search Trees.pptx mission Sk it
Lecture 09 - Binary Search Trees.pptx mission Sk it
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Trees gt(1)
Trees gt(1)Trees gt(1)
Trees gt(1)
 
4.2 bst 03
4.2 bst 034.2 bst 03
4.2 bst 03
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.ppt
 
bst.ppt
bst.pptbst.ppt
bst.ppt
 
5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx
 
mitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.pptmitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.ppt
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Data Structures
Data StructuresData Structures
Data Structures
 
Lec13
Lec13Lec13
Lec13
 
1.2 operations of tree representations
1.2 operations of tree representations 1.2 operations of tree representations
1.2 operations of tree representations
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
DAA PPT.pptx
DAA PPT.pptxDAA PPT.pptx
DAA PPT.pptx
 
b-tree.ppt
b-tree.pptb-tree.ppt
b-tree.ppt
 

More from Achmad Solichin

Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)
Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)
Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)Achmad Solichin
 
Materi Webinar Web 3.0 (16 Juli 2022)
Materi Webinar Web 3.0 (16 Juli 2022)Materi Webinar Web 3.0 (16 Juli 2022)
Materi Webinar Web 3.0 (16 Juli 2022)Achmad Solichin
 
Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)
Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)
Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)Achmad Solichin
 
Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)
Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)
Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)Achmad Solichin
 
Webinar PHP-ID: Machine Learning dengan PHP
Webinar PHP-ID: Machine Learning dengan PHPWebinar PHP-ID: Machine Learning dengan PHP
Webinar PHP-ID: Machine Learning dengan PHPAchmad Solichin
 
Webinar Data Mining dengan Rapidminer | Universitas Budi Luhur
Webinar Data Mining dengan Rapidminer | Universitas Budi LuhurWebinar Data Mining dengan Rapidminer | Universitas Budi Luhur
Webinar Data Mining dengan Rapidminer | Universitas Budi LuhurAchmad Solichin
 
TREN DAN IDE RISET BIDANG DATA MINING TERBARU
TREN DAN IDE RISET BIDANG DATA MINING TERBARUTREN DAN IDE RISET BIDANG DATA MINING TERBARU
TREN DAN IDE RISET BIDANG DATA MINING TERBARUAchmad Solichin
 
Metodologi Riset: Literature Review
Metodologi Riset: Literature ReviewMetodologi Riset: Literature Review
Metodologi Riset: Literature ReviewAchmad Solichin
 
Materi Seminar: Artificial Intelligence dengan PHP
Materi Seminar: Artificial Intelligence dengan PHPMateri Seminar: Artificial Intelligence dengan PHP
Materi Seminar: Artificial Intelligence dengan PHPAchmad Solichin
 
Percobaan Perpindahan Kalor melalui Konduksi, Konveksi dan Radiasi
Percobaan Perpindahan Kalor melalui Konduksi, Konveksi dan RadiasiPercobaan Perpindahan Kalor melalui Konduksi, Konveksi dan Radiasi
Percobaan Perpindahan Kalor melalui Konduksi, Konveksi dan RadiasiAchmad Solichin
 
Metodologi Riset: Literature Review
Metodologi Riset: Literature ReviewMetodologi Riset: Literature Review
Metodologi Riset: Literature ReviewAchmad Solichin
 
Breadth First Search (BFS) pada Graph
Breadth First Search (BFS) pada GraphBreadth First Search (BFS) pada Graph
Breadth First Search (BFS) pada GraphAchmad Solichin
 
Computer Vision di Era Industri 4.0
Computer Vision di Era Industri 4.0Computer Vision di Era Industri 4.0
Computer Vision di Era Industri 4.0Achmad Solichin
 
Seminar: Become a Reliable Web Programmer
Seminar: Become a Reliable Web ProgrammerSeminar: Become a Reliable Web Programmer
Seminar: Become a Reliable Web ProgrammerAchmad Solichin
 
The Big 5: Future IT Trends
The Big 5: Future IT TrendsThe Big 5: Future IT Trends
The Big 5: Future IT TrendsAchmad Solichin
 
Seminar: PHP Developer for Dummies
Seminar: PHP Developer for DummiesSeminar: PHP Developer for Dummies
Seminar: PHP Developer for DummiesAchmad Solichin
 
Pertemuan 1 - Algoritma dan Struktur Data 1
Pertemuan 1 - Algoritma dan Struktur Data 1Pertemuan 1 - Algoritma dan Struktur Data 1
Pertemuan 1 - Algoritma dan Struktur Data 1Achmad Solichin
 
Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016
Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016
Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016Achmad Solichin
 
Seminar: Mau jadi Android User atau Developer?
Seminar: Mau jadi Android User atau Developer?Seminar: Mau jadi Android User atau Developer?
Seminar: Mau jadi Android User atau Developer?Achmad Solichin
 

More from Achmad Solichin (20)

Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)
Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)
Kuliah Umum - Tips Publikasi Jurnal SINTA untuk Mahasiswa Galau (6 Agustus 2022)
 
Materi Webinar Web 3.0 (16 Juli 2022)
Materi Webinar Web 3.0 (16 Juli 2022)Materi Webinar Web 3.0 (16 Juli 2022)
Materi Webinar Web 3.0 (16 Juli 2022)
 
Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)
Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)
Webinar: Kesadaran Keamanan Informasi (3 Desember 2021)
 
Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)
Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)
Webinar PHP-ID: Mari Mengenal Logika Fuzzy (Fuzzy Logic)
 
Webinar PHP-ID: Machine Learning dengan PHP
Webinar PHP-ID: Machine Learning dengan PHPWebinar PHP-ID: Machine Learning dengan PHP
Webinar PHP-ID: Machine Learning dengan PHP
 
Webinar Data Mining dengan Rapidminer | Universitas Budi Luhur
Webinar Data Mining dengan Rapidminer | Universitas Budi LuhurWebinar Data Mining dengan Rapidminer | Universitas Budi Luhur
Webinar Data Mining dengan Rapidminer | Universitas Budi Luhur
 
TREN DAN IDE RISET BIDANG DATA MINING TERBARU
TREN DAN IDE RISET BIDANG DATA MINING TERBARUTREN DAN IDE RISET BIDANG DATA MINING TERBARU
TREN DAN IDE RISET BIDANG DATA MINING TERBARU
 
Metodologi Riset: Literature Review
Metodologi Riset: Literature ReviewMetodologi Riset: Literature Review
Metodologi Riset: Literature Review
 
Materi Seminar: Artificial Intelligence dengan PHP
Materi Seminar: Artificial Intelligence dengan PHPMateri Seminar: Artificial Intelligence dengan PHP
Materi Seminar: Artificial Intelligence dengan PHP
 
Percobaan Perpindahan Kalor melalui Konduksi, Konveksi dan Radiasi
Percobaan Perpindahan Kalor melalui Konduksi, Konveksi dan RadiasiPercobaan Perpindahan Kalor melalui Konduksi, Konveksi dan Radiasi
Percobaan Perpindahan Kalor melalui Konduksi, Konveksi dan Radiasi
 
Metodologi Riset: Literature Review
Metodologi Riset: Literature ReviewMetodologi Riset: Literature Review
Metodologi Riset: Literature Review
 
Breadth First Search (BFS) pada Graph
Breadth First Search (BFS) pada GraphBreadth First Search (BFS) pada Graph
Breadth First Search (BFS) pada Graph
 
Computer Vision di Era Industri 4.0
Computer Vision di Era Industri 4.0Computer Vision di Era Industri 4.0
Computer Vision di Era Industri 4.0
 
Seminar: Become a Reliable Web Programmer
Seminar: Become a Reliable Web ProgrammerSeminar: Become a Reliable Web Programmer
Seminar: Become a Reliable Web Programmer
 
The Big 5: Future IT Trends
The Big 5: Future IT TrendsThe Big 5: Future IT Trends
The Big 5: Future IT Trends
 
Modern PHP Developer
Modern PHP DeveloperModern PHP Developer
Modern PHP Developer
 
Seminar: PHP Developer for Dummies
Seminar: PHP Developer for DummiesSeminar: PHP Developer for Dummies
Seminar: PHP Developer for Dummies
 
Pertemuan 1 - Algoritma dan Struktur Data 1
Pertemuan 1 - Algoritma dan Struktur Data 1Pertemuan 1 - Algoritma dan Struktur Data 1
Pertemuan 1 - Algoritma dan Struktur Data 1
 
Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016
Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016
Sharing Penelitian S3 Lab Elins FMIPA UGM - 17 Februari 2016
 
Seminar: Mau jadi Android User atau Developer?
Seminar: Mau jadi Android User atau Developer?Seminar: Mau jadi Android User atau Developer?
Seminar: Mau jadi Android User atau Developer?
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

Binary Search Tree (BST) - Algoritma dan Struktur Data

  • 1. BINARY SEARCH TREE (BST) Algoritma dan Struktur Data Dr. Achmad Solichin, S.Kom, M.T.I
  • 2. REMEMBER: TREE TERMINOLOGY 2 A E B D F C G IH LJ MK N Node / Vertex Edges Root Leaves Left subtree Right subtree
  • 3. EXAMPLE TREE CALCULATIONS 3 A E B D F C G IH LJ MK N A Recall: Height of a tree is the maximum number of edges from the root to a leaf. Height = 0 A B Height = 1 What is the height of this tree? What is the depth of node G? What is the depth of node L? Depth = 2 Depth = 4 Height = 4
  • 4. BINARY TREE 4 • Binary tree: Each node has at most 2 children (branching factor 2) • Binary tree is • A root (with data) • A left subtree (may be empty) • A right subtree (may be empty) • Special Cases
  • 5. BINARY SEARCH TREE (BST) DATA STRUCTURE 4 121062 115 8 14 13 7 9 Structure property (binary tree)  Each node has  2 children  Result: keeps operations simple Order property  All keys in left subtree smaller than node’s key  All keys in right subtree larger than node’s key  Result: easy to find any given key 5 A binary search tree is a type of binary tree (but not all binary trees are binary search trees!)
  • 6. ARE THESE BST ? 3 1171 84 5 4 181062 115 8 20 21 7 15 6
  • 8. INSERTION IN BST 2092 155 12 307 17 insert(13) insert(8) insert(31) (New) insertions happen only at leaves – easy! 10 8 31 13 8 Again… worst case running time is O(n), which may happen if the tree is not balanced.
  • 10. SEARCHING IN BST Find “4” ! Start with root Go to left, because 4 < 8 Go to right, because 4 > 3Go to left, because 4 < 6 and we found it
  • 11. SEARCHING IN BST: ALGORITHM
  • 12. OTHER BST “FINDING” OPERATIONS FindMin: Find minimum node  Left-most node FindMax: Find maximum node  Right-most node 2092 155 12 307 1710 12
  • 13. DELETION IN BST 2092 155 12 307 17 Why might deletion be harder than insertion? 10 13
  • 14. DELETION IN BST Basic idea: find the node to be removed, then “fix” the tree so that it is still a binary search tree Three potential cases to fix:  Node has no children (leaf)  Node has one child  Node has two children 14
  • 15. DELETION – THE LEAF CASE 2092 155 12 307 17 delete(17) 10 15
  • 16. DELETION – THE ONE CHILD CASE 2092 155 12 307 10 16 delete(15)
  • 17. DELETION – THE ONE CHILD CASE 2092 5 12 307 10 17 delete(15)
  • 18. DELETION – THE TWO CHILD CASE 3092 205 12 7 What can we replace 5 with? 10 18 delete(5) 4
  • 19. DELETION – THE TWO CHILD CASE What can we replace the node with? Options: successor minimum node from right subtree findMin(node.right) predecessor maximum node from left subtree findMax(node.left) 19
  • 20. DELETION: THE TWO CHILD CASE (EXAMPLE) 3092 235 12 7 10 18 1915 3225 delete(23)
  • 21. DELETION: THE TWO CHILD CASE (EXAMPLE) 3092 235 12 7 10 18 1915 3225 delete(23)
  • 22. DELETION: THE TWO CHILD CASE (EXAMPLE) 22 3092 195 12 7 10 18 1915 3225 delete(23)
  • 23. DELETION: THE TWO CHILD CASE (EXAMPLE) 3092 195 12 7 10 18 15 3225 Success!  delete(23)
  • 26. REFERENSI  Slide by Lauren Milne, entitled “Lecture 6: Binary Search Trees”, University of Washington  Slide from King Abdulaziz University, entitled “Binary Search Tree”.  https://www.programiz.com/dsa/binary-search-tree  https://en.wikipedia.org/wiki/Binary_search_tree
  • 27. THANK YOU Dr. Achmad Solichin, S.Kom. M.T.I. Universitas Budi Luhur achmad.solichin@budiluhur.ac.id | http://achmatim.net

Editor's Notes

  1. 5
  2. 6
  3. 8
  4. 12
  5. 13
  6. 14
  7. 15
  8. 16
  9. 17
  10. 18
  11. 19