All pastes #2048373 Raw Edit

Something

public text v1 · immutable
#2048373 ·published 2011-04-19 18:44 UTC
rendered paste body
Q: Given an array, tell me if there are any duplicate values in that array.
A: Sort the array, start comparing values

var array;
sort(array);
for(i = 0; i < array.length - 1; i++) {
     if(array[i] == array[i+1]) return true;
}

Q: Do you know what breadth first search / depth first search is?  What is the difference?
A: Breadth first search searches all the adjacent nodes first, where depth first search will search down each adjacent node until it hits an end point.

Q: Describe a unique algorithm or data structure you find interesting.  Design Pattern is also cool.
A: kind of open

Q: Describe what a deadlock is.
A: Two more functions/proccesses/etc are waiting for one another to finish. :(

Q: Given an array of data structures that look like:

class MenuItem {
     String Name
     Array<MenuItem> Children
}

write a single method that will output all the MenuItem names and include the level number in front of them:

A: function PrettyPrint(menuItems, level) {

     foreach(MenuItem item in menuItems) {
        print level + ". " + item.name
        if(item.children)
             PrettyPrint(item.children, level + 1) 
     }
}