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

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

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?

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

View Full Document
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?
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.

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

View Full Document
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?
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.

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

View Full Document
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
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).

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

View Full Document
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.
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
Ask a homework question - tutors are online