SlideShare a Scribd company logo
Implement special cases here:
(define (delete t v)
(let ((path (find t v)))
(cond
(( empty? t ) )
((empty? (bst-root t)) )
((not ( = v (node-value (car path))) )
(( > (node-count (car path)) 1)
decrement count)
((equal? (car path) (bst-root t)) ;node were trying to delete
(cond ; nest conditiona;
( (let-AND right (car path) empty) ; case 0.1
root <- null
((let-root empty, right empty) ; case 1
root <- left car path ; case 1.1
((left-empty, right not empty) ; case 1.2
root <- right car path
(else (delete-node path))
(else (delete-node path))
)
)
)
)
)
)
)
)
)
Special cases
Top-Level Function: Delete Value from BST: (delete t v)
The first parameter t is a reference to a bst, and the second parameter v is a value to find and
delete. Like the insert function, delete will directly resolve a few special cases. For the general
cases, it will call (find t v) to obtain a list of nodes that represent a path from the root to the node to
be deleted, and will then call a helper function (delete-node path) to handle the rest of the work. In
the case of delete the helper function will further rely on secondary helper functions to resolve
cases and subcases.
Deletion logically breaks down into cases based on how many child nodes the node to delete has.
Each of those cases has subcases. The large number of cases implies the need for a
correspondingly larger set of test cases: a test case to trigger each deletion case.
Delete Cases
Before we look at the detailed code for delete in Racket, lets look at the general approach. As for
some of the other functions, it will be convenient to create a top-level function (delete t v) and
several helper functions that manage specific detailed cases. There will be some initial special
cases that should be managed separately, before launching any lower level helper function.
Special cases for (delete t v):
Tree t is empty: end the function because there is nothing to do.
At this point, call (find t v) to create the path from root to node to delete if it is present. Assume the
list returned is bound to a symbol named path. The node of interest will be the first node in the list:
(car path)
By examining node (car path), you can determine if the value to delete is present or not.
Value v is not in the tree: end the function because there is nothing to do.
Value v is in the tree:
o Is the count field > 1? Dont delete the node, simply decrement its count field.
o Is the count field = 1? In this case, we must move forward to actually delete the node.
Is the node to delete the root of the tree?
Does the node have 0 or 1 child nodes? This corresponds to delete cases
0.1, 1.1, and 1.2. Delete the node and update the root of the tree.
o If we reach this pointvalue v is in the tree, count field is 1, node is not the root if it has 0 or 1 child
nodes then the general delete case applies, call (delete-node path)
The remaining delete cases will be covered by the (delete-node path) helper function. Some
general considerations for node n (node to delete), node p (parent of n), and node c (child of n).
Is node n the left or right child of node p?
If node n only has one child, node c, is node c the left child or right child of node n?
If node n has two children, we will use an additional procedure to find the in-order predecessor
of n, node iop. We will locate node iop, physically delete it, and copy its value and count fields
into the original node, node n. This results in a logical but not physical delete of node n. Below is a
detailed enumeration of all delete cases based on child count. Subcases 0.1, 1.1, and 1.2 will be
handled as special cases by the top-level delete function because these cases cause the root of
the tree to change.
Since we are maintaining the result of (find t v) in path we can make the following assumptions for
all remaining cases:
Node to delete: (car path)
Parent of node to delete: (car (cdr path)) = (cadr path)
Child nodes of node to delete, if they exist:
o (node-left(carpath))
o (node-right(carpath))
Path from n to in-order predecessor node: ioppath (only needed if n has two child nodes)
In-order predecessor node: (car ioppath) (only needed if node n has two child nodes)
Dont confuse path (list of nodes from root of tree to n) with ioppath (list of nodes from n to iop)
Case 0: Child Count = 0
Subcase 0.1: parent is null implying node is root (already covered in top-level function) o node
being deleted is root of the tree and has 0 child nodes. Set root to null
Subcase 0.2: node is left child of parent o set left child of parent to null
Subcase 0.3: node is right child of parent
o Set right child of parent to null, root doesnt change
Case 1: Child Count = 1
Subcase 1.1: parent is null and child is left child of node (already covered in top-level) o node is
root ,set root to left child
Subcase 1.2: parent is null and child is right child of node (already covered in top-level) o Node is
root, set root to right child
Subcase 1.3: node is left child of parent and child is left child of node o set left child of parent to
left child of node
Subcase 1.4: node is left child of parent and child is right child of node o set left child of parent to
right child of node
Subcase 1.5: node is right child of parent and child is left child of node o set right child of parent to
left child of node
Subcase 1.6: node is right child of parent and child is right child of node o set right child of parent
to right child of node
The cases and subcases are similar, but still differ in the specifics. Take care to identify the correct
case and respond with the correct implementation for that case. In the above cases, note that the
root is the only node with no parent (if parent of n is null, then n is the root). Also note the deletion
cases that cause a change in the root of the tree (0.1, 1.1, and 1.2) are coded directly in the top-
level function.
Case 2: Child Count = 2
There is no easy way to delete a node with two child nodes. Instead we substitute the original
problem with a problem that is easier to solve:
Locate the in-order predecessor of the node to be deleted.
Move the value and count fields from the in-order predecessor node to the original node,
thereby erasing the previous value and count fields of the original node. This content
substitution achieves a logical removal of the original node.
Physically remove the in-order predecessor node
o Case 2.1: predecessor node is left of parent
o Case 2.2: predecessor node is right of paren

