Professional Documents
Culture Documents
Lecture05 Searching EN
Lecture05 Searching EN
Searching
an unsorted array
• Idea:
• A count-controlled loop is used to traverse through the sequence during which each
element is compared against the target value.
• If the item is in the sequence, the loop is terminated and True is returned.
• Otherwise, a full traversal is performed and False is returned after the loop
terminates.
Data Structures and Algorithms 6 FIT – HNUE 2021
Implementation of the linear search
a sorted array
• It's possible to terminate the search early when the value is not in the
sequence instead of always having to perform a complete traversal.
• Search 10??
• Recursive??
Data Structures and Algorithms 15 FIT – HNUE 2021
BINARY SEARCH TREE
• Searching
• Find min/max
• Insert
• Delete
• Idea:
• The target value is compared to the key in
the root node
• If the root contains the target value: the
process terminates successfully
• Otherwise:
• if the target is less than the root’s key: search
the left subtree
• if the target is greater than the root’s key:
search the right subtree
• Insert 30???
redirecting the link from the node’s parent to its child subtree
• Idea:
1) Find the logical successor, S,
of the node to be deleted, N.
2) Copy the key from node S to
node N.
3) Remove node S from the tree.