Comments for Arden Dertat Web Search and Information Retrieval Mon, 05 Dec 2011 21:30:59 +0000 hourly 1 http://wordpress.org/?v=3.1 Comment on Programming Interview Questions 19: Find Next Palindrome Number by Arda Antikacioglu /2011/12/01/programming-interview-questions-19-find-next-palindrome-number/#comment-677 Arda Antikacioglu Mon, 05 Dec 2011 21:30:59 +0000 /?p=841#comment-677 Actually, this takes O(log(n)) time since mirroring takes as long as the length of n, which is still linear in the length of the input and can be proven to be optimal. Actually, this takes O(log(n)) time since mirroring takes as long as the length of n, which is still linear in the length of the input and can be proven to be optimal.

]]>
Comment on Programming Interview Questions 7: Binary Search Tree Check by Arden /2011/10/10/programming-interview-questions-7-binary-search-tree-check/#comment-651 Arden Thu, 01 Dec 2011 19:07:59 +0000 /?p=569#comment-651 You're right, changed it. Thanks for the comment.. You’re right, changed it. Thanks for the comment..

]]>
Comment on Programming Interview Questions 7: Binary Search Tree Check by Anonymous /2011/10/10/programming-interview-questions-7-binary-search-tree-check/#comment-648 Anonymous Thu, 01 Dec 2011 04:54:58 +0000 /?p=569#comment-648 There's no reason to build a list of all node values in isBST2. You only need the value of the last node visited so far. Rename nodes to maxValBox and update it like this: maxValBox[0] = tree.val There’s no reason to build a list of all node values in isBST2. You only need the value of the last node visited so far. Rename nodes to maxValBox and update it like this:

maxValBox[0] = tree.val

]]>
Comment on Programming Interview Questions 8: Transform Word by Ilke /2011/10/17/programming-interview-questions-8-transform-word/#comment-645 Ilke Wed, 30 Nov 2011 06:07:26 +0000 /?p=597#comment-645 I didn't suggest loading the dictionary into a trie and then using it as it were graph :) Yes, if you use a Trie, every time you pop an element from the queue, you have to find all of its one-step-away neighbors on the fly, however this lookup is very cheap in a trie. Furthermore, you don't have to do full lookups for every possible neighboring word for additions / changes (for removal you have to, but that's only length - 1 lookups), the trie will guide you instead with non-null pointers. English language has more than 1 million words and it's expanding by ~10k words each year. Plus, source and target word inputs are bounded by the dictionary. Yes, this solution's lookups are faster on paper, but because of these two facts, I would go with a trie based solution rather than creating that huge hashtable, especially because it would be more efficient in practice. I didn’t suggest loading the dictionary into a trie and then using it as it were graph :)
Yes, if you use a Trie, every time you pop an element from the queue, you have to find all of its one-step-away neighbors on the fly, however this lookup is very cheap in a trie. Furthermore, you don’t have to do full lookups for every possible neighboring word for additions / changes (for removal you have to, but that’s only length – 1 lookups), the trie will guide you instead with non-null pointers.
English language has more than 1 million words and it’s expanding by ~10k words each year. Plus, source and target word inputs are bounded by the dictionary. Yes, this solution’s lookups are faster on paper, but because of these two facts, I would go with a trie based solution rather than creating that huge hashtable, especially because it would be more efficient in practice.

]]>
Comment on Programming Interview Questions 5: Linked List Remove Nodes by Arden /2011/09/29/programming-interview-questions-5-linkedlist-remove-nodes/#comment-641 Arden Tue, 29 Nov 2011 17:05:08 +0000 /?p=533#comment-641 Great solution, thanks! Great solution, thanks!

]]>
Comment on Programming Interview Questions 8: Transform Word by Arden /2011/10/17/programming-interview-questions-8-transform-word/#comment-640 Arden Tue, 29 Nov 2011 16:32:20 +0000 /?p=597#comment-640 Trie won't work because we can change or remove characters. For example, in a trie there won't be a direct link from cat to at, but we need that link here. And there won't be a link between cat and bat as well. Also in a trie intermediate nodes are not guaranteed to be actual words. Since trie is a tree it can't contain backward links, so it would work only if we were allowed to add characters, without removing or changing them. Trie won’t work because we can change or remove characters. For example, in a trie there won’t be a direct link from cat to at, but we need that link here. And there won’t be a link between cat and bat as well. Also in a trie intermediate nodes are not guaranteed to be actual words. Since trie is a tree it can’t contain backward links, so it would work only if we were allowed to add characters, without removing or changing them.

]]>
Comment on Programming Interview Questions 8: Transform Word by Ilke /2011/10/17/programming-interview-questions-8-transform-word/#comment-636 Ilke Tue, 29 Nov 2011 08:24:17 +0000 /?p=597#comment-636 Hey, You may want to load the dictionary into a Trie here, rather than a graph as you described. http://en.wikipedia.org/wiki/Trie Hey,
You may want to load the dictionary into a Trie here, rather than a graph as you described.

]]>
Comment on Programming Interview Questions 5: Linked List Remove Nodes by Anonymous /2011/09/29/programming-interview-questions-5-linkedlist-remove-nodes/#comment-609 Anonymous Sun, 27 Nov 2011 09:25:08 +0000 /?p=533#comment-609 The following pattern removes the need for special cases. <code> Node* RemoveNodesWithValue(Node* head, int k) { if (!head) { return head; } Node dummy; dummy.next = head; Node* prev = &dummy; Node* current = head; while (current) { if (current->data == k) { prev->next = current->next; delete current; current = prev->next; } else { prev = current; current = current->next; } } return dummy.next; } </code> The following pattern removes the need for special cases.


Node* RemoveNodesWithValue(Node* head, int k) {
if (!head) {
return head;
}

Node dummy;
dummy.next = head;
Node* prev = &dummy;
Node* current = head;

while (current) {
if (current->data == k) {
prev->next = current->next;
delete current;
current = prev->next;
}
else {
prev = current;
current = current->next;
}
}

return dummy.next;
}

]]>
Comment on Programming Interview Questions 6: Combine Two Strings by Arden /2011/10/10/programming-interview-questions-6-combine-two-strings/#comment-608 Arden Sun, 27 Nov 2011 04:16:39 +0000 /?p=551#comment-608 That's a great idea, we can definitely do that. We will save so much space by caching the indexes instead of the whole substring itself. And we can easily implement it by slightly modifying the above algorithm. Thanks for the idea.. That’s a great idea, we can definitely do that. We will save so much space by caching the indexes instead of the whole substring itself. And we can easily implement it by slightly modifying the above algorithm. Thanks for the idea..

]]>
Comment on Programming Interview Questions 6: Combine Two Strings by hero /2011/10/10/programming-interview-questions-6-combine-two-strings/#comment-606 hero Sat, 26 Nov 2011 23:22:17 +0000 /?p=551#comment-606 Hi Arden, I wonder if it would be possible to keep only the index number of failing string compared to original one in the cache instead of whole substring. For your example, it would cache the string tuple as {bc,f}, for some time rigth? Instead, would it be possible to cache {1,2} meaning that 1 is the substring of abc from the index 1 and so on. Hi Arden,

I wonder if it would be possible to keep only the index number of failing string compared to original one in the cache instead of whole substring. For your example, it would cache the string tuple as {bc,f}, for some time rigth? Instead, would it be possible to cache {1,2} meaning that 1 is the substring of abc from the index 1 and so on.

]]>