The interaction between
algorithm and
data structure
- Recall:
- Computer program =
algorithm +
data structure(s)
|
- Algorithms can
produce and
consume
information in
different ways:
- Some
algorithms
consume the
data in the
same order as
how the data was
produced
Production order: A B C D
Consumption order: A B C D
|
- Some
algorithms
consume the
data in the
reverse order as
was
produced:
Production order: A B C D
Consumption order: D C B A
|
- Etc, etc
|
|
Intro to the
queue
data structure
Analogy for the
queue data structure
- A queue
data structure is
like a queue of
people:
|
Analogy for the
queue data structure
- A queue
data structure is
like a queue of
people:
- The enqueue( ) operation
will "insert"/add
an item on
tail of the
queue:
|
Analogy for the
queue data structure
- A queue
data structure is
like a queue of
people:
- Dequeue( )
will remove
the item at the
head of the
queue
and
returns it.
|
Some
computer algorithms/processes
with a
natural LIFO
behavior
-
Scheduling
for fairness:
-
FIFO is
a service ordering that
is
fair
- Scheduling algorithms
that serve requests from
different clients
often implements
a FIFO service policy
using a queue
|
- The
Breath First Search (BFS)
algorithm in
graph applications
- The BFS
algorithm will
probe nodes that
are nearest to
the source nodes
first
- To implement the
"search the nearest nodes first"
behavior,
the BFS algorithm use a
queue to
store
nodes to
visit next
- You will study the
BFS algorithm in
CS 253...
|
|
❮
❯