Chapter 4 Linked Lists
Recall that linked lists enable us to dynamically adjust the size of a list, eliminating the need to preallocate a specific amount of memory.
Static Array
Preallocation Required! Wasteful if you allocate too much! Potentially fata
Chapter 13
Graphs
1
Graph
!
!
!
Set V of vertices and
E of edges
2
Subgraph
!
!
!
Subset of vertices
and edges
(a) A campus map as a graph; (b) a subgraph
3
Adjacent vertices
!
!
!
Joined by an edge
Library-Dormitory
Library-Student Union
4
Path
!
A
Ch 10
Trees
!1
Some terms to remember
root
node
siblings
leaf
nodes
!2
More terms .
left
subtree
right
subtree
!3
Let's look at a General tree first
root
root
R
L
L
L
L
L
L
!4
. and now a Binary tree
root
root
R
L
L
L
L
!5
Binary trees can be used for
eva
Achieving a
better solution
in three steps
Sunday, September 15, 13
A solution derived without a design will undoubtedly suffer from all sorts of problems. A solution that is properly designed however, will lead to
the correct solution with a minimal of c
Carrano Ch 3
Data Abstraction
1
Sunday, September 15, 13
1
Key Terms : Modularity
Favors simplicity
Small tasks are more manageable than large
tasks
Encourages reusability
Build large applications by using existing
components
Supports extensibility
Algorithm Efciency deals with
! Methods of Solution rather than programs!
!
! Efcient use of time and memory!
!
! Mathematical methods independent of coding,
computers or data
!1
Do not compare programs
! How are the algorithms coded?!
!
! What computer s
Recursion
1
Monday, October 14, 13
1
What is Recursion?
Solution given in terms of problem. Huh?
Each problem is a smaller instance of itself.
Implemented via functions.
Very powerful solving technique.
Monday, October 14, 13
2
Base Case and Recursive
Stack : ADT
LIFO Last In First Out
top of stack
bottom of stack
1
Sunday, September 15, 13
1
Stack : Operations
1. Create an empty stack.
2. Destroy a stack.
3. Determine if a stack is empty.
4. Add a new item to the stack.
5. Remove from the stack the it
Queue : ADT
1. Create an empty queue.
2. Destroy a queue.
3. Determine whether a queue is empty.
4. Add a new item to the queue.
5. Remove from the queue the item that was added earliest.
6. Retrieve from the queue the item that was added earliest.
1
Sund
! Pointers
!
Linked List
Objectives
!
!
!
!
!
!
!
What is a linked list?
Create a list
Insert a node
Delete a node
Traverse a list
Find a node
Add a head node
!
! Create a circular linked list
! Convert to a doubly linked list
! Compare to an array
!1
!
T
ADT: Table
!
! The ADT table, or dictionary!
! Uses a search key to identify
its items!
!
! Its items are records that
contain several pieces of
data
1
ADT Table : UML
2
ADT Table
!
! Our table assumes distinct search keys!
! Other tables could allow du
Chapter 5 Recursion
Recursion can be a very effective technique for solving what would otherwise be extremely elaborate problems.
Sample recursive applications include: Backtracking algorithms. Programming language definition. Matrix operations.
In additi
Chapter 6 Stacks
The stack abstract data type is essentially a list using the LIFO (lastin firstout) policy for adding and removing elements.
The principal stack operations:
Create an empty stack. Copy an existing stack.
Destroy a stack. Determine whe
Chapter 7 Queues
The queue abstract data type is essentially a list using the FIFO (first infirstout) policy for adding and removing elements.
The principal queue operations:
Create an empty queue. Copy an existing queue.
Destroy a queue. Determine wh
Chapter 8 Class Relationships
Up to this point, the C+ classes that we've used have been little more than elaborate structs. We're now going to examine some of the features of C+ classes that expand the language's objectoriented capabilities:
Inheritance
Chapter 9 Algorithm Efficiency & Sorting
Programming efficiently has been important up to this point, but we're now going to examine the methods that have been developed to determine just how efficient a program is.
Measuring Algorithm Efficiency Example
Chapter 10 Trees
The tree abstract data type provides a hierarchical structure to the representation of certain types of relationships.
Array Implementation Linked List Implementation Binary Search Trees Applications General Trees
Chapter 10 Trees 1Page
Additional Tree Traversal Example #1
/ Public function to "spell out" the values from the root to the tree's / / leaf nodes, with the results output on a separate line for each leaf. / template <class E> void BinaryTree<E>:spellFromTop(ofstream &os) cfw_
Chapter 11 Tables And Priority Queues
Simple arrays and linked lists are not the only structures that can effectively maintain tables of data.
Array Implementation of Table Linked List Implementation of Table Tree Implementation of Table Priority Queues
Chapter 13 Graphs
The graph ADT, while relatively unstructured, provides a platform for solving some of the most sophisticated problems in computer science.
Graph Abstract Data Types Topological Sort
Minimum Path Maximum Flow Spanning Tree
DepthFirst
The Eight Queens Problem
Backtracking
Problem: How do you place 8 queens on a chessboard in such a
way that no queens attack each other?
Possible Solutions:
Guess at a solution: C(64, 8) = 4,426,165,368 ways to arrange (aargh!)
Eliminate row | col at