More Related Content

Similar to Implement special cases here define delete t v let.pdf

(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf
(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf
(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf
ANANDSHOE
 
Unit8 C
Unit8 CUnit8 C
Unit8 C
arnold 7490
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREE
Siddhi Shrivas
 
2 4 Tree
2 4 Tree2 4 Tree
2 4 Tree
vikram singh
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
VijayaLakshmi506
 
Biary search Tree.docx
Biary search Tree.docxBiary search Tree.docx
Biary search Tree.docx
sowmya koneru
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
CourseHunt
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
skilljiolms
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Trees
TreesTrees
Tree
TreeTree
Tree
bhumish
 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
praveena p
 
Chap 5 Tree.ppt
Chap 5 Tree.pptChap 5 Tree.ppt
Chap 5 Tree.ppt
shashankbhadouria4
 
Trees
TreesTrees
Trees
9590133127
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
Muhazzab Chouhadry
 
Red black 1
Red black 1Red black 1
Red black 1
Core Condor
 
computer notes - Deleting a node
computer notes - Deleting a nodecomputer notes - Deleting a node
computer notes - Deleting a node
ecomputernotes
 
Master of Computer Application (MCA) – Semester 4 MC0080
Master of Computer Application (MCA) – Semester 4  MC0080Master of Computer Application (MCA) – Semester 4  MC0080
Master of Computer Application (MCA) – Semester 4 MC0080
Aravind NC
 
L 17 ct1120
L 17 ct1120L 17 ct1120
L 17 ct1120
Zia Ush Shamszaman
 
DS MCQS.pptx
DS MCQS.pptxDS MCQS.pptx
DS MCQS.pptx
BoomijaIT
 

Similar to Implement special cases here define delete t v let.pdf (20)

(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf
(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf
(a)PreOrder, PostOrder and Inorder are three ways you can iterate .pdf
 
Unit8 C
Unit8 CUnit8 C
Unit8 C
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREE
 
2 4 Tree
2 4 Tree2 4 Tree
2 4 Tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Biary search Tree.docx
Biary search Tree.docxBiary search Tree.docx
Biary search Tree.docx
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Trees
TreesTrees
Trees
 
Tree
TreeTree
Tree
 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
 
Chap 5 Tree.ppt
Chap 5 Tree.pptChap 5 Tree.ppt
Chap 5 Tree.ppt
 
Trees
TreesTrees
Trees
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Red black 1
Red black 1Red black 1
Red black 1
 
computer notes - Deleting a node
computer notes - Deleting a nodecomputer notes - Deleting a node
computer notes - Deleting a node
 
Master of Computer Application (MCA) – Semester 4 MC0080
Master of Computer Application (MCA) – Semester 4  MC0080Master of Computer Application (MCA) – Semester 4  MC0080
Master of Computer Application (MCA) – Semester 4 MC0080
 
L 17 ct1120
L 17 ct1120L 17 ct1120
L 17 ct1120
 
DS MCQS.pptx
DS MCQS.pptxDS MCQS.pptx
DS MCQS.pptx
 

More from ADITIEYEWEAR

In a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdfIn a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdf
ADITIEYEWEAR
 
In a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdfIn a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdf
ADITIEYEWEAR
 
In a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdfIn a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdf
ADITIEYEWEAR
 
In a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdfIn a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdf
ADITIEYEWEAR
 
In a recent poll the Gallup Organization found that 45 of.pdf
In a recent poll the Gallup Organization found  that 45 of.pdfIn a recent poll the Gallup Organization found  that 45 of.pdf
In a recent poll the Gallup Organization found that 45 of.pdf
ADITIEYEWEAR
 
In a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdfIn a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdf
ADITIEYEWEAR
 
In a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdfIn a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdf
ADITIEYEWEAR
 
In a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdfIn a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdf
ADITIEYEWEAR
 
In a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdfIn a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdf
ADITIEYEWEAR
 
In 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdfIn 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdf
ADITIEYEWEAR
 
In a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdfIn a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdf
ADITIEYEWEAR
 
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdfin 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
ADITIEYEWEAR
 
In a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdfIn a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdf
ADITIEYEWEAR
 
In a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdfIn a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdf
ADITIEYEWEAR
 
In 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdfIn 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdf
ADITIEYEWEAR
 
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdfIn 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
ADITIEYEWEAR
 
In 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdfIn 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdf
ADITIEYEWEAR
 
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdfimport yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
ADITIEYEWEAR
 
In 2020 Natural Selection a nationwide computer dating se.pdf
In 2020 Natural Selection a  nationwide computer dating se.pdfIn 2020 Natural Selection a  nationwide computer dating se.pdf
In 2020 Natural Selection a nationwide computer dating se.pdf
ADITIEYEWEAR
 
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdfIn 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
ADITIEYEWEAR
 

More from ADITIEYEWEAR (20)

In a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdfIn a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdf
 
In a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdfIn a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdf
 
In a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdfIn a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdf
 
In a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdfIn a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdf
 
In a recent poll the Gallup Organization found that 45 of.pdf
In a recent poll the Gallup Organization found  that 45 of.pdfIn a recent poll the Gallup Organization found  that 45 of.pdf
In a recent poll the Gallup Organization found that 45 of.pdf
 
In a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdfIn a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdf
 
In a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdfIn a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdf
 
In a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdfIn a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdf
 
In a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdfIn a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdf
 
In 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdfIn 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdf
 
In a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdfIn a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdf
 
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdfin 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
 
In a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdfIn a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdf
 
In a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdfIn a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdf
 
In 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdfIn 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdf
 
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdfIn 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
 
In 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdfIn 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdf
 
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdfimport yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
 
In 2020 Natural Selection a nationwide computer dating se.pdf
In 2020 Natural Selection a  nationwide computer dating se.pdfIn 2020 Natural Selection a  nationwide computer dating se.pdf
In 2020 Natural Selection a nationwide computer dating se.pdf
 
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdfIn 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
 

Recently uploaded

Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
Celine George
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
khuleseema60
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
 

Recently uploaded (20)

Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
 

Implement special cases here define delete t v let.pdf

  • 1. Implement special cases here: (define (delete t v) (let ((path (find t v))) (cond (( empty? t ) ) ((empty? (bst-root t)) ) ((not ( = v (node-value (car path))) ) (( > (node-count (car path)) 1) decrement count) ((equal? (car path) (bst-root t)) ;node were trying to delete (cond ; nest conditiona; ( (let-AND right (car path) empty) ; case 0.1 root <- null ((let-root empty, right empty) ; case 1 root <- left car path ; case 1.1 ((left-empty, right not empty) ; case 1.2 root <- right car path (else (delete-node path)) (else (delete-node path)) ) ) ) ) ) ) ) ) ) Special cases Top-Level Function: Delete Value from BST: (delete t v) The first parameter t is a reference to a bst, and the second parameter v is a value to find and delete. Like the insert function, delete will directly resolve a few special cases. For the general cases, it will call (find t v) to obtain a list of nodes that represent a path from the root to the node to be deleted, and will then call a helper function (delete-node path) to handle the rest of the work. In the case of delete the helper function will further rely on secondary helper functions to resolve cases and subcases. Deletion logically breaks down into cases based on how many child nodes the node to delete has. Each of those cases has subcases. The large number of cases implies the need for a correspondingly larger set of test cases: a test case to trigger each deletion case. Delete Cases Before we look at the detailed code for delete in Racket, lets look at the general approach. As for some of the other functions, it will be convenient to create a top-level function (delete t v) and several helper functions that manage specific detailed cases. There will be some initial special
  • 2. cases that should be managed separately, before launching any lower level helper function. Special cases for (delete t v): Tree t is empty: end the function because there is nothing to do. At this point, call (find t v) to create the path from root to node to delete if it is present. Assume the list returned is bound to a symbol named path. The node of interest will be the first node in the list: (car path) By examining node (car path), you can determine if the value to delete is present or not. Value v is not in the tree: end the function because there is nothing to do. Value v is in the tree: o Is the count field > 1? Dont delete the node, simply decrement its count field. o Is the count field = 1? In this case, we must move forward to actually delete the node. Is the node to delete the root of the tree? Does the node have 0 or 1 child nodes? This corresponds to delete cases 0.1, 1.1, and 1.2. Delete the node and update the root of the tree. o If we reach this pointvalue v is in the tree, count field is 1, node is not the root if it has 0 or 1 child nodes then the general delete case applies, call (delete-node path) The remaining delete cases will be covered by the (delete-node path) helper function. Some general considerations for node n (node to delete), node p (parent of n), and node c (child of n). Is node n the left or right child of node p? If node n only has one child, node c, is node c the left child or right child of node n? If node n has two children, we will use an additional procedure to find the in-order predecessor of n, node iop. We will locate node iop, physically delete it, and copy its value and count fields into the original node, node n. This results in a logical but not physical delete of node n. Below is a detailed enumeration of all delete cases based on child count. Subcases 0.1, 1.1, and 1.2 will be handled as special cases by the top-level delete function because these cases cause the root of the tree to change. Since we are maintaining the result of (find t v) in path we can make the following assumptions for all remaining cases: Node to delete: (car path) Parent of node to delete: (car (cdr path)) = (cadr path) Child nodes of node to delete, if they exist: o (node-left(carpath)) o (node-right(carpath)) Path from n to in-order predecessor node: ioppath (only needed if n has two child nodes) In-order predecessor node: (car ioppath) (only needed if node n has two child nodes) Dont confuse path (list of nodes from root of tree to n) with ioppath (list of nodes from n to iop) Case 0: Child Count = 0 Subcase 0.1: parent is null implying node is root (already covered in top-level function) o node being deleted is root of the tree and has 0 child nodes. Set root to null Subcase 0.2: node is left child of parent o set left child of parent to null Subcase 0.3: node is right child of parent o Set right child of parent to null, root doesnt change
  • 3. Case 1: Child Count = 1 Subcase 1.1: parent is null and child is left child of node (already covered in top-level) o node is root ,set root to left child Subcase 1.2: parent is null and child is right child of node (already covered in top-level) o Node is root, set root to right child Subcase 1.3: node is left child of parent and child is left child of node o set left child of parent to left child of node Subcase 1.4: node is left child of parent and child is right child of node o set left child of parent to right child of node Subcase 1.5: node is right child of parent and child is left child of node o set right child of parent to left child of node Subcase 1.6: node is right child of parent and child is right child of node o set right child of parent to right child of node The cases and subcases are similar, but still differ in the specifics. Take care to identify the correct case and respond with the correct implementation for that case. In the above cases, note that the root is the only node with no parent (if parent of n is null, then n is the root). Also note the deletion cases that cause a change in the root of the tree (0.1, 1.1, and 1.2) are coded directly in the top- level function. Case 2: Child Count = 2 There is no easy way to delete a node with two child nodes. Instead we substitute the original problem with a problem that is easier to solve: Locate the in-order predecessor of the node to be deleted. Move the value and count fields from the in-order predecessor node to the original node, thereby erasing the previous value and count fields of the original node. This content substitution achieves a logical removal of the original node. Physically remove the in-order predecessor node o Case 2.1: predecessor node is left of parent o Case 2.2: predecessor node is right of paren