### 6.1 Algorithms

*If some characters seem to be missing, it's because MathJax is not loaded correctly. Refreshing the page should fix it.*

Examples of classic algorithms you should know include various sorting algorithms (quicksort, radix sort), shortest path algorithms (Dijkstra’s, A*), tree algorithms (pre-, in-, post-order traversal), and solutions to popular problems such as the stable marriage problem and traveling salesman problem. You will probably never have to implement them since there already exist many efficient implementations, but it’s important to understand their underlying design principles and implementation tradeoffs in case you have to make similar decisions in your job.

There are also programming techniques that you should be comfortable with, such as dynamic programming, recursions, string manipulation, matrix multiplication, regular expression, and memory allocation. Below are some of the questions that you might want to go over to refresh your memory.

- Write a Python function to recursively read a JSON file.
- Implement an sorting algorithm, preferably quick sort or merge sort.
- Find the longest increasing subsequence in a string.
- Find the longest common subsequence between two strings.
- Traverse a tree in pre-order, in-order, and post-order.
- Given an array of integers and an integer k, find the total number of continuous subarrays whose sum equals . The solution should have runtime.
- There are two sorted arrays and with and elements respectively. Find the median of the two sorted arrays. The solution should have runtime.
- Write a program to solve a Sudoku puzzle by filling the empty cells. The board is of the size . It contains only 1-9 numbers. Empty cells are denoted with *. Each board has one unique solution.
- Given a memory block represented by an empty array, write a program to manage the dynamic allocation of that memory block. The program should support two methods:
`malloc()`

to allocate memory and`free()`

to free a memory block. - Given a string of mathematical expression, such as
`10 * 4 + (4 + 3) / (2 - 1)`

, calculate it. It should support four operators`+`

,`-`

,`:`

,`/`

, and the brackets`()`

. - Given a directory path, descend into that directory and find all the files with duplicated content.
- In Google Docs, you have the
`Justify alignment`

option that spaces your text to align with both left and right margins. Write a function to print out a given text line-by-line (except the last line) in Justify alignment format. The length of a line should be configurable. - You have 1 million text files, each is a news article scraped from various news sites. Since news sites often report the same news, even the same articles, many of the files have content very similar to each other. Write a program to filter out these files so that the end result contains only files that are sufficiently different from each other in the language of your choice. You’re free to choose a metric to define the “similarity” of content between files.