Compute the depth of a node v in tree T: int depth(T, v) Algorithm: int depth(T,v) { if T.isRoot(v) return 0 return 1 + depth(T, T.parent(v)) } Analysis: O(number of ancestors) = O(depth_v) in the worst case the path is a linked-list and v is the leaf ==> O(n), where n is the number of nodes in the tree
xsci 210: data structures trees – bowdoin college, vsci 210: data structures trees – bowdoin college, fsci 210: data structures trees – bowdoin college, dsci 210: data structures trees – bowdoin college, caci 210: data structures trees – bowdoin college, czci 210: data structures trees – bowdoin college, cxci 210: data structures trees – bowdoin college, cdci 210: data structures trees – bowdoin college, ceci 210: data structures trees – bowdoin college, cwci 210: data structures trees – bowdoin college, csxi 210: data structures trees – bowdoin college, csvi 210: data structures trees – bowdoin college, csfi 210: data structures trees – bowdoin college, csdi 210: data structures trees – bowdoin college, cscu 210: data structures trees – bowdoin college, cscj 210: data structures trees – bowdoin college, csck 210: data structures trees – bowdoin college, csco 210: data structures trees – bowdoin college, csc9 210: data structures trees – bowdoin college, csc8 210: data structures trees – bowdoin college, csci 110: data structures trees – bowdoin college, csci q10: data structures trees – bowdoin college, csci w10: data structures trees – bowdoin college, csci 310: data structures trees – bowdoin college, csci 220: data structures trees – bowdoin college, csci 2q0: data structures trees – bowdoin college, csci 219: data structures trees – bowdoin college, csci 21o: data structures trees – bowdoin college, csci 21p: data structures trees – bowdoin college, csci 21-: data structures trees – bowdoin college, csci 210: sata structures trees – bowdoin college, csci 210: xata structures trees – bowdoin college, csci 210: cata structures trees – bowdoin college, csci 210: fata structures trees – bowdoin college, csci 210: rata structures trees – bowdoin college, csci 210: eata structures trees – bowdoin college, csci 210: dzta structures trees – bowdoin college, csci 210: dsta structures trees – bowdoin college, csci 210: dwta structures trees – bowdoin college, csci 210: dqta structures trees – bowdoin college, csci 210: dara structures trees – bowdoin college, csci 210: dafa structures trees – bowdoin college, csci 210: daga structures trees – bowdoin college, csci 210: daya structures trees – bowdoin college, csci 210: da6a structures trees – bowdoin college, csci 210: da5a structures trees – bowdoin college, csci 210: datz structures trees – bowdoin college, csci 210: dats structures trees – bowdoin college, csci 210: datw structures trees – bowdoin college, csci 210: datq structures trees – bowdoin college, csci 210: data atructures trees – bowdoin college, csci 210: data ztructures trees – bowdoin college, csci 210: data xtructures trees – bowdoin college, csci 210: data dtructures trees – bowdoin college, csci 210: data etructures trees – bowdoin college, csci 210: data wtructures trees – bowdoin college, csci 210: data srructures trees – bowdoin college, csci 210: data sfructures trees – bowdoin college, csci 210: data sgructures trees – bowdoin college, csci 210: data syructures trees – bowdoin college, csci 210: data s6ructures trees – bowdoin college, csci 210: data s5ructures trees – bowdoin college, csci 210: data steuctures trees – bowdoin college, csci 210: data stductures trees – bowdoin college, csci 210: data stfuctures trees – bowdoin college, csci 210: data sttuctures trees – bowdoin college, csci 210: data st5uctures trees – bowdoin college, csci 210: data st4uctures trees – bowdoin college, csci 210: data stryctures trees – bowdoin college, csci 210: data strhctures trees – bowdoin college, csci 210: data strjctures trees – bowdoin college, csci 210: data strictures trees – bowdoin college, csci 210: data str8ctures trees – bowdoin college, csci 210: data str7ctures trees – bowdoin college, csci 210: data struxtures trees – bowdoin college, csci 210: data struvtures trees – bowdoin college, csci 210: data struftures trees – bowdoin college, csci 210: data strudtures trees – bowdoin college, csci 210: data strucrures trees – bowdoin college, csci 210: data strucfures trees – bowdoin college, csci 210: data strucgures trees – bowdoin college, csci 210: data strucyures trees – bowdoin college, csci 210: data struc6ures trees – bowdoin college, csci 210: data struc5ures trees – bowdoin college, csci 210: data structyres trees – bowdoin college, csci 210: data structhres trees – bowdoin college, csci 210: data structjres trees – bowdoin college, csci 210: data structires trees – bowdoin college, csci 210: data struct8res trees – bowdoin college, csci 210: data struct7res trees – bowdoin college, csci 210: data structuees trees – bowdoin college, csci 210: data structudes trees – bowdoin college, csci 210: data structufes trees – bowdoin college, csci 210: data structutes trees – bowdoin college, csci 210: data structu5es trees – bowdoin college, csci 210: data structu4es trees – bowdoin college, csci 210: data structurws trees – bowdoin college, csci 210: data structurss trees – bowdoin college, csci 210: data structurds trees – bowdoin college, csci 210: data structurrs trees – bowdoin college, csci 210: data structur4s trees – bowdoin college, csci 210: data structur3s trees – bowdoin college, csci 210: data structurea trees – bowdoin college, csci 210: data structurez trees – bowdoin college, csci 210: data structurex trees – bowdoin college, csci 210: data structured trees – bowdoin college, csci 210: data structuree trees – bowdoin college, csci 210: data structurew trees – bowdoin college, csci 210: data structures rrees – bowdoin college, csci 210: data structures frees – bowdoin college, csci 210: data structures grees – bowdoin college, csci 210: data structures yrees – bowdoin college, csci 210: data structures 6rees – bowdoin college, csci 210: data structures 5rees – bowdoin college, csci 210: data structures teees – bowdoin college, csci 210: data structures tdees – bowdoin college, csci 210: data structures tfees – bowdoin college, csci 210: data structures ttees – bowdoin college, csci 210: data structures t5ees – bowdoin college, csci 210: data structures t4ees – bowdoin college