6 views

Uploaded by Ali Ali

- Data Structures PPT
- GateGenie cs
- Cp2201 Data Structures
- vit ece 2nd year syllabus
- drm_user
- Description of VivaVisualCode
- algoritham quition
- 1508.04872
- Cs301 Exam Questions
- Separating Input Language and Formatter in GNU Lillpond
- Dictionary
- Unit 3 Trees Notes
- AVL Trees
- Clone-Based Mobile Agent Itinerary Planning Using Separate Trees For Data Fusion In WSNS
- Binary Search Tree
- a9
- An Efficient Data Gathering Mechanism using M_Collectors
- Boat
- Solution DS
- AVL tree

You are on page 1of 2

<

2 1 6 9 4 = 8

closestBefore(k) closestAfter(k)

>

Binary search performs operation find(k) on a dictionary implemented by means of an array-based sequence, sorted by key

similar to the high-low game at each step, the number of candidate items is halved terminates after O(log n) steps

A lookup table is a dictionary implemented by means of a sorted sequence

We store the items of the dictionary in an array-based sequence, sorted by key We use an external comparator for the keys

Example: find(7)

0 1 1 1 1 3 3 4 4 4 5 5 5 7 7 8 9 9 9 9 11 11 11 11 14 14 14 14 16 16 16 16 18 18 18 18 3 19

Performance:

m

8 8 8

l

0

h

19 19 19

l

0 0

m

3 3

h

7

find takes O(log n) time, using binary search insertItem takes O(n) time since in the worst case we have to shift n/2 items to make room for the new item removeElement take O(n) time since in the worst case we have to shift n/2 items to compact the items after the removal

l

4

m

5

h

7

l=m =h

Binary Search Trees

The lookup table is effective only for dictionaries of small size or for dictionaries on which searches are the most common operations, while insertions and removals are rarely performed (e.g., credit card authorizations)

Binary Search Trees 4

A binary search tree is a binary tree storing keys (or key-element pairs) at its internal nodes and satisfying the following property:

Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have key(u) key(v) key(w)

Search (9.1.1)

An inorder traversal of a binary search trees visits the keys in increasing order

6 2 1 4 8 9 Algorithm find (k, v) To search for a key k, if T.isExternal (v) we trace a downward return Position(null) path starting at the root if k < key(v) The next node visited return find(k, T.leftChild(v)) depends on the else if k = key(v) outcome of the return Position(v) comparison of k with else { k > key(v) } the key of the current return find(k, T.rightChild(v)) node 6 If we reach a leaf, the < key is not found and we 2 return a null position > 8 Example: find(4) 1 4 =

Binary Search Trees 5

Insertion (9.1.2)

To perform operation insertItem(k, o), we search for key k Assume k is not already in the tree, and let let w be the leaf reached by the search We insert k at node w and expand w into an internal node Example: insert 5 <

2 1 6 9 4

Deletion (9.1.2)

> > w

6 2 1 4 5 8 9 8

To perform operation removeElement(k), we search for key k Assume key k is in the tree, and let let v be the node storing k If node v has a leaf child w, we remove v and w from the tree with operation removeAboveExternal(w) Example: remove 4

<

2 1

6 9

>

4 v 8 5

6 2 1 5 8 9

Deletion (cont.)

We consider the case where the key k to be removed is stored at a node v whose children are both internal

we find the internal node w that follows v in an inorder traversal we copy key(w) into node v we remove node w and its left child z (which must be a leaf) by means of operation removeAboveExternal(z) 1 3 2 6

Performance

v

8 9

w z

1 5 2

Consider a dictionary with n items implemented by means of a binary search tree of height h

the space used is O(n) methods findElement() , insertItem() and removeElement() take O(h) time

v

8 6 9

Example: remove 3

The height h is O(n) in the worst case and O(log n) in the best case

Binary Search Trees 10

