Re: [algogeeks] fastest sequential access

2012-11-21 Thread vishal chaudhary
singly linked list

On Wed, Nov 21, 2012 at 8:21 PM, shady sinv...@gmail.com wrote:

 which data structure among the follow has fastest sequential access ?
 i)   vector
 ii)  Singly linked list
 iii) Doubly linked list

 it won't be doubly linked list as it involves more pointer manipulations
 than singly linked list...

 --




-- 




Re: [algogeeks] Array Problem

2012-11-15 Thread vishal chaudhary
Hi
you can first sort the array which can be done in O(nlogn) complexity if
the number of items in the array is n.
Then using the indexing of arrays you can divide the array into two groups
whose difference is going to be maximum and this can be done in O(1)
complexity.
So the complete algorithm is going to take O(nlogn) complexity.
Kindly share an alternative algorithm if you find  one with lower
complexity.

Vishal

On Wed, Nov 7, 2012 at 7:43 PM, Arun Kindra reserve4placem...@gmail.comwrote:

 Given an unsorted array, how to divide them into two equal arrays whose
 difference of sum is minimum.

 --
 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] Array Problem

2012-11-15 Thread vishal chaudhary
Hi
Sorry for that as i misinterpreted the question.
for the difference to be minimum, i think(not completely sure) we can first
sort the array
and then we can start putting the elements at even index in the last part
of the array and the odd ones in the starting in the new array
you can do this in the same array itself i guess but you have to do some
kind of shifting.
by doing this for all the elements and dividing them into two groups.
I hope this helps.

Vishal


On Fri, Nov 16, 2012 at 9:46 AM, bharat b bagana.bharatku...@gmail.comwrote:

 @ vishal : how can u divide an array into 2 groups whose difference is
 maximum in O(1). why max?

 solution : http://www.youtube.com/watch?v=GdnpQY2j064




 On Fri, Nov 16, 2012 at 9:22 AM, vishal chaudhary 
 vishal.cs.b...@gmail.com wrote:

 Hi
 you can first sort the array which can be done in O(nlogn) complexity if
 the number of items in the array is n.
 Then using the indexing of arrays you can divide the array into two
 groups whose difference is going to be maximum and this can be done in O(1)
 complexity.
 So the complete algorithm is going to take O(nlogn) complexity.
 Kindly share an alternative algorithm if you find  one with lower
 complexity.

 Vishal


 On Wed, Nov 7, 2012 at 7:43 PM, Arun Kindra 
 reserve4placem...@gmail.comwrote:

 Given an unsorted array, how to divide them into two equal arrays whose
 difference of sum is minimum.

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


  --
 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] increment operator...

2012-11-06 Thread vishal chaudhary
Hi anil

first of all when the program starts k = 5
then compiler enters if region
then k is incremented before it is compared with 5 ie k = 6
then condition is checked ie ++k  5 and it comes out to be false
then as it was end operation compiler does not evaluate the second
statement ie k++/5
then it goes for or and increments the k variable and then k = 7
then it finds that condition k=8 to be true.
now one of the condition in the or is true and it then prints the value of
k as 7
hope this helps u.

Vishal Chaudhary

2012/11/6 Anil Sharma anilsharmau...@gmail.com

 main()
  {
   int k = 5;
   if (++k  5  k++/5 || ++k = 8);
   printf(%d , k);
  }

 the output shud be 8 but it comes out to be 7.why???
 as increment operator has higher precedence among them so increment shud
 be done throughout at first and after then other operators shud be
 evaluated.sooutput shud be 8.

 --
 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] Check if a binary tree is Binary Search Tree or not.

2012-11-05 Thread vishal chaudhary
hi all,
yes you can do it that way, but the thing is why are you increasing the
complexity of the problem by again checking the inorder traversal output to
be checked for increasing order.
just traverse through the ones recursively(as we do it in the inoder
traversal) through all the nodes and check whether the left child is less
than the root and root is smaller than the right node.


Warm Regards
Vishal Chaudhary
BE(Hons) Computer Science and Engineering
BITS Pilani





On Tue, Nov 6, 2012 at 12:34 AM, shady sinv...@gmail.com wrote:

 Hi,
 Can we check this by just doing an inorder traversal, and then checking if
 it is in increasing order or not ?

 --
 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] Virtual functions in constructor

2012-10-10 Thread Kumar Vishal
  FYI ..
 http://www.artima.com/cppsource/nevercall.html
 If you read the VTABLE and and how virtual function is implemented then
 you understand automatically why virtual is not applicable in constructor
 case .
 One more request its algo-group please try to avoid out of the topic
questions .
 Thanks
 Kumar Vishal



On Wed, Oct 10, 2012 at 2:16 AM, rahul sharma rahul23111...@gmail.comwrote:

 Guys i have read that concept of virtual fxn is not applicable in case of
 constructors..I means using virtual function in constructors always call
 local function..i wan to read more on this..can nybody explain use of
 virtual functions in constructor or provide me with a link for this..

 thnx

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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Finding top 10 most frequent repeated word

2012-09-08 Thread Kumar Vishal
   if it can be loaded we can use map , else look for external sorting
   coming to second point it dynamically changing leads lot of
  other questions before going give algo .

On Sat, Sep 8, 2012 at 7:43 PM, Navin Kumar algorithm.i...@gmail.comwrote:

 Given a file which has billions of words and file can  be loaded in
 memory. Now find 10 most frequent words in file. What if file is
 dynamically changing means words are continuously added to it.

 What if file cant be loaded in memory.

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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Gate complaxity question

2012-08-25 Thread vishal yadav
Because you can always find a positive constant c for which following
inequality hold true.
  A(n) = cW(n) i.e. the avg. case time complexity always upper bounded by
worst case time complexity. Which is the definition of Big O.

On Sat, Aug 25, 2012 at 7:11 PM, rahul sharma rahul23111...@gmail.comwrote:

 *Let w(n) and A(n) denote respectively, the worst case and average case
 running time of an algorithm executed on an input of size n. which of the
 following is ALWAYS TRUE?*
 (A) [image: A(n) = \Omega(W(n))]
 (B) [image: A(n) = \Theta(W(n))]
 (C) [image: A(n) = O(W(n))]
 (D) [image: A(n) = o(W(n))]

 answer is c

 plz explain y???

 --
 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] Gate complaxity question

2012-08-25 Thread vishal yadav
You have to discard option d because , according to definition of small o
notation if f(n) =o(g(n)) then for ALL constants c 0 you have f(n) 
cg(n). or Lim(n-infinite) f(n)/g(n) = 0.

On Sat, Aug 25, 2012 at 10:24 PM, vishal yadav vishalyada...@gmail.comwrote:

 Because you can always find a positive constant c for which following
 inequality hold true.
   A(n) = cW(n) i.e. the avg. case time complexity always upper bounded by
 worst case time complexity. Which is the definition of Big O.

 On Sat, Aug 25, 2012 at 7:11 PM, rahul sharma rahul23111...@gmail.comwrote:

 *Let w(n) and A(n) denote respectively, the worst case and average case
 running time of an algorithm executed on an input of size n. which of the
 following is ALWAYS TRUE?*
 (A) [image: A(n) = \Omega(W(n))]
 (B) [image: A(n) = \Theta(W(n))]
 (C) [image: A(n) = O(W(n))]
 (D) [image: A(n) = o(W(n))]

 answer is c

 plz explain y???

 --
 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] Data Cache implementation problem

2012-08-11 Thread Kumar Vishal
 Huffman tree ???

On Fri, Aug 10, 2012 at 11:38 PM, Varma Selvaraj varm...@gmail.com wrote:

 A data cache needs to be implemented for the top 100 data items selected
 based on their frequency of access.
 The most frequent data member must be accessed  fastest. And the access
 time/iterations of each data member from the cache should correspond to the
 frequncy of its access.

 Please choose the right data structure and find the right algorithm for
 the scenario? Can anyone help on this question?


 Thanks and Regards,
 Varma

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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Fwd: general tree into BST

2012-07-28 Thread Kumar Vishal
 Take all element sort them and Make BST then Convert it to Red Black
Tree

On Fri, Jul 27, 2012 at 7:11 AM, Sathish babu satbrucei...@gmail.comwrote:


 **~Sathish Babu~**



 -- Forwarded message --
 From: Sathish babu satbrucei...@gmail.com
 Date: Wed, Jul 25, 2012 at 9:52 PM
 Subject: general tree into BST
 To: algogeeks@googlegroups.com


 Hey hi, can anyone provide the code to convert general tree into BST and
 BST into general treeThanks in advance...
 **~Sathish Babu~**


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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Kumar Vishal
MSB is at end or at the last of the array .. ??

On Tue, Jun 26, 2012 at 5:43 PM, saurabh singh saurab...@gmail.com wrote:

 ^ Does it make any difference?
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT
 blog:geekinessthecoolway.blogspot.com



 On Tue, Jun 26, 2012 at 5:32 PM, Navin Kumar algorithm.i...@gmail.comwrote:

 whether it is in character array or integer array??


 On Tue, Jun 26, 2   012 at 3:40 PM, Ashish Goel ashg...@gmail.comwrote:


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

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


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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Kumar Vishal
I mean 123 is store as 1,2,3 or   3,2,1

On Tue, Jun 26, 2012 at 6:01 PM, Kumar Vishal kumar...@gmail.com wrote:

 MSB is at end or at the last of the array .. ??

 On Tue, Jun 26, 2012 at 5:43 PM, saurabh singh saurab...@gmail.comwrote:

 ^ Does it make any difference?
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT
 blog:geekinessthecoolway.blogspot.com



 On Tue, Jun 26, 2012 at 5:32 PM, Navin Kumar algorithm.i...@gmail.comwrote:

 whether it is in character array or integer array??


 On Tue, Jun 26, 2   012 at 3:40 PM, Ashish Goel ashg...@gmail.comwrote:


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

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


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




 --
 Regards
 Kumar Vishal
 _
 *http://wethecommonpeople.wordpress.com/   *
 *h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
 *
 _





-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Find the Pair of X,Y [ 1/x + 1/y = 1/N! ]

2012-06-26 Thread Kumar Vishal
 @Kishore
   in below link no one deals with how to calculate or escape calculating
factorial (n)

On Tue, Jun 26, 2012 at 12:28 PM, Kishore kkishoreya...@gmail.com wrote:

 Go thru this
 http://stackoverflow.com/questions/8650827/sample-testcase-for-interviewstreet-equationsyou
  should be able to solve the question


 On Tue, Jun 26, 2012 at 1:58 AM, prakash y yprakash@gmail.com wrote:

 @Vishal,
 If the output should be the total no.of pairs, then i think there are
 infinite no.of such pairs. but not sure.
 Can someone provide me the link to the actual problem and some analysis
 of solution?

 Thanks,
 ~Prakash.

 On Mon, Jun 25, 2012 at 9:45 PM, Kumar Vishal kumar...@gmail.com wrote:

Sorry My Mistake *Number of pairs should be OUTPUT...*


 On Mon, Jun 25, 2012 at 8:49 PM, prakash y yprakash@gmail.comwrote:

 2! - x=y=4
 3! - x=y=12
 4! - x=y=48
 5! - x=y=240
 6! - x=y=1440
 I don't have proof to prove x = y always.
 But if x=y, then the answer should be x=y=2*n!

 On Mon, Jun 25, 2012 at 5:04 PM, Roshan kumar...@gmail.com wrote:

 Few Months back I found the problem
 on Code Sprint
 1/x + 1/y = 1/N! (N factorial).   For large value of N
 we have to find the par of (X,Y) which satisfy the equation
 my sol was slow ,
 can any pleas help me .

 Thanks
 Kumar Vishal

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




 --
 Regards
 Kumar Vishal
 _
 *http://wethecommonpeople.wordpress.com/   *
 *h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
 *
 _


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


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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Find the Pair of X,Y [ 1/x + 1/y = 1/N! ]

2012-06-26 Thread Kumar Vishal
@ SAM Thanks

On Tue, Jun 26, 2012 at 8:21 PM, SAMM somnath.nit...@gmail.com wrote:

 1 /x  + 1/y  = 1/(n!)
 * Consider N = n! , *
 *The Equation becoz :-*

 1/x + 1/y = 1/N
 or  (x+y)/xy = 1/N
 or  N( x + y ) = xy

 *Changing sides we get :-*
   xy - N(x+y) = 0

 *Adding N^2 on both sides we get :-*
  xy - N( x +  y) + N^2 = N^2
 or  xy - Nx - Ny + N^2 = N^2
 or  x(y - N) -  N (y - N ) = N^2
 or  (x - N) (y - N) = N^2


 From this equation we find that we can find the number of solution equal
 to the total number of divisors of (N ^ 2) .or ( n! ^2) .

 So you need to find the divisors of the square of the n! which can be done
 by finding the primes factor of the n! 

 For example :-  n!  = p1^a * p2^b *  pn^x     *[ p1 , p2 ..
 pn are the prime factors ]*

 (n1 ^ 2) = p1^2a * p2^2b *  pn^2x

 So the number of divisors are *(2a + 1) * (2b +1 ) *  (2x
 + 1) *.. You need to calculate this ...

 No need to calculate the factorial  just need to check for the prime
 factor from (2 to n ) .

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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] 1/x + 1/y = 1/(n factorial)

2012-06-25 Thread Kumar Vishal
 
We have to find number of Pair(x,y)
which will satisfy the eq:
1/x + 1/y = 1/(n factorial)

for large 0  N  10 ^ 4 N is integer 
Its problem from Code Sprint 
I tried to solve it by taking LOG but the sol 
was very slow , can any one please help 

Thanks
Kumar Vishal 

-- 
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/-/9SPU8dameBgJ.
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] Find the Pair of X,Y [ 1/x + 1/y = 1/N! ]

2012-06-25 Thread Kumar Vishal
@Prakash
   The Pattern given by u is because factorial (n) is always *even *so u
can always divide them
   in two equal part .
   what about
   1/6= 1/8 + 1/24( 6  = factorial (3))

On Mon, Jun 25, 2012 at 11:24 PM, Kishore kkishoreya...@gmail.com wrote:

 This is from interviewstreet named with equations


 On Mon, Jun 25, 2012 at 11:19 AM, prakash y yprakash@gmail.comwrote:

 2! - x=y=4
 3! - x=y=12
 4! - x=y=48
 5! - x=y=240
 6! - x=y=1440
 I don't have proof to prove x = y always.
 But if x=y, then the answer should be x=y=2*n!

 On Mon, Jun 25, 2012 at 5:04 PM, Roshan kumar...@gmail.com wrote:

 Few Months back I found the problem
 on Code Sprint
 1/x + 1/y = 1/N! (N factorial).   For large value of N
 we have to find the par of (X,Y) which satisfy the equation
 my sol was slow ,
 can any pleas help me .

 Thanks
 Kumar Vishal

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


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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Find the Pair of X,Y [ 1/x + 1/y = 1/N! ]

2012-06-25 Thread Kumar Vishal
   Sorry My Mistake *Number of pairs should be OUTPUT...*

On Mon, Jun 25, 2012 at 8:49 PM, prakash y yprakash@gmail.com wrote:

 2! - x=y=4
 3! - x=y=12
 4! - x=y=48
 5! - x=y=240
 6! - x=y=1440
 I don't have proof to prove x = y always.
 But if x=y, then the answer should be x=y=2*n!

 On Mon, Jun 25, 2012 at 5:04 PM, Roshan kumar...@gmail.com wrote:

 Few Months back I found the problem
 on Code Sprint
 1/x + 1/y = 1/N! (N factorial).   For large value of N
 we have to find the par of (X,Y) which satisfy the equation
 my sol was slow ,
 can any pleas help me .

 Thanks
 Kumar Vishal

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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Question asked in Amazon Online test

2012-06-23 Thread Kumar Vishal
bcaz choosing any vertical will automatically fix the horizontals and
vice verse
(u+r) C r= (u+r) C u

On Sat, Jun 23, 2012 at 1:08 PM, Kumar Vishal kumar...@gmail.com wrote:

Let u and r be the distance to move in the up and right directions.
 u=y2-y1 and r=x2-x1.
(u+r) C r


 On Sat, Jun 23, 2012 at 11:40 AM, Guruprasad Sridharan 
 sridharan.mi...@gmail.com wrote:

 Let u and r be the distance to move in the up and right directions.
 u=y2-y1 and r=x2-x1.

 We have to move a total of u+r units. So the answer would be (u+r)!/u!r!
 since we are counting only the distinct paths.
 Each path from (x1,y1) to (x2,y2)  may be expressed as a sequence of u+r
 steps consisting of U or R.
 If seq[i] has U then it means we moved up at the i th step. Similarly R
 is for right. The number of distinct paths would be the number of distinct
 arrangements of the sequence.

 On Sat, Jun 23, 2012 at 11:05 AM, Gobind Kumar Hembram 
 gobind@gmail.com wrote:

 Given two positions in a 2-D matrix, say (x1, y1) and (x2, y2) where
 x2=x1 and y2=y1. Find the total number of distinct paths between
 (x1, y1) and (x2, y2). You can only move in right direction i.e.
 positive x direction (+1, 0) or in up direction i.e. positive y
 direction (0, +1) from any given position.

 Example: If the given coordinates are  (3,3)  and (5,5), the number of
 distinct paths are 6 :  one going through 3,5 ; one going through 5,3
 and four going through 4,4.

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




 --
 Regards
 Kumar Vishal
 _
 *http://wethecommonpeople.wordpress.com/   *
 *h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
 *
 _





-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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] Question asked in Amazon Online test

2012-06-23 Thread Kumar Vishal
   Let u and r be the distance to move in the up and right directions.
u=y2-y1 and r=x2-x1.
   (u+r)Cr

On Sat, Jun 23, 2012 at 11:40 AM, Guruprasad Sridharan 
sridharan.mi...@gmail.com wrote:

 Let u and r be the distance to move in the up and right directions.
 u=y2-y1 and r=x2-x1.

 We have to move a total of u+r units. So the answer would be (u+r)!/u!r!
 since we are counting only the distinct paths.
 Each path from (x1,y1) to (x2,y2)  may be expressed as a sequence of u+r
 steps consisting of U or R.
 If seq[i] has U then it means we moved up at the i th step. Similarly R is
 for right. The number of distinct paths would be the number of distinct
 arrangements of the sequence.

 On Sat, Jun 23, 2012 at 11:05 AM, Gobind Kumar Hembram 
 gobind@gmail.com wrote:

 Given two positions in a 2-D matrix, say (x1, y1) and (x2, y2) where
 x2=x1 and y2=y1. Find the total number of distinct paths between
 (x1, y1) and (x2, y2). You can only move in right direction i.e.
 positive x direction (+1, 0) or in up direction i.e. positive y
 direction (0, +1) from any given position.

 Example: If the given coordinates are  (3,3)  and (5,5), the number of
 distinct paths are 6 :  one going through 3,5 ; one going through 5,3
 and four going through 4,4.

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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Kumar Vishal
 What I can think
  is case is :

  10
 / \
6 13
   / \
  4   5
 / \   \
6   7   8
   / \   \
  9   a   b

   so from a-b is
 a-7-4-2-5-8-b

 1- Left Tree then
 2- Right Tree
 add them

On Sat, Jun 23, 2012 at 3:49 PM, Kumar Vishal kumar...@gmail.com wrote:

   What I can think
   is case is :

 1
  / \
 2   3
/ \
   4   5
  / \   \
 6   7   8
/ \   \
   9   a   b

so from a-b is
  a-7-4-2-5-8-b



 On Sat, Jun 23, 2012 at 2:44 PM, Avinash jain.av...@gmail.com wrote:

 Some how I found that we need to run bfs twice to get the largest
 distance between any two nodes of a tree. Please explain me how it works.
 regards,
 avinash

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




 --
 Regards
 Kumar Vishal
 _
 *http://wethecommonpeople.wordpress.com/   *
 *h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
 *
 _





-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Kumar Vishal
  What I can think
  is case is :

1
 / \
2   3
   / \
  4   5
 / \   \
6   7   8
   / \   \
  9   a   b

   so from a-b is
 a-7-4-2-5-8-b



On Sat, Jun 23, 2012 at 2:44 PM, Avinash jain.av...@gmail.com wrote:

 Some how I found that we need to run bfs twice to get the largest distance
 between any two nodes of a tree. Please explain me how it works.
 regards,
 avinash

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




-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/http://kumartechnicalarticles.wordpress.com/
*
_

-- 
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: validate bit pattern : MS question

2012-05-17 Thread Vishal Thanki
On Sat, Apr 7, 2012 at 11:24 AM, Dave dave_and_da...@juno.com wrote:
 @Ashgoel: Try this:

 bool OnesZerosOnes(unsigned int n)
 {
     if( !(n  1) || !(n = n+1) ) return 0;
     n |= n-1;
     return !(n  (n+1));
 }

 Here is how it works:

 !(n  1) is true if the number has trailing zeros.

 If the number has trailing ones, n = n+1 replaces the trailing ones with
 zeros.

 !(n = n+1) is true if there are only trailing ones, i.e., the original
 number was zeros followed by ones.

 n |= n-1 replaces trailing zeros with ones. Thus, if the original number is
 ones followed by zeros followed by ones, the zeros have been changed to
 ones.

 (n  (n+1)) replaces the trailing ones with zeros. If the number is now
 zero, the number is valid, otherwise the number is invalid.

 Dave



Superb, Dave!!

 On Tuesday, April 3, 2012 7:00:36 PM UTC-5, ashgoel wrote:

 verify that the bits of a number are in format 1s followed by 0s followed
 by 1s like 1110001 is valid but 100100100 is not

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

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

 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] Re: Operating System

2011-10-07 Thread Vishal Beri
You can try Operating System Concepts and Principles by Gelvin

On Fri, Oct 7, 2011 at 8:32 PM, Brijesh brijeshupadhyay...@gmail.comwrote:

 Yeah...anyone plz tell good book for OS concepts

 --
 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/-/aVShOmMEE_cJ.
 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] Find the Max from each sub-array of size k

2011-09-02 Thread vishal jain
 I made a small program with window size k = 2;

int max(int n, int m)
{
 if ( n  m )
 return n;
 else
 return m;
}
int main()
{
int arr[8]={3,5,1,9,0,4,-1,7};
int i,j;
for (i=0;i!=j  i=7;i++)
for (j=0;j!=i  j=7; j++)
{
int k = max(arr[i], arr[j]);
cout[arr[i],arr[j]] = ;
coutk\n;
}
return 0;
}

output is :

[5,3] = 5
[1,3] = 3
[1,5] = 5
[9,3] = 9
[9,5] = 9
[9,1] = 9
[0,3] = 3
[0,5] = 5
[0,1] = 1
[0,9] = 9
[4,3] = 4
[4,5] = 5
[4,1] = 4
[4,9] = 9
[4,0] = 4
[-1,3] = 3
[-1,5] = 5
[-1,1] = 1
[-1,9] = 9
[-1,0] = 0
[-1,4] = 4
[7,3] = 7
[7,5] = 7
[7,1] = 7
[7,9] = 9
[7,0] = 7
[7,4] = 7
[7,-1] = 7


On Fri, Sep 2, 2011 at 3:43 PM, WgpShashank shashank7andr...@gmail.comwrote:

 Hi Anup , here is naive approach

 There is a sliding window of size w which is moving from the very left of
 the array to the very right. You can only see the w numbers in the window.
 Each time the sliding window moves rightwards by one position.

 Following is an example:
 The array is [1 3 -1 -3 5 3 6 7], and w is 3.

 Window position Max
 --- -
 [1 3 -1] -3 5 3 6 7 3
 1 [3 -1 -3] 5 3 6 7 3
 1 3 [-1 -3 5] 3 6 7 5
 1 3 -1 [-3 5 3] 6 7 5
 1 3 -1 -3 [5 3 6] 7 6
 1 3 -1 -3 5 [3 6 7] 7

 The obvious solution with run time complexity of O(nw) is which is not
 efficient enough. Every time the window is moved, we have to search for the
 maximum from w elements in the window. where w is size of window  n is size
 of array

 1st Method(Naive Approach)

 Data Structure Used : Array
 Algorithm: A.for all i=0 to n-w+1 (we should have at-least w elements in
 window)
 B.for all j=i to i+w (keep incrementing windows size form left to right)
 C find maximum inn each window  print it or put in array (Auxiliary)

 For more efficient approaches you can have a look here

 http://shashank7s.blogspot.com/2011/06/given-array-and-integer-k-find-maximum.html

 correct me if anything wrong or other approaches you can thing of ?

 Thanks
 Shashank Mani
 Computer Science
 Birla Institute of Technology Mesra

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

 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] Re: Static variable

2011-08-31 Thread vishal jain
I executed on linux machine..

I am gettign output

0-1-2-3-4-5-6-7-8 :(

for code
int main()
{
static int i=10;
while(--i0)
{
 main();
 printf(%d,i);
}
return 0;
}


On Wed, Aug 31, 2011 at 7:48 PM, Abhishek Mallick 
abhishek.mallick2...@gmail.com wrote:

 The recursion will run 10 times printing nothing. Then ones it returns
 on the 10th one. It will start printing from 0 to -8 (As i is static).

 On Aug 31, 6:33 pm, ravi maggon maggonr...@gmail.com wrote:
  Ans would be 00, keep in mind that i is static variable.
 
   On Wed, Aug 31, 2011 at 6:59 PM, rohit raman.u...@gmail.com wrote:
   123456789
 
   --
   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/-/OsL6-Vp91qoJ.
   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.
 
  --
 
  Regards
  Ravi Maggon
  Final Year, B.E. CSE
  Thapar University

 --
 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] Re: Static variable

2011-08-31 Thread vishal jain
Yes,

Your ans is very logical...

As i is static it will continue decrementing the value for all printf stored
in stack
 printf(%d,i); ---0
 printf(%d,i);1
printf(%d,i);2
printf(%d,i);3
printf(%d,i);4
printf(%d,i);5
printf(%d,i);6
printf(%d,i);7
printf(%d,i);8



On Wed, Aug 31, 2011 at 8:18 PM, rahul sharma rahul23111...@gmail.comwrote:

 i thnink it works as follow:-


 firstly
 loop goes pushing into stack
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);

 now i is 1
 --i
 means --1
 i=0;

 now all printf are poped printing --i
 from 0;

 m i ryt?



 On Aug 31, 7:40 pm, rahul sharma rahul23111...@gmail.com wrote:
  these two are same
 
  On Aug 31, 7:36 pm, ravi maggon maggonr...@gmail.com wrote:
 
 
 
 
 
 
 
   I check out the code:
 
   #includestdio.h
   main()
   {
   static int i=10;
   while(i0)
   {
   --i;
   main();
   printf(%d,i);
   }
 
   }
 
   if you run this you get 00 as output
 
   but if you run this
 
   #includestdio.h
   main()
   {
   static int i=10;
   while(i0)
   {
   --i;
   main();
   printf(%d,i);
   }
 
   }
 
   You get 0-1-2-3-4-5-6-7-8 as output.
 
   Whats the difference in these?
 
   On Wed, Aug 31, 2011 at 7:52 PM, aditi garg aditi.garg.6...@gmail.com
 wrote:
 
@abhishek: y till -8?
 
On Wed, Aug 31, 2011 at 7:50 PM, vishal jain vishal.l...@gmail.com
 wrote:
 
I executed on linux machine..
 
I am gettign output
 
0-1-2-3-4-5-6-7-8 :(
 
for code
int main()
 
{
static int i=10;
while(--i0)
{
 main();
 printf(%d,i);
}
return 0;
}
 
On Wed, Aug 31, 2011 at 7:48 PM, Abhishek Mallick 
abhishek.mallick2...@gmail.com wrote:
 
The recursion will run 10 times printing nothing. Then ones it
 returns
on the 10th one. It will start printing from 0 to -8 (As i is
 static).
 
On Aug 31, 6:33 pm, ravi maggon maggonr...@gmail.com wrote:
 Ans would be 00, keep in mind that i is static variable.
 
  On Wed, Aug 31, 2011 at 6:59 PM, rohit raman.u...@gmail.com
 wrote:
  123456789
 
  --
  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/-/OsL6-Vp91qoJ.
  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.
 
 --
 
 Regards
 Ravi Maggon
 Final Year, B.E. CSE
 Thapar University
 
--
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.
 
--
Aditi Garg
Undergraduate Student
Electronics  Communication Divison
NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
Sector 3, Dwarka
New Delhi
 
 --
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.
 
   --
 
   Regards
   Ravi Maggon
   Final Year, B.E. CSE
   Thapar University

 --
 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] Re: Static variable

2011-08-31 Thread vishal jain
because i is static..

On Wed, Aug 31, 2011 at 8:23 PM, aditya kumar
aditya.kumar130...@gmail.comwrote:

 @rahul : wen the values are pushed on to the stack they are like 9 , 8 , 7
 , till 0 so when they pop out shouldnt it be follwing the order 0 1 2 till 9
 . i realy dont know why the o/p is 0 -1 -2 and so on ??


 On Wed, Aug 31, 2011 at 8:18 PM, rahul sharma rahul23111...@gmail.comwrote:

 i thnink it works as follow:-


 firstly
 loop goes pushing into stack
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);
 printf(%d,i);

 now i is 1
 --i
 means --1
 i=0;

 now all printf are poped printing --i
 from 0;

 m i ryt?



 On Aug 31, 7:40 pm, rahul sharma rahul23111...@gmail.com wrote:
  these two are same
 
  On Aug 31, 7:36 pm, ravi maggon maggonr...@gmail.com wrote:
 
 
 
 
 
 
 
   I check out the code:
 
   #includestdio.h
   main()
   {
   static int i=10;
   while(i0)
   {
   --i;
   main();
   printf(%d,i);
   }
 
   }
 
   if you run this you get 00 as output
 
   but if you run this
 
   #includestdio.h
   main()
   {
   static int i=10;
   while(i0)
   {
   --i;
   main();
   printf(%d,i);
   }
 
   }
 
   You get 0-1-2-3-4-5-6-7-8 as output.
 
   Whats the difference in these?
 
   On Wed, Aug 31, 2011 at 7:52 PM, aditi garg 
 aditi.garg.6...@gmail.comwrote:
 
@abhishek: y till -8?
 
On Wed, Aug 31, 2011 at 7:50 PM, vishal jain vishal.l...@gmail.com
 wrote:
 
I executed on linux machine..
 
I am gettign output
 
0-1-2-3-4-5-6-7-8 :(
 
for code
int main()
 
{
static int i=10;
while(--i0)
{
 main();
 printf(%d,i);
}
return 0;
}
 
On Wed, Aug 31, 2011 at 7:48 PM, Abhishek Mallick 
abhishek.mallick2...@gmail.com wrote:
 
The recursion will run 10 times printing nothing. Then ones it
 returns
on the 10th one. It will start printing from 0 to -8 (As i is
 static).
 
On Aug 31, 6:33 pm, ravi maggon maggonr...@gmail.com wrote:
 Ans would be 00, keep in mind that i is static variable.
 
  On Wed, Aug 31, 2011 at 6:59 PM, rohit raman.u...@gmail.com
 wrote:
  123456789
 
  --
  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/-/OsL6-Vp91qoJ.
  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.
 
 --
 
 Regards
 Ravi Maggon
 Final Year, B.E. CSE
 Thapar University
 
--
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.
 
--
Aditi Garg
Undergraduate Student
Electronics  Communication Divison
NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
Sector 3, Dwarka
New Delhi
 
 --
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.
 
   --
 
   Regards
   Ravi Maggon
   Final Year, B.E. CSE
   Thapar University

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


-- 
You received this message because you

Re: [algogeeks] Novell - Technical Interview

2011-07-29 Thread Vishal Thanki
For 2nd,

Are you looking for this? /lib/modules/kernel_versionbuild/ ?
Or the kernel image? It can be found under /boot/. But that depends
upon the distribution, there is no symbolic link present for kernel
image as far as i know.

On Fri, Jul 29, 2011 at 9:45 AM, rajeev bharshetty rajeevr...@gmail.com wrote:
 1 )System map in Linux is a Symbol table used by the kernel.
 Mapping of symbol names and addresses.
 2 ) IS it /usr/src/linux ???

 On Fri, Jul 29, 2011 at 8:10 AM, Reynald reynaldsus...@gmail.com wrote:

 1. What is a System Map file in Linux? Why do we need it?
 2. Mention the file name which is a symbolic link to the system kernel.

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




 --
 Regards
 Rajeev N B

 Winners Don't do Different things , they do things Differently

 --
 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] Facebook Intern F2F Interview

2011-07-28 Thread Vishal Thanki
+1 Nikhil

On Thu, Jul 28, 2011 at 4:26 PM, Nikhil Jindal fundoon...@yahoo.co.in wrote:
 Generate a random number from 1 to 100.
 If it is less than or equal to x, return true, else return false.
 This will ensure that ur returning true with x/100 probability.
 Cheers
 Nikhil Jindal

 On Thu, Jul 28, 2011 at 4:21 PM, KK kunalkapadi...@gmail.com wrote:

 bool foo(int x)

 // Implement this function where 0 = x = 100
 It should return true x% of times n false otherwise

 first i told him to have a static int s then increment it each time
 the func is called...
 and if  s % (100 - x ) == 0 then true else false.

 then he told me to have some different approach..

 I told him like this:

 bool foo(int x)
 {
    // checking if x is btw 0  100

    if(x == 0)
              return false;
    if(x == 100)
              return true;

     srand(time(0));
     int rno = rand();

     if(rno % (100 - x) == 0)
            return True;
     else
           return False;
 }

 He was like okk but i think he was not completely satisfied
 Any other Approach...

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


-- 
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] sizeof() question.

2011-07-27 Thread Vishal Thanki
I am not sure about the first question, but if you use sizeof(main()),
it gives the ans 4.
vishal@ubuntu:~/progs/c\ 09:12:57 PM $ cat alg.c
#includestdio.h
int main()
{
printf(%d\n,sizeof(main()));
 return 0;
}
vishal@ubuntu:~/progs/c\ 09:13:00 PM $ gcc alg.c
vishal@ubuntu:~/progs/c\ 09:13:02 PM $ ./a.out
4
vishal@ubuntu:~/progs/c\ 09:13:03 PM $


The reason why it doesn't overflow is because sizeof() operator
calculates the size at compile time, and it doesn't really invoke
main().

Vishal

On Wed, Jul 27, 2011 at 9:02 PM, Charlotte Swazki
charlotteswa...@yahoo.fr wrote:
 Hi there,

 I have two questions,

 Why sizeof(main) == 1 ? (sizeof(func) == 1).
 Not 4 bytes ?.sizeof(void) == 1 too.


 And this code doesn't stackoverflow ?
 int main() {

  sizeof(main());
 }



 Thanks,

 --
 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] Small Doubt

2011-07-27 Thread Vishal Thanki
@ rajeev,

vishal@ubuntu:~/progs/c\ 09:25:38 AM $ cat alg.c
#includestdio.h
int main()
{
int *p = (int *)0xff;
*p = 4;
return 0;
}

vishal@ubuntu:~/progs/c\ 09:25:42 AM $ gcc alg.c
vishal@ubuntu:~/progs/c\ 09:25:45 AM $ ./a.out
Segmentation fault
vishal@ubuntu:~/progs/c\ 09:25:46 AM $


On Thu, Jul 28, 2011 at 9:13 AM, rajeev bharshetty rajeevr...@gmail.com wrote:
 @anika : I just found out that it can be done as
 int *p = (int *)0x0ff ;
 *p=4;
 then 4 gets stored in 0x0ff location .
 Guys can it be done . Is it Legal ??

 On Thu, Jul 28, 2011 at 9:11 AM, Anika Jain anika.jai...@gmail.com wrote:

 segmentation fault comes when we try to modify or do illegal access to the
 memory that has not been allocated to us..
 the trial to make your variable be at some location of your wish can be
 done only by int *p=4000; *p=10;  but it is illegal coz 4000 memory address
 is not alloted yet for your program.

 On Wed, Jul 27, 2011 at 11:26 PM, Puneet Gautam puneet.nsi...@gmail.com
 wrote:

 @Anika : pls elaborate the segmentatin part...!


 On 7/27/11, Anika Jain anika.jai...@gmail.com wrote:
  no we cant..
  coz when we do say int *p=4000;
  its fine till now.. and if we do *p=10; it is segmentation fault..
 
  On Wed, Jul 27, 2011 at 10:35 PM, rShetty rajeevr...@gmail.com wrote:
 
  Usually when I declare a variable it will be stored in memory location
  with some address .
  Such as  consider I declare int x=10 , it will stored in some address
  1003 (say).
  Now my question is can I control the address being assigned to a
  variable in C . Say, I want to store x in address in 4000 and not in
  1003 defined by the compiler .(Usually this can be done in assembly).
  Can I do that ? Correct me If i am wrong
 
  --
  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.
 
 

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



 --
 Regards
 Rajeev N B

 Winners Don't do Different things , they do things Differently

 --
 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] Facebook Interview question at NIT Warangal

2011-07-26 Thread Vishal Thanki
@ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
following is the code..

#include stdio.h
#include stdlib.h

void print_comb(int *a, int len)
{
int tlen = len;
int i, j, k;

for (i=0;i5;i++) {
for (j=i+1; j4;j++) {
printf(%d , a[i]);
k=j;
while(tlen-1  0) {
printf(%d , a[k]);
k++;
tlen--;
}
printf(\n);
tlen = len;
}
}
}

int main(int argc, char *argv[])
{
int len = atoi(argv[1]);
int arr[] = {1,2,3,4};
print_comb(arr, len);
return 0;
}


On Tue, Jul 26, 2011 at 1:01 PM, Ankur Garg ankurga...@gmail.com wrote:
 Hi
 Dont u think the subsets will also be
 {2,1}
 {3,1}
 {3,2}
 {4,1}
 {4,2}
 {4,3}
 On Tue, Jul 26, 2011 at 11:59 AM, sumit sumitispar...@gmail.com wrote:

 Given an array of size n, print all the possible subset of array of
 size k.
 eg:-
 input:
 a[]={1,2,3,4}, k = 2
 output:
 1,2
 1,3
 1,4
 2,3
 2,4
 3,4

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


-- 
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] Facebook Interview question at NIT Warangal

2011-07-26 Thread Vishal Thanki
anyway, the code i posted is buggy.. doesn't work for k=3.. don't use it :)

On Tue, Jul 26, 2011 at 1:02 PM, Vishal Thanki vishaltha...@gmail.com wrote:
 @ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
 following is the code..

 #include stdio.h
 #include stdlib.h

 void print_comb(int *a, int len)
 {
        int tlen = len;
        int i, j, k;

        for (i=0;i5;i++) {
                for (j=i+1; j4;j++) {
                        printf(%d , a[i]);
                        k=j;
                        while(tlen-1  0) {
                                printf(%d , a[k]);
                                k++;
                                tlen--;
                        }
                        printf(\n);
                        tlen = len;
                }
        }
 }

 int main(int argc, char *argv[])
 {
        int len = atoi(argv[1]);
        int arr[] = {1,2,3,4};
        print_comb(arr, len);
        return 0;
 }


 On Tue, Jul 26, 2011 at 1:01 PM, Ankur Garg ankurga...@gmail.com wrote:
 Hi
 Dont u think the subsets will also be
 {2,1}
 {3,1}
 {3,2}
 {4,1}
 {4,2}
 {4,3}
 On Tue, Jul 26, 2011 at 11:59 AM, sumit sumitispar...@gmail.com wrote:

 Given an array of size n, print all the possible subset of array of
 size k.
 eg:-
 input:
 a[]={1,2,3,4}, k = 2
 output:
 1,2
 1,3
 1,4
 2,3
 2,4
 3,4

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



-- 
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] Facebook Interview question at NIT Warangal

2011-07-26 Thread Vishal Thanki
Here is the working code..

#include stdio.h
#include stdlib.h
int a[] = {1,2,3,4,5};
#define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
void print_comb(int len)
{
int tlen = len;
int i, j, k;
int al = ARRLEN(a);
for (i = 0; i  al; i++) {
for (j=i+len-1; jal;j++) {
for (k = i; k  i+len-1; k++) {
printf(%d , a[k]);
}
printf(%d\n, a[j]);
}
}
}

int main(int argc, char *argv[])
{
int len = atoi(argv[1]);
print_comb(len);
return 0;
}



On Tue, Jul 26, 2011 at 5:18 PM, praneethn praneeth...@gmail.com wrote:

 check this link:

 *http://www.stefan-pochmann.info/spots/tutorials/sets_subsets/*

 On Tue, Jul 26, 2011 at 11:59 AM, sumit sumitispar...@gmail.com wrote:

 Given an array of size n, print all the possible subset of array of
 size k.
 eg:-
 input:
 a[]={1,2,3,4}, k = 2
 output:
 1,2
 1,3
 1,4
 2,3
 2,4
 3,4

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


-- 
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] Interview Puzzle - 100 Prisoners and Caps

2011-07-22 Thread Vishal Jain
Hi All,

In my last interview(given few months back), I was asked the following
puzzle..

http://goo.gl/jrnpc

Could you please tell me the solution for the same?

Thanks  Regards
Vishal Jain
MNo: +91-9540611889
Tweet @jainvis
Blog @ jainvish.blogspot.com
Success taste better when target achieved is bigger.

P *We have a responsibility to the environment.*

*Before printing this e-mail or any other document, let's ask
ourselves whether we need a hard copy.*

-- 
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] Interview Puzzle - 100 Prisoners and Caps

2011-07-22 Thread Vishal Jain
I think Aditi's solution is correct. I was doing the same thing using XOR
function... So basically I was saying to use XOR and interviewer was asking
for something better... I could not find this solution...

Thanks Aditi.

Thanks  Regards
Vishal Jain
MNo: +91-9540611889
Tweet @jainvis
Blog @ jainvish.blogspot.com
Success taste better when target achieved is bigger.

P *We have a responsibility to the environment.*

*Before printing this e-mail or any other document, let's ask
ourselves whether we need a hard copy.*




On Fri, Jul 22, 2011 at 10:19 PM, aditi garg aditi.garg.6...@gmail.comwrote:

 I think this can be answered like dis...
 let us say that the persons have decided amongst themselves that if the the
 number of people wearing white in front of dem is even he wud say white and
 if odd he wud say black
 Now suppose the 100th person counts the number of hats and finds it to be
 even... he wud say white...
 now the 99th person will do the same...if he still finds the number to be
 even and since the 100th person sed white(i.e even) he would say black...now
 if the 100th person had sed black (ie odd white) and the count comes out to
 be even thus 99 wud be wearing a white hat...
 Now that 98th person knows dat 99 had sed the correct hat and using the
 same method can say the correct hat color...thus all can be saved except the
 100th prisoner...
 Also note dat the 100th prisoner also has a 50% chance to survive...

 Hope dis helps :)


 On Fri, Jul 22, 2011 at 10:05 PM, Shubham Maheshwari 
 shubham@gmail.com wrote:

 could some1 plz post the xplainations ...


 On Fri, Jul 22, 2011 at 8:04 PM, Pankaj jatka.oppimi...@gmail.comwrote:

 Chetan,

 No. How could you relate this problem with that? Do you find something
 similar?

 ~
 Pankaj


 On Fri, Jul 22, 2011 at 8:01 PM, chetan kapoor 
 chetankapoor...@gmail.com wrote:

 josehus problem???


 On Fri, Jul 22, 2011 at 7:57 PM, Pankaj jatka.oppimi...@gmail.comwrote:

 Skipp Riddle,
 Yes.
 100th prisoner will risk his life. Similar puzzle was discuss recently.
 Does anyone remember the name or thread?


 ~
 Pankaj


 On Fri, Jul 22, 2011 at 7:55 PM, SkRiPt KiDdIe anuragmsi...@gmail.com
  wrote:

 Worst case 99 get released.
 Is that correct..?

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


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


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




 --
 Aditi Garg
 Undergraduate Student
 Electronics  Communication Divison
 NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
 Sector 3, Dwarka
 New Delhi

 9718388816

  --
 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] Re: sbtration

2011-07-11 Thread Vishal Thanki
z = x + (-y)

:)

On Tue, Jul 12, 2011 at 10:58 AM, Sunny T sunny.1...@gmail.com wrote:
 i would say.. implementing subtraction using division and modulus is more
 costly and complicated. bit manipulation is the fastest among all
 these techniques.
  x=a-b = (a/b)*b + a%b
 .here u are performing... totally 4 operations..1 division,1
 multiplication,1 modulus and 1 addition..

 it can be easily done by...

 x=a+(~b+1). this solution takes less number of operation than
 ur solution and involve less costly operators.

 On Tue, Jul 12, 2011 at 10:29 AM, Dave dave_and_da...@juno.com wrote:

 @Chandy: Let a = 5 and b = 3. Then x = 5 - 3 = (5/3)*3 + 5%3 = 1*3 + 2
 = 5. Check?

 Dave

 On Jul 11, 11:38 pm, chandy jose paul jpchaa...@gmail.com wrote:
  Y are u guys complicating things.Its as simple as this
 
   x=a-b = (a/b)*b + a%b
 
 
 
  On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:
   @Aditya: Since 124 is a 3-digit number, I think it would make more
   sense to use the 3-digit 10's complement of 46, i.e., 954. Then 124 +
   954 = 1078. Since we are working in 3-digit numbers, the 1 represents
   an overflow, which you ignore. Thus, the answer is 78.
 
   Dave
 
   On Jul 11, 2:42 pm, aditya pratap contacttoadity...@gmail.com wrote:
suppose u want to do 124 - 46
 
step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
step2: add 124 + 54 = 178
step3: neglect 1 from 178 and answer will be 78.
 
correct me if i am wrong.
 
On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain
anika.jai...@gmail.com
   wrote:
 how to do subtraction of two integers widout using subtractn??
 
 --
 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.
 
--
Regards
Aditya Pratap
MCA II
 
   --
   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.- 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 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.




 --
 Warm Regards,
 Sunny T

 --
 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] Google Question

2011-07-08 Thread Vishal Thanki
google this question!!

On Fri, Jul 8, 2011 at 11:47 AM, priyanshu priyanshuro...@gmail.com wrote:
 How to find the number users connected to the web??

 --
 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] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
Off Topic:
Sorry for the diversion, but I was just wondering how easy it has
become to code in languages other than c. Here is the code i wrote for
the above mentioned problem in Python. It takes command line arg as
string. something like

vishal@ubuntu:~/progs/python\ 02:45:07 PM $ cat rev.py
#!/usr/bin/python
import sys
strn=
for i in (sys.argv[1].split())[::-1]:
strn+=i+ 
print strn

vishal@ubuntu:~/progs/python\ 02:45:09 PM $ ./rev.py This is a new world
world new a is This

vishal@ubuntu:~/progs/python\ 02:47:15 PM $





On Thu, Jul 7, 2011 at 1:19 PM, Piyush Sinha ecstasy.piy...@gmail.com wrote:
 @Navneettake a look at the solution below and tell if there is any bug
 in it...

 #include string.h

 typedef struct revll
 {
     char s[100];
     struct revll *next;
 }revll;

 revll *rev_str(char *a)
 {
   char temp[100];
   int i,len=strlen(a),j=0;
   revll *head,*p;
   head=NULL;
   for(i=0;ilen;i++)
   {
    if(a[i]!=' ')
    {
     temp[j++] = a[i];
    }
    else
    {
    temp[j] = '\0';
    p = (revll *)malloc(sizeof(revll));
    p-next = head;
    strcpy(p-s,temp);
    head = p;
    j=0;
    }
   }
   /*for last word*/
   temp[j] = '\0';
   p = (revll *)malloc(sizeof(revll));
   p-next = head;
   strcpy(p-s,temp);
   head = p;
   return head;
 }

 main()
 {
   char a[100];
   revll *head;
   gets(a);
   head = rev_str(a);
   while(head)
   {
  printf(%s-,head-s);
  head=head-next;
   }
   system(pause);
 }



 On Thu, Jul 7, 2011 at 9:10 AM, Navneet Gupta navneetn...@gmail.com wrote:

 @Piyush, could you elaborate your approach with Linked List?
 From what i am getting, even with Linked List, you would need two
 traversals at least.

 On Thu, Jul 7, 2011 at 2:07 AM, Piyush Sinha ecstasy.piy...@gmail.com
 wrote:
  Can we do it using linked list if ONE TIME TRAVERSAL is a constraint??
 
  On 7/6/11, Tushar Bindal tushicom...@gmail.com wrote:
  I read that solution.
  But the same doubt as Navneet which I think you also raised i one of
  your
  posts on that thread
 
  On Wed, Jul 6, 2011 at 10:34 PM, Navneet Gupta
  navneetn...@gmail.comwrote:
 
  Saurabh,
 
  I understood your solution but wonder if it is purely single traversal
 
  In affect, you have a second traversal when you are popping the
  strings from stack to form the reverse order string.
 
  Though the second activity is less than O(n) i.e. O(#words in string)
  Nice solution, this way we can also get rid of extra spaces easily in
  the actual string if that is also to be done.
 
  On Wed, Jul 6, 2011 at 10:16 PM, saurabh singh saurab...@gmail.com
  wrote:
   I have proposed my solution in one of the previous posts.Check the
  solution
   there
  
   On Wed, Jul 6, 2011 at 10:10 PM, Tushar Bindal
   tushicom...@gmail.com
   wrote:
  
   good job
   but how can this be done in one traversal as asked on the Adobe
  Interview
   Questions thread.
  
  
  
   On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta
   navneetn...@gmail.com
   wrote:
  
   I think somebody on this thread has asked this question but i am
   not
   able to find that.
  
   Question was if a string is like my name is ram, then output
   should
   be ram is name my.
  
   Wrote the code for same, so sharing.
  
   #includeiostream
   #includestring
   using namespace std;
  
   void SwapStringChars(string str, int pos1, int pos2)
   {
          char ch = str[pos1];
          str[pos1] = str[pos2];
          str[pos2] = ch;
   }
  
   void reverseString(string str, int left, int right)
   {
          for(int i = left ; i = left + (right-left)/2 ; i++)
                  SwapStringChars(str, i, right + left -i));
   }
  
   void reverseWordsInString(string str)
   {
          char space = ' ';
          int len = str.length();
          int startIndex = 0, endIndex = 0;
          while(endIndex  len - 1)
          {
                  while(str[endIndex] != space  endIndex 
  len)endIndex++;
                  reverseString(str, startIndex, endIndex-1);
                  startIndex = endIndex;
                  while(str[startIndex] == space)startIndex++;
                  endIndex = startIndex;
          }
   }
  
   int main()
   {
          string str;
          cout\nEnter enter the string :;
          getline(cin,str);
  
          //Reverse whole string at once
          reverseString(str, 0, str.length() - 1);
  
          //Reverse Individual words in string
          reverseWordsInString(str);
          coutstr;
          cin.get();
          return 0;
   }
  
   --
   Regards,
   Navneet
  
   --
   You received this message because you are subscribed to the Google
  Groups
   Algorithm Geeks group.
   To post to this group, send email

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
@Navneet, it works with multiple spaces between words.. And here is
the two line solution :)

import sys
print  .join((sys.argv[1].split())[::-1])



On Thu, Jul 7, 2011 at 3:12 PM, Navneet Gupta navneetn...@gmail.com wrote:
 @Vishal, can you see if your program works well for more than single
 space between words? Not sure how split functions helps.

 BTW, Perl also is very strong language for string manipulations.
 (Specially designed for efficient string operations)

 On Thu, Jul 7, 2011 at 2:48 PM, Vishal Thanki vishaltha...@gmail.com wrote:
 Off Topic:
 Sorry for the diversion, but I was just wondering how easy it has
 become to code in languages other than c. Here is the code i wrote for
 the above mentioned problem in Python. It takes command line arg as
 string. something like

 vishal@ubuntu:~/progs/python\ 02:45:07 PM $ cat rev.py
 #!/usr/bin/python
 import sys
 strn=
 for i in (sys.argv[1].split())[::-1]:
        strn+=i+ 
 print strn

 vishal@ubuntu:~/progs/python\ 02:45:09 PM $ ./rev.py This is a new world
 world new a is This

 vishal@ubuntu:~/progs/python\ 02:47:15 PM $





 On Thu, Jul 7, 2011 at 1:19 PM, Piyush Sinha ecstasy.piy...@gmail.com 
 wrote:
 @Navneettake a look at the solution below and tell if there is any bug
 in it...

 #include string.h

 typedef struct revll
 {
     char s[100];
     struct revll *next;
 }revll;

 revll *rev_str(char *a)
 {
   char temp[100];
   int i,len=strlen(a),j=0;
   revll *head,*p;
   head=NULL;
   for(i=0;ilen;i++)
   {
    if(a[i]!=' ')
    {
     temp[j++] = a[i];
    }
    else
    {
    temp[j] = '\0';
    p = (revll *)malloc(sizeof(revll));
    p-next = head;
    strcpy(p-s,temp);
    head = p;
    j=0;
    }
   }
   /*for last word*/
   temp[j] = '\0';
   p = (revll *)malloc(sizeof(revll));
   p-next = head;
   strcpy(p-s,temp);
   head = p;
   return head;
 }

 main()
 {
   char a[100];
   revll *head;
   gets(a);
   head = rev_str(a);
   while(head)
   {
  printf(%s-,head-s);
  head=head-next;
   }
   system(pause);
 }



 On Thu, Jul 7, 2011 at 9:10 AM, Navneet Gupta navneetn...@gmail.com wrote:

 @Piyush, could you elaborate your approach with Linked List?
 From what i am getting, even with Linked List, you would need two
 traversals at least.

 On Thu, Jul 7, 2011 at 2:07 AM, Piyush Sinha ecstasy.piy...@gmail.com
 wrote:
  Can we do it using linked list if ONE TIME TRAVERSAL is a constraint??
 
  On 7/6/11, Tushar Bindal tushicom...@gmail.com wrote:
  I read that solution.
  But the same doubt as Navneet which I think you also raised i one of
  your
  posts on that thread
 
  On Wed, Jul 6, 2011 at 10:34 PM, Navneet Gupta
  navneetn...@gmail.comwrote:
 
  Saurabh,
 
  I understood your solution but wonder if it is purely single traversal
 
  In affect, you have a second traversal when you are popping the
  strings from stack to form the reverse order string.
 
  Though the second activity is less than O(n) i.e. O(#words in string)
  Nice solution, this way we can also get rid of extra spaces easily in
  the actual string if that is also to be done.
 
  On Wed, Jul 6, 2011 at 10:16 PM, saurabh singh saurab...@gmail.com
  wrote:
   I have proposed my solution in one of the previous posts.Check the
  solution
   there
  
   On Wed, Jul 6, 2011 at 10:10 PM, Tushar Bindal
   tushicom...@gmail.com
   wrote:
  
   good job
   but how can this be done in one traversal as asked on the Adobe
  Interview
   Questions thread.
  
  
  
   On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta
   navneetn...@gmail.com
   wrote:
  
   I think somebody on this thread has asked this question but i am
   not
   able to find that.
  
   Question was if a string is like my name is ram, then output
   should
   be ram is name my.
  
   Wrote the code for same, so sharing.
  
   #includeiostream
   #includestring
   using namespace std;
  
   void SwapStringChars(string str, int pos1, int pos2)
   {
          char ch = str[pos1];
          str[pos1] = str[pos2];
          str[pos2] = ch;
   }
  
   void reverseString(string str, int left, int right)
   {
          for(int i = left ; i = left + (right-left)/2 ; i++)
                  SwapStringChars(str, i, right + left -i));
   }
  
   void reverseWordsInString(string str)
   {
          char space = ' ';
          int len = str.length();
          int startIndex = 0, endIndex = 0;
          while(endIndex  len - 1)
          {
                  while(str[endIndex] != space  endIndex 
  len)endIndex++;
                  reverseString(str, startIndex, endIndex-1);
                  startIndex = endIndex;
                  while(str[startIndex] == space)startIndex++;
                  endIndex = startIndex

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
yea, expression   .join((sys.argv[1].split())[::-1]) will return the string!!

On Thu, Jul 7, 2011 at 3:36 PM, Navneet Gupta navneetn...@gmail.com wrote:
 @Vishal,

 Don't confuse printing in reverse with actually modifying the actual
 string to reverse word order in it :)

 On Thu, Jul 7, 2011 at 3:34 PM, Vishal Thanki vishaltha...@gmail.com wrote:
 @Navneet, it works with multiple spaces between words.. And here is
 the two line solution :)

 import sys
 print  .join((sys.argv[1].split())[::-1])



 On Thu, Jul 7, 2011 at 3:12 PM, Navneet Gupta navneetn...@gmail.com wrote:
 @Vishal, can you see if your program works well for more than single
 space between words? Not sure how split functions helps.

 BTW, Perl also is very strong language for string manipulations.
 (Specially designed for efficient string operations)

 On Thu, Jul 7, 2011 at 2:48 PM, Vishal Thanki vishaltha...@gmail.com 
 wrote:
 Off Topic:
 Sorry for the diversion, but I was just wondering how easy it has
 become to code in languages other than c. Here is the code i wrote for
 the above mentioned problem in Python. It takes command line arg as
 string. something like

 vishal@ubuntu:~/progs/python\ 02:45:07 PM $ cat rev.py
 #!/usr/bin/python
 import sys
 strn=
 for i in (sys.argv[1].split())[::-1]:
        strn+=i+ 
 print strn

 vishal@ubuntu:~/progs/python\ 02:45:09 PM $ ./rev.py This is a new world
 world new a is This

 vishal@ubuntu:~/progs/python\ 02:47:15 PM $





 On Thu, Jul 7, 2011 at 1:19 PM, Piyush Sinha ecstasy.piy...@gmail.com 
 wrote:
 @Navneettake a look at the solution below and tell if there is any bug
 in it...

 #include string.h

 typedef struct revll
 {
     char s[100];
     struct revll *next;
 }revll;

 revll *rev_str(char *a)
 {
   char temp[100];
   int i,len=strlen(a),j=0;
   revll *head,*p;
   head=NULL;
   for(i=0;ilen;i++)
   {
    if(a[i]!=' ')
    {
     temp[j++] = a[i];
    }
    else
    {
    temp[j] = '\0';
    p = (revll *)malloc(sizeof(revll));
    p-next = head;
    strcpy(p-s,temp);
    head = p;
    j=0;
    }
   }
   /*for last word*/
   temp[j] = '\0';
   p = (revll *)malloc(sizeof(revll));
   p-next = head;
   strcpy(p-s,temp);
   head = p;
   return head;
 }

 main()
 {
   char a[100];
   revll *head;
   gets(a);
   head = rev_str(a);
   while(head)
   {
  printf(%s-,head-s);
  head=head-next;
   }
   system(pause);
 }



 On Thu, Jul 7, 2011 at 9:10 AM, Navneet Gupta navneetn...@gmail.com 
 wrote:

 @Piyush, could you elaborate your approach with Linked List?
 From what i am getting, even with Linked List, you would need two
 traversals at least.

 On Thu, Jul 7, 2011 at 2:07 AM, Piyush Sinha ecstasy.piy...@gmail.com
 wrote:
  Can we do it using linked list if ONE TIME TRAVERSAL is a constraint??
 
  On 7/6/11, Tushar Bindal tushicom...@gmail.com wrote:
  I read that solution.
  But the same doubt as Navneet which I think you also raised i one of
  your
  posts on that thread
 
  On Wed, Jul 6, 2011 at 10:34 PM, Navneet Gupta
  navneetn...@gmail.comwrote:
 
  Saurabh,
 
  I understood your solution but wonder if it is purely single 
  traversal
 
  In affect, you have a second traversal when you are popping the
  strings from stack to form the reverse order string.
 
  Though the second activity is less than O(n) i.e. O(#words in string)
  Nice solution, this way we can also get rid of extra spaces easily in
  the actual string if that is also to be done.
 
  On Wed, Jul 6, 2011 at 10:16 PM, saurabh singh saurab...@gmail.com
  wrote:
   I have proposed my solution in one of the previous posts.Check the
  solution
   there
  
   On Wed, Jul 6, 2011 at 10:10 PM, Tushar Bindal
   tushicom...@gmail.com
   wrote:
  
   good job
   but how can this be done in one traversal as asked on the Adobe
  Interview
   Questions thread.
  
  
  
   On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta
   navneetn...@gmail.com
   wrote:
  
   I think somebody on this thread has asked this question but i am
   not
   able to find that.
  
   Question was if a string is like my name is ram, then output
   should
   be ram is name my.
  
   Wrote the code for same, so sharing.
  
   #includeiostream
   #includestring
   using namespace std;
  
   void SwapStringChars(string str, int pos1, int pos2)
   {
          char ch = str[pos1];
          str[pos1] = str[pos2];
          str[pos2] = ch;
   }
  
   void reverseString(string str, int left, int right)
   {
          for(int i = left ; i = left + (right-left)/2 ; i++)
                  SwapStringChars(str, i, right + left -i));
   }
  
   void reverseWordsInString(string str)
   {
          char space = ' ';
          int len = str.length

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
#!/usr/bin/python
import sys
string=sys.argv[1]
string= .join((string.split())[::-1])
print string

How does this sound? :P

On Thu, Jul 7, 2011 at 3:43 PM, Vishal Thanki vishaltha...@gmail.com wrote:
 yea, expression   .join((sys.argv[1].split())[::-1]) will return the 
 string!!

 On Thu, Jul 7, 2011 at 3:36 PM, Navneet Gupta navneetn...@gmail.com wrote:
 @Vishal,

 Don't confuse printing in reverse with actually modifying the actual
 string to reverse word order in it :)

 On Thu, Jul 7, 2011 at 3:34 PM, Vishal Thanki vishaltha...@gmail.com wrote:
 @Navneet, it works with multiple spaces between words.. And here is
 the two line solution :)

 import sys
 print  .join((sys.argv[1].split())[::-1])



 On Thu, Jul 7, 2011 at 3:12 PM, Navneet Gupta navneetn...@gmail.com wrote:
 @Vishal, can you see if your program works well for more than single
 space between words? Not sure how split functions helps.

 BTW, Perl also is very strong language for string manipulations.
 (Specially designed for efficient string operations)

 On Thu, Jul 7, 2011 at 2:48 PM, Vishal Thanki vishaltha...@gmail.com 
 wrote:
 Off Topic:
 Sorry for the diversion, but I was just wondering how easy it has
 become to code in languages other than c. Here is the code i wrote for
 the above mentioned problem in Python. It takes command line arg as
 string. something like

 vishal@ubuntu:~/progs/python\ 02:45:07 PM $ cat rev.py
 #!/usr/bin/python
 import sys
 strn=
 for i in (sys.argv[1].split())[::-1]:
        strn+=i+ 
 print strn

 vishal@ubuntu:~/progs/python\ 02:45:09 PM $ ./rev.py This is a new 
 world
 world new a is This

 vishal@ubuntu:~/progs/python\ 02:47:15 PM $





 On Thu, Jul 7, 2011 at 1:19 PM, Piyush Sinha ecstasy.piy...@gmail.com 
 wrote:
 @Navneettake a look at the solution below and tell if there is any 
 bug
 in it...

 #include string.h

 typedef struct revll
 {
     char s[100];
     struct revll *next;
 }revll;

 revll *rev_str(char *a)
 {
   char temp[100];
   int i,len=strlen(a),j=0;
   revll *head,*p;
   head=NULL;
   for(i=0;ilen;i++)
   {
    if(a[i]!=' ')
    {
     temp[j++] = a[i];
    }
    else
    {
    temp[j] = '\0';
    p = (revll *)malloc(sizeof(revll));
    p-next = head;
    strcpy(p-s,temp);
    head = p;
    j=0;
    }
   }
   /*for last word*/
   temp[j] = '\0';
   p = (revll *)malloc(sizeof(revll));
   p-next = head;
   strcpy(p-s,temp);
   head = p;
   return head;
 }

 main()
 {
   char a[100];
   revll *head;
   gets(a);
   head = rev_str(a);
   while(head)
   {
  printf(%s-,head-s);
  head=head-next;
   }
   system(pause);
 }



 On Thu, Jul 7, 2011 at 9:10 AM, Navneet Gupta navneetn...@gmail.com 
 wrote:

 @Piyush, could you elaborate your approach with Linked List?
 From what i am getting, even with Linked List, you would need two
 traversals at least.

 On Thu, Jul 7, 2011 at 2:07 AM, Piyush Sinha ecstasy.piy...@gmail.com
 wrote:
  Can we do it using linked list if ONE TIME TRAVERSAL is a constraint??
 
  On 7/6/11, Tushar Bindal tushicom...@gmail.com wrote:
  I read that solution.
  But the same doubt as Navneet which I think you also raised i one of
  your
  posts on that thread
 
  On Wed, Jul 6, 2011 at 10:34 PM, Navneet Gupta
  navneetn...@gmail.comwrote:
 
  Saurabh,
 
  I understood your solution but wonder if it is purely single 
  traversal
 
  In affect, you have a second traversal when you are popping the
  strings from stack to form the reverse order string.
 
  Though the second activity is less than O(n) i.e. O(#words in 
  string)
  Nice solution, this way we can also get rid of extra spaces easily 
  in
  the actual string if that is also to be done.
 
  On Wed, Jul 6, 2011 at 10:16 PM, saurabh singh saurab...@gmail.com
  wrote:
   I have proposed my solution in one of the previous posts.Check the
  solution
   there
  
   On Wed, Jul 6, 2011 at 10:10 PM, Tushar Bindal
   tushicom...@gmail.com
   wrote:
  
   good job
   but how can this be done in one traversal as asked on the Adobe
  Interview
   Questions thread.
  
  
  
   On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta
   navneetn...@gmail.com
   wrote:
  
   I think somebody on this thread has asked this question but i am
   not
   able to find that.
  
   Question was if a string is like my name is ram, then output
   should
   be ram is name my.
  
   Wrote the code for same, so sharing.
  
   #includeiostream
   #includestring
   using namespace std;
  
   void SwapStringChars(string str, int pos1, int pos2)
   {
          char ch = str[pos1];
          str[pos1] = str[pos2];
          str[pos2] = ch;
   }
  
   void reverseString(string str, int left, int right)
   {
          for(int i = left ; i

Re: [algogeeks] Explanation

2011-07-07 Thread Vishal Thanki
you are overwriting terminating null char!!

On Fri, Jul 8, 2011 at 10:23 AM, rShetty rajeevr...@gmail.com wrote:
 #includestdio.h
 #includestring.h
 int main()
 {
  char str[]=This is rajeev\n;
  char str1[10];
  memset(str,'0',4);
  printf(%s,str);
  memcpy(str1,str,10);
  printf(\n this is string 1\n);
  printf(%s\n,str1);
  return 0;
 }

 Output is :

  is rajeev

  this is string 1
  is ra is rajeev


 it copies 10 characters from str to str1 so the printing  is ra is
 Ok what abt the repeating result?

 --
 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] Explanation

2011-07-07 Thread Vishal Thanki
memcpy is usually used to copy data structures other than strings. Use
strcpy for copying strings!!

On Fri, Jul 8, 2011 at 11:25 AM, Navneet Gupta navneetn...@gmail.com wrote:
 @Vishal, still the array str1 is also 10 bytes only, I know that memcpy
 overwrites the null character but not sure then what is the correct approach
 if i still want to use memcpy. Thoughts?

 On Fri, Jul 8, 2011 at 10:51 AM, Vishal Thanki vishaltha...@gmail.com
 wrote:

 you are overwriting terminating null char!!

 On Fri, Jul 8, 2011 at 10:23 AM, rShetty rajeevr...@gmail.com wrote:
  #includestdio.h
  #includestring.h
  int main()
  {
   char str[]=This is rajeev\n;
   char str1[10];
   memset(str,'0',4);
   printf(%s,str);
   memcpy(str1,str,10);
   printf(\n this is string 1\n);
   printf(%s\n,str1);
   return 0;
  }
 
  Output is :
 
   is rajeev
 
   this is string 1
   is ra is rajeev
 
 
  it copies 10 characters from str to str1 so the printing  is ra is
  Ok what abt the repeating result?
 
  --
  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.




 --
 Regards,
 Navneet


 --
 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] Reversing the order of words in String

