What is the number of strings of size x where each character of the string can have one of y values? [6417f]
What does the following program print? [8991f]
int main()
{
int v1, v2, v3;
v1 = 0x5cf882
v2 = 0xff3792
v3 = v1 ^ v2;
printf("0x%x\n", v3 ^ v1);
return 0;
}
|
int a20a72(const vector <int> &v, const map <int, int> &w) {
{
int i, rv;
map <int, int>::const_iterator wit;
rv = 0;
for (i = 0; i < v.size(); i++) {
wit = w.find(v[i]);
if (wit != w.end()) rv += wit->second;
}
return rv;
}
|
int a358df(const vector <int> &v, map <int, int> &p, int m)
{
int i;
p.clear();
for (i = 0; i < v.size(); i++) p.insert(make_pair(v[i]%m, i));
}
|
int a5e11(const map <int, int> &v, const map <int, int> &w)
{
map <int, int>::const_iterator vit, wit;
int rv;
rv = 0;
for (vit = v.begin(); vit != v.end(); vit++) {
wit = w.find(vit->first);
if (wit != w.end()) rv += wit->second;
}
return rv;
}
|
int ac3f4(const vector <int> &v, multimap <int, int> &p)
{
int i;
p.clear();
for (i = 0; i < v.size(); i++) p.insert(make_pair(v[i], i));
}
|
int ac4a7(const vector <int> &v, unordered_multimap <int, int> &p)
{
int i;
p.clear();
for (i = 0; i < v.size(); i++) p.insert(make_pair(v[i], i));
}
|
int ae639(int n)
{
int i, j, rv;
rv = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < i; j++)
rv += f(i,j);
}
}
return rv;
}
|
What is the big-O running time of performing m Union() operations on an instance of disjoint sets with n elements. The implementation is "Union by rank with path compression." [c3d75]
What is the big-O running time of performing m Find() operations on an instance of disjoint sets with n elements? The implementation is "Union by rank with path compression." [d171a]
What does the following program print? [ea518]
int main()
{
int v1, v2;
v1 = 0x4a;
v2 = 0x8c;
printf("0x%x\n", v1 | v2);
return 0;
}
|
What does the following program print? [eea0c]
int main()
{
int v1, v2;
v1 = 0x4a;
v2 = 0x7c;
printf("0x%x\n", v1 & v2);
return 0;
}
|
Suppose that v.size() equals n and l.size() equals m.
What is the big-O running time of the following procedure?
What does the following program print? [ffc6f]
The following is an instance of disjoint sets. We are doing union by size.
Suppose I do Union(2,66). Please answer the following:
A. What is the value in index 2 of the links vector? [A]
The following is an instance of disjoint sets. We are doing union by height.
Suppose I do Union(0,4). Please answer the following:
A. What is the value in index 0 of the links vector? [A]
The following is an instance of disjoint sets. We are doing union by rank with path compression.
Suppose I do Find(10). Please answer the following:
A. What is the value in index 4 of the links vector? [A]
Part A: You force each of your employees to choose a password composed of exactly 5 lower-case letters followed by 4 single numeric digits. How many potential passwords are there? [---------]
Part B: You are running a lottery. You have a machine with 17 ping-pong balls, numbered 1 to 17. It has been programed to choose one of these balls at random every second. Each time a ball is chosen, it is put back onto the machine, so your machine always has the same 17 balls. Your lottery number is composed of the ping-pong ball numbers chosen in the last 6 seconds, ordered from most recently-chosen to least recently-chosen. How many different lottery numbers are there? [---------]
Part C: You are buying a new home. In your old home, you had 17 different TV's. Your new home only has room for 12 TV's, so you have to donate 5 of them to charity. How many different ways are there for you to donate those 5 TV's to charity? [---------]
Part D: There is a skyscraper in New York City whose spire has 11 lights arranged vertically. You can put a gel over a light, and that makes it a specific color. You have 11 different-colored gels. Each night, you'll use all of the gels, but you want to make sure that the gels form a different arrangement of colors every night. How many nights can you go without ever repeating an arrangement? [---------]
Part E: I'm having breakfast at a bed-and-breakfast, and my host asks me what kind of juice I want. Instead of just saying "Orange", I was dumb enough to ask what she had. She said, "I have 12 kinds of juice. You can have any of them on their own, or you can combine any of them that you want in equal quantities. Or you can skip juice altogether! See, there are infinite combinations!!" You're too polite to tell her that she's wrong. How many combinations are there? (I hate to say that this is a true story, but it is): [---------]
Please write the procedure exactly_n(), which has the following prototype:
The return value should be a set of numbers that are in exactly n of the
sets in sets. For example, suppose that sets represents the following
three sets:
You cannot use any additional data structures in your implementation. You only need some ints
(I used four).
Your colleague has guaranteed you the following things about f():
Write a program that prints out the smallest value n for which f(n) is true.
Simply call f() when you want to use it -- your colleague has written that for you.
Your program should run optimally from a big-O standpoint.
Here's an example -- we start with this configuration:
The tee in hole 5 can "jump" the tee
in hole 6, and land in hole 7, removing the tee in hole 6:
For example, in the top picture above, we can have the tee in hole 9 jump the tee in hole 8,
landing in hole 7; and we remove the tee in hole 8:
Write a procedure with the following prototype:
The procedure should return true if you can play the game all the way down to just one
tee left on the board. It should return false otherwise. Hint -- use recursion like
the Sudoku solver.
Examples:
Remember to set your input box to "preformatted" and resize it so that it's big -- that helps
you see what you're writing.
void make_list(const vector <int> &v, list <int> &l)
{
int i;
list <int>::const_iterator lit;
l.clear();
for (i = 0; i < v.size(); i++) {
for (lit = l.begin(); lit != l.end() && *lit < v[i]; lit++) ;
l.insert(lit, v[i]);
}
}
ffc6f
int main()
{
int v1;
v1 = 0x4a;
printf("0x%x\n", v1 << 12);
return 0;
}
Question 17 - 6 points
f7527

