{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

04-BinaryTrees - Supporting Search Queries with Linked...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Supporting Search Queries with Linked Lists Suppose we have implemented a List ADT. What is the b t l it hi f th d th t h best complexity we can achieve for a method that searches the list for a specified key?
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Supporting Search Queries with Linked Lists Suppose we have implemented a List ADT. What is the b t l it hi f th d th t h best complexity we can achieve for a method that searches the list for a specified key? O(N) – We have to compare the query key to the key in every node of the list. Does the complexity change if we assume that the keys in the list are in sorted order?
Image of page 2
Supporting Search Queries with Linked Lists Suppose we have implemented a List ADT. What is the b t l it hi f th d th t h best complexity we can achieve for a method that searches the list for a specified key? O(N) – We have to compare the query key to the key in every node of the list. Does the complexity change if we assume that the keys in the list are in sorted order? No, the key to be found may be at the tail of the list.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Supporting Search Queries with Linked Lists Why can’t the binary search algorithm with a sorted Why can t the binary search algorithm with a sorted linked list? How would we have to augment a sorted linked list to allow use of the binary search algorithm to find a specified key? Or does binary search require keys to be stored in a Or does binary search require keys to be stored in a sorted array?
Image of page 4
Binary Trees A Binary Tree is a data structure that uses two pointers at h d key each node: left right In some cases the binary tree structure is used to represent the natural relationships that exist in a dataset In most the natural relationships that exist in a dataset. applications, however, there is information stored at each node that facilitates the efficient retrieval of other information t d i th t stored in the tree.
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The term “binary tree” derives from the branching that The term binary tree derives from the branching that occurs when the two pointers are allowed to point to other than adjacent nodes: left pointer right pointer
Image of page 6
Binary Search Trees left key (Nodes with keys that are (N d ith k th t t right less than that of the node) (Nodes with keys that are not less than that of the node) It is common to have the left pointer of each node point to nodes having key fields that are less than that of its key field d h i h i i h l h and the right pointer point to ones that are not less than (greater-than-or-equal to) its key field. A binary tree in which all nodes satisfy the above condition is referred to as a Binary Search Tree (BST).
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
BSTs vs Linked Lists Th i i l di ti ti b t li k d li t d The principle distinction between a linked list and a BST is that the structure of the BST is determined by the content of the key fields to provide efficient by the content of the key fields to provide efficient access to specified nodes.
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern