[algogeeks] Re: Directi Written Q 2012

2012-07-30 Thread Zyro
int func(int start,int end)
{
   int count=0;
   for(int i=start;i=end;i++)
{ 
   int tmp=i;
   while(tmp!=0)
   {
  tmp=tmp(tmp-1);
  count++;
   }
   }
  return count;
}

Worst Case complexity : O((b-a)*32)

Please let me know if there is another gud way to do it.. :) 

On Tuesday, 24 July 2012 15:09:42 UTC+5:30, ruru wrote:

 find no. of 1's in binary format of numbers from 1 to 100. like for 
 1 to 10 answer is 17 


On Tuesday, 24 July 2012 15:09:42 UTC+5:30, ruru wrote:

 find no. of 1's in binary format of numbers from 1 to 100. like for 
 1 to 10 answer is 17 


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/WrMDDsQp1BoJ.
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: Write a C program to reconstruct a BST from a given array of preorder traversal.

2012-07-05 Thread Zyro


 @Navin : Why r u sorting the array .. BST can be made using the preorder 
 traversal if null nodes are well defined in the given traversal.. Right??


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/VCvNv0yZtxMJ.
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: Write a C program to reconstruct a BST from a given array of preorder traversal.

2012-07-05 Thread Zyro
??

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/HQ_TvoKSLNgJ.
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: simple FILE reading problem.

2012-07-05 Thread Zyro
@Navin : Read a line .. store it in a string .. then extract numbers frm 
it.. It will be more faster i think.. :)
On Wednesday, 4 July 2012 22:44:04 UTC+5:30, Navin Kumar wrote: 

 Suppose a file.txt contains : 50 40 30 # # 5 # 10 # #

 i want to fetch only integers. How should i fetch it. I tried with fgetc 
 and fscanf but it was too complicated.

 My approach: fetched one word at a time and put it into separate string 
 and then i converted that string to integer(if each character of that 
 string was between '0' to '9').

 Is there any simple way to do this. 
  


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/sR5uBPpS2HQJ.
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: Represent a number in base of minus 2 ????

2012-01-30 Thread Zyro
@Sharad..  Thanx..   :)

On Jan 31, 2:42 am, sharad dixit sharad.emine...@gmail.com wrote:
 @zyro May be this solves your problem...

 #include iostream

 using namespace std;

 int main()
 {
     int no;
     char digit[50];

     int counter=0;
     cin  no;

     do {
         if ( no% 2 == 0) {
             digit[counter++]='0';
         }
         else
         {
             digit[ counter++ ]='1';
         }

         if ( no  0 ){
             no = (1 - no)/2;
         }
         else if(no0){
             no = -no/2;
         }

     }
     while ( no );

     for ( int i = counter- 1; i = 0; i--) {
         cout  digit[ i ] ;
     }
     cout  endl;
     return 0;









 }
 On Sun, Jan 29, 2012 at 8:51 PM, saurabh singh saurab...@gmail.com wrote:
  Use a pen and paper:) Generate a few numbers in base -2 by hand.You
  will get the logic.
  Saurabh Singh
  B.Tech (Computer Science)
  MNNIT
  blog:geekinessthecoolway.blogspot.com

  On Sun, Jan 29, 2012 at 11:44 PM, Zyro vivkum...@gmail.com wrote:

  0

   --
  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.

 --
 -Sharad Dixit
  B.Tech(IT)
  Indian Institute of Information Technology Allahabad
 --- 
 --
 We aim above the mark to hit the mark.
 ~ Ralph Waldo Emerson

-- 
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] Represent a number in base of minus 2 ????

2012-01-29 Thread Zyro
Write a function that takes an integer and returns a char array that
contains the -2 (minus 2) base representation of the given integer.
Example:
Input Output
7 11011
3 111
2 110

Plzzz  help  ???

-- 
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: Represent a number in base of minus 2 ????

2012-01-29 Thread Zyro
@Anika

7 = 1*((-2)^4) + 1*((-2)^3) + 0*((-2)^2) + 1*((-2)^1) + 1*((-2)^0) ...

simlilary for other numbers...


-- 
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: Problem

2011-11-19 Thread Zyro
@all : Thanks  :)

On Nov 19, 3:55 pm, Amol Sharma amolsharm...@gmail.com wrote:
 that's what i was saying :)
 --

 Amol Sharma
 Third Year Student
 Computer Science and Engineering
 MNNIT Allahabad
  http://gplus.to/amolsharma99
 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99

 On Sat, Nov 19, 2011 at 2:10 PM, shady sinv...@gmail.com wrote:
  sorry, we don't need to do so much computation minimizing the
  difference of the maximum and minimum array in the selected array is
  the solution.
  difference will always be = largest element - smallest element

  On Nov 19, 1:20 pm, shady sinv...@gmail.com wrote:
   aim : minimize the sum of elements of a sorted set of size k.
   mehdi's solution is correct,
   1. sort the whole array,
   2. and then as you add new element to the set
      a. delete the oldest element added along with its difference
      b. add the difference of the newly added element.

   O(nlogn)

   On Nov 19, 11:36 am, Zyro vivkum...@gmail.com wrote:

sorry...minimize sum of the difference between the elements of the
subset..

On Nov 19, 10:03 am, shady sinv...@gmail.com wrote:

 what do you mean by difference among them ?
 do we need to select the elements to minimize the sum between
 consecutive elements ? or only the first and last element ?

 On Nov 18, 6:30 pm, Zyro vivkum...@gmail.com wrote:

  Q: Select the K elements in an array of size N which are having the
  minimum difference among them?
  For Example : If you have an array like arr[]={9,5,2,6,3,11} and
  value
  of K is 3. Then ans would be {2,3,5}.

  --
  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.



[algogeeks] Problem

2011-11-18 Thread Zyro
Q: Select the K elements in an array of size N which are having the
minimum difference among them?
For Example : If you have an array like arr[]={9,5,2,6,3,11} and value
of K is 3. Then ans would be {2,3,5}.

-- 
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: Problem

2011-11-18 Thread Zyro
sorry...minimize sum of the difference between the elements of the
subset..

On Nov 19, 10:03 am, shady sinv...@gmail.com wrote:
 what do you mean by difference among them ?
 do we need to select the elements to minimize the sum between
 consecutive elements ? or only the first and last element ?

 On Nov 18, 6:30 pm, Zyro vivkum...@gmail.com wrote:

  Q: Select the K elements in an array of size N which are having the
  minimum difference among them?
  For Example : If you have an array like arr[]={9,5,2,6,3,11} and value
  of K is 3. Then ans would be {2,3,5}.

-- 
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: Problem

2011-11-18 Thread Zyro
The Sum of the difference in the Subset  containing the K elements
must be minimum...
As in above example  {9,5,2,6,3,11} where K=3
In case of {2,3,5}
3-2=1
5-3=2
sum of the difference is 3...In all other subsets we cant have sum of
the difference  less than 3...so {2,3,5} is the required answer.

On Nov 19, 10:03 am, shady sinv...@gmail.com wrote:
 what do you mean by difference among them ?
 do we need to select the elements to minimize the sum between
 consecutive elements ? or only the first and last element ?

 On Nov 18, 6:30 pm, Zyro vivkum...@gmail.com wrote:

  Q: Select the K elements in an array of size N which are having the
  minimum difference among them?
  For Example : If you have an array like arr[]={9,5,2,6,3,11} and value
  of K is 3. Then ans would be {2,3,5}.

-- 
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.