Algorithms for Interviews: "Algorithms For Interviews"
Summary
Algorithms For Interviews (AFI) is a book that aims to help engineers interviewing for software development positions as well as their interviewers. AFI consists of 174 solved algorithm design problems. It covers core material, such as searching and sorting; general design principles, such as graph modeling and dynamic programming; advanced topics, such as strings, parallelism and intractability. It also covers system design, problem solving, and interviewing techniques. AFI's authors are practicing algorithmists, with extensive academic and industrial experience. They have collectively published over 100 articles on applied algorithms, applied their skills at Google, Microsoft, IBM, Qualcomm, and a number of smaller software startups, and conducted many job interviews for various computer science jobs.
Example
Let's begin with the picture on the front cover of the book, reproduced on the right. You may have observed that the portrait of Alan Turing is constructed from a number of pictures ("tiles") of great computer scientists and mathematicians.
Suppose you were asked in an interview to design a program that takes an image and a collection of s X s-sized tiles and produce a mosaic from the tiles that resembles the image. A good way to begin may be to partition the image into s X s-sized squares, compute the average color of each such image square, and then find the tile that is closest to it in the color space. Here distance in color space can be the Euclidean distance over Red-Green-Blue (RGB) intensities for the color. As you look more carefully at the problem, you might conclude that it would be better to match each tile with an image square that has a similar structure. One way could be to perform a coarse pixelization (2 X 2 or 3 X 3) of each image square and finding the tile that is "closest" to the image square under a distance function defined over all pixel colors (for example, Euclidean Distance over RGB values for each pixel). Depending on how you represent the tiles, you end up with the problem of finding the closest point from a set of points in a k-dimensional space.
If there are m tiles and the image is partitioned into n squares, then a brute-force approach would have O(m n) time complexity. You could improve on this by first indexing the tiles using an appropriate search tree. A more detailed discussion on this approach is presented in the book.
If in a 45-60 minute interview, you can work through the above ideas, write some pseudocode for your algorithm, and analyze its complexity, you would have had a fairly successful interview. In particular, you would have demonstrated to your interviewer that you possess several key skills:
The ability to rigorously formulate and abstract a real-world problem.
The skills to solve problems and design algorithms.
The tools to go from an algorithm to a working program.
The analytical techniques required to determine the computational complexity of your solution.
No comments:
Post a Comment