Re: [algogeeks] C output

2012-10-17 Thread Vikas Kumar
#includestdio.h
int main()
{
   char str[]={'a','b','c'};
   char str1[]={abc};
  printf(%d,sizeof(str));
printf(%d,sizeof(str1));
getchar();
}

This is giving 3 in case of str and 4 in case of str1 bcz str is array of
character and str1 is a string.
For understanding this point consider a integer array int arr[] =
{1,2,3,4}; then for this sizeof(arr) is 16 means 4*sizeof(int). So in the
same way for str in given program it is giving 3*sizeof(char) i.e. 3.

sizeof(anyString) = lengthOfString +1 ( +1 for '\0')
strlen(anyString)  = simple length
sizeof(anyArray) = numberofElementPresentInArray*sizeof(dataType)


-- 
*Thanks,*
*Vikas Kumar*
*
*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] coding round question

2011-10-30 Thread vikas kumar
There  are a number of integer ranges say [ L, R]i denoting left and
right of segment i, lets says we are given K such segments and we
define one operation as move which makes our chosen segment to move
either +1 or -1 so after
move(i, +1) segment i will be [L+1, R+1]. There are some particular
numbers which are made using 4 or 7 : any cobination of 4 and 7 are
accepted.
A tweak is a number which is lucky and belong to each segment.
we will be provided k segments and n as max number of move attempts.
we have to maximize tweak .
e.g. k =2  and n = 7
 L and R are :
40 45
47 74

maximum tweaks are: 2

42 47
44 71

tweak : 44 47 number of moves 5

I was asked this question in a coding round ? anyone suggest how to
implement this?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: coding round question

2011-10-30 Thread vikas kumar
The question was from startup company verego (may be misspelled),

you understood it in correct way.

We are given 'k' number of ranges in the fashion L, R
they are all integers in big ranges , (assume long long for the case)

then we are given move operation defined as
move( i, +1/-1)  : so range (i) will be moved to +1/-1 : (L+1/-1, R
+1/-1)
maximum number of move attempts can be 'n' provided as input

some numbers are defined as lucky , in this case interviewer said all
combinations of 4 and 7 are lucky
e.g. 4 7 47 74 447 474 .


tweak is a number which is lucky and lies in all ranges ( could be
after you have exausted all the moves )

so we need to use the move in such a way which maximize the tweaks.

He told me to write a brute force for this but even that shook me .
Can any one want to discuss what could be possible approaches for this
question ?




On Oct 30, 6:53 pm, Siddhartha Banerjee thefourrup...@gmail.com
wrote:
 could you please explain the question in a bit more detail?
 especially the partThere are some particular
 numbers which are made using 4 or 7 : any combination of 4 and 7 are
 accepted.

 from what i understand of the question, there are some intervals given...
 we can move the intervals left or right by one unit, any such movement
 counts as one move... we have to move the segments in such a way that it
 maximizes the maximum number of segments where a number can lie...the
 maximum number of moves allowed are given... is that true???

 by the way, which company's coding round was it???

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: C Question

2011-06-11 Thread vikas kumar
x is a pointer which can be changed from out side and stores the
pointers for int*

On Jun 8, 10:58 am, Vishal Thanki vishaltha...@gmail.com wrote:
 Following declaration makes the x as a volatile pointer to an integer.

 int *volatile x;

 But what does following means?

 int **volatile x;

 ~Vishal

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: intel puzzle

2011-02-24 Thread Vikas Kumar
@priyaranjan
No,Your triangle will be right angle triangle.

In fact any triangle chosen will be right angle triangle.

Proof:

suppose there are 2 planes kept at parallel with each other.(top bottom)
join corresponding vertices of up to down and form  cube.

Now 3 points chosen can be on same plane .(means 2 must be adjacent)
so right angle triangle is only possible

or at least 2 points are on same plane and 3rd point is other plane(pigeon
hole as only 2 holes are there for 3 pegions)

Now as 3 rd point always lies on perpendicular point so triagle formed will
always be right angled.

On Thu, Feb 24, 2011 at 5:23 PM, awesomeandroid
priyaranjan@gmail.comwrote:

 The only way to get an acute triangle this way is to connect the
 diagonals of three adjacent faces. You can select 3 adjacent faces of
 a cube in (6*4*2)/(3*2*1) = 8 different ways.

 Regards
 Priyaranjan
 http://code-forum.blogspot.com

 On Feb 23, 12:10 am, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
  answer is 8 ,,, duno how
 
 
 
 
 
 
 
 
 
  On Wed, Feb 23, 2011 at 12:31 AM, Sundi sundi...@gmail.com wrote:
   Is it not 8C3 = 56
 
   On Feb 22, 9:55 pm, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
Think of the 8 vertices of a given cube. You are allowed to join
 three
vertices to form a triangle. How many such unique acute triangles can
 you
make ??
 
