浦 (pu)hopeful musings
StercusUrsus
read my profile
sign my guestbook

Visit StercusUrsus's Xanga Site!

Name:
Gender: Male


Message: message me
AIM: maestro pu


Member Since: 8/21/2003

SubscriptionsSites I Read
Capt_Crazeman
Louis_Kong
voidsoul379
Rustophilus
WackoSisters
Livsinme
w_general
ThunderSaber
noitomedite
L3in
melt_like_lemondrops
ShadowReflection
Laurae
o_o2009
krysta627
MatriiX0119
blueraider
potterzfan
jamz_thefob
JediSolusar
Reiierrei
Sakamura
leehsueh
OrientalPyro
vwu3
ZurgIzuG
Mikut2
xkoyxwo88
RubyDragon
chocoberries
dr_blt
BadLoss
MissBanana
loha
alternativehorizon
jenqtpiglitz
Shadayuki
starrlightz12
BewareOfCheese
sarangkangta
crystalize114
brendan_hsu
JadesFireMJ
escaflowne_pa
theleakyredburger
spottiedottie
q3solid
smilestwinkle
persiankittie949
serbbballjunkie
xiaotu
w0iny
perpetualgrace
Genie5
eighthdaydc
conniedeclares
ChRiStInArAe
jlin1216
x_b0nxn33h_x
shadowknight2k
BacekJ
Perpetual_Paladin
Ladybug999
viLlaNewEva
jeannie829
tofuness
Buhbee39
KrisCL
Sherin
lynxlatan347
adorkablestar
h2g2_zaphod
h2g2_marvin
h2g2_arthur
eugene3
ChocoMirage
yourfatalignorance
TruantProdigy
ninga_monkey
elements108
homan_lee
lilxdanny
zuzunkie
presenceofevil
Exegesis
HaiWolfe
LHSCreativeWriters
sunshinepark143
AznSSJ2
crazybassoonist
superab0
al3gr1a
elKell
qtluckistar
ReeZOffDaHeeZ
gaterader
Jesus_____Christ
clarinetgod42
Caryloo
ElizaMcClare
binarythought
CarTire86
JeanKnee
Zero054
bush108
aznaxn
TechArt
NightBlade39
comradejenson
LovelyLadyAlice

Groups Blogrings
Royal Blue and Gold / LHS
previous - random - next

Agnosticism
previous - random - next

*~PiAnO LoVe~*
previous - random - next

~¤§ Cornell Class of 2009 §¤~
previous - random - next

Google Interns
previous - random - next


Posting Calendar

|<< oldest | newest >>|
view all weblog archives

Get Involved!

Suggest a link

Recommend to friend

Create a site

Thursday, May 15, 2008

Summer Apartment

 

<3

47b8db30b3127cce9854892f714e00000067108AZOGzJs5YtL

47b8db30b3127cce9854892b714a00000057108AZOGzJs5YtL

 

47b8db30b3127cce98548917717600000057108AZOGzJs5YtL

 

47b8db30b3127cce98548915717400000057108AZOGzJs5YtL

 

 


Wednesday, April 16, 2008

omg e-mail

The amount of non-spam e-mail I get these days is slightly ridiculous.



Yep.. that's just one day.  And it's not even a really bad day.  A really bad day would be when I received email sent to course staff -- the night before the project was due.  That was 300 e-mails in 1 day.


Wednesday, September 26, 2007

some interview problems



Question 1: Finding singletons among duplicates
Given an input array of n integers, where all but one integer shows up twice in the array, write an algorithm that - given the input array - will return the integer which shows up only once.

Give an O(n^2) solution with O(1) space complexity (a)
Give an O(n log n) solution with O(1) space complexity (b)
Give an O(n) solution with O(n) space complexity (c)
Give an O(n) solution with O(1) space complexity (d)
Give an O(n) solution with O(1) space complexity using only MULTIPLY and DIVIDE (e)

Question 2: Fixed sized subset sum
Given an input array of n integers and a target number x, write an algorithm that - given the input array - will return whether (and which) any two numbers in the input array add up to x.

Give an O(n^2) solution with O(1) space complexity (f)
Give an O(n log n) solution with O(1) space complexity (g)
Give an O(n) solution with O(n) space complexity (h)

Now -- given the same input array, write an algorithm that - given the input array - will return whether (and which) any three numbers in the input array add up to x.

Give an O(n^2 log n) solution with O(1) space complexity (i)
Give an O(n^2) solution with O(n) space complexity (j)

Now -- given the same input and some integer m, write an algorithm that - given the input array - will return whether (and which) any m numbers in the input array add up to x.