B. What is the value in index 66 of the links vector? [B]
C. What is the value in index 2 of the sizes vector? [C]
D. What is the value in index 66 of the sizes vector? [D]
Question 18 - 6 points
76112

B. What is the value in index 4 of the links vector? [B]
C. What is the value in index 0 of the heights vector? [C]
D. What is the value in index 4 of the heights vector? [D]
Question 19 - 6 points
8df0f

B. What is the value in index 10 of the links vector? [B]
C. What is the value in index 16 of the links vector? [C]
D. What is the value in index 50 of the links vector? [D]
E. What is the value in index 52 of the links vector? [E]
F. What is the value in index 67 of the links vector? [F]
Question 20 - 20 points
Please answer each of the following. Don't calculate it out to be a number, but simply give an expression. Use the carat (^) for exponentiation, exclamation point (!) for factorial, and C(n,k) for n-choose-k.
Question 21 - 10 points
You are representing sets composed of numbers from 0 through 30 using integers and bit arithmetic.
int exactly_n(const vector <int> &sets, int n);
{ { 0, 2, 5, 8 },
{ 0, 3, 9, 11 },
{ 0, 3, 8, 11 } }
Then:
Question 22 - 12 points
Your colleague has written a function called f() with the following prototype:
bool f(long long n);
Question 23 - 12 Points
You've invented a puzzle that involves a block of wood with 17 holes numbered 0 through 16,
and 16 golf tees. You put the tees in all of the holes except for one, and then you play
the game as follows:
Obviously, you can represent the state of any game, with any number of tees and holes, with
a string that contains just '0' and '1' characters. '0' means empty hole, and '1' means that
there is a tee in the hole.



bool can_i_solve(string &s);
String Answer
1 true -- Any string with just one '1' is solved and "true"
01 true
10 true
00010 true
11111 false -- Any string with more than one tee, where you can't jump, is solved.
110 true -- One jump will do
011 true -- Ditto
101 false -- You can't make any jumps.
1101 true -- Jump 1 with 0, then 2 with 3.
11001 false -- You can jump 1 with 0, but then you're left with 00101.