- Data Structures PPTUploaded byGuru Samy
- GateGenie csUploaded byKumar Gaurav
- Cp2201 Data StructuresUploaded byPiyush Kumar
- vit ece 2nd year syllabusUploaded bypranavateja12399
- drm_userUploaded byvkm
- Description of VivaVisualCodeUploaded byTatyanazaxarova2
- algoritham quitionUploaded byriha145
- 1508.04872Uploaded byErlander Spirit
- Cs301 Exam QuestionsUploaded byPrince Islamabad
- Separating Input Language and Formatter in GNU LillpondUploaded byStephen Testerov
- DictionaryUploaded bysachnish123
- Unit 3 Trees NotesUploaded byDayabaran Gangatharan
- AVL TreesUploaded bydkmayura
- Clone-Based Mobile Agent Itinerary Planning Using Separate Trees For Data Fusion In WSNSUploaded byJohn Berg
- Binary Search TreeUploaded byparthasarathy
- a9Uploaded byZhichao Wang
- An Efficient Data Gathering Mechanism using M_CollectorsUploaded bythesij
- BoatUploaded byjdroxy4201108
- Solution DSUploaded byVishal Mohan Goyal
- AVL treeUploaded byCh Asim
- Topic Wise Technical Questions Compiled With ExplainationsUploaded bykavneetrekhi
- People SoftUploaded byhardanu
- DS_outsidin_Chapter_2.pptUploaded byAmber Lyons
- 1827.pdfUploaded byRavi Kumar
- DS Lab CycleUploaded bysunilbabukp
- Data StructureUploaded bySrikanth Reddy G
- Depression, Medial UsageUploaded bywati
- CSE-II-I-DS-UNIT-8.pdfUploaded bybskc_sunil
- Cs 201 Solved Midterm PapersUploaded bymc190204343 MOHSIN AHMED KHAN
- Syntax Directed DefnsUploaded bymemoegyptian

- AVLTreesUploaded bysfernando
- Spanning Tree 2Uploaded byapi-3839714
- Merge SortUploaded byAli Ali
- HeapUploaded byAli Ali
- 12 ProbabilityUploaded byakbisoi1
- Hash TablesUploaded byVishnu Priya
- GraphUploaded bykpingad
- Divide and ConquerUploaded byAli Ali
- DFSUploaded bysonal
- Lecture Notes 235 AUploaded byAli Ali
- Adityanigam_mtech_pptUploaded byAli Ali
- ThesisUploaded byAli Ali
- Adityanigam Mtech ReportUploaded byAli Ali

- 596 Retrofit DsUploaded bypatopick
- notes scatter plotsUploaded byapi-256105506
- EspindolaPizanoArielTonatiuh_Lab1Uploaded byArielTonatiuh
- Programming Using Glade and PerlUploaded byksenthil77
- fortiwifi-40C-quickstartUploaded byIsmael Alvarez Diaz
- Resume - Vivek SunderUploaded byRKgowthu Ramu
- Homework 4Uploaded bysunil kumar
- SAP GRC 99411GRCAC_InstallationsUploaded byakeel377
- Directorate of Primary EducationUploaded bykhalidhassan566
- TM tablrt conter.pdfUploaded byHeryanto Matheos
- Operation Management.quiz No 3..for PrintUploaded byfaisalch97
- Assignment 5Uploaded byIhsan ul Haq
- Interface Modules 2015 ENGUploaded bywagospb
- 10.1.1.17.3977Uploaded byNikolay Karelin
- X7R Tip & RingUploaded bydovesnest_in
- casestudyonapple-171008173042Uploaded byNischal Singh Attri
- Design and Analysis of Experiments 3Uploaded byapi-3723257
- Ac - De Re de Dicto DistinctionsUploaded byKK-bookslover
- Canon Parts ManualsUploaded byOscar Pereira
- Construction of Syntax TreesUploaded bymangalasery
- Assignment 1Uploaded byAnonymous aoL1SPjfB
- OscillatorUploaded byludihemicar
- Class D RF Power AmplifierUploaded byhaoyuqian
- G8-English-Lesson-Exemplar-1st-Quarter-1.pdfUploaded byKierlyn Bontia Cerujano
- GK247_G-012Uploaded byJesus Salvador
- mp24schUploaded byTailerDurden
- The Deployment Pipeline by Dave Farley 2007Uploaded byJohncy Joseph
- EasyPLC Manual 140319Uploaded byAnonymous 50FYYM2
- System Management Mode Rootkits by Shawn Embleton and Sherri SparksUploaded bystimoceiver
- The Economics of the Cloud MicrosoftUploaded byViorel Horlescu