--
With Regards,
*Jalaj Jaiswal* (+919019947895)
Software developer, Cisco Systems
B.Tech IIIT ALLAHABAD
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  With Regards,
  *Jalaj Jaiswal* (+919019947895)
  Software developer, Cisco Systems
  B.Tech IIIT ALLAHABAD

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Maths

2011-02-16 Thread Vikas Kumar
f(n)=n-1.

On Wed, Feb 16, 2011 at 7:39 PM, Akshata Sharma
akshatasharm...@gmail.comwrote:

 please help..

 if f(n+1) = max{ f(k) + f(n-k+1) + 1} for 1 = k = n; f(1)  = 0.
 Find f(n+1) in terms of n.
 Eg: f(4) = ? n = 3; 1= k = 3; f(4) = max{f(1) + f(3) + 1, f(2) +
 f(2)+1, f(3) + f(1) +1}

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Maximize the Time to see TV

2011-02-01 Thread Vikas Kumar
@Snehal

just a hint: there is no need of that channel 1  channel 2.

just treat each program as independent program.

On Mon, Jan 31, 2011 at 10:44 PM, snehal jain learner@gmail.com wrote:

 or provide some link


 On Mon, Jan 31, 2011 at 10:44 PM, snehal jain learner@gmail.comwrote:

 @ juver++

 can you please share your approach


 On Mon, Jan 31, 2011 at 8:43 PM, Divya Jain sweetdivya@gmail.comwrote:

 @ above

 ur code fails for following example
 channel 1 : prog1 8:00-9:00, prog 2 9:00-10:00
 channel 2 : prog1 8:15-10:00

 your code returns 8:15- 10
 and the answer should be channel1/prog1 + channel1/prog2




 On 21 January 2011 12:54, Anand anandut2...@gmail.com wrote:


 Sort all program with their starting time.

 Appy the below pseudo code to find max number of programs he can watch.

 for(i=i;ilen;i++)
 {
 /*Check for overlap */
if(p[i].start  p[i-1].end)
{
 end = i;
}
else
{
   /*Index of the first program to be watch*/
   if((p[i-1].end - p[i-1].start)  (p[i].end - p[i].start))
   {
  start = i;
   }
}

 }
  return end - start;


 On Thu, Jan 20, 2011 at 10:11 PM, snehal jain learner@gmail.comwrote:

 There is a TV avid person. HE wants to spend his max time on TV. There
 are N channels with different program of different length and diff
 times. WAP so that the person cam spend his max time watching TV.
 Precondition: If that person watches a program, he watches it
 completely.

 Ex:
 Channel1: prog1 – 8:00- 8:30
 prog2: 9:00 – 10:00
 prog3: 10:15 – 12:00

 channel2: prg1 – 8:15 – 10:00
 prg2: 10:30 – 12:00

 So in this case max time will be if he watches:

 ch2/prg1 + ch1/prg3

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: ReVerse a string using recursion

2010-09-24 Thread vikas kumar
use it like this

char* strrev(char *)


strrev(str)


void strrev(char *str)
{
  xstrrev(str , 0, strlen(str)); // code posted by Nishant
}

:-)

On Sep 23, 11:35 pm, albert theboss alberttheb...@gmail.com wrote:
 Ur function prototype is not similar to one i posted before

 check it out

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Inserting a box with lesser dimension into a box of bigger dimensions than that.

2010-09-22 Thread vikas kumar
you can search for box stacking problem in google. There is a DP
method.

On Sep 22, 12:11 am, Dave dave_and_da...@juno.com wrote:
 Certainly having a smaller volume is necessary for a box to fit in
 another box, but it is not sufficient. E.g., a box of size 1 x 1 x 1
 will not fit in a box of size 2 x 2 x 1/2.

 Dave

 On Sep 21, 1:16 pm, rajess rajeshrules...@yahoo.com wrote:



  find the volume of boxes as v=l*b*h
  sort boxes in volumes in descending order and this is the way to
  insert boxes one into another

  On Sep 21, 7:55 pm, Rashmi Shrivastava rash...@gmail.com wrote:

   If there are n number of boxes and each with different dimensions and your
   job is to insert one box having lesser dimension than that to another.
   Consider size of boxes as,
   b1-s1(h1,l1,w1)
   b2-s2(h2,l2,w2)
   .
   .
   .
   bn-sn(hn,ln,wn)- Hide quoted text -

  - Show quoted text -- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: ind out which row has the maximum number of 1's in 2D array

2010-09-22 Thread vikas kumar

int getMaxOneRow()
{
...int maxOne = 0, maxRow = 0;
...for (curRow=0; curRowrowSize; curRow++)
...{
..int n = getOneCount(curRow);
..if(n  maxOne)
..{
.maxOne = n;
.maxRow = curRow;
..}
...}
return maxRow;
}

