04-BinaryTrees

04-BinaryTrees - Supporting Search Queries with Linked Lists Suppose we have implemented a List ADT What is the best complexity we can achieve for

Info iconThis 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 best complexity we can achieve for a method that searches the list for a specified key?
Background image of page 1

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

View Full DocumentRight Arrow Icon
Supporting Search Queries with Linked Lists Suppose we have implemented a List ADT. What is the 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?
Background image of page 2
Supporting Search Queries with Linked Lists Suppose we have implemented a List ADT. What is the 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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Supporting Search Queries with Linked Lists hy 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? r does binary search require keys to be stored in a Or does binary search require keys to be stored in a sorted array?
Background image of page 4
Binary Trees A Binary Tree is a data structure that uses two pointers at ey each node: left right key In some cases the binary tree structure is used to represent e natural relationships that exist in a dataset In most the natural relationships that exist in a dataset. In most applications, however, there is information stored at each node that facilitates the efficient retrieval of other information stored in the tree.
Background image of page 5

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

View Full DocumentRight Arrow Icon
he 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 ght pointer right pointer
Background image of page 6
Binary Search Trees ft key (Nodes with keys that are left 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 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).
Background image of page 7

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

View Full DocumentRight Arrow Icon
STs vs Linked Lists BSTs vs Linked Lists The principle distinction between a linked list and a BST is that the structure of the BST is determined y the content of the key fields to provide efficient by the content of the key fields to provide efficient access to specified nodes.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/06/2010 for the course CS 2050 taught by Professor Uhlmann during the Fall '09 term at Missouri (Mizzou).

Page1 / 62

04-BinaryTrees - Supporting Search Queries with Linked Lists Suppose we have implemented a List ADT What is the best complexity we can achieve for

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online