Give an O(n^(m-1)) solution with O(n) space complexity (k)

Now -- for the special case of m = 4

Give an O(n^2) solution with O(n^2) space complexity (l)


Solutions
a. For each of n numbers, check if it exists elsewhere in the length n list: n*n.  Uses no additional space besides pointers.
b. Sort the list in constant space with a pivot algorithm (quicksort, etc) that's O(n log n) bounded.  Check for duplicates afterwards by sweeping in O(n) time.  Uses no additional space.
c. Put each number into a HashSet.  If the number is already in the HashSet, mark it as existing twice.  In the end, only one number will not be marked.  HashSet takes O(n) space to make (amortizing expands it), but the sweep operation only takes O(n) time.
d. Huffman Code.  Since integers take constant bitspace, bitwise xor every number in the array together.  The result will be the number that's missing.
e. I have no bloody clue.
f. For each of the n numbers, run through the size n list and check if the pairs of numbers sum to the target.  n*n = n^2 time but constant space.
g. Sort it first.  Keep pointers to the smallest and largest items in the array.  If the smallest+largest is equal to the target, return.  If the smallest+largest is larger than the target, decriment the pointer from the largest to the second largest item.  If the smallest+largest is smaller than the target, increment the pointer from the smallest to the second smallest.  Repeat.  The pointers will eventually converge in O(n) time - so time bound is due to sorting in O(n log n). 
h. Another Hash based algorithm.  Create a HashMap type repository with target-arrayvalues.  Find if those values match up with the actual array values.
i, j, and k) For the array newTargets = Target-ArrayValues, note that if any 2 numbers add up to a number in newTargets, then we have the 3 numbers that add up to the target.  Thus we have reduced the problem with 3 items to n problems each with 2 items.  The complexity is simply n*Problem(2).  Thus for m levels, we find that the complexity is O(n * n * ... * n *Problem(2)) where the n's occur m-2 times.
l) Create a new array which is all possible sums of pairs of numbers in the inital array, called sumItems.  Note that if any 2 items in sumItems add up to the target, then the problem is solved.  It takes n^2 time to generate sumItems, and n^2 time w/ n^2 space to check whether any 2 items in sumItems add up to the target (using a Hash method).  Thus the overall complexity is n^2 bound with n^2 space bound.


Thursday, January 04, 2007

google

I had two 45 minute interviews with google.  They asked me some non-technical questions about school, etc.  Then they asked a technical question for 25-30 minutes:

First one (which I botched) asked me this question:
Memory optimization of search algorithms
  1. Given one million 32-bit numbers how would you sort it?
    (I answered first with a description of mergesort, then quicksort)
  2. What's the run time complexity? didn't botch, yay
  3. Now what would you do if you had only 2 MB of memory.  Does that affect your algorithm?
    (I botched this for a while and eventually got it; You need to segment into 2 MB sections and merge afterwards)
  4. Now what about mergesort with only 2MB of memory? Does that affect your algorithm?
    (Slightly botched; Mergesort is memory friendly)
  5. Now what if the numbers weren't 32-bit, but were unique telephone numbers?
    (Botched this one a little bit before eventually reaching the solution: Use an array of 2^14 booleans to store whether a telephone number exists.  O(n) complexity for scanning telephone numbers into array, and O(n) for outputting array into new list.

Second one, which I didn't botch, asked me this question:
Graph traversal algorithms and complexity
  1. Implement the following function (over the phone, yay):
    boolean isReachable(Node a, Node b){
     
    }
    given the class:
    class Node{
      public Set<Node> getNeighbors();
      //return all neighbors (undirected graph)
    }

  2. (My solution was a simple depth search):
    boolean isReachable(Node a, Node b){
      Queue<Node> current = new Queue<Node>();
      Set<Note> checked = new HashSet<Node>();
      current.push(a);
      while(!current.empty()){
        Node x = current.pop();
        if(x==b) return true;
        checked.add(x);
        Set<Node> neighbors = x.getNeighbors();
        for(Node curNighbor : neighbors){
          if(!checked.contains(curNeighbor))
            current.push(curNeighbor);
        }
      }
      return false;
    }

  3. What is the complexity for a graph where each node has only one neighbor?
    (That was easy, O(n); thank goodness I chose a simple algorithm)
  4. What is the complexity for a graph where every node is connected with every other?
    (O(n^2))
  5. What is the worst case complexity? Why?
    (O(n^2), since the queue only ever has n elements, and the foreach can at most go through n elements)
------------------------

in other news:

sweet.  32 gigabyte flash drive [link]