int getOneCount(int row)
{
...int count =0;
...for(int i =0; icolumnSize; i++)
...{
..if(matrix[row][i] == 1)
..{
..  count++;
..}
...}
}


time complexity O(n^2)
space complexity O(1)


On Sep 21, 9:51 pm, coolfrog$ dixit.coolfrog.div...@gmail.com
wrote:
 There is a 2 dimensional array with each cell containing a 0 or 1 ,
  Design an algorithm to
 find out which row has the maximum number of 1's , Your algorithm should
 have O(n2)
 time and no space complexity.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Unbounded dictionary lookup

2010-09-22 Thread vikas kumar
we can approach it like
*lets start with index 0
if (found)  return index
else
 index += INCR_;

*we will try to increment with INCR_ until one of the following
conditions met
  index goes out of bounds
  found the words which must come after the value eg meet should
occur prior to must
  found the word itself
*after above we will get some range to be searched for and we can
apply linear or binary search to find the string

the analysis will depend on the INCR_ and n values

hence worst case complexity will be
gertWordAt complexity multiplied by
O(log INCR_ ) binary search after range selection
O(n/INCR_)   searchinh for finding the correct range

Now you might want to have some logic to determine correct INCR_ value
if your dictionary is really changing at high frequency ;)



On Sep 22, 12:53 am, Minotauraus anike...@gmail.com wrote:
 high= const.(10^const)

 What's const? The point of this isn't that it's a difficult prob to
 solve. Point lies in working with the design to make this close to log
 n.

 Define what value const holds.

 On Sep 21, 9:12 am, coolfrog$ dixit.coolfrog.div...@gmail.com
 wrote:



  its dictionary means shorted ordered arry.
  let low = 1; and high= const.(10^const)

  Boolean isWord(String word)
     {  while(low = high)
          {   mid = (low+ high)/2;
                  if(word = getWordAt(mid))
                    return true;
                 if( word  getWordAt(mid))
                     {  high = mid-1
                     }
                  else
                       low = mid+1;
           }

   }
  Its a simple Binary Search Algorithm ...
     who's complexity is O(log n) times.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: number of inversion pairs

2010-09-20 Thread vikas kumar
use a bst and insert in it reverse of array. use a count in bst node
and incr count at each right child insertion

On Sep 14, 11:00 am, Shiv ... shivsinha2...@gmail.com wrote:
 A pseudo code-
 
   int n; //= number of inputs.
   cin*a; // the inputs.

   int ** invArr;
   *inVArr[n-1] = NULL;
   //initialise all the elemnts with Null to be safe.

   for(int i = n-1; i  =0; i--) {
     for (int j = i; j  n; j++ )
     {
       if(a[i] == a[j]) {
         *invArr[i] = *invArr[j];
         break;
       }
       if( a[i]  a[j]) {
         invArr[i][0] = a[j];
         *invArr[i] + 1 = *invArr[j];
         break;
       }
     } //inner for
   }//outer for

   //print invArr;
 ==

 Please note the worst case would still be O(n^2). But I think average will
 be significantly improved.   (I will be happy if someone can do these
 calculations. :)) )

 And this is such a pseudo code. I will be grateful if someone can make this
 run-able.

 -thanks.

 On Tue, Sep 14, 2010 at 2:34 AM, Wladimir Tavares 
 wladimir...@gmail.comwrote:



  My two cents

  If you were asked in O(n log n)

  you have to modified the merge sort algorithm for count the number of
  inversion!

  Wladimir Araujo Tavares
 http://www.si.ufc.br/~wladimirhttp://www.si.ufc.br/%7Ewladimir/
  Fiz uma faculdade! Só não fiz a segunda porque acabaram os tijolos.

  On Mon, Sep 13, 2010 at 1:05 PM, sharad kumar 
  aryansmit3...@gmail.comwrote:

  linear decreasing sub sequence problem

  On Mon, Sep 13, 2010 at 9:10 PM, Raj N rajn...@gmail.com wrote:

  Given an array of n integers find all the inversion pairs in O(n)
  Inversion pair is one where a[i]a[j], ij

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

  --
  yezhu malai vaasa venkataramana Govinda Govinda

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google Interview Question

2010-09-17 Thread vikas kumar
nice recurrence