2011-07-06 Thread Vishal Thanki
If we only need to print the words in reverse order, strtok+recursion
can help. Following is the code (which also stores the string into
another string, not memory efficient though):

#include stdio.h
#include string.h
#include stdlib.h

char str[] = This is a new world;
char sstr[sizeof(str)];

char *print_rev(char *tok)
{
char *nstr = NULL;
if (tok) {
nstr = strtok(NULL,  );
print_rev(nstr);
if (nstr) {
//  printf(%s , nstr);
strcpy(sstr[strlen(sstr)], nstr);
sstr[strlen(sstr)] = ' ';
}
}
return nstr;

}

int main(int argc, char *argv[])
{
char *nstr;
printf(Org string -- %s\n, str);
nstr = strtok(str,  );
print_rev(str);
strcpy(sstr[strlen(sstr)], nstr);
printf(New string -- %s\n, sstr);
return 0;
}


On Thu, Jul 7, 2011 at 9:10 AM, Navneet Gupta navneetn...@gmail.com wrote:
 @Piyush, could you elaborate your approach with Linked List?
 From what i am getting, even with Linked List, you would need two
 traversals at least.

 On Thu, Jul 7, 2011 at 2:07 AM, Piyush Sinha ecstasy.piy...@gmail.com wrote:
 Can we do it using linked list if ONE TIME TRAVERSAL is a constraint??

 On 7/6/11, Tushar Bindal tushicom...@gmail.com wrote:
 I read that solution.
 But the same doubt as Navneet which I think you also raised i one of your
 posts on that thread

 On Wed, Jul 6, 2011 at 10:34 PM, Navneet Gupta navneetn...@gmail.comwrote:

 Saurabh,

 I understood your solution but wonder if it is purely single traversal

 In affect, you have a second traversal when you are popping the
 strings from stack to form the reverse order string.

 Though the second activity is less than O(n) i.e. O(#words in string)
 Nice solution, this way we can also get rid of extra spaces easily in
 the actual string if that is also to be done.

 On Wed, Jul 6, 2011 at 10:16 PM, saurabh singh saurab...@gmail.com
 wrote:
  I have proposed my solution in one of the previous posts.Check the
 solution
  there
 
  On Wed, Jul 6, 2011 at 10:10 PM, Tushar Bindal tushicom...@gmail.com
  wrote:
 
  good job
  but how can this be done in one traversal as asked on the Adobe
 Interview
  Questions thread.
 
 
 
  On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta navneetn...@gmail.com
  wrote:
 
  I think somebody on this thread has asked this question but i am not
  able to find that.
 
  Question was if a string is like my name is ram, then output should
  be ram is name my.
 
  Wrote the code for same, so sharing.
 
  #includeiostream
  #includestring
  using namespace std;
 
  void SwapStringChars(string str, int pos1, int pos2)
  {
         char ch = str[pos1];
         str[pos1] = str[pos2];
         str[pos2] = ch;
  }
 
  void reverseString(string str, int left, int right)
  {
         for(int i = left ; i = left + (right-left)/2 ; i++)
                 SwapStringChars(str, i, right + left -i));
  }
 
  void reverseWordsInString(string str)
  {
         char space = ' ';
         int len = str.length();
         int startIndex = 0, endIndex = 0;
         while(endIndex  len - 1)
         {
                 while(str[endIndex] != space  endIndex 
 len)endIndex++;
                 reverseString(str, startIndex, endIndex-1);
                 startIndex = endIndex;
                 while(str[startIndex] == space)startIndex++;
                 endIndex = startIndex;
         }
  }
 
  int main()
  {
         string str;
         cout\nEnter enter the string :;
         getline(cin,str);
 
         //Reverse whole string at once
         reverseString(str, 0, str.length() - 1);
 
         //Reverse Individual words in string
         reverseWordsInString(str);
         coutstr;
         cin.get();
         return 0;
  }
 
  --
  Regards,
  Navneet
 
  --
  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.
 
 
 
 
  --
  Tushar Bindal
  Computer Engineering
  Delhi College of Engineering
  Mob: +919818442705
  E-Mail : tushicom...@gmail.com
  Website: www.jugadengg.com
 
  --
  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.
 
 
 
  --
  Saurabh Singh
  B.Tech (Computer Science)
  MNNIT ALLAHABAD
 
 
  --
  You received this message because you are subscribed to the Google
  Groups
  Algorithm Geeks group.
  To post to this group, send email to 

Re: [algogeeks] Re: 2 D array(dynamic allocation)

2011-07-05 Thread Vishal Thanki
Hi Gene,

I was thinking the same thing which you implemented in your first
snippet. But I tried it without using typedef. Following is my code:

#include stdio.h
#include malloc.h

int main()
{
int (*ptr)[4] ;
ptr = (int ((*)[4]))malloc(2*sizeof(int (*)[4]));
if (ptr) {
int i,j,cnt =0;
for (i= 0; i  2;i++)
for (j = 0; j  4; j++)
ptr[i][j] = cnt++;

for (i= 0; i  2;i++)
for (j = 0; j  4; j++)
printf(%d\n,ptr[i][j]);

/* Free will not work, as the above code
 * overwrites the signature used by free
 */
/* free((ptr)); */
}
return 0;
}


This code is buggy, because as soon as the malloc returns, I try to
write some data and in that process, I am overwriting the signature
(which is used by free()), and hence free() call fails. Can you point
out the problem?

Thanks,
Vishal

On Sun, Jul 3, 2011 at 2:12 AM, Gene gene.ress...@gmail.com wrote:
 Unfortunately this invokes undefined behavior, so it may not work for
 all architectures and compilers.  It relies on pointers to int having
 the same alignment as int.

 By far the best way to do this is use C99 features:

 double (*a)[n_cols] = calloc(n_rows, sizeof *a);

 If you don't have C99 and the row length is fixed, then you can
 allocated a 2d array very easily:

 #include stdio.h
 #include stdlib.h

 #define ROW_SIZE 10
 typedef double ROW[ROW_SIZE];

 int main(void)
 {
  int i, j n_rows = 15;
  ROW *array = malloc(n_rows * sizeof(ROW));
  for (i  = 0; i  n_rows; i++)
    for (j = 0; j  ROW_SIZE; j++)
      array[i][j] = 100 * i + j;
  for (i  = 0; i  n_rows; i++) {
    for (j = 0; j  ROW_SIZE; j++)
      printf(%5.0f, array[i][j]);
    printf(\n);
  }
  return 0;
 }

 If you need both array axes to be variable, then the norm is to
 allocate a 1d array and define a macro to allow 2d access:

 #include stdio.h
 #include stdlib.h

 typedef double *ARRAY;
 #define Elt(A, I, J, NCOLS)  ((A)[(I) * (NCOLS) + (J)])

 int no_fixed(void)
 {
  int i, j, n_rows = 15, n_cols = 10;
  ARRAY array = malloc(n_rows * n_cols * sizeof array[0]);
  for (i  = 0; i  n_rows; i++)
    for (j = 0; j  n_cols; j++)
      Elt(array, i, j, n_cols) = 100 * i + j;
  for (i  = 0; i  n_rows; i++) {
    for (j = 0; j  n_cols; j++)
      printf(%5.0f, Elt(array, i, j, n_cols));
    printf(\n);
  }
  return 0;
 }


 On Jul 2, 2:05 pm, vaibhav shukla vaibhav200...@gmail.com wrote:
 @sandeep sir: thnx... good 1 :)





 On Sat, Jul 2, 2011 at 11:32 PM, Sandeep Jain sandeep6...@gmail.com wrote:
  Here's my solution.

  int** allocateMatrix(int m, int n)
  {
   int **rowList = (int**)malloc(sizeof(int)*m*n + sizeof(int*)*m);
   int *colList = (int*)(rowList+m);
   int i;
   for(i=0; im; i++)
   {
     rowList[i] = colList+i*n;
   }
   return rowList;
  }

  And here's the main method to test/understand the allocation.

  int main()
  {
   int m=3, n=4;
   int **mat = allocateMatrix(m,n);
   int i, j, c=0;
   int wordCount= m*n+m; //sizeof(int)*4*5 + sizeof(int*)*4; counting
  words so sizeof is not needed
   int* memMap = (int*)mat;

   // Fill array elements with some values to be able to test
   for(i=0; im; i++)
     for(j=0; jn; j++)
      mat[i][j] = c++;

   printf(\nAddress\t    Value\n);
   for(i=0; iwordCount; i++)
     printf(\n%u\t== %u, memMap+i, memMap[i]);

   getchar();
  }

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

 --
   best wishes!!
 Vaibhav Shukla- 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 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] Re: find output

2011-07-05 Thread Vishal Thanki
+1 @Sankalp

On Tue, Jul 5, 2011 at 5:02 PM, sankalp srivastava
richi.sankalp1...@gmail.com wrote:
 A better place to put these types of questions would be www.stackoverflow.com

 On Jul 4, 10:45 pm, amit kumar amitthecoo...@gmail.com wrote:
 thanx guys...

 On Mon, Jul 4, 2011 at 5:11 PM, mahesh.jnumc...@gmail.com 







 mahesh.jnumc...@gmail.com wrote:
  In while loop, the value of i will be used as 0 as it is post decrement so
  the value of i will decrement after the while loop is executed.
  so 0!=0 will fail and the value of i will get decrement and will be printed
  as -1.

  On Mon, Jul 4, 2011 at 3:54 PM, amit the cool 
  amitthecoo...@gmail.comwrote:

  main()
  {
  int i=0;
  while(+(+i--)!=0)
  i-=i++;
  printf(%d,i);
  }

  output sud be 1
  bt it is -1;
  why??

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

 --
 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] c doubt

2011-07-04 Thread Vishal Thanki
because \061 is considered as a single char in ur string..

On Mon, Jul 4, 2011 at 12:52 PM, Sangeeta sangeeta15...@gmail.com wrote:
 #Iincludestdio.h
 #includestring.h
 main()
 {
 char str[]=S\061AB;
 printf(\n%d,strlen(str));
 }
 output:4
 why?

 --
 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] Fwd: anu_test Segmentation fault

2011-07-03 Thread Vishal Thanki
Don't allocate too much static memory in stack, it will cause
troubles. You are doing int[2000][2000], i.e. 2000*2000*4 bytes of
memory in stack. Use dynamic memory allocation for such large chunk. I
modified your code as below and it doesn't give seg fault.
#includestdio.h
#include malloc.h
#includestring.h
#define MAX 2000
using namespace std;

int minimum(int a,int b,int c)
{
if(ab  ac) return a;
if(bc) return b;
return c;
}

int LevenshteinDistance(char *a, char *b)
{
int **d;
int m=0,n=0,i,j;
char s[MAX]=0;
char t[MAX]=0;
d = (int **)malloc(MAX*sizeof(int));
for (i=0;iMAX;i++)
d[i] = (int *)malloc(MAX*sizeof(int));
strcat(s,a);
strcat(t,b);
m=strlen(s);
n=strlen(t);
printf(%s%s,s,t);
for(i=0;i=m;i++) d[i][0]=i ;
for(j=0;j=n;j++) d[0][j]=j;

for(j=1;j=n;j++)
{
for(i=1;i=m;i++)
{
if (s[i] == t[j])
d[i][j]=d[i-1][j-1];
else
d[i][j]=minimum(d[i-1][j] + 
(s[i]==t[i]?0:1),d[i][j-1] +
1,d[i-1][j-1] + 1 );
}

}
//TODO: Free d
return d[m][n];
}


int main()
{
int t,ed;
char s1[MAX],t1[MAX];
scanf(%d,t);
while( t--)
{
scanf(%s%s,s1,t1);
//couts1t1endl;
ed=LevenshteinDistance(s1,t1);
printf(%d\n,ed);
}

return 0;
}


On Sun, Jul 3, 2011 at 9:08 PM, HARSH PAHUJA hpahuja.mn...@gmail.com wrote:


 -- Forwarded message --
 From: HARSH PAHUJA hpahuja.mn...@gmail.com
 Date: Sun, Jul 3, 2011 at 8:37 AM
 Subject: anu_test Segmentation fault
 To: anutest...@googlegroups.com


 http://www.ideone.com/QuMcn
 plzz help.
 y the above program is giving seg fault

 #includestdio.h
 #includestring.h
 #define MAX 2000
 //using namespace std;
 int minimum(int a,int b,int c)
 {
 if(ab  ac) return a;
 if(bc) return b;
 return c;
 }
 int LevenshteinDistance(char a[], char b[])
 {
 int d[2000][2000]={0};
 int m=0,n=0,i,j;
 char s[MAX]=0;
 char t[MAX]=0;
 strcat(s,a);
 strcat(t,b);
 m=strlen(s);
 n=strlen(t);
 printf(%s%s,s,t);
 for(i=0;i=m;i++) d[i][0]=i ;
 for(j=0;j=n;j++) d[0][j]=j;
 for(j=1;j=n;j++)
 {
 for(i=1;i=m;i++)
 {
 if (s[i] == t[j])
 d[i][j]=d[i-1][j-1];
 else
 d[i][j]=minimum(d[i-1][j] + (s[i]==t[i]?0:1),d[i][j-1] + 1,d[i-1][j-1] + 1
 );
 }
 }
 return d[m][n];
 }

 int main()
 {
 int t,ed;
 char s1[MAX],t1[MAX];
 scanf(%d,t);
 while( t--)
 {
 scanf(%s%s,s1,t1);
 //couts1t1endl;
 ed=LevenshteinDistance(s1,t1);
 printf(%d\n,ed);
 }
 return 0;
 }

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



 --
 HARSHIT PAHUJA
 M.N.N.I.T.
 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] please explain

