Vous êtes sur la page 1sur 3

Algorithms and Data Structures: Course Assignments

Although we use Python throughout the course, any other suitable language (e.g., Java, C#
or C++) may be used to implement assignments.

Assignment #1: Calculator for arithmetic expressions (15 points)


The task is to implement a program that calculates the value of an arithmetic
expression that is entered by the user. The user interface is irrelevant: it can be command-
line, or a desktop graphical interface, or a web interface. The implementation of a fancy UI
does not substitute for mistakes in implementing the main functionality.
The expression consists of numbers (integers or floating point) and arithmetic
operators (+, -, *, /, ^). The expressions are given in the infix notation. The program should
correctly calculate the result and display it. It should also detect syntax errors in the
expression if they exist.
The program may also display the given expression in postfix form as a source of
verification of correctness.
Tokenization of the input string is provided by tokenizer.py.

Useful description of the infix-to-postfix conversion:


http://csis.pace.edu/~wolf/CS122/infix-postfix.htm

This assignment is an exercise in using stacks, both for conversion of expressions


from infix to postfix form, and for calculating the value of expressions from the postfix form.

Assignment #2: Nine men's morris (20 points)


The task is to implement a program that plays the game of Nine men's morris against
the user. The user interface is irrelevant: it can be command-line, or a desktop graphical
interface, or a web interface. The implementation of a fancy UI does not substitute for
mistakes in implementing the main functionality.
Nine men's morris is a two-player game (A and B, or White and Black) that employs 9
pieces for each player on a board with 24 different locations. The pieces can be placed only
at empty line intersections, and movement of pieces is possible only along the lines, one
step at a time. The player who is left with only 2 pieces or is not able to move any piece
loses the game. The game consists of three phases:
Phase 1: Placing pieces. The game begins with an empty board. The players
determine who plays first, then take turns placing their men one per play on empty points.
If a player is able to place three of his pieces on contiguous points in a straight line, vertically
or horizontally, he has formed a mill and may remove one of his opponent's pieces from the
board and the game, with the caveat that a piece in an opponent's mill can only be removed
if no other pieces are available. After all men have been placed, phase two begins.
Phase 2: Moving pieces. Players continue to alternate moves, this time moving a
man to an adjacent point. A piece may not "jump" another piece. Players continue to try to
form mills and remove their opponent's pieces as in phase one. A player can "break" a mill
by moving one of his pieces out of an existing mill, then moving it back to form the same
mill a second time (or any number of times), each time removing one of his opponent's
men. The act of removing an opponent's man is sometimes called "pounding" the opponent.
When one player has been reduced to three men, phase three begins.
Phase 3: Flying. When a player is reduced to three pieces, there is no longer a
limitation on that player of moving to only adjacent points: The player's men may "fly" (or
"hop", or "jump") from any point to any vacant point. Some rules sources say this is the way
the game is played, some treat it as a variation, and some don't mention it at all. Flying was
introduced to compensate when the weaker side is one man away from losing the game.
Our implementation of the game does not need to include phase 3 - it is optional.

This assignment is an exercise in using trees. However, since the game tree is too big
to be fully explored (unlike for the game of "tic-tac-toe") we have no use of the simple
minimax algorithm for playing the game. The usual solution for exploring a game tree which
is too big to be fully explored is alpha-beta pruning. The assignment should implement
alpha-beta pruning for evaluation of moves played against the user.

Useful links:
https://en.wikipedia.org/wiki/Alphabeta_pruning
https://kartikkukreja.wordpress.com/2014/06/29/alphabetasearch/
https://kartikkukreja.wordpress.com/2014/03/17/heuristicevaluation-function-for-nine-
mens-morris/
https://www.youtube.com/watch?v=xBXHtz4Gbdo

A tournament of different NMM implementations is available at:


https://www.hackerrank.com/challenges/morrisnine

Assignment #3: A simple search engine (35 points)


The task is to implement a simple search engine. The program should, upon startup,
traverse the given folder and it's subfolders, parse HTML files in them and build a suitable
in-memory data structure needed to carry out efficient searching. After that, the user can
enter textual queries and receive ranked lists of retrieved documents. Ranking is dependent
on (1) the number of occurences of the given words in the document, (2) the number of
documents with links pointing to the given document, and (3) the number of occurences of
the given words in the documents with links pointing to the given document.

Extra 5 points are awarded for each of the optional functions:


the use of logical operators AND, OR, NOT in searching
support for phrases (sequences of words)
hinting
"did you mean" functionality

Test files and the HTML parser are given in test.zip.

This assignment is an exercise in using search trees and graphs. The integral part of
the assignment is the choice of the data structure that will enable efficient searching. Please
mind that this task assumes the use of in-memory data structures.
Final exam: Oral exam (30 points)
The final exam is carried out as an oral exam where the student and the teacher
discuss the features, space and time complexity of various algorithms and data structures.
The recommended textbook is:
Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser. Data
Structures and Algorithms in Python. Wiley, 2013. ISBN 978-1-118-29027-9
(print) and 978-1-118-54958-2 (e-text)
http://multimedia.ucc.ie/Public/training/cycle1/algorithms-in-python.pdf

There is an equivalent book for Java and C++ from the same authors.