On Sep 14, 9:29 pm, Gene gene.ress...@gmail.com wrote:
 You can approach this the same way you'd do it by hand.  Build up the
 string of brackets left to right.  For each position, you have a
 decision of either ( or ) bracket except for two constraints:
 (1) if you've already decided to use n left brackets, then you can't
 use a another left bracket and
 (2) if you've already used as many right as left brackets, then you
 can't use another right one.

 This suggests the following alorithm. Showing what happens on the
 stack is a silly activity.

 #include stdio.h

 // Buffer for strings of ().
 char buf[1000];

 // Continue the printing of bracket strings.
 //   need is the number of ('s still needed in our string.
 //   open is tne number of ('s already used _without_ a matching ).
 //   tail is the buffer location to place the next ) or (.
 void cont(int need, int open, int tail)
 {
   // If nothing needed or open, we're done.  Print.
   if (need == 0  open == 0) {
     printf(%s\n, buf);
     return;
   }

   // If still a need for (, add a ( and continue.
   if (need  0) {
     buf[tail] = '(';
     cont(need - 1, open + 1, tail + 1);
   }

   // If still an open (, add a ) and continue.
   if (open  0) {
     buf[tail] = ')';
     cont(need, open - 1, tail + 1);
   }

 }

 void Brackets(int n)
 {
   cont(n, 0, 0);

 }

 int main(void)
 {
   Brackets(3);
   return 0;

 }

 On Sep 14, 10:57 am, bittu shashank7andr...@gmail.com wrote:



  Write a function Brackets(int n) that prints all combinations of well-
  formed brackets. For Brackets(3) the output would be ((())) (()()) (())
  () ()(()) ()()()

  with explaination dat is at every call what is contant of stack during
  pushing and popping- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Yahoo Question

2010-09-17 Thread vikas kumar
@Bittu
I am confused about one point you need to process atleast n*k
elements so how will you do it in nlogk time. It seems really
tricky if possible.it's min time should be O(nk). correct me if I
am wrong.

On Sep 17, 6:34 am, tkcn tkcna...@gmail.com wrote:
 Use k-way merging +1.

 1. Before the merging start, sorting these lists according to the
 first element of each list.  // O(k log k)
 2. So the first element in the first list is the smallest element. Put
 the smallest into the result array. // O(1)
 3. Then, using binary search to find the new position of the first
 list  // O(k)
 4. These lists are still sorted, so the first element in the first
 list is still smallest. Just repeat the step 2, 3 n times.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Amazon Question

2010-09-17 Thread vikas kumar
struct list
{
 median -- median from the start to num
 number ---number
list *next
};

during insertion : insert in sorted LL
after that all subseq node's median has to be modified
O(n)
during median_retriev
check the median value and return that
O(1)

I assumed deletion is not happening. if supported , can be done in
O(n)

On Sep 15, 8:24 pm, bittu shashank7andr...@gmail.com wrote:
 Propose a data structure that would store numbers, without any
 knowledge about them, and allow to perform the operations: insert, get
 median, as efficiently as possible same as before, only this time the
 numbers are from a group V, which is |V|n

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Drawing a graph

2010-09-17 Thread vikas kumar
use opengl library to draw the graph or whatever. take RED BOOK for
reference.

On Sep 14, 5:54 pm, Mithun avmit...@gmail.com wrote:
 Can anyone help me with the code for drawing a graph in C or CPP
 (using graphics)

 Input is an Adjacency matrix

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google Interview Question-Snake and Ladder Design

2010-09-17 Thread vikas kumar
take this approach

fill array of snakes starting position in snake[num_snake]

for each snake[i] , take the end of snake and fill in some other array
take random number gen and fill these arrays--
e.g. end_snake[i] = ran(start_snake[i]-10) // so that snake does not
end up in same row

same logic for ladders

after filling check snake start/end /ladder start/end are not
coinciding

after that u need to make dice object and again ran will come to
rescue :)

now current pos of board can be controlled using player color and
board array
incr /decr  using dice move and snake start/end, ladder start/end
array





