----------------------------------------------------------------------------
COMP SCI 731 - Data Struc & Algorithms - Lecture 2 - Monday, June 26, 2000
----------------------------------------------------------------------------
Today: [ ] More on the use of stacks
Announcements: For the next two weeks we will meet, in addition to our
MWF 11-12 time, on TR 8:30-10.
Stacks, cont
------------
Example 2: Evaluating an infix expression
Assume binary operators of +,-, *, / with usual precedence,
group left to right, parenthesis to change prcedence
4 + 5 * 3 - 7 * (20 - (5-3)) END
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |5 |
| | | | | | | | |3 | | | | | | | | | | | | | |20| |20| |20| |20| |20|
| | | | |5 | |5 | |5 | |15| | | | | |7 | |7 | |7 | |7 | |7 | |7 | |7 | |7 |
|4 | |4 | |4 | |4 | |4 | |4 | |19| |19| |19| |19| |19| |19| |19| |19| |19| |19|
|__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__|
| | | | | | | | | | | | | | | | | | | | | | | | | | |( | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | |- | |- | | | | |
| | | | | | | | | | | | | | | | | | | | |( | |( | |( | |( | | | | |
| | | | | | |* | |* | | | | | | | | | |* | |* | |* | |* | |* | | | | |
| | |+ | |+ | |+ | |+ | |+ | | | |- | |- | |- | |- | |- | |- | |- | | | | |
|__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__| |__|
/\
* has higher - has lower - has same prec etc.
prec than +, so prec than *, so as +, so satisfy
push it satisfy * obligation the + prec to get
left-to-right grouping
Do a couple examples to illustrate
o Comparing precedence of operator that you scan to operator at the TOS
o left-to-right vs right-to-left associativity
o error processing
Review of graph representations: adjacency lists
------------------------------------------------
(We are doing this to do DFS and, in particular, to count the
number of components of a graph using DFS. DFS uses a stack,
either explicitly or implicitly.)
First, a reminder about graphs and their representation:
Review the definition of a (simple, undirected) graph G = (V,E).
The adjacency list representation of a graph.
Note that the lists in the adjacency list of each vertext may be ordinary
linked lists, or they may be (dyanmically allocated) arrays. The latter
is often faster. Either way, we can list the neighbors of a vertex v, N(v),
in O(|N(v)|) time.
Reminder what it means for a graph to be connected.