COMPUTER SCIENCE 3100 -- DATA STRUCTURES + ALGORITHMS

Study Questions for the Second In-Term Exam

======================================================================
Chapter Four:  Arrays and Matrices

What is an array mapping function?  What is it used for?
Explain its importance to implementing the array as an abstract
data structure.

Suppose that X_type is a data type whose size is 5 cells of
memory.  Suppose that a 1D array A[3000] of elements of type
X_type has base address 123458.  What is the base address of
A[2113]?

What if A[200][300] is a 2D array?  What would then be the base
address of A[121][24]?

======================================================================
Chapter Five: Stacks
Chapter Six: Queues

What are the difficulties, advantages, and disadvantages of
implementing a stack as an array?

What are the difficulties, advantages, and disadvantages of
implementing a queue as an array?

In comparison with the array implementation, what are the
difficulties, advantages and disadvantages of implementing a
stack as a linked list?

In comparison with the array implementation, what are the
difficulties, advantages and disadvantages of implementing a
queue as a linked list?

Describe several applications of stacks and queues.

Explain how linked lists can be implemented with "simulated"
pointers.

Explain how a stack or a queue can be viewed as a special case
of a priority queue.

======================================================================
Chapter Seven: Skip Lists and Hashing

What is the main reason for hashing?

Define "open addressing."

Define "chaining."

Name the properties that a good hashing function must have.

Define "perfect hash function"

Describe two different commonly used hash functions.

Describe two different "collision resolution" strategies that
can be used for hashing.

Explain why it would be a good idea to use a prime table size
when hashing and using open addressing.

======================================================================
Chapter Eight: Binary and Other Trees

Define the following terms:  tree, binary tree, height, level,
root, leaf, child, parent, sibling, descendant, ancestor, path,
degree of a tree node, full binary tree, complete binary tree.

How many edges has a binary tree with n nodes?

What is the maximum nunber of nodes in a binary tree of height
n?

Write pseudo code for a recursive procedure that traverses an
arbitrary binary tree in PreOrder.  Same thing for PostOrder.
Same thing for InOrder.

Write pseudo code for a non-recursive procedure that uses a
queue as an auxiliary data structure and traverses an arbitrary
binary tree in LevelOrder.

Name and describe applications of each of the following kinds
of traversal of a binary tree.

InOrder, PreOrder, PostOrder, LevelOrder, Reverse InOrder,
Reverse LevelOrder.

List the letters in the nodes of the tree shown below in each
of the following orders:

    a)  PreOrder
    b)  PostOrder
    c)  InOrder

Warning:  The labels of the nodes have been chosen to be
UNrelated to any of these orderings.


                                  T
                                  ..
                              .        .
                          .                .
                          S                 Q
                         ..                ..
                       .    .            .    .
                     .        .        .        .
                     H        V        C        P
                    .       .         .
                  .       .         .
                 K       Y         D
                        ..
                       .  .
                      .    .
                      U    F

======================================================================
Chapter Nine: Priority Queues

Give a definition of a priority queue.

Give a definition of a heap.

What are the difficulties or disadvantages of the array
implementation of a priority queue that do NOT arise in
connection with the array implementations of stacks and queues?

                                       40
                                       ..
                                   .        .
                             .                   .
                         .                           .
                      20                              60
                     ..                               ..
                   .    .                           .    .
                 .        .                       .        .
               10          30                   50          80
               ..          ..                   ..          ..
              .  .        .  .                 .  .        .  .
            .     .     .     .               .    .      .    .
           05     15   25     35             45    55    70    100

The binary tree shown ABOVE can be transformed into a HEAP by
applying the process of "heapification" that I discussed in
class.  (Sahni calls this the "heap initialization").  Fill in
the diagram BELOW to show what the resulting heap looks like
after this process is carried out.  Make this a "MAX HEAP" --
LARGER elements above, SMALLER elements below.

                                       __
                                       ..
                                   .        .
                             .                   .
                         .                           .

                     __                                __
                     ..                                ..
                   .    .                            .    .
                 .        .                        .        .

               __          __                    __          __
               ..          ..                    ..          ..
              .  .        .  .                  .  .        .  .
            .     .     .     .                .    .      .    .

          __     __    __     __              __    __    __    __


Using the filled-in diagram above, show how to delete some
items from the heap, and how to insert some.  (The procedures
involve sifting down and sifting up).

Describe the "formula based" (array) representation of a heap.
(See p382-384).

Show how the elements of an array get moved around during a
heap sort.
======================================================================