On Sep 15, 2:38 am, Minotauraus anike...@gmail.com wrote:
 And please stop posting the same thing twice. It's been happening for
 the past couple of days at least.

 @Question:
 I think you can use graphs and flood fill algo for this. Every
 possible move can be represented with an edge. Flood fill will help
 you figure out possible moves from you current position.

 What do you think?

 On Sep 14, 2:51 am, ankur aggarwal ankur.mast@gmail.com wrote:



  @bittuu
  write your algo then code

  On Tue, Sep 14, 2010 at 1:36 PM, bittu shashank7andr...@gmail.com wrote:
   #includestdlib.h
   #includestdio.h
   #includemath.h
   #includeconio.h

   int turn, square;
   long game, totalgames;
   int seed;
   int chutehit[10], ladderhit[9];
   float RunningTurnTotal;
   float average;

   char reply;

   void ChuteStats()
   {printf(Chute and Ladder Statistics:\n\n);

   printf(Chute0: %d     Ladder0: %d\n, chutehit[0], ladderhit[0]);
   printf(Chute1: %d     Ladder1: %d\n, chutehit[1], ladderhit[1]);
   printf(Chute2: %d     Ladder2: %d\n, chutehit[2], ladderhit[2]);
   printf(Chute3: %d     Ladder3: %d\n, chutehit[3], ladderhit[3]);
   printf(Chute4: %d     Ladder4: %d\n, chutehit[4], ladderhit[4]);
   printf(Chute5: %d     Ladder5: %d\n, chutehit[5], ladderhit[5]);
   printf(Chute6: %d     Ladder6: %d\n, chutehit[6], ladderhit[6]);
   printf(Chute7: %d     Ladder7: %d\n, chutehit[7], ladderhit[7]);
   printf(Chute8: %d     Ladder8: %d\n, chutehit[8], ladderhit[8]);
   printf(Chute9: %d                \n, chutehit[9]);
   }

   int main()
   {
   printf(Welcome to the Chutes and Ladders simulation \n);
   printf(...\n);
   srand(1);

   //printf(How many games would you like me to run? __ );
   //scanf(%i,totalgames);
   ///printf(\n You have chosen to run %i games... thank you! \n,
   totalgames);

   totalgames+=2;
   RunningTurnTotal=0.0;
              game=1;
          do{

          turn=0;
                  square=0;                             /** Reset game **/
           do                                           /** Begin game loop
   **/

                  {
              ++turn;
              RunningTurnTotal = RunningTurnTotal + 1;

              square = square + 1 + rand()%6;       /** Spin and move
   **/

                  printf(square =%d \n,square);

                  if (square == 1) {square=23; ++ladderhit[0];} /** Ladders?
   **/
                  if (square == 4) {square=14; ++ladderhit[1];}
                  if (square == 9) {square=31; ++ladderhit[2];}
                  if (square == 21) {square=42; ++ladderhit[3];}
                  if (square == 28) {square=84; ++ladderhit[4];}
                  if (square == 36) {square=44; ++ladderhit[5];}
                  if (square == 51) {square=67; ++ladderhit[6];}
                  if (square == 71) {square=91; ++ladderhit[7];}
                  if (square == 80) {square=100;++ladderhit[8];}/// so when 
   80
   comes raech to our goal exit

                  if (square == 98) {square=78; ++chutehit[0];} /** Chutes ?
   **/
                  if (square == 95) {square=75; ++chutehit[1];}
                  if (square == 93) {square=73; ++chutehit[2];}
                  if (square == 87) {square=24; ++chutehit[3];}
                  if (square == 62) {square=19; ++chutehit[4];}
                  if (square == 64) {square=60; ++chutehit[5];}
                  if (square == 56) {square=53; ++chutehit[6];}
                  if (square == 49) {square=11; ++chutehit[7];}
                  if (square == 48) {square=26; ++chutehit[8];}
                  if (square == 16) {square=6; ++chutehit[9];}

         } while (square100);//terminate if random no. is  100

         printf(\n\n Game over after %d turns\n, turn);
         printf(\nSimulation complete... beginning statistical
   analysis...\n\n);
        printf(Total number of games played: %d \n, game);
        printf(Total number of turns: %f \n, RunningTurnTotal);
        average = RunningTurnTotal / game;
        printf(Avg number of turns per game: %f \n, average);
        printf(\n);
        ChuteStats();
        printf(\n);

           ++game;
           printf(\n\n Would you like to run the simulation again?
   (1=Yes)...);
           scanf(%i,reply);
           if(reply==1)//e.g. reply==1
           totalgames+=1;
           else
           exit(0);// exit

    } while 

[algogeeks] Re: Amazon intern Question

2010-09-04 Thread vikas kumar
I think Gene is right. they are asking more than search here. Thanks
to Gene for suggesting this idea :)
now the how part,
   we can have a level of abstraction:
   no of products matching to name --- use trie, suffix tree, some
genetic algo,  string matching, ms tree..
   based on products get first abstraction like: category --- like
video, audio,  and display most preferred products also from that
category in sub format
 .




On Sep 2, 6:40 am, Gene gene.ress...@gmail.com wrote:
 Even if you're only matching words, there are different kinds of
 similarity.  Check out the soundex algorithm, for example. Levenshtein
 distance.  The Hungarian algorithm.  What does 50% similarity mean
 anyway?  I know of no accepted meaning.

 My point is that if you're in an interview situation and you ask
 intelligent questions about the question you're asked, you are more
 likely to get the job.  At least I would be more likely to give it to
 you.  I've been responsible for hiring quite a few people.

 On Sep 1, 11:52 am, Chakravarthi Muppalla chakri...@gmail.com wrote:



  @Gene, it isn't about related words, its abt matching words!

  On Wed, Sep 1, 2010 at 8:26 PM, saurabh singh saurabh.n...@gmail.comwrote:

   I think DS will be somewhere between suffix and trie DS

   On Wed, Sep 1, 2010 at 9:35 AM, jaladhi dave 
   jaladhi.k.d...@gmail.comwrote:

   trie

   On Wed, Sep 1, 2010 at 5:45 PM, Arun yourarunb...@gmail.com wrote:

   You are given the amazon.com database which consists of names of
   millions of products. When a user enters a search query for particular
   object with the keyword say foo , output all the products which have
   names having 50% or more similarity with the given keyword ie foo

   Write the most efficient algorithm for the same.

   --
   You received this message because you are subscribed to the Google 
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups
.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

    --
   You received this message because you are subscribed to the Google Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups
