CSCI 255 Fall 2023Introduction to Algorithms and Discrete Structures Archived Class

# Homework 13

• For full credit, provide context for each problem, show all calculations, and justify all answers by providing enough comments to explain your reasoning.
• Homework assignments must be very neatly written or typeset (e.g. using Word or OpenOffice).
• You can get up to 50% credit on a problem if you get significant outside assistance. Thus, if you are totally stuck on a problem it might be worth getting help. However, you must indicate any assistance/collaboration (See the Homework Assistance section on the Policies page). Failure to do so could result in a failing grade for the course! Note that getting help from the Help Center or me does not count as significant outside assistance, but talking with your classmates or searching on the Internet does!
• If a problem asks for an algorithm, you should give the most efficient algorithm you can find to ensure full credit. You should also specify the complexity of the algorithm with justification, whether or not the problem asks for it.

## Details

1. (8) Design an efficient algorithm to find all anagrams of a given word using a list of words from a dictionary (which you can assume is in alphabetical order). For instance, given tea, the algorithm would output eat, ate, tea, etc., but not aet since that is not a word in the dictionary. Give the worst-case complexity of your algorithm given that the dictionary has m words, the input word has n characters, and for simplicity assume the average word in the dictionary has k characters.
2. (25) Show all of the steps of inserting the letter of ALGORITHMS into each of the following data structures in order (e.g. A, then L, etc.)
1. A regular (unbalanced) BST
2. An AVL tree
3. A 2-3tree
4. A Min Heap
5. A Max Heap
3. (8) Compute
131303 mod 101
by hand using one of the binary exponentiation algorithms. That is, you are not allowed to use a calculator, computer, abacus, or any other computational device besides your brain. Show all of your work (which should be a table with 3-5 columns). You are permitted to verify that your answer is correct with the use of a computer or calculator. In case it is not clear, you may do all of your intermediate computations modulo 101 and you will still get the same answer. For instance, 13*13=169=68 mod 101, so you can use 68 instead of 169 in the next calculation.