2011-06-30 Thread Vishal Thanki
Rujin is right, here is the code which compiles..

vishal@ubuntu:~/progs/c\ 11:04:37 AM $ cat alg.c
#includestdio.h
int maxdiff(int arr[]);
int main()
{
int p,arr[]={2,4,1,6,23,4};
p=maxdiff(arr);
printf(\n MAX Diff is \t %d,p);
return 0;
}
int maxdiff(int arr[])
{
int diff=0,len,i,j;
unsigned p;
len=sizeof(arr)/sizeof(arr[0]);
for(i=0;ilen;i++)
{
for(j=i;jlen;j++)
{
p=arr[j]-arr[i];
if((p-diff)0)
diff=p;
}
}
return diff;
}
vishal@ubuntu:~/progs/c\ 11:04:40 AM $ gcc alg.c -Wall


On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa varunpahwa2...@gmail.com wrote:
 actually u r passing arr,and receiving arr[] which actually receives the
 first element address. So arr will be a reference to first address. so its
 size will be 4  bytes and arr size will also be 4 bytes. so ur len contains
 only 1. so ur loop runs only once.i hope it clears.

 On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh asingh...@gmail.com wrote:

 still it's not working

 On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao drizzle...@gmail.com wrote:

 int maxdiff(int );
 int maxdiff(int arr[]);
 The signatures of  maxdiff function are  not the same.

 On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh asingh...@gmail.com
 wrote:

 this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
 integer from pointer without a cast) . Please explain the reasons.


 #includestdio.h
 #includeconio.h
 int maxdiff(int );
 main()
 {
   int p,arr[]={2,4,1,6,23,4};
   p=maxdiff(arr);
   printf(\n MAX Diff is \t %d,p);
   getch();
   }
 int maxdiff(int arr[])
 {
     int diff=0,len,i,j;
     unsigned p;
     len=sizeof(arr)/sizeof(arr[0]);
     for(i=0;ilen;i++)
     {
   for(j=i;jlen;j++)
   {
  p=arr[j]-arr[i];
  if((p-diff)0)
  diff=p;
   }
     }
     return diff;
     }

 --
 with regards,
 Ashwini kumar singh
 ECE Final yr.
 NIT 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.



 --
 with regards,
 Ashwini kumar singh
 ECE Final yr.
 MNNIT Allahabad
 Mobile: 7505519402

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



 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112 ,08011820777
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.

 --
 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] Re: Statement Riddle

2011-06-27 Thread Vishal Thanki
this may be  a reverse race, who comes last will win..

On Mon, Jun 27, 2011 at 6:22 PM, Dave dave_and_da...@juno.com wrote:
 Force indain driver finishes second in race. Ferari was next to last.

 Dave



 On Jun 27, 2:18 am, Lavesh Rawat lavesh.ra...@gmail.com wrote:
 *Statement Riddle  - 27 june
  *
 *
 *
 **
 *'Ferari driver' easily beats the 'force indain driver' in a two care
 race.How did Indian newspapers *
 *truthfully report so to look as 'force indain drive' had outdone the
 'ferari driver'
 Think ??
 *
 *Update Your Answers at* : Click
 Herehttp://dailybrainteaser.blogspot.com/2011/06/statement-riddle.html?la...

 *Solution:*
 Will be updated after 1 day

 --

                     Never explain yourself. Your friends don’t need it and
 your enemies won’t believe 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.



-- 
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] Reverse

2011-06-27 Thread Vishal Thanki
this code will only print, it will not store the reverse string.

On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal
kamakshi...@gmail.com wrote:
 #include stdio.h
 #include stdlib.h
 void revers(char *s)
 {
      if(*s)
      {
                     revers(++s);
                     s--;
                     printf(%c ,*s);
      }

 }
 int main(int argc, char *argv[])
 {
     char arr[]=string;
     revers(arr);

   system(PAUSE);
   return 0;
 }
 will s be counted as temporary variable in this?
 On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote:

 Reversing a String without using a temporary variable ?


 Rajeev N B

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




 --
 Regards,
 Kamakshi
 kamakshi...@gmail.com

 --
 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] Reverse

2011-06-27 Thread Vishal Thanki
and yes, s will be stored in stack everytime you call the function,
so its a temp variable..

string reverse is a simple logic, just iterate i through 1 to n/2 and
swap the i to n-i

On Mon, Jun 27, 2011 at 10:06 PM, Vishal Thanki vishaltha...@gmail.com wrote:
 this code will only print, it will not store the reverse string.

 On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal
 kamakshi...@gmail.com wrote:
 #include stdio.h
 #include stdlib.h
 void revers(char *s)
 {
      if(*s)
      {
                     revers(++s);
                     s--;
                     printf(%c ,*s);
      }

 }
 int main(int argc, char *argv[])
 {
     char arr[]=string;
     revers(arr);

   system(PAUSE);
   return 0;
 }
 will s be counted as temporary variable in this?
 On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote:

 Reversing a String without using a temporary variable ?


 Rajeev N B

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




 --
 Regards,
 Kamakshi
 kamakshi...@gmail.com

 --
 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] [Brain Teaser] Sherlock puzzle 24 June

2011-06-24 Thread Vishal Thanki
she got killed because of suffocation :P

On Fri, Jun 24, 2011 at 12:35 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote:
 sherlock puzzle Solution - 24 june

 A wife and her husband were driving in their car on the highway. All of a
 sudden, they ran out of gas. So the husband said to the wife, 'Now, you stay
 here. I will go down the highway to the nearest gas station, and I will be
 about 1 hour. Just listen to the radio and read some books, and remember to
 lock all the windows and doors. I will leave the keys with you.' So, off the
 husband went, and the wife first locked ALL the windows and doors. Next, she
 turned on the radio, and this is what she heard on the news report:

 'THERE IS A MURDERER ON THE LOOSE. HE WAS LAST SEEN ON THE HIGHWAY, WEARING
 ALL BLACK, ABOUT 5 FOOT 11 INCHES. PLEASE, BE AWARE AND CONTACT THE POLICE
 IMMEDIATELY.' The wife got very scared. She turned off the radio and double
 checked the locked doors. Then she saw the murderer, only a couple feet away
 from the car. An hour later, the husband returned to his car. Inside the
 car, his wife was DEAD, she had been murdered. All the windows were still
 locked, and the doors. No windows were broken, and the car was in PERFECT
 condition. No scratches or anything, it was the same way as when he left it.
 How did the murderer kill the wife?Yo dont need to be sherlock holmes to
 solve this ??

 Update Your Answers at : Click Here

 --

                     Never explain yourself. Your friends don’t need it and
 your enemies won’t believe 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.


-- 
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] C Error

2011-06-23 Thread Vishal Thanki
Hey all,

I think I am missing something very basic in C, and which is troubling
me. Following code is not compiling for me, can anyone explain why?

vishal@ubuntu:~/progs/c\ 09:07:01 AM $ cat ternary.c
#include stdio.h
#include stdlib.h
int main(int argc, char *argv[])
{
int x = atoi(argv[1]);
int y = 10;
(x  10) ? y++: x = 10;
return x;
}
vishal@ubuntu:~/progs/c\ 09:07:08 AM $ gcc ternary.c
ternary.c: In function ‘main’:
ternary.c:7: error: lvalue required as left operand of assignment


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] C Error

2011-06-23 Thread Vishal Thanki
yes, i understand that.. but is there any limitation in ternary
operator that the 2nd expression (after :)should not use assignment
operator?



On Fri, Jun 24, 2011 at 9:21 AM, Wladimir Tavares wladimir...@gmail.com wrote:
 Try this:
 #include stdio.h
 #include stdlib.h
 int main(int argc, char *argv[])
 {
        int x = atoi(argv[1]);
        int y = 10;
        x = (x  10) ? y++: 10;
        return x;
 }
 Wladimir Araujo Tavares
 Federal University of Ceará






 On Fri, Jun 24, 2011 at 12:40 AM, Vishal Thanki vishaltha...@gmail.com
 wrote:

 Hey all,

 I think I am missing something very basic in C, and which is troubling
 me. Following code is not compiling for me, can anyone explain why?

 vishal@ubuntu:~/progs/c\ 09:07:01 AM $ cat ternary.c
 #include stdio.h
 #include stdlib.h
 int main(int argc, char *argv[])
 {
        int x = atoi(argv[1]);
        int y = 10;
        (x  10) ? y++: x = 10;
        return x;
 }
 vishal@ubuntu:~/progs/c\ 09:07:08 AM $ gcc ternary.c
 ternary.c: In function ‘main’:
 ternary.c:7: error: lvalue required as left operand of assignment


 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.


 --
 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] C Error

2011-06-23 Thread Vishal Thanki
Okay, I found the problem i think,

(x  10) ? y++: x = 10 is evaluated as ((x  10) ? y++: x) = 10
which is wrong..

(x  10) ? y++: (x = 10) will work.


On Fri, Jun 24, 2011 at 9:22 AM, Vishal Thanki vishaltha...@gmail.com wrote:
 yes, i understand that.. but is there any limitation in ternary
 operator that the 2nd expression (after :)should not use assignment
 operator?



 On Fri, Jun 24, 2011 at 9:21 AM, Wladimir Tavares wladimir...@gmail.com 
 wrote:
 Try this:
 #include stdio.h
 #include stdlib.h
 int main(int argc, char *argv[])
 {
        int x = atoi(argv[1]);
        int y = 10;
        x = (x  10) ? y++: 10;
        return x;
 }
 Wladimir Araujo Tavares
 Federal University of Ceará






 On Fri, Jun 24, 2011 at 12:40 AM, Vishal Thanki vishaltha...@gmail.com
 wrote:

 Hey all,

 I think I am missing something very basic in C, and which is troubling
 me. Following code is not compiling for me, can anyone explain why?

 vishal@ubuntu:~/progs/c\ 09:07:01 AM $ cat ternary.c
 #include stdio.h
 #include stdlib.h
 int main(int argc, char *argv[])
 {
        int x = atoi(argv[1]);
        int y = 10;
        (x  10) ? y++: x = 10;
        return x;
 }
 vishal@ubuntu:~/progs/c\ 09:07:08 AM $ gcc ternary.c
 ternary.c: In function ‘main’:
 ternary.c:7: error: lvalue required as left operand of assignment


 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.


 --
 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] [brain teaser ] A Riddle

2011-06-22 Thread Vishal Thanki
was he driving a bus or tram?

On Wed, Jun 22, 2011 at 12:36 PM, Yameni Dhankar yamenid...@gmail.com wrote:
 was he driving an ambulance?

 On Wed, Jun 22, 2011 at 12:33 PM, Lavesh Rawat lavesh.ra...@gmail.com
 wrote:

 A Riddle

 A bus driver was heading down a street in Delhi. He went right past a stop
 sign without stopping, he turned left where there was a 'no left turn' sign
 and he went the wrong way on a one-way street. Then he went on the left side
 of the road past a cop car. Still - he didn't break any traffic laws. Why
 not?

 Update Your Answers at : Click Here
 Solution:
 Will be updated after 1 day



 --

                     Never explain yourself. Your friends don’t need it
 and your enemies won’t believe 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.



 --
 Yameni Dhankar
 Division of Computer Engineering(Undergraduate),
 Netaji Subhas Institute of Technology,
 New Delhi

 --
 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] Find the error..

2011-06-22 Thread Vishal Thanki
memory leak and memory allocation check, make sure malloc return non-null.

On Wed, Jun 22, 2011 at 7:04 PM, Shachindra A C sachindr...@gmail.com wrote:
 @balaji, the memory allocated from the heap using malloc needs to be
 released before termination of the program. there should be two additional
 statements as follows:
 free(p);
 free(q);

 On Wed, Jun 22, 2011 at 6:09 PM, PRITPAL SINGH pritpal2...@gmail.com
 wrote:

 @balaji

 I think memory leak is the only problem with the code.
 rest is fine

 On Wed, Jun 22, 2011 at 6:03 PM, Balaji S balaji.ceg...@gmail.com wrote:

 @pritpal : Refer ques 5 at
 http://www.youthrocker.com/2011/06/interview-questions-amazon-placement.html

 @shachindra : wats tat :-o

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



 --
 Regards
 Pritpal Singh Banga
 (RIT2008021)
 BTech ( IT ) , 6th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Official email : rit2008...@iiita.ac.in
 Mobile: +91-9793907703

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



 --
 Regards,
 Shachindra A C

 --
 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] Interview Question: Puzzle: Probability

2011-06-22 Thread Vishal Jain
Navneet,

Your answer is correct, it would have been great if you could have explained
it for others.
I myself took good time to understand it...

Here is the answer

http://exploreriddles.blogspot.com/2011/06/interview-questions-puzzle.html


To maximize the chances of retrieving Red Ball, it is mandatory to reduce
the chances of retrieving Blue ball.

To reduce the chances.

1. It is possible to put all the black ball in one jar. It will reduce the
probability of retrieving black ball to half.

2. Now to reduce the probability of withdrawing Blue balls, need to maximize
number of red balls in the jar with blue balls. Maximum red balls we have is
50.

So based on above 2 points...

one jar can have 1 Red ball, and other will contain rest 99 balls.

So probability of choosing red ball is
(Probability of Choosing Jar 1)*(Probability of Choosing Red Ball From jar
1) + (Probability of Choosing Jar 2)*(Probability of Choosing Red Ball From
jar 2)

(1/2)*(1) + (1/2)(49/99)

Thanks  Regards
Vishal Jain
MNo: +91-9540611889
Tweet @jainvis
Blog @ jainvish.blogspot.com
Success taste better when target achieved is bigger.

P *We have a responsibility to the environment.*

*Before printing this e-mail or any other document, let's ask
ourselves whether we need a hard copy.*




On Tue, Jun 14, 2011 at 7:47 PM, Navneet Gupta navneetn...@gmail.comwrote:

 Put one red ball in one jar and rest 99 balls in other jar.

 Probability in that case is 1/2*1 + 1/2*49//99

 On Tue, Jun 14, 2011 at 7:45 PM, Vishal Jain jainv...@gmail.com wrote:

 Folks,

 This question was asked during a screening process of a product based
 company. Please answer.

 http://exploreriddles.blogspot.com/2011/06/interview-questions-puzzle.html

 Thanks  Regards
 Vishal Jain
 Success taste better when target achieved is bigger.

 P *We have a responsibility to the environment.*

 *Before printing this e-mail or any other document, let's ask ourselves 
 whether we need a hard copy.*


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




 --
 --Navneet

  --
 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] Output please..

2011-06-18 Thread Vishal Thanki
btw, i didn't understand the reason/motive behind this question? was
it some kind of test??

On Sat, Jun 18, 2011 at 11:45 AM, Harshal hc4...@gmail.com wrote:
 compiler error?? if the void is replaced by int, ans=155.

 On Sat, Jun 18, 2011 at 11:33 AM, Balaji S balaji.ceg...@gmail.com wrote:

 main()
  { int i=5;
  printf(%d,fun(fun(fun(fun( fun(i));
 }

  void fun (int i)
  {
 if(i%2)
 return (i+(7*4)-(5/2)+(2*2));
  else


 return (i+(17/5)-(34/15)+(5/2));
 }

 --
 With Regards,
     Balaji.S

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



 --
 Harshal Choudhary,
 III Year B.Tech CSE,
 NIT Surathkal, Karnataka, India.


 --
 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] Interview Question: Puzzle: Probability

2011-06-14 Thread Vishal Jain
Folks,

This question was asked during a screening process of a product based
company. Please answer.

http://exploreriddles.blogspot.com/2011/06/interview-questions-puzzle.html

Thanks  Regards
Vishal Jain
Success taste better when target achieved is bigger.

P *We have a responsibility to the environment.*

*Before printing this e-mail or any other document, let's ask
ourselves whether we need a hard copy.*

-- 
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] output

2011-06-14 Thread Vishal Thanki
@ Harshal, you are absolutely right. Again, this kind of code is
highly discouraged when used in real life projects. And there is no
need to go into details of how to evaluate such expressions, which are
not complying to standards.

On Wed, Jun 15, 2011 at 10:49 AM, Harshal hc4...@gmail.com wrote:
 Google sequence points. The C Standard states that between the previous and
 next sequence point an object shall have its stored value modified at most
 once by the evaluation of an expression.
 So, expressions like i++ + ++i can produces different results on different
 compilers. Its not a standard expression a per Standard.
 On Wed, Jun 15, 2011 at 9:47 AM, Bhavesh agrawal agr.bhav...@gmail.com
 wrote:


 int a,c=5;
 a=c++ + ++c + c++ + ++c;
 printf(%d\n,a);
 c=5;
 a=c++ + ++c + c++;
 printf(%d\n,a);
 c=5;
 a=++c + ++c;
 printf(%d\n,a);
 c=5;
 a=++c + ++c + ++c;
 printf(%d\n,a);

 compiled with gcc and the outputs are
 25
 18
 14
 22
  can anyone plz explain these outputs



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



 --
 Harshal Choudhary,
 III Year B.Tech CSE,
 NIT Surathkal, Karnataka, India.


 --
 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] C OUTPUT HELP

2011-06-11 Thread Vishal Thanki
In 1st program, 2nd printf requires one more argument. And basically
%a is used for printing a double value in hex. see man 3 printf.

On Sat, Jun 11, 2011 at 5:29 PM, nicks crazy.logic.k...@gmail.com wrote:
 Hello friends..plz help me in understanding the following C Output

 first one is --

 #includestdio.h
 #includeconio.h
 main()
 {
 int a=5;
 printf(a=%d\n,a);
 printf(%a=%d,a);
 getch();
 }
 OUTPUT -
 a=5
 0x1.2ff380p-1021=4199082


 and the other one is --

 #includestdio.H
 # include conio.h
 int i=2;
 main()
 {
  void add();
  add(i++,--i);
     printf(\ni=%d \n,i);system(pause);
 }
 void add(int a ,int b)
 {
  printf(\na=%d b=%d,a,b);
 }

  OUTPUT -
 a=1 b=1
 i=2

 --
 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] C Question

2011-06-07 Thread Vishal Thanki
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] C doubt

2011-06-05 Thread Vishal Thanki
Usually it is a bad practice to increment the pointer. Rather, one
should use the indexing variable to dereference the pointer at some
index. One more bug in your code was, you are allocating the space for
only 3 ints for p and storing 4 ints. Here is the code with some
modification.

#include stdio.h
int main(){

int *p,i=0;
void *x;
p=(int *)malloc(4*sizeof(int));
x=malloc(24);
p[0]=1;
p[1]=2;
p[2]=3;
p[3]=4;
while(i4){
*(((int *)x)+i) = p[i];
i++;
}

for(i=0;i4;i++){
printf(%d\n,p[i]);
printf(%d\n,((int *)x)[i]);
}
return 0;
}


On Sun, Jun 5, 2011 at 6:19 PM, Piyush Sinha ecstasy.piy...@gmail.com wrote:
 @Amit Jaspal...there is a fundamental error in the code related to
 pointersu have incremented the pointers p and x..so before the printf
 loop, pointer p (as well as x) is pointing to 4th location...I hope I am
 clear...

 this can be done by creating two more pointers that will initialised as the
 base location of p and x...

 #include stdio.h
 int main(){

    int *p,*a,i=0;
    void *x,*b;
    p=(int *)malloc(3*sizeof(int));
    a =p;
    x=malloc(24);
    b = x;
    p[0]=1;
    p[1]=2;
    p[2]=3;
    p[3]=4;
    while(i4){
    *((int *)x)=*p;
    ((int *)x)++;
    p++;
    i++;
    }

    for(i=0;i4;i++){
    printf(%d\n,a[i]);
    printf(%d\n,((int *)b)[i]);
    }


     system(pause);
     return 0;
 }


 On Sun, May 29, 2011 at 11:38 PM, amit amitjaspal...@gmail.com wrote:

 Suppose I want to copy an integer array to another array pointed by a
 void pointer of different size.
 Some thing like this is done probably in realloc function.

 The problem is it is not working for me ... here's the code

 #include stdio.h
 int main(){

        int *p,i=0;
        void *x;
        p=(int *)malloc(3*sizeof(int));
        x=malloc(24);
        p[0]=1;
        p[1]=2;
        p[2]=3;
        p[3]=4;
        while(i4){
                *((int *)x)=*p;
                ((int *)x)++;
                p++;
                i++;
        }

        for(i=0;i4;i++){
                printf(%d\n,p[i]);
                printf(%d\n,((int *)x)[i]);
        }
        return 0;
 }


 Can anyone suggest what is happening wrong in this code.or what
 can be a better way to do 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.




 --
 Piyush Sinha
 IIIT, Allahabad
 +91-8792136657
 +91-7483122727
 https://www.facebook.com/profile.php?id=10655377926

 --
 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] gcc debugger