.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

   --
   Thanks  Regards,
   Saurabh

   --
   You received this message because you are subscribed to the Google Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups
.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

  --
  Thanks  Regards,
  Chakravarthi.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Subsequence

2010-08-25 Thread Vikas Kumar
can you define what here subsequence means?

On Wed, Aug 25, 2010 at 9:32 PM, Rahul rv.wi...@gmail.com wrote:

 @Jaswanth
 It will be really kind if you will state the algorithm rather than
 providing codes, as it is tedious.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Linked List

2010-08-19 Thread vikas kumar
you are right in the way in cpp code it is not required but in C , you
can not write like node * start. it only recognise new type when
typedef is applied. second one is already explained by vijay

On Aug 18, 6:16 pm, Vijay kvija...@gmail.com wrote:
 1. typedef is used to rename the data type. Here struct node is actual
 data type of linked list node and is renamed to NODE using
 typedef .Instead of using struct node each time we   declares a new
 node variable we can use simply NODE.

 2.**start is required if you pass actual parameter as address,
                 suppose NODE *temp = (NODE *) malloc (sizeof(NODE));
 is the new node created; and you have to use the following function
 call

                      createemptylist(temp);

                 It is important to pass this by address as changes
 made in the called function should be reflected on the linked list.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: how to implement TAIL command of unix.

2010-08-16 Thread vikas kumar
the method of farword seek is inefficient. consider case of 10
lines and you want to display only 3-4 lines. better seek from end.

use a buffer[buf_size].

let size =filesize.
lc = 0;
while(lc = given line input)
{
fseek(fp, size);
if(size  buf_size)
  fread(fp, size, buffer);
else
  fread(fp, size, buf_size);

parse buf_size for '\n'
 if( \n is in buffer )
   increment line counter(lc ++)
if(size  buf_size)
   size -= buf_size
}

// you know the size, read the buffer one by one and print it
OR
// you could have put them while reading on to stack and print it out
now


On Aug 15, 8:46 am, Dave dave_and_da...@juno.com wrote:
 Enter the lines into a FIFO queue as you read them. After you have
 enqueued n lines, dequeue a line every time you enqueue one, so that
 the queue will contain the last n (or fewer) lines of the file.

 Dave

 On Aug 13, 1:13 pm, amit amitjaspal...@gmail.com wrote:



  I am trying using fseek but somehow its not working?- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Dynamic Programming Problem on Strings

2010-08-13 Thread vikas kumar
what about printing these strings onto terminal. can printing of the
string is also similar. I tried to develop the algo but got messed
up.can some one help?

On Aug 8, 2:53 am, Amir hossein Shahriari
amir.hossein.shahri...@gmail.com wrote:
 @ankur: dp[i][j] number of (prefix) strings that have i As and j Bs is:
 dp[i-1][j] number of (prefix) strings that have i-1 As and j Bs appended by
 A
 +
 dp[i][j-1] number of (prefix) strings that have i As and j-1 Bs appended by
 B

 @ashish: wikipedia has some nice proofs for catalan number formula:
 en.wikipedia.org/wiki/Catalan_number

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: interesting c++ questions

2010-08-04 Thread vikas kumar
1) Yes ofcourse
2) yes you can
3) yes ofcourse
4) yes
5) i dont think . May we our default constructor def not matching ;)

On Aug 3, 8:42 pm, Raj N rajn...@gmail.com wrote:
 1) Can a constructor call another constructor to initialize the same
 object?
 2) Can a struct variable be assigned to another if the structure
 contains an array as a field?
 3) Can we pass a private member by reference to a non member function?
 4) Can the destructor be called explicitly?
 5) Can copy constructor be the default constructor of a class?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Amazon Placement Question

2010-08-02 Thread vikas kumar
driver(Tree *root)
{
   node *array = malloc(sizeof(node *) *H ); /* take the height node
pointer array. this will act as source pointer of each list */
   makeList(root, 0, array)
}

makeList(Tree *root, int level, node *array)
{
   if(! root) return ;

  /*do a Depth traversal and store the list pointer*/
  append(array[level], root);

  /*Traverse the left and right subtrees and store them in list*/
  makeList(root-left, level+1, array);
  makeList(root-right, level+1, array);
}

time complexity is O(n) space complexity O(log n)
( assuming append has O(1) complexity)


