You are on page 1of 2

Data Structures and Algorithms

Lab 3 (5% of final grade)


(100 points total)

All code must be your own and follow the guidelines in lecture notes and textbook. Use
proper coding styles including comments and indentation. No code from Internet sources is
allowed in this assignment. All code must be in C++ programming language.

1. Implement in C++ the Print of Arithmetic Expressions algorithm using representations of


Binary Trees as listed below. Test using the example below. Submit screenshots of the
results and code files in a zip file.
a. linked-based representation of binary tree
b. array-based representation of binary tree

2. Implement in C++ the Evaluation of Arithmetic Expressions algorithm using


representations of Binary Trees as listed below. Test using the example below. Submit
screenshots of the results and code files in a zip file.
a. linked-based representation of binary tree
b. array-based representation of binary tree

3. Implement in C++ the Preorder traversal using linked-based representation of General


Trees. Test using the example below. Submit screenshots of the results and code files in a
zip file.
4. Write a program that can play Tic-Tac-Toe effectively. To do this, you will need to create a
game tree T, which is a tree where each node corresponds to a game configuration,
which, in this case, is a representation of the tic-tac-toe board. The root node
corresponds to the initial configuration. For each internal node v in T, the children of v
correspond to the game states we can reach from v’s game state in a single legal move for
the appropriate player, A (the first player) or B (the second player). Nodes at even depths
correspond to moves for A and nodes at odd depths correspond to moves for B. External
nodes are either final game states or are at a depth beyond which we don’t want to
explore. We score each external node with a value that indicates how good this state is
for player A. In large games, like chess, we have to use a heuristic scoring function, but for
small games, like tic-tac-toe, we can construct the entire game tree and score external
nodes as +1, 0, −1, indicating whether player A has a win, draw, or lose in that
configuration. A good algorithm for choosing moves is minimax. In this algorithm, we
assign a score to each internal node v in T, such that if v represents A’s turn, we compute
v’s score as the maximum of the scores of v’s children (which corresponds to A’s optimal
play from v). If an internal node v represents B’s turn, then we compute v’s score as the
minimum of the scores of v’s children (which corresponds to B’s optimal play from v)

5. Implement the array-based HeapSort in C++ and compare its results with the sorting
algorithms from Project. Submit a writeup of your findings (including at least one
comparison graph) and code files in a zip file.

You might also like