2011-06-04 Thread Vishal Thanki
http://www.yolinux.com/TUTORIALS/GDB-Commands.html

this may help

On Sat, Jun 4, 2011 at 11:57 PM, nitish goyal nitishgoy...@gmail.com wrote:
 @ saurabh singh
 thanks

 On Sat, Jun 4, 2011 at 11:44 PM, saurabh singh saurabh.n...@gmail.com
 wrote:

 Do man gdb

 On Sat, Jun 4, 2011 at 11:20 PM, rahul rahulr...@gmail.com wrote:

 gdb a.out
 b(break) main .
 den do press n(next) to execute next stmt.
 if next instruction is function...
 press s(step).



 On Sat, Jun 4, 2011 at 11:19 PM, nitish goyal nitishgoy...@gmail.com
 wrote:

 n ?

 do not understand it.
 Please elaborate

 On Sat, Jun 4, 2011 at 11:17 PM, rahul rahulr...@gmail.com wrote:

 n

 On Sat, Jun 4, 2011 at 11:16 PM, nitish goyal nitishgoy...@gmail.com
 wrote:

 Please tell me the commands to use the gdb debugger

 To run the code line by line

 --
 Regards,
 Nitish Goyal
 Undergraduate Student Of NSIT,
 Computer Engineering (B.E.)
 Asst. PlaceComm 2011
 contact me:- +91-605824
 Reply at :-  nitishgoyal.n...@gmail.com

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



 --
 Regards,
 Nitish Goyal
 Undergraduate Student Of NSIT,
 Computer Engineering (B.E.)
 Asst. PlaceComm 2011
 contact me:- +91-605824
 Reply at :-  nitishgoyal.n...@gmail.com

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



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



 --
 Regards,
 Nitish Goyal
 Undergraduate Student Of NSIT,
 Computer Engineering (B.E.)
 Asst. PlaceComm 2011
 contact me:- +91-605824
 Reply at :-  nitishgoyal.n...@gmail.com

 --
 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] A simple C question

2011-06-03 Thread Vishal Thanki
can use fork() also..

On Fri, Jun 3, 2011 at 11:57 AM, anand karthik
anandkarthik@gmail.com wrote:
 (!printf(Hello))

 On Jun 3, 2011 11:52 AM, Arpit Mittal mrmittalro...@gmail.com wrote:
 Please help me in this question.

 What's the condition so that the following code prints both HelloWorld !

 if condition
 printf (Hello);
 else
 printf(World);




 --
 -Arpit Mittal
 6th Semester,
 Indian Institute of Information Technology,Allahabad
 Email : arpitmittal.ii...@gmail.com
 rit2008...@iiita.ac.in
 Contact : +91-8853049787

 Let every man be respected as an individual and no man idolized.

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


-- 
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] A simple C question

2011-06-03 Thread Vishal Thanki
vishal@ubuntu:~/progs/c\ 12:11:53 PM $ cat fork.c
#include stdio.h
#include stdlib.h

int main()
{
if (fork()) {
printf(hello );
} else {
printf(world\n);
}
return 0;
}
vishal@ubuntu:~/progs/c\ 12:11:56 PM $ gcc fork.c
vishal@ubuntu:~/progs/c\ 12:12:06 PM $ ./a.out
hello world


On Fri, Jun 3, 2011 at 12:09 PM, Naveen Kumar
naveenkumarve...@gmail.com wrote:
 Hi Vishal,

 Can you show us how it be done with fork?

 On Fri, Jun 3, 2011 at 12:02 PM, Vishal Thanki vishaltha...@gmail.com
 wrote:

 can use fork() also..

 On Fri, Jun 3, 2011 at 11:57 AM, anand karthik
 anandkarthik@gmail.com wrote:
  (!printf(Hello))
 
  On Jun 3, 2011 11:52 AM, Arpit Mittal mrmittalro...@gmail.com wrote:
  Please help me in this question.
 
  What's the condition so that the following code prints both
  HelloWorld !
 
  if condition
  printf (Hello);
  else
  printf(World);
 
 
 
 
  --
  -Arpit Mittal
  6th Semester,
  Indian Institute of Information Technology,Allahabad
  Email : arpitmittal.ii...@gmail.com
  rit2008...@iiita.ac.in
  Contact : +91-8853049787
 
  Let every man be respected as an individual and no man idolized.
 
  --
  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.
 

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




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


-- 
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] A simple C question

2011-06-03 Thread Vishal Thanki
@sachindra, @naveen,
this was just a plain trick to execute if and else block. i agree
with your concerns :)

2011/6/3 Vιиodh vinodh...@gmail.com:
 @vishal:
 can u explain the fork()  solution??

 On Fri, Jun 3, 2011 at 12:16 PM, Shachindra A C sachindr...@gmail.com
 wrote:

 There can be some synchronisation problems with fork() right? say world
 might get printed first...or maybe the letters can get jumbled too...We
 cannot guarantee the order of execution unless we use semaphores.

 On Fri, Jun 3, 2011 at 12:14 PM, Naveen Kumar naveenkumarve...@gmail.com
 wrote:

 oh yes,
 gud one

 On Fri, Jun 3, 2011 at 12:12 PM, Vishal Thanki vishaltha...@gmail.com
 wrote:

 vishal@ubuntu:~/progs/c\ 12:11:53 PM $ cat fork.c
 #include stdio.h
 #include stdlib.h

 int main()
 {
        if (fork()) {
                printf(hello );
        } else {
                printf(world\n);
        }
        return 0;
 }
 vishal@ubuntu:~/progs/c\ 12:11:56 PM $ gcc fork.c
 vishal@ubuntu:~/progs/c\ 12:12:06 PM $ ./a.out
 hello world


 On Fri, Jun 3, 2011 at 12:09 PM, Naveen Kumar
 naveenkumarve...@gmail.com wrote:
  Hi Vishal,
 
  Can you show us how it be done with fork?
 
  On Fri, Jun 3, 2011 at 12:02 PM, Vishal Thanki
  vishaltha...@gmail.com
  wrote:
 
  can use fork() also..
 
  On Fri, Jun 3, 2011 at 11:57 AM, anand karthik
  anandkarthik@gmail.com wrote:
   (!printf(Hello))
  
   On Jun 3, 2011 11:52 AM, Arpit Mittal mrmittalro...@gmail.com
   wrote:
   Please help me in this question.
  
   What's the condition so that the following code prints both
   HelloWorld !
  
   if condition
   printf (Hello);
   else
   printf(World);
  
  
  
  
   --
   -Arpit Mittal
   6th Semester,
   Indian Institute of Information Technology,Allahabad
   Email : arpitmittal.ii...@gmail.com
   rit2008...@iiita.ac.in
   Contact : +91-8853049787
  
   Let every man be respected as an individual and no man idolized.
  
   --
   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.
  
 
  --
  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.
 
 
 
 
  --
  Cheers
  Naveen 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.
 

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




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



 --
 Regards,
 Shachindra A C

 --
 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,
 Vιиodh

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

Re: [algogeeks] A simple C question

2011-06-03 Thread Vishal Thanki
to use the semaphores, you have to allocate them using shared memory.
as once you call fork(), both the process will have their own data, so
the semaphores allocated in parent will differ from child. you can
have a shared memory (man shmget) to allocate semaphores and use it..

btw, i think we are missing the essence of the question here. the code
needs a condition so that both if and else gets executed. the
printf(hello) and printf(world) are just instructions in both the
code. the order doesn't matter when you have both the code executed.

On Fri, Jun 3, 2011 at 11:55 PM, nitish goyal nitishgoy...@gmail.com wrote:
 But if i have to make sure that hello should be printed first, then i have
 to apply synchronization.
 please answer my question. how we can semaphores over here

 On Fri, Jun 3, 2011 at 11:26 PM, nicks crazy.logic.k...@gmail.com wrote:

 @naveen.. thanks...i got it finally :)

 On Fri, Jun 3, 2011 at 10:35 AM, Naveen Kumar naveenkumarve...@gmail.com
 wrote:

 when we fork a new process, parent gets the PID of the chid as return
 value and child will get 0 as return value.
 Same address space is copied and both of them start executing this
 program in their own address space.
 In Modern OSes 99% of the time child comes first so child process is
 execute else part and parent will execute if place.



 On Fri, Jun 3, 2011 at 10:58 PM, nicks crazy.logic.k...@gmail.com
 wrote:

 i mean why both the if else statements are working by using fork ?

 On Fri, Jun 3, 2011 at 10:20 AM, Naveen Kumar
 naveenkumarve...@gmail.com wrote:

 Process don't share address space when forked.


 On Fri, Jun 3, 2011 at 10:40 PM, nitish goyal nitishgoy...@gmail.com
 wrote:

 @ Lalit
 You are right.

 that's why i am saying how i can use semaphores in the above example

 On Fri, Jun 3, 2011 at 10:37 PM, LALIT SHARMA lks.ru...@gmail.com
 wrote:

 While using fork(), child shares parent address space ,

 Correct me If I am wrong ..

 On Fri, Jun 3, 2011 at 10:28 PM, nitish goyal
 nitishgoy...@gmail.com wrote:
  Hi all,
 
  I am stuck with this code..Can anyone tell me how to implement
  semaphores in
  fork system call
  Code:
 
  #includestdio.h
 
  int signal(int *n);
  int wait(int *n);
 
 
  int main()
  {
      int n;
      n=0;
      if(fork())
      {
          printf(Hello);
          signal(n);
      }
      else
      {
          wait(n);
          printf(World);
      }
  }
  int signal(int *n)
  {
      (*n)++;
  }
  int wait(int *n)
  {
      while((*n)=0);
      (*n)--;
  }
 
  Since parent process and child process will be having different
  address
  spaces...so change of n in one address space will not be visible to
  other.so
  please tell me how to make n visible to both the processes
 
  On Fri, Jun 3, 2011 at 2:45 PM, Subhransu
  subhransu.panigr...@gmail.com
  wrote:
 
  Here you go in C code
   http://codepad.org/gk6AZj0T
 
 
  int main()
  {
  if(printf(hello)!=0) {
   printf(world);
  }
  else {
   printf(SCREWED ! ! !); }
 
  return 0;
  }
 
 
  Subhransu Panigrahi
 
  Mobile: +91-9840931538
  Email: subhransu.panigr...@gmail.com
 
 
  On Fri, Jun 3, 2011 at 1:57 PM, Naveen Kumar
  naveenkumarve...@gmail.com
  wrote:
 
  Hi Shachindra,
  I don't think letters will be jumbled because we a calling one
  api to
  output on console  tty's driver takes whole line and output it
  at once.
 
  On Fri, Jun 3, 2011 at 12:40 PM, Vishal Thanki
  vishaltha...@gmail.com
  wrote:
 
  @sachindra, @naveen,
  this was just a plain trick to execute if and else block. i
  agree
  with your concerns :)
 
  2011/6/3 Vιиodh vinodh...@gmail.com:
   @vishal:
   can u explain the fork()  solution??
  
   On Fri, Jun 3, 2011 at 12:16 PM, Shachindra A C
   sachindr...@gmail.com
   wrote:
  
   There can be some synchronisation problems with fork() right?
   say
   world
   might get printed first...or maybe the letters can get
   jumbled
   too...We
   cannot guarantee the order of execution unless we use
   semaphores.
  
   On Fri, Jun 3, 2011 at 12:14 PM, Naveen Kumar
   naveenkumarve...@gmail.com
   wrote:
  
   oh yes,
   gud one
  
   On Fri, Jun 3, 2011 at 12:12 PM, Vishal Thanki
   vishaltha...@gmail.com
   wrote:
  
   vishal@ubuntu:~/progs/c\ 12:11:53 PM $ cat fork.c
   #include stdio.h
   #include stdlib.h
  
   int main()
   {
          if (fork()) {
                  printf(hello );
          } else {
                  printf(world\n);
          }
          return 0;
   }
   vishal@ubuntu:~/progs/c\ 12:11:56 PM $ gcc fork.c
   vishal@ubuntu:~/progs/c\ 12:12:06 PM $ ./a.out
   hello world
  
  
   On Fri, Jun 3, 2011 at 12:09 PM, Naveen Kumar
   naveenkumarve...@gmail.com wrote:
Hi Vishal,
   
Can you show us how it be done with fork?
   
On Fri, Jun 3, 2011 at 12:02 PM, Vishal Thanki
vishaltha...@gmail.com
wrote:
   
can use fork() also..
   
On Fri, Jun 3, 2011 at 11:57 AM, anand karthik
anandkarthik@gmail.com wrote:
 (!printf(Hello))

 On Jun 3, 2011

Re: [algogeeks] c output

2011-06-01 Thread Vishal Thanki
you may want to read: http://c-faq.com/expr/seqpoints.html

On Wed, Jun 1, 2011 at 5:19 PM, himanshu kansal
himanshukansal...@gmail.com wrote:
 a=++b*++b;
 if b=3 initially, then a is coming out to be 25.why

 --
 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] sum of two n bit binary intergers

2011-05-31 Thread Vishal Thanki
#include stdio.h

int main()
{
int a[8] = {1,0,1,1,0,0,1,1};
int b[8] = {1,0,1,1,0,0,1,1};
int c[9] = {0};

int size = sizeof(a)/sizeof(a[0]);

int i;
int carry = 0;
for (i = size-1; i = 0; i--) {
if (a[i]  b[i]) {
if (carry) {
c[i+1] = 1;
} else
carry = 1;
} else if (a[i] || b[i]) {
if (!carry) {
c[i+1] = 1;
}
} else if (carry){
carry = 0;
c[i+1] = 1;
}
}
c[i+1] = carry;

printf(Printing summed array\n);  
for (i = 0; i  size+1; i++) {
printf(%d , c[i]);
}
printf(\n);
}


On Wed, Jun 1, 2011 at 8:46 AM, D.N.Vishwakarma@IITR deok...@gmail.com wrote:
 There are two n length array A[1...n] ,B[1...n] in which n-bit binary
 integers are stored... We have to sum these two integers and store it in n+1
 length array C[1...n+1] in binary form

 --
 With Regards
 Deoki Nandan Vishwakarma
 IITR MCA
 Mathematics Department

 --
 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] Google Interview Question

2011-05-29 Thread Vishal Jain
Can this work...

Lets say I have following numbers
8 9 7 4 2 121 23 21 24 27 35 79 2334 6785

Now repeat the last number to make all the number of equal length...
     1211 2333 2111 2444 2777 3555 7999 2334 6785

Sort the following numbers in descending order.
  7999  6785 ...

Now merge the numbers based on their actual value.
987976785..

I have not testing this entirely, but after seeing solution(Multiplying by
10) at top, I though this might work better.


Thanks  Regards
Vishal Jain
MNo: +91-9540611889
Tweet @jainvis
Blog @ jainvish.blogspot.com
Success taste better when target achieved is bigger.

P *We have a responsibility to the environment.*

*Before printing this e-mail or any other document, let's ask
ourselves whether we need a hard copy.*




On Sun, May 29, 2011 at 12:58 PM, Ashish Goel ashg...@gmail.com wrote:

 Radix/bucket sort..

 won't that help?

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



 On Fri, May 27, 2011 at 7:15 PM, adityasir...@gmail.com wrote:

 how about this case:

  9, 100 - 9100
 100 9
 9100

  2, 3, 9, 78 --
  78 9 3 2
 9 78 3 2

 I guess solution should be:-
 sort the array of numbers in an ascending order and then check for the
 first element in the array, if there is any other element greater than it,
 shift all the elements one right and place that element in the left most
 space.


 On Fri, May 27, 2011 at 9:37 AM, wujin chen wujinchen...@gmail.comwrote:

 @Piyush, how to deal with this case :100 , 10


 2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com

 we can work out if we sort according to the leftmost integer

 On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
  are you kidding me. Just simple sort wont work.
 
  On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
  radhakrishnance...@gmail.com wrote:
 
  sort :)
 
 
  On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
 
  Hi all,
 
  Given an array of elements find the largest possible number that can
  be formed by using the elements of the array.
 
  eg: 10 9
  ans: 910
 
  2 3 5 78
 
  ans: 78532
 
  100 9
 
  ans: 9100
 
  --
  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.
 
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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


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


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

Re: [algogeeks] Re: spoj--two squares problem

2011-05-29 Thread Vishal Jain
Hi Saurabh,

Can you try it for 10? Could not really understand, what are you gonna
communicate?

10 = 2*5 (2^2 + 1^2 )*(1*2 + 1^2)... If with this logic you are saying 10 is
prime then all numbers divisible by 5 should be prime.

Could you elaborate your answer more?

Thanks  Regards
Vishal Jain
MNo: +91-9540611889
Tweet @jainvis
Blog @ jainvish.blogspot.com
Success taste better when target achieved is bigger.

P *We have a responsibility to the environment.*

*Before printing this e-mail or any other document, let's ask
ourselves whether we need a hard copy.*




On Sun, May 29, 2011 at 6:46 AM, saurabh singh saurab...@gmail.com wrote:

 In fact we can...though not directly..SInce every number can be broken down
 as facotrs of primeUse that property


 On Sun, May 29, 2011 at 1:12 AM, Tushar Bindal tushicom...@gmail.comwrote:

 that theorem is for odd primes
 9 is not an odd prime
 so we can;t apply this theorem


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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT 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] Re: Sudoku verification problem

2011-05-29 Thread Vishal Thanki
yes, you are right. bitmap will be filled in the process of solving
the grid. in verify routine, if the expression evaluates to false, it
mean an element is encountered which is already present in row, col
and 3x3 cube. this way you an tell that the solution is wrong.

hope that helps.


On Sun, May 29, 2011 at 2:01 PM, Dumanshu duman...@gmail.com wrote:
 here in this part
 if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
                    (((bitmap[bj]  matrix[i][j])  0x1) == 0x0) 
                                        (((bitmap[bk]  matrix[i][j])
  0x1) == 0x0)) {
                                bitmap[bi] |= 1  matrix[i][j];
                                bitmap[bj] |= 1  matrix[i][j];
                                bitmap[bk] |= 1  matrix[i][j];

 I think you are checking the same values which u have already set in
 the bitmap using the fill_bitmap function. like suppose the 1st cell
 of the matrix has value 5. then using fill bitmap u have the set
 corresponding 5th bit in all 3 places(row col 3by3 cell) using bi bj
 and bk.
 now in the verify function u checking the same bit against that matrix
 value which u have already set. so everytime ur if statement will
 evaluate to false.

 I may be wrong... plz help.

 On May 28, 9:15 pm, Vishal Thanki vishaltha...@gmail.com wrote:
 here is the code..

 #define bi  (i)
 #define bj  (GRID_SIZE+j)
 #define bk  (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt)))

 /*glb_sqrt should be the square root of grid_size (i.e. 3 if its a 9x9
 sudoku). */

 /* #define bk  (int)((GRID_SIZE*2)+(5*(i/5)+(j/5))) */

 /*
  * This function will verify solved grid. It will start with each element
  * in grid and update the bitmap step by step. As soon as it encounters an
  * element which is already present in bitmap, it will return error.
  *
  */

 int verify()
 {
         int i, j, k;
         int bitmap[GRID_SIZE*3] = {0};
         int bmp_idx;
         for (i = 0; i  GRID_SIZE; i++) {
                 for (j = 0; j  GRID_SIZE; j++) {
                         if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
                                         (((bitmap[bj]  matrix[i][j])  
 0x1) == 0x0) 
                                         (((bitmap[bk]  matrix[i][j])  
 0x1) == 0x0)) {
                                 bitmap[bi] |= 1  matrix[i][j];
                                 bitmap[bj] |= 1  matrix[i][j];
                                 bitmap[bk] |= 1  matrix[i][j];
                         } else {
                                 printf(Sudoku Error: i = %d, j = %d\n, i, 
 j);
                                 return -1;
                         }

                 }
         }
         return 0;







 }
 On Sat, May 28, 2011 at 11:53 AM, Dumanshu duman...@gmail.com wrote:
  Given a n by n matrix. Suggest an algorithm to verify its correctness
  given a configuration. User can enter numbers only between 1 to n.
  I need this in 2 ways -
  1. for the n by n matrix, suggest an elegant way for validating it.
  2. suggest a data structure for this sudoku so that the structure aids
  in its verification.

  thnx for the 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 
  athttp://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.



-- 
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: Sudoku verification problem