On Aug 1, 2:26 am, Nikhil Jindal fundoon...@yahoo.co.in wrote:
 @Ram Kumar: Yes. Simple and affective.

 Just at each node:

 node-left-side=node-right
 node-right-side=node-side-left

 i.e at each node you are setting the side of each of your child. Go on and
 just do it for all nodes. Done.

 On Sat, Jul 31, 2010 at 9:39 AM, Ram Kumar harrypotter@gmail.comwrote:





  DONT DO A BFS!! NOT WORTH IT! CALL THE NEW POINTER AS 'SIDE' POINTER.

  for every root connect its left and right, for every root connect
  root-right and root-SIDE-left

  that ll do

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 Please access the attached hyperlink for an important electronic 
 communications 
 disclaimer:http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php- Hide 
 quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: number of BST's

2010-07-31 Thread vikas kumar
int countTree(int num)
{
   if(num = 1) return 1;
   int sum =0;
   for(i =1; inum; ++i)
   {
  left = countTree(i-1);
  right = countTree(num - i);
  sum += left*right;
   }

  return sum;
}

The code snippet is self explanatory. Let me know if any difficulty.

On Jul 30, 11:28 am, Pramod Negi negi.1...@gmail.com wrote:
 Follow up on Catalon Nubmer...

 On Fri, Jul 30, 2010 at 10:44 AM, Amit Jaspal amitjaspal...@gmail.comwrote:



  n is clearly a number lets say 3 then BST's with 1,2,3 values as key are to
  be calculated

  On Fri, Jul 30, 2010 at 9:08 AM, Apoorve Mohan 
  apoorvemo...@gmail.comwrote:

  @AMIT: what does n represents?

  On Fri, Jul 30, 2010 at 5:46 AM, sharad kumar 
  aryansmit3...@gmail.comwrote:

  @amit is it BST or binary tree??cos BST is unique rite???binary tree meas
  use catalan numbers 2nCn/(n+1)!

  On Thu, Jul 29, 2010 at 9:56 PM, amit amitjaspal...@gmail.com wrote:

  Given the numbers from 1 to n, write an algorithm to find how many
  distinct binary search trees can be formed.. eg n=4, no of distinct
  bst's are 14. ??

  --
  You received this message because you are subscribed to the Google
  Groups Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

  --
  yezhu malai vaasa venkataramana Govinda Govinda

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

  --
  regards

  Apoorve Mohan

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

  --
  Amit Jaspal
  Btech IT IIIT- Allahabad

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups­.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Merging of Binary trees

2010-07-27 Thread vikas kumar
if it is a simple BT then you can simply attach the root to either
child ( which is null ) of other tree . just simply go leftmost and
then assign root of other tree as left child, as suggested by Gene.

On Jul 27, 8:23 am, Gene gene.ress...@gmail.com wrote:
 You actually only need a singly linked list.  See and old discussion
 about this at

 http://groups.google.com/group/comp.programming/msg/41f46b2801c4f84e

 This will do the job in O(n).

 On Jul 26, 11:00 pm, Ashish Goel ashg...@gmail.com wrote:



  Jalaj,

  How do you convert a Circular DLL to BST??
  Please refer my solution, and coorect it if needed;)

  Regards
  Ashish

  On 7/26/10, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:

   suppose both trees contains n nodes
   then converting to dll both the trees O(n) + O(n)
   then merging two dll's O(n)
   converting back to tree also O(2*n)=O(n)..// not sure about it

   code for converting tree to dll
   node * bsttolist(node *root){
             if(root==NULL) return NULL;
             node *l=bsttolist(root-left);
             node *r=bsttolist(root-right);
             root-left=root;
             root-right=root;
             append(l,root);
             append(l,r);
             return l;
   }

   here append function merges two circular doubly linked lists , you can 
   make
   that on your own

   On Mon, Jul 26, 2010 at 5:52 PM, Manjunath Manohar 
   manjunath.n...@gmail.com
   wrote:

   @jalaj: could u pls elaborate on that a bit more..will it have the
   complexity of O(n logn logn), and also can u provide the pseudocode pls..

   --
   You received this message because you are subscribed to the Google Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups
.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

   --
   With Regards,
   Jalaj Jaiswal
   +919026283397
   B.TECH IT
   IIIT ALLAHABAD

   --
   You received this message because you are subscribed to the Google Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

  --
  Best Regards
  Ashish Goel
  Think positive and find fuel in failure
  +919985813081
  +919966006652
  Ho- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Merging of Binary trees

2010-07-26 Thread vikas kumar
are you asking for BST or simple BT. what are the conditions you want
to follow if simple BT

On Jul 26, 12:59 am, AlgoBoy manjunath.n...@gmail.com wrote:
 Does anyone know how to merge two binary trees in O(n logn logn)
 complexity..
 intiutive solution is to flatten both the trees (by inorder
 traversal ) and then construct a new one...
 but how to do this efficiently in O(n logn logn)..pls help

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-14 Thread vikas kumar
Thanks Amit and srikanth for pointing that out. I should have done
some analysis before posting this solution.
we can do this problem in 2 steps:
find-min-diff(arr a)
{
   sort(a)
   find(a, 0, min=INF, i=0, j=0)
   return {min, i, j}
}

