Title: Doubly Linked Lists
1CSE 331- Lecture 14
Chapter 9 Doubly Linked Lists API Implementation
Header Node Circular Form Chapter 10 Tree
Terminology node, leaf, root, parent, child,
height Binary Tree
Return Midterm Exam Answer questions
about Maze Search Program
2Abstract Model of a List Object
3Circular Doubly Linked Lists
- Implemented on a Computer it might look something
like this.
The 4 node is the front() node the 2 node is
the back() node begin() returns an iterator to
the 4 node end() returns an iterator to he header
node
4Updating a Doubly Linked List
5Inserting a Node at a Position
// insert newNode before curr newNode-gtprev
curr-gtprev newNode-gtnext curr curr-gtprev-gtnext
newNode curr-gtprev newNode
6Deleting a Node at a Position
// unlink the node (curr) from the
list curr-gtprev-gtnext curr-gtnext curr-gtnext-gtp
rev curr-gtprev delete curr
7Tree Structures
8Tree Structures
9Tree Structures
10Tree Terminology
- Node location containing value(s)
- Parent node 1 link above here in tree
- Child node 1 link below here in tree
- Root top (first) node in tree
- Leaf A node without any children
- Interior node any non-leaf node
- Ancestor any node on a path between root and
here - Descendent any node reachable by a path from
here downward in tree - Level number of links traversed from root to
here - Height (depth) length of longest path from root
to any leaf - Subtree Any node (chosen as root) along with
all of its descendents
11Tree Node Level and Path Length
12Binary Tree Definition
- A binary tree T is a finite set of nodes with one
of the following properties - (a) T is a tree if the set of nodes is empty.
(An empty tree is a tree.) - (b) The set consists of a root, R, and exactly
two distinct binary trees, the left
subtree TL and the right subtreeTR.
The nodes in T consist of node R and all
the nodes in TL and TR.
13Binary Tree Nodes
14Tree Node Level and Path Length Depth Discussion
15Tree Node Level and Path Length Depth Discussion
16Tree Node Level and Path Length Depth Discussion
17Tree Node Level and Path Length Depth Discussion
18Summary Slide 1
- Doubly linked lists - provide the most
flexible implementation for the sequential
list. - Its nodes have pointers to the next
and the previous node, so the program can
traverse a list in either the forward or
backward direction. - Traverse a list by
starting at the first node and follow the
sequence of next nodes until you arrive back
at the header. - To traverse a list in reverse
order, start at the last node and follow the
sequence of previous nodes until arriving back
at the header.
19Summary Slide 2
- trees - hierarchical structures that place
elements in nodes along branches that
originate from a root. - Nodes in a tree are
subdivided into levels in which the topmost
level holds the root node. - Any node in a
tree may have multiple successors at the
next level. Hence a tree is a non-linear
structure. - Tree terminology with which you
should be familiar parent child
descendents leaf node interior node
subtree.
20Summary Slide 3
- Binary Trees - Most effective as a storage
structure if it has high density - ie
data are located on relatively short paths from
the root. - A complete binary tree has
the highest possible density - an n-node
complete binary tree has depth int(log2n).
- At the other extreme, a degenerate binary tree
is equivalent to a linked list and exhibits
O(n) access times.