You are on page 1of 4

Ngy 24 thng 6 nm 2014 Screening Test

http://elearning.epsilon-mobile.com/moodle/mod/quiz/review.php?attempt=37&showall=1 1/4
Home JWI
Junior Web Intern
You are l ogged i n as Nguyen Ki m Hi eu (Log out)
Question 1
Compl ete
Marked out of 1.00
Fl ag questi on
Information
Fl ag questi on
Question 2
Compl ete
Marked out of 1.00
Fl ag questi on
Started on Tuesday, 24 June 2014, 4:13 PM
State Finished
Completed on Tuesday, 24 June 2014, 6:09 PM
Time taken 1 hour 55 mins
Grade Not yet graded
You have two sort algorithm. How can you know which one works better?
- phc tp ca thut ton l yu t cn xt n u tin
- Tuy nhin cn ph thuc vo tng trng hp. C th mt thut ton c phc tp cao
nhng trong hon cnh ca bi ton n li ph hp hn (do khng gian phn t nh chng hn,
..) hoc c th thut gii c phc tp thp nhng hin thc kh khn v khng cn thit.
Implement a function to determine if an ANSI string (array of characters) has all unique
characters (C++ or Java). Example: abcdefghijklm -> true, aba -> false.
Additional libraries/APIs are not allowed.
Function prototype for C++ and C:
bool unique(char* str) {
}
Function prototype for Java:
bool unique(char[] str) {
}
What is the complexity of your algorithm?
bool unique(char* str) {
// Boolean array used to check out the duplication of each character
bool charArray[256];
// Initialize the array
for (int i = 0; i < 256; i++) {
charArray[i] = false;
}
// counter i
int i =0;
while (char[i] != '\0') {
// Determine the ascii value of the character
int ascii = (int)char[i];
if (charArray[ascii] != false) {
Quiz navigation
Show one page at a time
Finish review
1 i 2 3 4 5
i 6 7 8 i 9
10 11
Ngy 24 thng 6 nm 2014 Screening Test
http://elearning.epsilon-mobile.com/moodle/mod/quiz/review.php?attempt=37&showall=1 2/4
Question 4
Compl ete
Marked out of 1.00
Fl ag questi on
Question 5
Compl ete
Marked out of 1.00
Fl ag questi on
Information
Fl ag questi on
Question 6
Compl ete
Marked out of 1.00
Fl ag questi on
Question 3
Not answered
Marked out of 1.00
Fl ag questi on
return false;
} else charArray[ascii] = true;
i++;
}
return true;
}
complexity O(n). With n is the length of the string

Can you think of a linear solution? Explain your answer.
Can you use hash table (bng bm) for this problem?
C th s dng bng bm cho bi ton ny. Thut gii nh sau:
- Duyt qua tng phn t ca mng
- Xc nh kha, nu kha ny tn ti trong bng th tr v false. Ngc li, lu gi tr kha
mi ny
- Lp li cho n khi kt thc chui
* phc tp: O(n)
Can you think of an algorithm that uses sorting?
C th s dng sorting hin thc thut gii theo cc bc:
- Sp xp li chui
- Duyt qua chui v kim tra s trng lp lin tip ca cc k t
- Nu c tr v false, ngc li true.
Implement binary search algorithm (tm kim nh phn).
Function prototype for C++ and C:
bool binarySearch(int a[], int n, int value) {
// <a> is an sorted array of <n> integers.
// return true/false if <value>is inside <a>.
}
Function prototype for Java:
bool binarySearch(int[] a, int value) {
// <a> is an sorted array of integers.
// return true/false if <value> is/isnt inside <a>.
}

What is the complexity of your algorithm?
bool binarySearch(it a[], int n, int value) {
int first = 0;
int last = n - 1;
int mid = (first + last) / 2;
while (first <= last) {
if (a[mid] < value) {
Ngy 24 thng 6 nm 2014 Screening Test
http://elearning.epsilon-mobile.com/moodle/mod/quiz/review.php?attempt=37&showall=1 3/4
Question 7
Compl ete
Marked out of 1.00
Fl ag questi on
Question 8
Compl ete
Marked out of 1.00
Fl ag questi on
Information
Fl ag questi on
Question 9
Compl ete
Marked out of 1.00
Fl ag questi on
first = mid + 1;
} else if {
return true;
} else {
last = mid - 1;
}
mid = (first + last) / 2;
}
return false;
}
complexity: O(log2(n))
Let say I have an sorted array of 1 million integers, and I have 1 million integers to
search, should I use binary search? What if I have 10 million integers? What if I have only 10
integers?
Khi s tm kim qu ln th tm kim nh phn khng cn ph hp na. Nn thay th bng cch
s dng hm bm.
What is a hash table? At which condition hash table is prefered over binary search?
Bng bm l cu trc d liu lu tng cp gi tr (key, data) phc v cho vic tm kim bng
phng php bm.
Bng bm c u tin s dng khi d liu c kch thc ln cng nh s ln truy xut din
ra thng xuyn lin tc.
Implement a function that reverse every words in a string. Example: the lazy fox jumps -> eht
yzal xof spmuj. Additional libraries/APIs are not allowed.
Function prototype for C++ and C:
bool reverseWords(char* str) {
}
Function prototype for Java:
bool reverseWords(char[] str) {
}
What is the complexity of your algorithm?
bool reverseWords(char* str) {
int start = 0;
int i =0;
while (str[i] != '\0') {
if (str[i] == ' ') {
reverse(str, start, i - 1);
start = i + 1;
}
i++;
}
}

void reverse (char* a, int start, int end) {
int mid = (start + end) / 2;
int length = end - start + 1;
char temp;
Ngy 24 thng 6 nm 2014 Screening Test
http://elearning.epsilon-mobile.com/moodle/mod/quiz/review.php?attempt=37&showall=1 4/4
You are logged in as Nguyen Kim Hieu (Log out)
JWI
Question 11
Not answered
Marked out of 5.00
Fl ag questi on
Question 10
Not answered
Marked out of 1.00
Fl ag questi on
for (int i = start; i<= mid; i++) {
temp = a[i];
if (length % 2 == 0) {
a[i] = a[mid * 2 - i + 1];
a[mid * 2 - i + 1] = temp;
} else {
a[i] = a[mid * 2 - i];
a[mid * 2 - i] = temp;
}
}
}
Complexity : O(n*n)
Can you think of a linear solution?
Implement a phone management program which satisfy the following requirement:
- User can add new phone with name.
- User can look for an existing phone number in database.
- User can remove an existing record (phone + contact name) in the database.

Hint: zip your source code then attach below.
Finish review