find(a, index, min, i, j)
{
   if(a[index+1] - a[index]   min){
  min = a[index+1] - a[index];
  i= index, j= index+1
   }
   find(a, index+1, min, i, j)
}

run time -- sorting time + O(n)
space-- sorting complexity + O(1)

Let us discuss if we can do it without sorting the array elements.

I have one more question here , suppose we have some dynamic array
( of const size ) where insertions and removal is happening
dynamically ---
you want the 2 elements from the array having least difference. Design
a data structure for this. Less than O(n) solution appreciated.

On Jul 14, 9:27 am, Ashish Goel ashg...@gmail.com wrote:
 count sort and then find mindiff

 fot (int i=1;in;i++)
 if (a[i]-a[i-1] mindiff) { mindiff =a[i]-a[i-1]; ele1=a[i-1]; ele2=a[i];}

 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

 On Tue, Jul 13, 2010 at 2:47 PM, Tech Id tech.login@gmail.com wrote:
  Construct a BST for the array - O(nlogn)
  Traverse the tree and find a node which has
  minimum difference with either its left or
  right child in whole of the tree.
  (Because the required numbers have to be
  adjacent to each other in a sorted array). - O(n)

  = Total order:O(nlogn)

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
traverse array with 2 elements keeping track of 2 min elements. time
O(n) space O(1)

On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
 Constraint - O(n)

 On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
  Given an array of size n.find 2 numbers from array whose difference is
  least.

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 Amit Jaspal
 Btech IT IIIT- Allahabad

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: There are 2 type of values - 1 byte and 2 byte given a pointer to any point in the string tell me if its a 1B or 2B value ending there. MSB of 1-byte character is 0 and MSB of 2-byte

2010-07-12 Thread vikas kumar
is it something different than this

   foo(char *p, int num)
   {
if(!p) return error


if(num  0  p[num-1] == 0) print  2 byte value
else
 print 1 byte value
   }

On Jul 11, 11:18 pm, Tech Id tech.login@gmail.com wrote:
 Question is not clear to me :(
 Can you explain a little more and also give an example if possible?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
traverse array with 2 elements keeping track of 2 min elements. time
O(n) space O(1)

On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
 Constraint - O(n)

 On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
  Given an array of size n.find 2 numbers from array whose difference is
  least.

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 Amit Jaspal
 Btech IT IIIT- Allahabad

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
I did not get your point.
for 2 6 3 7
min 2
sec min 3
difference is 1
answer is 2 and 3
what more is asked??

On Jul 12, 2:21 pm, srikanth sg srikanthini...@gmail.com wrote:
 2 6 3  7
 check for this

 On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.comwrote:

  traverse array with 2 elements keeping track of 2 min elements. time
  O(n) space O(1)

  On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
   Constraint - O(n)

   On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
Given an array of size n.find 2 numbers from array whose difference is
least.

--
You received this message because you are subscribed to the Google
  Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com

.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

   --
   Amit Jaspal
   Btech IT IIIT- Allahabad

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Find the next number for a given number without using any arithmetic operators(use bit operations)

2010-06-25 Thread vikas kumar
adder with add value 1

On Jun 24, 8:30 pm, jaladhi dave jaladhi.k.d...@gmail.com wrote:
 Another approach :http://codepad.org/CqKIZJeO

 On Thu, Jun 24, 2010 at 7:31 PM, mohit ranjan shoonya.mo...@gmail.comwrote:

  @Dave

  Can u plz explain the logic behind this..

  Mohit

  On Thu, Jun 24, 2010 at 12:44 AM, Dave dave_and_da...@juno.com wrote:

  c = 1
  repeat
     d = n and c
     n = n xor c
     c = d left shifted by 1
  until c = 0

  Dave

  On Jun 23, 11:05 am, vijay auvija...@gmail.com wrote:
    Find the next number for a given number without using any arithmetic
   operators(use bit operations)

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Find the next number for a given number without using any arithmetic operators(use bit operations)

2010-06-25 Thread vikas kumar
adder with add value 1

On Jun 24, 8:30 pm, jaladhi dave jaladhi.k.d...@gmail.com wrote:
 Another approach :http://codepad.org/CqKIZJeO

 On Thu, Jun 24, 2010 at 7:31 PM, mohit ranjan shoonya.mo...@gmail.comwrote:

  @Dave

  Can u plz explain the logic behind this..

  Mohit

  On Thu, Jun 24, 2010 at 12:44 AM, Dave dave_and_da...@juno.com wrote:

  c = 1
  repeat
     d = n and c
     n = n xor c
     c = d left shifted by 1
  until c = 0

  Dave

  On Jun 23, 11:05 am, vijay auvija...@gmail.com wrote:
    Find the next number for a given number without using any arithmetic
   operators(use bit operations)

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.