2011-05-29 Thread Vishal Thanki
sorry, i made a mistake in explaining. when you are solving the gird,
you will have the matrix[][] array partially filled. the bitmap used
for solving the grid is different than the one being used for
verifying. in case of verifying, you will have a completely blank
bitmap, with not bits set. you will iterate through the matrix array
and set the bits in bitmap accordingly. so the if condition will
evaluate to true for all the conditions till you have the correct
values for cells in grid. as soon as you get a duplicate value for a
cell, the condition will become false. i hope that is clear.

hope that helps.

PS: just ignore the fill_bitmap() routine, it is only used at the
starting of solving the grid, and not for verifying. if you observe
the verify() routine, the bitmap[] array is a local array and
initialized to 0 before use.



On Sun, May 29, 2011 at 5:40 PM, Dumanshu duman...@gmail.com wrote:
 no... what i mean to say is you have filled the bitmap in the process
 of solving the grid. The way you are  filling the bitmap is - you are
 taking values from the matrix and placing them in the bitmaps using bi
 bj bk.

 now in the verification you are checking the same matrix value against
 the same bitmap field. it will always evaluate out to be false for
 your if.
 your if statement is checking whether the matrix value and the bitmap
 value is same or not. you have used the matrix value to fill the
 bitmap so obviously they will be same.

 see in fill bitmap funciton u did for some i,j -

  bmp[bi] |= 1  matrix[i][j];
                                bmp[bj] |= 1  matrix[i][j];
                                bmp[bk] |= 1  matrix[i][j];
 that is for some particular i,j say 5,4
 u took value matrix[5][4] =8 and set the bit in bitmap after
 calculating bi,bj,bk - these values are bi ==5, bj== 13 and bk == 10
 so now in bmp[5], bmp[10] and bmp[13] u have set the 8th bit.

 now in verify function

  if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
                                        (((bitmap[bj]  matrix[i][j])
  0x1) == 0x0) 
                                        (((bitmap[bk]  matrix[i][j])
  0x1) == 0x0)) {
                                bitmap[bi] |= 1  matrix[i][j];
                                bitmap[bj] |= 1  matrix[i][j];
                                bitmap[bk] |= 1  matrix[i][j];

 here during the loop when i==5 and j==4, the if condition will always
 evaluate to false.

 same thing will happen for every value in the matrix because the
 corresponding bit has been set earlier.

 so how is ur verification function working???



 On May 29, 3:35 pm, Vishal Thanki vishaltha...@gmail.com wrote:
 yes, you are right. bitmap will be filled in the process of solving
 the grid. in verify routine, if the expression evaluates to false, it
 mean an element is encountered which is already present in row, col
 and 3x3 cube. this way you an tell that the solution is wrong.

 hope that helps.







 On Sun, May 29, 2011 at 2:01 PM, Dumanshu duman...@gmail.com wrote:
  here in this part
  if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
                     (((bitmap[bj]  matrix[i][j])  0x1) == 0x0) 
                                         (((bitmap[bk]  matrix[i][j])
   0x1) == 0x0)) {
                                 bitmap[bi] |= 1  matrix[i][j];
                                 bitmap[bj] |= 1  matrix[i][j];
                                 bitmap[bk] |= 1  matrix[i][j];

  I think you are checking the same values which u have already set in
  the bitmap using the fill_bitmap function. like suppose the 1st cell
  of the matrix has value 5. then using fill bitmap u have the set
  corresponding 5th bit in all 3 places(row col 3by3 cell) using bi bj
  and bk.
  now in the verify function u checking the same bit against that matrix
  value which u have already set. so everytime ur if statement will
  evaluate to false.

  I may be wrong... plz help.

  On May 28, 9:15 pm, Vishal Thanki vishaltha...@gmail.com wrote:
  here is the code..

  #define bi  (i)
  #define bj  (GRID_SIZE+j)
  #define bk  (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt)))

  /*glb_sqrt should be the square root of grid_size (i.e. 3 if its a 9x9
  sudoku). */

  /* #define bk  (int)((GRID_SIZE*2)+(5*(i/5)+(j/5))) */

  /*
   * This function will verify solved grid. It will start with each element
   * in grid and update the bitmap step by step. As soon as it encounters an
   * element which is already present in bitmap, it will return error.
   *
   */

  int verify()
  {
          int i, j, k;
          int bitmap[GRID_SIZE*3] = {0};
          int bmp_idx;
          for (i = 0; i  GRID_SIZE; i++) {
                  for (j = 0; j  GRID_SIZE; j++) {
                          if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
  
                                          (((bitmap[bj]  matrix[i][j])  
  0x1) == 0x0) 
                                          (((bitmap[bk]  matrix[i][j])  
  0x1) == 0x0

Re: [algogeeks] Re: Sudoku verification problem

2011-05-29 Thread Vishal Thanki
what i understood from your problem is, when the configuration is
given by user, it can be directly stored into matrix[][] array. that
will solve your problem in o(n^2), where n=9.

On Sun, May 29, 2011 at 5:50 PM, Dumanshu duman...@gmail.com wrote:
 I think ur verification function is correct but it works only if user
 is entering the values one by one. as soon as he enters a duplicate
 value it will show a error. It will work for the case of ur solver as
 ur code itself is generating the values.
 But here in this verification problem u r given a configuration from a
 user.  i.e. all values at once not one by one.

 So one thing that can be done is use ur fillbitmap function and then
 check if any of the 9 Least significant bits of the 27 values in ur
 bmp array is not set. If thats the case then sukoku isn't correct.
 but then this code would take O(n^2) = (3*n*n) time here n is 9.

 On May 29, 5:10 pm, Dumanshu duman...@gmail.com wrote:
 no... what i mean to say is you have filled the bitmap in the process
 of solving the grid. The way you are  filling the bitmap is - you are
 taking values from the matrix and placing them in the bitmaps using bi
 bj bk.

 now in the verification you are checking the same matrix value against
 the same bitmap field. it will always evaluate out to be false for
 your if.
 your if statement is checking whether the matrix value and the bitmap
 value is same or not. you have used the matrix value to fill the
 bitmap so obviously they will be same.

 see in fill bitmap funciton u did for some i,j -

  bmp[bi] |= 1  matrix[i][j];
                                 bmp[bj] |= 1  matrix[i][j];
                                 bmp[bk] |= 1  matrix[i][j];
 that is for some particular i,j say 5,4
 u took value matrix[5][4] =8 and set the bit in bitmap after
 calculating bi,bj,bk - these values are bi ==5, bj== 13 and bk == 10
 so now in bmp[5], bmp[10] and bmp[13] u have set the 8th bit.

 now in verify function

   if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
                                         (((bitmap[bj]  matrix[i][j])
  0x1) == 0x0) 
                                         (((bitmap[bk]  matrix[i][j])
  0x1) == 0x0)) {
                                 bitmap[bi] |= 1  matrix[i][j];
                                 bitmap[bj] |= 1  matrix[i][j];
                                 bitmap[bk] |= 1  matrix[i][j];

 here during the loop when i==5 and j==4, the if condition will always
 evaluate to false.

 same thing will happen for every value in the matrix because the
 corresponding bit has been set earlier.

 so how is ur verification function working???

 On May 29, 3:35 pm, Vishal Thanki vishaltha...@gmail.com wrote:







  yes, you are right. bitmap will be filled in the process of solving
  the grid. in verify routine, if the expression evaluates to false, it
  mean an element is encountered which is already present in row, col
  and 3x3 cube. this way you an tell that the solution is wrong.

  hope that helps.

  On Sun, May 29, 2011 at 2:01 PM, Dumanshu duman...@gmail.com wrote:
   here in this part
   if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
                      (((bitmap[bj]  matrix[i][j])  0x1) == 0x0) 
                                          (((bitmap[bk]  matrix[i][j])
0x1) == 0x0)) {
                                  bitmap[bi] |= 1  matrix[i][j];
                                  bitmap[bj] |= 1  matrix[i][j];
                                  bitmap[bk] |= 1  matrix[i][j];

   I think you are checking the same values which u have already set in
   the bitmap using the fill_bitmap function. like suppose the 1st cell
   of the matrix has value 5. then using fill bitmap u have the set
   corresponding 5th bit in all 3 places(row col 3by3 cell) using bi bj
   and bk.
   now in the verify function u checking the same bit against that matrix
   value which u have already set. so everytime ur if statement will
   evaluate to false.

   I may be wrong... plz help.

   On May 28, 9:15 pm, Vishal Thanki vishaltha...@gmail.com wrote:
   here is the code..

   #define bi  (i)
   #define bj  (GRID_SIZE+j)
   #define bk  (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt)))

   /*glb_sqrt should be the square root of grid_size (i.e. 3 if its a 9x9
   sudoku). */

   /* #define bk  (int)((GRID_SIZE*2)+(5*(i/5)+(j/5))) */

   /*
    * This function will verify solved grid. It will start with each 
   element
    * in grid and update the bitmap step by step. As soon as it encounters 
   an
    * element which is already present in bitmap, it will return error.
    *
    */

   int verify()
   {
           int i, j, k;
           int bitmap[GRID_SIZE*3] = {0};
           int bmp_idx;
           for (i = 0; i  GRID_SIZE; i++) {
                   for (j = 0; j  GRID_SIZE; j++) {
                           if bitmap[bi]  matrix[i][j])  0x1) == 
   0x0) 
                                           (((bitmap[bj]  matrix[i][j]) 
0x1) == 0x0

Re: [algogeeks] C Output

2011-05-29 Thread Vishal Thanki
a  0.08f will make it compare to float. by default 0.08 is
considered as double.

On Sun, May 29, 2011 at 9:51 PM, Ankit Agarwal ankitgeniu...@gmail.com wrote:
 #includestdio.h

 int main(void)
 {
     float a=0.08;
     if(a0.08)
         printf(Hello\n);
     else
         printf(Hii\n);
     return 0;
 }

 The o/p is: Hello    why

 --
 Ankit Agarwal

 --
 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] C Output

2011-05-29 Thread Vishal Thanki
you may want to check how the floats and doubles are stored into
memory using ieee notation.

i tried to print 0.08 and 0.08f in hex format and got the following result.

vishal@ubuntu:~/progs/c\ 10:03:56 AM $ cat fl.c
#include stdio.h
int main()
{
float f=0.08;
if (f  0.08f)
printf(hi\n);
else
printf(hello\n);

printf (%x %x\n,0.08, 0.08f);
return 0;
}
vishal@ubuntu:~/progs/c\ 10:04:06 AM $ gcc fl.c
fl.c: In function ‘main’:
fl.c:10: warning: format ‘%x’ expects type ‘unsigned int’, but
argument 2 has type ‘double’
fl.c:10: warning: format ‘%x’ expects type ‘unsigned int’, but
argument 3 has type ‘double’
vishal@ubuntu:~/progs/c\ 10:04:11 AM $ ./a.out
hello
47ae147b 3fb47ae1
vishal@ubuntu:~/progs/c\ 10:04:14 AM $

ps: please ignore the warning in the code.

On Sun, May 29, 2011 at 10:23 PM, sravanreddy001
sravanreddy...@gmail.com wrote:
 and, I read it long time back that.. the value of 0.8 alone will be stored
 as 0.7995 (not sure on the number of 9's but.. the last digit in the
 precision will be a 5)
 that could be a reason.
 may be what vishal said is correct.

 --
 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] Finding Blocks in a matrix

2011-05-29 Thread Vishal Thanki
what about using a hash function?

On Mon, May 30, 2011 at 10:18 AM, ross jagadish1...@gmail.com wrote:
 Given a matrix, you need to find the number of blocks in it.
 A block has the same numbers.
 EG:
 1 1 3
 1 2 3
 2 2 4
 has 4 blocks namely,
 1 1
 1
   2
 2 2

 3
 3

 4

 1 2 3
 4 5 6
 7 8 9
 has 9 blocks



 1 1 1
 1 1 3
 4 4 5
 has 4 blocks,
 1 1 1
 1 1

 3

 5

 4 4

 I used an algorithm as follows,
 for each element[i,j] in the matrix,
   enqueue adjacent indices into a queue if they contain the same
 element.
  else
 incremt blockcount;

 return blockcount;

 But, this complexity is O(n^3) any better solution exists?

 --
 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] Re: Finding Blocks in a matrix

2011-05-29 Thread Vishal Thanki
Okay, i thought it this way: iterate through the whole matrix, and
take the value  as a key to a hash table. and the value
corresponding to the key would be the count. increment the count
everytime you encounter the same key. it is very easy to implement
this in python (using dictionary) but i am not sure what will be the
most efficient data structure to implement this in c/c++.

Vishal

On Mon, May 30, 2011 at 10:31 AM, ross jagadish1...@gmail.com wrote:
 @vishal
 Hi,
 I do not get you.
 Can you please elaborate a little more how you ll use hash?

 On May 30, 8:50 am, Vishal Thanki vishaltha...@gmail.com wrote:
 what about using a hash function?







 On Mon, May 30, 2011 at 10:18 AM, ross jagadish1...@gmail.com wrote:
  Given a matrix, you need to find the number of blocks in it.
  A block has the same numbers.
  EG:
  1 1 3
  1 2 3
  2 2 4
  has 4 blocks namely,
  1 1
  1
    2
  2 2

  3
  3

  4

  1 2 3
  4 5 6
  7 8 9
  has 9 blocks

  1 1 1
  1 1 3
  4 4 5
  has 4 blocks,
  1 1 1
  1 1

  3

  5

  4 4

  I used an algorithm as follows,
  for each element[i,j] in the matrix,
    enqueue adjacent indices into a queue if they contain the same
  element.
   else
  incremt blockcount;

  return blockcount;

  But, this complexity is O(n^3) any better solution exists?

  --
  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 
  athttp://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.



-- 
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: Finding Blocks in a matrix

2011-05-29 Thread Vishal Thanki
@anshu, i got you. my bad!!

On Mon, May 30, 2011 at 10:49 AM, anshu mishra
anshumishra6...@gmail.com wrote:
 @vishal ur sol wil give wrong answer for this
 1 1 2
 1 3 1
 2 3 4
 answer should be 6 but ur sol wil give 4.

 --
 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] Sudoku verification problem

2011-05-28 Thread Vishal Thanki
here is the code..

#define bi  (i)
#define bj  (GRID_SIZE+j)
#define bk  (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt)))

/*glb_sqrt should be the square root of grid_size (i.e. 3 if its a 9x9
sudoku). */

/* #define bk  (int)((GRID_SIZE*2)+(5*(i/5)+(j/5))) */


/*
 * This function will verify solved grid. It will start with each element
 * in grid and update the bitmap step by step. As soon as it encounters an
 * element which is already present in bitmap, it will return error.
 *
 */

int verify()
{
int i, j, k;
int bitmap[GRID_SIZE*3] = {0};
int bmp_idx;
for (i = 0; i  GRID_SIZE; i++) {
for (j = 0; j  GRID_SIZE; j++) {
if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
(((bitmap[bj]  matrix[i][j])  0x1) 
== 0x0) 
(((bitmap[bk]  matrix[i][j])  0x1) 
== 0x0)) {
bitmap[bi] |= 1  matrix[i][j];
bitmap[bj] |= 1  matrix[i][j];
bitmap[bk] |= 1  matrix[i][j];
} else {
printf(Sudoku Error: i = %d, j = %d\n, i, j);
return -1;
}


}
}
return 0;
}


On Sat, May 28, 2011 at 11:53 AM, Dumanshu duman...@gmail.com wrote:
 Given a n by n matrix. Suggest an algorithm to verify its correctness
 given a configuration. User can enter numbers only between 1 to n.
 I need this in 2 ways -
 1. for the n by n matrix, suggest an elegant way for validating it.
 2. suggest a data structure for this sudoku so that the structure aids
 in its verification.

 thnx for the 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.



-- 
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] Sudoku verification problem

2011-05-28 Thread Vishal Thanki
Forgot to mention that you have to fill the bitmap before calling this
routine. This code is the part of the actual sudoku solver code. Here
is the bitmap filling code which is very simple..

void fill_bitmap(int *bmp)
{
int i, j;
for (i = 0; i  GRID_SIZE; i++) {
for (j = 0; j  GRID_SIZE; j++) {
if (matrix[i][j]) {
bmp[bi] |= 1  matrix[i][j];
bmp[bj] |= 1  matrix[i][j];
bmp[bk] |= 1  matrix[i][j];
}
}
}
}

Need not to mention that marix[][] is the 2-D array to represent sudoku grid.

On Sat, May 28, 2011 at 9:45 PM, Vishal Thanki vishaltha...@gmail.com wrote:
 here is the code..

 #define bi  (i)
 #define bj  (GRID_SIZE+j)
 #define bk  (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt)))

 /*glb_sqrt should be the square root of grid_size (i.e. 3 if its a 9x9
 sudoku). */

 /* #define bk  (int)((GRID_SIZE*2)+(5*(i/5)+(j/5))) */


 /*
  * This function will verify solved grid. It will start with each element
  * in grid and update the bitmap step by step. As soon as it encounters an
  * element which is already present in bitmap, it will return error.
  *
  */

 int verify()
 {
        int i, j, k;
        int bitmap[GRID_SIZE*3] = {0};
        int bmp_idx;
        for (i = 0; i  GRID_SIZE; i++) {
                for (j = 0; j  GRID_SIZE; j++) {
                        if bitmap[bi]  matrix[i][j])  0x1) == 0x0) 
                                        (((bitmap[bj]  matrix[i][j])  0x1) 
 == 0x0) 
                                        (((bitmap[bk]  matrix[i][j])  0x1) 
 == 0x0)) {
                                bitmap[bi] |= 1  matrix[i][j];
                                bitmap[bj] |= 1  matrix[i][j];
                                bitmap[bk] |= 1  matrix[i][j];
                        } else {
                                printf(Sudoku Error: i = %d, j = %d\n, i, j);
                                return -1;
                        }


                }
        }
        return 0;
 }


 On Sat, May 28, 2011 at 11:53 AM, Dumanshu duman...@gmail.com wrote:
 Given a n by n matrix. Suggest an algorithm to verify its correctness
 given a configuration. User can enter numbers only between 1 to n.
 I need this in 2 ways -
 1. for the n by n matrix, suggest an elegant way for validating it.
 2. suggest a data structure for this sudoku so that the structure aids
 in its verification.

 thnx for the 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.




-- 
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] [CodeFest] Participate in Manthan - Algorithm Intensive Programming Contest

2011-03-13 Thread vishal kumar rai
Hello,

*CodeFest'11* http://codefest.org.in/, the annual online international
coding festival of Computer Engineering Society IT-BHU, presents
Manthanhttp://codefest.org.in/event.php?name=manthan-
the *algorithm intensive* programming contest.

The contest aims to provide a platform for programmers round the globe to
showcase their problem-solving and programming skills. Most problems of the
event will be real life computing problems where coders will be required to
prune existing standard algorithms to find the solution for the domain
specific application of the algorithm.

We are proud to have Codeforces http://www.codeforces.com/ as our partner
for Manthan 2011 http://codefest.org.in/event.php?name=manthan. The
Contest will be hosted on Codeforces http://www.codeforces.com/ and will
follow the rules http://codefest.org.in/event.php?name=manthan#rules similar
to that of Codeforces Beta Round.

*Google Sponsored* event with
Prizeshttp://codefest.org.in/event.php?name=manthan#prizes
 worth *50,000 INR*. Besides, *Certificates* to *top 50* participants.

*Follow the 
registrationhttp://codefest.org.in/event.php?name=manthan#participate
procedure
to register for Manthan. Registrations will close 10 minutes before the
event starts.*

*Event Details:*

   - The *main event* is scheduled on *March 13 at 2200 Hrs IST
(UTC+5.30)*http://www.timeanddate.com/worldclock/fixedtime.html?p1=176year=2011month=3day=13hour=22min=0sec=0
   - *Rules* http://codefest.org.in/event.php?name=manthan#rules of
   contest similar to Codeforces Beta Rounds.
   - The Contest will be of *4 hours* consisting of *5-6 problems*.
   - *Programing languages allowed:* C, C++ , Pascal, Java, C#, Python,
   Ruby, PHP, F# and Haskell.
   - Open to all,* students* as well as *professionals.*
   - Declaration of *Results* on *March 16 at 1800 Hrs IST*.

Visit the Manthan event page http://codefest.org.in/event.php?name=manthan to
see further details.

For further queries, feel free to contact the event coordinator at:
*Saket Jalan* +91 808 169 7891
manthan.codef...@itbhu.ac.in

*We look forward to your participation in the event.*

