programming-pearls

Debugging and Binary Search

"Programming Pearls" in the column 2 ("AHA! Algorithm") talks about how binary search aids in various processes like sorting, tree traversals. But it mentions that binary seach can be used in "program debugging". Can somebody please explain how this is done? ...

Fastest algorithm for circle shift N sized array for M position

What is the fastest algorithm for circle shifting array for m positions? For example [3 4 5 2 3 1 4] shift m = 2 positions should be [1 4 3 4 5 2 3] Thanks a lot ...

Help me understand this "Programming pearls" bitsort program

Jon Bentley in Column 1 of his book programming pearls introduces a technique for sorting a sequence of non-zero positive integers using bit vectors. I have taken the program bitsort.c from here and pasted it below: /* Copyright (C) 1999 Lucent Technologies */ /* From 'Programming Pearls' by Jon Bentley */ /* bitsort.c -- bitmap sort...

Error in qsort function in Programming Pearls?

Hello, is it just me or this code in Programming Pearls is wrong (quicksort wants 2 const voids, no?) If so, is my solution right? Apologies, just learning... int wordncmp(char *p, char* q) { int n = k; for ( ; *p == *q; p++, q++) if (*p == 0 && --n == 0) return 0; return *p - *q; } int sortcmp(char **p, char **q) ...

How is Programming Pearls 2nd ed different from the first edition?

I enjoyed reading Jon Bentley's Programming Pearls 1st edition a long time ago. Is the second edition worth buying? Are there significant changes, other than code being written in C/C++? P.S.: I've seen what the author says, but I wanted to seek opinion from other readers as to what they really thought of it. ...

Longest Non-Overlapping Substring

I wonder if anyone knows the (optimal?) algorithm for longest recurring non-overlapping sub string. For example, in the string ABADZEDGBADEZ the longest recurring would be "BAD". Incidentally if there is no such result, the algorithm should alert that such a thing has occurred. My guess is that this involves suffix trees. I'm sure th...

Find a missing 32bit integer among a unsorted array containing at most 4 billion ints

Hi, This is the problem described in Programming pearls. I can not understand binary search method descrbied by the author. Can any one helps to elaborate? Thanks. EDIT: I can understand binary search in general. I just can not understand how to apply binary search in this special case. How to decide the missing number is in or not in...

Solutions to the 'Programming Pearls' book by Jon Bentley

Hi.. Is there a place where I can find the solutions to the 'Programming Pearls' book by Jon Bentley ? I need to verify what ever little exercise problems I solve.. Thank you .. ...

Wanting help in writing the query in sql server 2008 on displaying the result set side by side

I have the Customers table as follows: Firstname Lastname DateofBirth dev ger 12-5-1977 sjr ind 12-5-1977 man lak 14-9-1981 I want the query based on the above table to return the customers having the same date of birth.But it should be displayed as follows: Firstname Lastname DateofBirth Firstname ...