Practice Problems

For your assigned problem, first explain how you would guide a confused student and then present a solution as you would to a small group of students.
  1. Write an algorithm that reads a file and print the k most frequently occurring words along with their counts.

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    What is the runtime of your solution?

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  2. Prove the following:
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  3. You are the project manager for your company's largest software development project. You know that the best software has the most code, but there is a limit. Use too much code and your supervisor will say there is bloated code. Given a list of the sizes of various components you could include in the software, and the maximum amount of code you are allowed to have, determine the biggest size the sofware can be (your software must be less than or equal to the maximum). For example:
       sizes = {25,50,60,120} maximum = 130 
    
    Your method will return 120 since all other combinations of components either produce less code, or are greater than the 130 limit. If no software can be built return -1. public class CodeBloat { public int biggest(int[] sizes, int maximum) { // fill in code here } } Notes: If no software can be built return -1

    Constraints

    Examples

    1. {1,2,3,4,5}
      15
      
      Returns: 15

      All of the code can be used

    2. {20,40,45,60,60}
      86
      
      Returns: 85

      Using 40 and 45 will produce the largest amount of code.

    3. {89,73,20,5,5,10000,900}
      995
      
      Returns: 994

    4. {122}
      1
      
      Returns: -1
    
    

  4. Given a random variable, X, with a mean, μ, and standard deviation, σ, what is Var[(X-μ)/σ]?

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  5. Given a virtual memory system with 32-bit virtual addresses, 36-bit physical addresses, 4Kbyte pages and 64-entry direct-mapped translation lookaside buffer (TLB), describe how the translation lookaside buffer works and what happens on both TLB hits andmisses.
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  6. There is a laser cannon at coordinates (0, 0) on the cartesian plane. There are also several targets on the plane. Each target is vertical line segment, and the endpoints of the i-th target are at coordinates (x[i], y1[i]) and (x[i], y2[i]). A random angle between -Pi/2 and Pi/2, inclusive, is chosen, and a single shot is fired. The angle -Pi/2 is straight down vertically, 0 is straight to the right horizontally, and Pi/2 is straight up vertically. A shot is a straight ray of infinite length starting from the point (0, 0). A shot hits a target if there is a common point between them. Return the expected number of targets that will be hit by the single shot. Hitting a target doesn't change the direction of the laser shot.

    public class LaserShooting { public double numberOfHits(int[] x, int[] y1, int[] y2) { // fill in code here } } Notes: A return value with either an absolute or relative error of less than 1.0e-9 is considered correct.

    Constraints

    Examples

    1. {1}
      {-1}
      {1}
      
      Returns: 0.5
      
      The only one target will be hit with probability 1/2.
    2. {1,2}
      {-1,-2}
      {1,2}
      
      Returns: 1.0
      
      Both targets will be hit with probability 1/2.
    3. {3,4,7,1}
      {1,2,3,4}
      {4,3,2,1}
      
      Returns: 0.4623163952488826
      
      
    4. {134,298,151,942}
      {-753,-76,19,568}
      {440,689,-39,672}