Be free and Happy coding :)

Regards,
Team CodeFest
Visit us at http://itbhu.ac.in/codefest/
Check out our page at http://facebook.com/codefest/
Follow us at http://twitter.com/c0defest/
Read our blog at http://itbhu.ac.in/codefest/blog

-- 
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] Invitation to CodeFest - the international online coding festival of Computer Engineering Society, ITBHU

2011-02-12 Thread vishal kumar rai
Hello ,

We are delighted to inform you that *Codefest
'11*http://www.itbhu.ac.in/codefest/,
the *annual International online coding festival* of *Computer Engineering
Society, IT-BHU*, has been unveiled. CodeFest is a unique fest wherein
concepts of mathematics, logic, artificial intelligence, algorithms,
language syntax, etc. are required to be deployed in programming; these
concepts manifest themselves in solving problems effectively and
efficiently! CodeFest was started last year. CodeFest'10 was a phenomenal
success with participation from all over the globe. CodeFest'11 is geared up
with some new and pepped up events, while maintaining the integrity of its
standards.
*
*
*Here is a brief description of the constituent online events:*

   - *Mathmania http://itbhu.ac.in/codefest/event.php?name=mathmania:* A
   mathematical puzzle contest that puts mathematical and computational skills
   to test.
  - Main Contest on Feb 27,10:00 pm
   - *Manthan http://itbhu.ac.in/codefest/event.php?name=manthan:* An
   algorithm intensive programming contest that would require coders to tailor
   existing standard algorithms.
  - Main Contest on Mar 13,12:00 pm
   - *Perplexed
http://itbhu.ac.in/codefest/event.php?name=perplexed%21:*A
programming contest, aimed to test the knowledge of C, wherein codes
will
   be rewarded against syntactic constraints.
  - Main Contest on Mar 11,12:00 pm
   - *Ratespiel http://itbhu.ac.in/codefest/event.php?name=ratespiel:* A
   technical contest covering different areas of Computer Science.
  - Round 1A on Feb 12,10:00 pm
  - Round 1B on Feb 13,04:00pm
  - Round 1C on Feb 13,10:00pm
   - *Virtual Combathttp://itbhu.ac.in/codefest/event.php?name=virtual+combat
   :* An educational game wherein teams of programmed robotic tanks will
   fight the battles for glory. Codes Do Fight! Watch
thishttp://www.youtube.com/watch?v=v1rY3tyTj50out.
  - Phase 1 already started.

Visit our *website http://itbhu.ac.in/codefest/* for more details.
*
*
*Few exciting statistics about CodeFest:*

   - 2354 registrations (including 128 professionals) from 680 different
   institutions, across 59 countries in CodeFest '10.
   - Total prize money was a whopping amount of 260,000 INR last year making
   it the largest online coding festival in the Indian subcontinent!
   - CodeFest '10 gained recognition from several international
   organizations including CodeChef, Adobe, British Telecom, TCS and IEEE

*Latest @ CodeFest '11:*

   - Already *more than 1400
registrationshttp://itbhu.ac.in/codefest/index.php#userlist
   * from more than *50 countries*.
   - Recognition from giants like *Google, IBM, and Codeforces.*
   - Prizes of more than* 200,000 INR assured*.
   - More than *1300 battleshttp://itbhu.ac.in/codefest/vc-all-matches.php
   * have already been fought among the participants of Virtual Combat in
   under a week.

The Codefest'11 team has set out to unleash a yet another coding
extravaganza. We hope that your participation would raise the level of
competition in Codefest'11. Feel free to contact us at
codef...@itbhu.ac.inor reach us personally at:

   - Mohit Bansal +91 930 505 3020
   - Saket Saurabh +91 945 282 5690

We wish you all the best for Codefest'11 and for your future endeavours.

Be free and Happy Coding!

Regards,
Team Codefest
Visit us at http://itbhu.ac.in/codefest
Like our page at http://facebook.com/codefest
Follow us at http://twitter.com/c0defest/
Read our blog at http://itbhu.ac.in/codefest/blog

-- 
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] CodeFest - Online Coding Festival by Computer Engineering Society, IT-BHU

2011-01-27 Thread vishal kumar rai


Hello,

We are delighted to inform you that 
*Codefest'11*http://www.itbhu.ac.in/codefest/, 
the *annual International online coding festival* of *Computer Engineering 
Society, IT-BHU*, has been unveiled. CodeFest is a unique fest wherein 
concepts of mathematics, logic, artificial intelligence, algorithms, 
language syntax, etc. are required to be deployed in programming; these 
concepts manifest themselves in solving problems effectively and 
efficiently! 

CodeFest was started last year. CodeFest'10 was a phenomenal success with 
participation from all over the globe. CodeFest'11 is geared up with some 
new and pepped up events, while maintaining the integrity of its 
standards.This year CodeFest has associated with 
*Technex'11*http://itbhu.ac.in/technex, 
the *annual all India Technical Festival of IT-BHU*, to expand its horizons. 


*Here is a brief description of the constituent online events:*

   - *Mathmania http://itbhu.ac.in/codefest/event.php?name=mathmania:* A 
   mathematical puzzle contest that puts mathematical and computational skills 
   to test. 
   - *Manthan http://itbhu.ac.in/codefest/event.php?name=manthan:* An 
   algorithm intensive programming contest that would require coders to tailor 
   existing standard algorithms.
   - *Perplexed http://itbhu.ac.in/codefest/event.php?name=perplexed%21:*A 
programming contest, aimed to test the knowledge of C, wherein codes will 
   be rewarded against syntactic constraints. 
   - *Ratespiel http://itbhu.ac.in/codefest/event.php?name=ratespiel:* A 
   technical contest covering different areas of Computer Science.
   - *Virtual Combathttp://itbhu.ac.in/codefest/event.php?name=virtual+combat
   :* An educational game wherein teams of programmed robotic tanks will 
   fight the battles for glory. Codes Do Fight! Watch 
thishttp://www.youtube.com/watch?v=v1rY3tyTj50out. 
   
Visit our *website* http://itbhu.ac.in/codefest/ for more details.

*Few exciting statistics about Codefest'10:* 
   
   - 2354 registrations (including 128 professionals) from 680 different 
   institutions, across 59 countries 
   - Some participants were among the winners of Google Code Jam, Top Coder 
   SRMs and ACM ICPC 
   - Total prize money was a whopping amount of 260,000 INR! 
   - Codefest '10 was the largest online coding festival of the Indian 
   subcontinent in 2010 in terms of prize money!
   - Codefest'10 was the second largest online coding festival of the Indian 
   subcontinent in 2010, next to Bitwise
   - Gained recognition from several international organizations including 
   Codechef, Adobe, British Telecom, TCS and IEEE
   
The Codefest'11 team has set out to unleash a yet another coding 
extravaganza. We hope that your participation would raise the level of 
competition in Codefest'11. Feel free to contact us at codef...@itbhu.ac.inor 
reach us personally at: 
   
   - Mohit Bansal mohit.bansal.cs...@itbhu.ac.in 
   - Saket Saurabh saket.saurabh.cs...@itbhu.ac.in

We wish you all the best for Codefest'11 and for your future endeavours.

Happy coding, and be free!

Regards,
Team Codefest
Visit us at http://itbhu.ac.in/codefest 
Mail us at codef...@itbhu.ac.in
Check out our page at http://facebook.com/codefest
Follow us at http://twitter.com/c0defest/
Read our blog at http://itbhu.ac.in/codefest/blog 


 


-- 
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] CodeFest - Online Coding Festival by Computer Engineering Society, IT-BHU

2011-01-27 Thread vishal kumar rai
Hello,

We are delighted to inform you that
*Codefest'11*http://www.itbhu.ac.in/codefest/,
the *annual International online coding festival* of *Computer Engineering
Society, IT-BHU*, has been unveiled. CodeFest is a unique fest wherein
concepts of mathematics, logic, artificial intelligence, algorithms,
language syntax, etc. are required to be deployed in programming; these
concepts manifest themselves in solving problems effectively and
efficiently!

CodeFest was started last year. CodeFest'10 was a phenomenal success with
participation from all over the globe. CodeFest'11 is geared up with some
new and pepped up events, while maintaining the integrity of its
standards.This year CodeFest has associated with
*Technex'11*http://itbhu.ac.in/technex,
the *annual all India Technical Festival of IT-BHU*, to expand its horizons.


*Here is a brief description of the constituent online events:*

   - *Mathmania http://itbhu.ac.in/codefest/event.php?name=mathmania:* A
   mathematical puzzle contest that puts mathematical and computational skills
   to test.
   - *Manthan http://itbhu.ac.in/codefest/event.php?name=manthan:* An
   algorithm intensive programming contest that would require coders to tailor
   existing standard algorithms.
   - *Perplexed
http://itbhu.ac.in/codefest/event.php?name=perplexed%21:*A
programming contest, aimed to test the knowledge of C, wherein codes
will
   be rewarded against syntactic constraints.
   - *Ratespiel http://itbhu.ac.in/codefest/event.php?name=ratespiel:* A
   technical contest covering different areas of Computer Science.
   - *Virtual Combathttp://itbhu.ac.in/codefest/event.php?name=virtual+combat
   :* An educational game wherein teams of programmed robotic tanks will
   fight the battles for glory. Codes Do Fight! Watch
thishttp://www.youtube.com/watch?v=v1rY3tyTj50out.

Visit our *website* http://itbhu.ac.in/codefest/ for more details.

*Few exciting statistics about Codefest'10:*

   - 2354 registrations (including 128 professionals) from 680 different
   institutions, across 59 countries
   - Some participants were among the winners of Google Code Jam, Top Coder
   SRMs and ACM ICPC
   - Total prize money was a whopping amount of 260,000 INR!
   - Codefest '10 was the largest online coding festival of the Indian
   subcontinent in 2010 in terms of prize money!
   - Codefest'10 was the second largest online coding festival of the Indian
   subcontinent in 2010, next to Bitwise
   - Gained recognition from several international organizations including
   Codechef, Adobe, British Telecom, TCS and IEEE

The Codefest'11 team has set out to unleash a yet another coding
extravaganza. We hope that your participation would raise the level of
competition in Codefest'11. Feel free to contact us at
codef...@itbhu.ac.inor reach us personally at:

   - Mohit Bansal mohit.bansal.cs...@itbhu.ac.in
   - Saket Saurabh saket.saurabh.cs...@itbhu.ac.in

We wish you all the best for Codefest'11 and for your future endeavours.

Happy coding, and be free!

Regards,
Team Codefest
Visit us at http://itbhu.ac.in/codefest
Mail us at codef...@itbhu.ac.in
Check out our page at http://facebook.com/codefest
Follow us at http://twitter.com/c0defest/
Read our blog at http://itbhu.ac.in/codefest/blog

-- 
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: Single linked list questions.

2011-01-06 Thread vishal raja
@sourabh,
In addition to your solution, If there is any cycle(loop) exist in the link
list your algo will fail.
To solve this problem first detect this cycle if there is any and count the
element in the cycle, and then you can do the mathematics.



On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar sourabhjak...@gmail.comwrote:

 for second question calculate the difference in length of two linked list.
 and than shift the head of longest linked list to the calculated
 difference. while the head of shorest is at the first node of that linked
 list.
 Than iterate both to see if info is equal and that is the merging point.
 complexity-o(n).
 hope this help


 On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.com wrote:

 Yes, but recursion stack's size is limited instead of iterative version.

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




 --
 SOURABH JAKHAR,(CSE)(3 year)
 ROOM NO 167 ,
 TILAK,HOSTEL
 'MNNIT ALLAHABAD


 The Law of Win says, Let's not do it your way or my way; let's do it the
 best way.

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



Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread vishal raja
@aditya,
Who said it's a Y shaped structure, It can very well has a cycle.
Assume the case when the last node is not pointing to NULL but to a node in
the list.



On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.com wrote:

 @vishal
 saurabh is right
 its merging at only one point its a Y-shaped structure



 On Thu, Jan 6, 2011 at 7:29 PM, vishal raja vishal.ge...@gmail.comwrote:


 @sourabh,
 In addition to your solution, If there is any cycle(loop) exist in the
 link list your algo will fail.
 To solve this problem first detect this cycle if there is any and count
 the element in the cycle, and then you can do the mathematics.



 On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar 
 sourabhjak...@gmail.comwrote:

 for second question calculate the difference in length of two linked
 list.
 and than shift the head of longest linked list to the calculated
 difference. while the head of shorest is at the first node of that linked
 list.
 Than iterate both to see if info is equal and that is the merging point.
 complexity-o(n).
 hope this help


 On Thu, Jan 6, 2011 at 6:48 PM, juver++ avpostni...@gmail.com wrote:

 Yes, but recursion stack's size is limited instead of iterative version.


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




 --
 SOURABH JAKHAR,(CSE)(3 year)
 ROOM NO 167 ,
 TILAK,HOSTEL
 'MNNIT ALLAHABAD


 The Law of Win says, Let's not do it your way or my way; let's do it the
 best way.

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




 --
 Regards
 Aditya Kumar
 B-tech 3rd year
 Computer Science  Engg.
 MNNIT, 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.



Re: [algogeeks] Re: combinations problem

2010-12-29 Thread vishal raja
@juver, ofcourse , and that's not a big deal.

On Wed, Dec 29, 2010 at 5:11 PM, juver++ avpostni...@gmail.com wrote:

 Yes, it's true. But we should process DP in the following order not to take
 one element more than once.

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



Re: [algogeeks] Divide an array into two equal subsets

2010-12-29 Thread vishal raja
But the same solution I've given above can give you the solution for this
problem .
In the formed table of P[i][j] , you can take another variable attached to
it as count[i][j] for how many items we have selected yet.
So you gotta find , the max. value of j which has count = 50.
count[i][j] = count[i-1][j]   if P(i-1,j) ==1
count[i][j] = count[i-1][j-a[i]]  if P(i-1,j-a[i]) ==1
else count[i][j] = 0





On Thu, Dec 30, 2010 at 11:42 AM, vishal raja vishal.ge...@gmail.comwrote:

 yeah, My bad.
 Missed that.

   On Wed, Dec 29, 2010 at 10:52 PM, Wladimir Tavares 
 wladimir...@gmail.com wrote:

 Sum up all the number and divide by 2

 Using the algorithm subset problem to find a number close to median


 Wladimir Araujo Tavares
 *Federal University of Ceará

 *





 On Wed, Dec 29, 2010 at 2:07 PM, Ankur Khurana 
 ankur.kkhur...@gmail.comwrote:

 How will you divide and array of approx 100 elements into two sub sets
 of 50 each such that the difference between both the subsets is the
 minimum possible one . .

  Thanks in advance .
 Ankur

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



Re: [algogeeks] Answer This

2010-12-17 Thread vishal raja
There were 20 green eyed people and they will commit suicide on 20th day
altogether.
See, There is atleast one green-eyed man.
So let's take the case if there was only one gree-eyed man.
than that man could've seen the colour of all other blued-eyed people and
commit suicide on the very first day.
if there were two of them, then these two guys can see each other as
green-eyed guy, they wait for a day , on the second day they realize that
there must be one more green-wyed guy other than than that guy .
so it goes like that , and using same iteration we can see if there are n
green-eyed people , they will all commit suicide altogether on n-th day.

-- 
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] Arrays

2010-09-20 Thread vishal raja
add up all the elements in array A  say sumA and array B say sumB ,substract
the sumA from sumB... You'll get the element.

On Tue, Sep 21, 2010 at 5:36 AM, Anand anandut2...@gmail.com wrote:

 Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers
 and B contains n+1 integers of which n are same as in array B but in
 different order and one extra element x. Write an optimized algorithm to
 find the value of element x. Use only one pass of both arrays A and B.

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



Re: [algogeeks] Yahoo!!!! Puzzle

2010-09-14 Thread vishal raja
take out that one A pill that's there in the jar. take the half of all the
four pills, that's how u'll make sure that u've had 1 of 'A' and 1 of 'B'
pill.



On Tue, Sep 14, 2010 at 2:52 PM, bittu shashank7andr...@gmail.com wrote:

 You are on a strict medical regimen that requires you to take two
 types of pills each day. You must take exactly one A pill and exactly
 one B pill at the same time. The pills are very expensive, and you
 don't want to waste any. So you open the bottle of A pills, and tap
 one out into your hand. Then you open the bottle of B pills and do the
 same thing -- but you make a mistake, and two B pills come out into
 your hand with the A pill. But the pills are all exactly identical.
 There is no way to tell A pills apart from B pills. How can you
 satisfy your regimen and take exactly one of each pill at the same
 time, without wasting any pills?


 Write  Algorithm to Solve dis Problem in  constant time..isn't it..???





 Regard's
 Shashank Mani Narayan  Don't Be Evil U Can Earn While U learn
 Computer Science  Engineering
 Birla Institute of  Technology,Mesra
 Cell No. +91-9166674831

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



Re: [algogeeks] Re: To sort an array of 0,1,2

2010-08-23 Thread Kumar Vishal
yes we can
 a possible solution what i can think is
treat 12 (same entity )
and 0 as other so in first pass we will short array which will have (all
zeros first , then 12 in some random order )
take index number of zero then in second pass short for 1  2

still O(n) but takes 2 pass



On Mon, Aug 23, 2010 at 12:10 PM, Manjunath Manohar 
manjunath.n...@gmail.com wrote:

 is it possible to do without any extra space...

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




-- 
Kumar Vishal

StAy HunGrY , StAy fOOlisH

Contact No:- 09560193839

-- 
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] Next higher element

2010-06-23 Thread Kumar Vishal
hi the number should be just next higher element or any higher element

like
if my arr is like

arr= 2 5 1 3 7 6
 the next higher element for 5
 should be what (7 or 6 )  because 6 is more closer to 7 but 7 comes first
in arr

On Wed, Jun 23, 2010 at 11:18 AM, Raj N rajn...@gmail.com wrote:

 Design a data structure to find the next higher element for each
 element in an array.
 For e.g. if array is 1 2 3 4 5 8 6
 o/p should be
 (element) (next higher element)
 1 2
 2 3
 3 4
 4 5
 5 8
 8 nothing
 6 nothing

 The array need not be sorted.
 Constraints-O(n) time 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Kumar Vishal

StAy HunGrY , StAy fOOlisH

Contact No:- 09560193839

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

2008-02-23 Thread Vishal
Can we just not post the code here for debugging? This group more related to
algorithms than implementations. If your code is not working, use debugger.

On Sat, Feb 23, 2008 at 6:22 AM, monty 1987 [EMAIL PROTECTED] wrote:

 Find out why this program is not working which converts list
 representation of graph in adjacency matrix
 #includeiostream
 using namespace std;



 struct node
 {
 node* point;
 node* next;
 int info;
 };
 node * getnode(int i);
 void adja(int count,node **p);

 int main()
 {
 int count,wt,j,i;
 node *r1,*r2;
 char c='y';
 coutEnter the no. of nodes;
 cincount;
 node * root[50];
 for(i=0;icount;++i)
 {

 root[i]=getnode(i);
 if(i!=0)
 root[i-1]-next=root[i];
 }
 for(i=0;icount;++i)
 {
 c='y';
 r2=root[i];
 while(c=='y')
 {
 coutEnter the node connected to i+1 th node :;
 cinj;
 coutEnter the weight;
 cinwt;
 if(r2==root[i])
 {
 r2-point=getnode(wt);
 r2=r2-point;
 r2-point=root[j-1];
 r2-info=wt;

 }
 else
 {
 r2-next=getnode(wt);
 r2=r2-next;
 r2-point=root[j-1];
 r2-info=wt;
 }
 coutEnter y for more node else n :-;
 cinc;
 }
 }
 adja(count,root[0]);

 }
 node * getnode(int i)
 {
 node * s=new node;
 s-info=i;
 s-next=NULL;
 s-point=NULL;
 return s;
 }
 void adja(int count,node **p)
 {
 node *k;
 int adj[50][50],i,flag,j;
 couter;
 for(i=0;icount;++i)
 for(j=0;jcount;j++)
 adj[i][j]=0;

 for(i=0;icount;++i)
 {
 coutrr;
 k=*(p+i);
 while(k!=NULL)
 {

 flag=0;

 if(flag==0)
 {
 k=k-point;
 adj[i][k-info]=k-info;
 flag=1;
 }
 else
 {
 k=k-next;
 adj[i][k-info]=k-info;
 }


 }

 }
 for(i=0;icount;++i)
 {
 for(j=0;jcount;j++)
 coutadj[i][j]\t;
 cout\n;
 }



 }



 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



  1   2   >