Re: [algogeeks] Need help

2018-04-22 Thread Saurabh Paliwal
Hi,
An approach could be to guess the answer `A` and check if in `A` time, all
the tasks can be completed.
For checking, just iterate through the k people, the number of tasks
completed would be `A`/k[i] (integer division) for everyone.
If sigma(`A`/k[i]) >= N, `A` works. Now do a binary search to find the
minimum `A` which works. The upper bound could be N*min(k[i]) giving all
tasks to be solved by the person which takes the least amount of time.

Time complexity will be k*log(N*min(k[i])

On Sun, Apr 22, 2018 at 1:58 PM, pawan yadav 
wrote:

> Hi All,
>
> Has anybody solved the following problem?
>
> https://www.careercup.com/question?id=5196860946907136
>
> -Pawan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Find all the subarrays in a given array with sum=k

2016-03-23 Thread Saurabh Agrawal
Hi,

This question was asked in Amazon interview few days back.
Please explain to me the part after building the SUM array.

With Regards,

Saurabh Agrawal

On Sun, Feb 21, 2016 at 9:08 PM, Saurabh Paliwal <
saurabh.paliwa...@gmail.com> wrote:

> Hi,
> I can think of an approach that is neither recursion nor dynamic
> programming. ( I would like to know, how to solve it using dp, as you say,
> though)
>
> 1. Take an auxiliary array SUM which stores the sum of all entries from
> beginning to that index.
> 2. Now, you have to find all the pairs(i,j | j > i, SUM[j] - SUM[i] == k)
> 3. Start from right, use a C++ STL map or Java TreeMap to store (number
> minus k) and its ocurence count and add the occurence count to the answer.
> I will explain for the given example.
> arr = [1,3,1,7,-4,-11,3,4,8]
> SUM = [0,1,4,5,12,8,-3,0,4,12] (We always start from second index in
> the SUM array storing 0 for the first index)
> map M;
> answer = 0;
>
> iterating from right,
> 12 -> answer = answer + M[12] (=0), M[ 12 - 12 ] = 1
> 4 -> answer = answer + M[4] (=0), M [ 4 - 12] = 1
> 0 -> answer = 0 + M[0] , M [-12] = 1
> notice, how the answer will now be 1. Why, you ask, because I found a pair
> of indices which was required.
> -3 -> answer = 1 + M[-3], M [-15] = 1
> 8 -> answer = 1 + M[8], M [-4] = 1
> 12 -> answer = 1 + M[12], M[0] = 2
> because M[0] was 1 before.
> 5 -> answer = 1 + M[5], M[-7] = 1
> 4 -> answer = 1 + M[4], M[-8] = 2
> 1 -> answer = 1 + M[1], M[-11] = 1
> 0 -> answer = 1 + M[0], M[-12] = 2
> hence,
> answer = 3.
> Insertion in map takes logarithmic time. Overall complexity will be
> O(nlog(n))
>
> NOTE:
> If you have to output indices, rather than the number, you can use a
> map> in which case the vector will store all the indices,
> where the number came, and its size will tell the count.
> I hope that makes sense. Feel free to ask if you didn't get something.
>
>
> On Sun, Feb 21, 2016 at 3:18 PM, Shubh Aggarwal <
> shubh.aggarwal...@gmail.com> wrote:
>
>> Given an array of n elements(both +ve -ve allowed)
>> Find all the subarrays with a given sum k!
>> I know the solution using dynamic programming. It has to be done by
>> recursion (as asked by the interviewer)
>>
>> For ex
>>
>> arr = 1 3 1 7 -4 -11 3 4 8
>>
>> k = 12
>>
>> answer = {1 3 1 7},  {4 8}, {1 3 1 7 -4 -11 3 4 8}
>>
>> You have to print {from index,  to last index} so for above example {0,
>> 3}; {0,8}; {7,8} is the answer
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>
>
> --
>  -Saurabh Paliwal
>
>B-Tech. Comp. Science and Engg.
>
>IIT ROORKEE
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Find all the subarrays in a given array with sum=k

2016-02-21 Thread Saurabh Paliwal
Hi,
I can think of an approach that is neither recursion nor dynamic
programming. ( I would like to know, how to solve it using dp, as you say,
though)

1. Take an auxiliary array SUM which stores the sum of all entries from
beginning to that index.
2. Now, you have to find all the pairs(i,j | j > i, SUM[j] - SUM[i] == k)
3. Start from right, use a C++ STL map or Java TreeMap to store (number
minus k) and its ocurence count and add the occurence count to the answer.
I will explain for the given example.
arr = [1,3,1,7,-4,-11,3,4,8]
SUM = [0,1,4,5,12,8,-3,0,4,12] (We always start from second index in
the SUM array storing 0 for the first index)
map M;
answer = 0;

iterating from right,
12 -> answer = answer + M[12] (=0), M[ 12 - 12 ] = 1
4 -> answer = answer + M[4] (=0), M [ 4 - 12] = 1
0 -> answer = 0 + M[0] , M [-12] = 1
notice, how the answer will now be 1. Why, you ask, because I found a pair
of indices which was required.
-3 -> answer = 1 + M[-3], M [-15] = 1
8 -> answer = 1 + M[8], M [-4] = 1
12 -> answer = 1 + M[12], M[0] = 2
because M[0] was 1 before.
5 -> answer = 1 + M[5], M[-7] = 1
4 -> answer = 1 + M[4], M[-8] = 2
1 -> answer = 1 + M[1], M[-11] = 1
0 -> answer = 1 + M[0], M[-12] = 2
hence,
answer = 3.
Insertion in map takes logarithmic time. Overall complexity will be
O(nlog(n))

NOTE:
If you have to output indices, rather than the number, you can use a
map> in which case the vector will store all the indices,
where the number came, and its size will tell the count.
I hope that makes sense. Feel free to ask if you didn't get something.


On Sun, Feb 21, 2016 at 3:18 PM, Shubh Aggarwal  wrote:

> Given an array of n elements(both +ve -ve allowed)
> Find all the subarrays with a given sum k!
> I know the solution using dynamic programming. It has to be done by
> recursion (as asked by the interviewer)
>
> For ex
>
> arr = 1 3 1 7 -4 -11 3 4 8
>
> k = 12
>
> answer = {1 3 1 7},  {4 8}, {1 3 1 7 -4 -11 3 4 8}
>
> You have to print {from index,  to last index} so for above example {0,
> 3}; {0,8}; {7,8} is the answer
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Openings in Mentor Graphics,Noida Location

2016-02-18 Thread Saurabh Agrawal
Hi,

PFA.

With Regards,

Saurabh Agrawal

On Tue, Nov 17, 2015 at 10:04 AM, Ashish kumar Jain 
wrote:

> Anybody interested to join Mentor Graphics Noida having 1-10 years of
> experience in C/C++/DS/Algo can forward his/her resume to me.
>
> Please understand that the opening needs to be closed urgently.So,Hurry up.
>
> Note: Please ignore if inappropriate for this forum.
>
>
> --
> Regards,
> Ashish
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Resume.docx
Description: MS-Word 2007 document


Re: [algogeeks] Re: Find max sum of elements in an array ( with twist)

2016-01-12 Thread Saurabh Paliwal
you don't need to have arrays to store everything. A more memory efficient
way is to store 2 values at each iteration whether to take this number or
not. Below is a python code doing just that.

def main():
numbers = map(int, raw_input().split())
maxTakingThis = 0
maxNotTakingThis = 0
for number in numbers:
maxTakingPrevious = maxTakingThis
maxNotTakingPrevious = maxNotTakingThis
maxTakingThis = number +
max(maxTakingPrevious,maxNotTakingPrevious)
maxNotTakingThis = maxTakingPrevious
print max(maxTakingThis,maxNotTakingThis)
return 0
if(__name__=="__main__"):
main()

On Tue, Jan 12, 2016 at 9:51 PM, yomama  wrote:
>
> Here's a solution in javascript
> var data = [10 , 20 , 30, -10 , -50 , 40 , -50, -1, -3];
> function max(array) {
> var i = array[0];
> array.forEach(function(val) {
> if(val > i)
> i = val;
> });
> return i;
> }
> function maxSum(i, data, canSkip) {
>var len = data.length  - i;
>if( len === 1) {
>if(canSkip && data[i] < 0) {
>return 0;
>} else {
>return data[i];
>}
>} else if(len <1) {
>   return 0;
>}
>var skippedI =  maxSum(i + 1, data, false);
>var notSkippedISkippedJ =  maxSum(i + 1, data, true) + data[i];
>var notSkippedINotSkippedJ =  maxSum(i + 2, data, true) + data[i] +
(data[i+1] || 0);
>if(canSkip) {
> return max([skippedI, notSkippedISkippedJ,
notSkippedINotSkippedJ]);
>} else {
> return max([notSkippedISkippedJ, notSkippedINotSkippedJ]);
>}
> }
>
> console.log(maxSum(0, data, true));
>
> On Tuesday, March 24, 2015 at 6:47:46 AM UTC-7, atul007 wrote:
>>
>> Given a array with +ve and -ve integer , find the maximum sum such that
you are not allowed to skip 2 contiguous elements ( i.e you have to select
atleast one of them to move forward).
>>
>> eg :-
>>
>> 10 , 20 , 30, -10 , -50 , 40 , -50, -1, -3
>>
>> Output : 10+20+30-10+40-1 = 89
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to algogeeks+unsubscr...@googlegroups.com.




-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Opening in Oracle IDC: Having experience in C/C++ 1.5 to 3 yr

2015-11-16 Thread saurabh singh
Banned for spamming.
Again a request to the members to post algorithm related queries. Stuck in
some programming problem? Post it here. Not understanding some algorithm?
Post it here. Found an interesting problem? Post it

On Mon, Nov 16, 2015 at 8:56 AM shashi kant  wrote:

> HI, thanks for letting me know ...
>
> *Shashi Kant *
> *"Think positive and find fuel in failure"*
>
> *Senior Member technical Staff*
> *Oracle India Pvt Ltd*
> http://thinkndoawesome.blogspot.com/
>
> On Mon, Nov 16, 2015 at 4:31 AM, Shachindra A C 
> wrote:
>
>> You're not supposed to post job ads over here. Please help keeping the
>> group clean.
>>
>> On Wed, Nov 11, 2015 at 7:55 PM, shashi kant 
>> wrote:
>>
>>> hi,
>>>
>>> *Note:* if an inappropriate mail ..please do ignore
>>>
>>> Opening in Oracle IDC: Having experience in C/C++ 1.5 to 3 yr ..mail
>>> your resume to me
>>>
>>>
>>>
>>> Regards,
>>> *Shashi Kant *
>>> *"Think positive and find fuel in failure"*
>>>
>>> *Senior Member technical Staff*
>>> *Oracle India Pvt Ltd*
>>> http://thinkndoawesome.blogspot.com/
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>
>>
>> --
>> Regards,
>> Shachindra A C
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Openings in Mentor Graphics,Noida Location

2015-11-16 Thread saurabh singh
Banned for spamming.
Again a request to the members to post algorithm related queries. Stuck in
some programming problem? Post it here. Not understanding some algorithm?
Post it here. Found an interesting problem? Post it.

On Tue, Nov 17, 2015 at 10:04 AM Ashish kumar Jain 
wrote:

> Anybody interested to join Mentor Graphics Noida having 1-10 years of
> experience in C/C++/DS/Algo can forward his/her resume to me.
>
> Please understand that the opening needs to be closed urgently.So,Hurry up.
>
> Note: Please ignore if inappropriate for this forum.
>
>
> --
> Regards,
> Ashish
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Re: [BANNED!!!] Urgent need Lead - Java Developer in Atlanta, GA

2015-11-02 Thread saurabh singh
Yes, I would like that. I am sure about other admins, but I am guilty of
ignoring mails on the group. I am finding it hard to manage things between
job, other interests and google groups that I own/moderate. People who want
to volunteer to moderate this group, please reply (unicast to me,
*avoid reply all).*
Obviously also post stuff proactively so that the discussions can resume. :)

On Tue, Nov 3, 2015 at 12:02 AM Deshank Baranwal  wrote:

> I guess we need new admins who can actively moderate the group.
>
>
> On Mon, Nov 2, 2015 at 6:30 PM, Shachindra A C 
> wrote:
>
>> Well, you need to ban a whole lot more people.
>>
>> On Mon, Nov 2, 2015 at 10:16 AM, saurabh singh 
>> wrote:
>>
>>> FYI, have banned this user and several others who mistook this group for
>>> a recruitment platform. Can we revive the legacy of this group again?
>>>
>>>
>>> On Mon, Nov 2, 2015 at 11:36 PM Shaik Asif 
>>> wrote:
>>>
>>>> Hi Partner,
>>>>
>>>> This is Shaik from Deegit Inc. Partner find the below requirement for
>>>> your consultants. If there are available. Please get back to me ASAP on
>>>> sh...@deegit.com
>>>>
>>>> *WE ARE LOOKING FOR 10+ YEAR'S RESUME'S*
>>>>
>>>> *Position: Lead - Java Developer *
>>>>
>>>> Location: Atlanta, GA 30301
>>>>
>>>> Duration: Long Term
>>>>
>>>>
>>>>
>>>> *Required skills: *
>>>>
>>>> · Experience in Unemployment Insurance
>>>>
>>>> · Core java, Spring MVC, SQL Transactions Annotations
>>>>
>>>> · experience with systems consulting, development and systems
>>>> engineering in software projects technical design and development of Java
>>>> based systems
>>>>
>>>> · Experience developing systems within the framework and
>>>> governance of a well-defined Systems Engineering Life Cycle (SELC)
>>>>
>>>> · Experience in the role of systems consultant on projects of
>>>> high complexity that typically have multiple concurrent and related
>>>> activities
>>>>
>>>> · Delivery role handling complex Java projects
>>>>
>>>> · demonstrated technical experience with:
>>>>
>>>> · Java, JSP/Servlets, XML,
>>>>
>>>> · SOAP, Struts/Spring/Hibernate
>>>>
>>>> · Knowledge of Design Patterns, UML and Web Services.
>>>>
>>>> · Knowledge of Weblogic.
>>>>
>>>> · Understanding of SQL queries, Stored procedure, DB Design
>>>> etc.
>>>>
>>>> · Knowledge of Junit Framework and Testing Techniques,
>>>> Code-Coverage using java based tools like Eclipse
>>>>
>>>> Best Regards,
>>>>
>>>> ___
>>>>
>>>>
>>>>
>>>> Shaik | Deegit Inc |
>>>>
>>>> 1900 East Golf Rd., Suite 925 | Schaumburg, IL 60173 |
>>>>
>>>> Ph: 847.440.2436 ext - 358 | Fax: 847.330.1987
>>>>
>>>> sh...@deegit.com | www.deegit.com |
>>>>
>>>>
>>>>
>>>> “GSA Approved - GS-35F-0405V”
>>>>
>>>> "Certified Minority Business Enterprise (MBE)"
>>>>
>>>> "Winner - Deloitte Technology Fast 500 for 2008"
>>>>
>>>> "Winner - Inc. 5000 fastest growing firm for 2008"
>>>>
>>>> "Winner - Inc. 5000 fastest growing firm for 2009"
>>>>
>>>>
>>>>
>>>> "Right Person for the Right Job in the Right Time"
>>>>
>>>>
>>>>
>>>> The information transmitted is intended only for the person or entity
>>>> to which it is addressed and may contain confidential and/or privileged
>>>> material. Any review, retransmission, dissemination or other use of, or
>>>> taking of any action in reliance upon, this information by persons or
>>>> entities other than the intended recipient is prohibited. If you received
>>>> this in error, please contact the sender and delete the material from any
>>>> computer.
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>
>>
>> --
>> Regards,
>> Shachindra A C
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


[algogeeks] Re: [BANNED!!!] Urgent need Lead - Java Developer in Atlanta, GA

2015-11-02 Thread saurabh singh
FYI, have banned this user and several others who mistook this group for a
recruitment platform. Can we revive the legacy of this group again?

On Mon, Nov 2, 2015 at 11:36 PM Shaik Asif  wrote:

> Hi Partner,
>
> This is Shaik from Deegit Inc. Partner find the below requirement for your
> consultants. If there are available. Please get back to me ASAP on
> sh...@deegit.com
>
> *WE ARE LOOKING FOR 10+ YEAR'S RESUME'S*
>
> *Position: Lead - Java Developer *
>
> Location: Atlanta, GA 30301
>
> Duration: Long Term
>
>
>
> *Required skills: *
>
> · Experience in Unemployment Insurance
>
> · Core java, Spring MVC, SQL Transactions Annotations
>
> · experience with systems consulting, development and systems
> engineering in software projects technical design and development of Java
> based systems
>
> · Experience developing systems within the framework and
> governance of a well-defined Systems Engineering Life Cycle (SELC)
>
> · Experience in the role of systems consultant on projects of
> high complexity that typically have multiple concurrent and related
> activities
>
> · Delivery role handling complex Java projects
>
> · demonstrated technical experience with:
>
> · Java, JSP/Servlets, XML,
>
> · SOAP, Struts/Spring/Hibernate
>
> · Knowledge of Design Patterns, UML and Web Services.
>
> · Knowledge of Weblogic.
>
> · Understanding of SQL queries, Stored procedure, DB Design etc.
>
> · Knowledge of Junit Framework and Testing Techniques,
> Code-Coverage using java based tools like Eclipse
>
> Best Regards,
>
> ___
>
>
>
> Shaik | Deegit Inc |
>
> 1900 East Golf Rd., Suite 925 | Schaumburg, IL 60173 |
>
> Ph: 847.440.2436 ext - 358 | Fax: 847.330.1987
>
> sh...@deegit.com | www.deegit.com |
>
>
>
> “GSA Approved - GS-35F-0405V”
>
> "Certified Minority Business Enterprise (MBE)"
>
> "Winner - Deloitte Technology Fast 500 for 2008"
>
> "Winner - Inc. 5000 fastest growing firm for 2008"
>
> "Winner - Inc. 5000 fastest growing firm for 2009"
>
>
>
> "Right Person for the Right Job in the Right Time"
>
>
>
> The information transmitted is intended only for the person or entity to
> which it is addressed and may contain confidential and/or privileged
> material. Any review, retransmission, dissemination or other use of, or
> taking of any action in reliance upon, this information by persons or
> entities other than the intended recipient is prohibited. If you received
> this in error, please contact the sender and delete the material from any
> computer.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


RE: [algogeeks] Yo! Help me make a Music Video

2014-12-28 Thread saurabh singh
Nope. Forwarding this mail to a group with over 1 k members is definitely 
begging. It's shameless begging as it can get. No,Didn't bother to open the 
link. Also banning you from the group. 

-Original Message-
From: "Shrey Choudhary" 
Sent: ‎12/‎28/‎2014 4:52 PM
To: "a.mat...@accenture.com" ; "Aadhaar Sharma" 
; "Aakanksha Raghav" ; 
"abhijitcomplete ." ; "Abhilash Rajpoot" 
; "Abhinav kapur" ; 
"abhinay.mo...@tctinfotech.com" ; 
"admin.off...@oberoigroup.com" ; "Airtel 
Presence" ; "Akash Bajaj" ; "Akhil 
Saraf" ; "algogeeks@googlegroups.com" 
; "ami.ta...@gmail.com" ; 
"Amit Goel" ; "Amit Kumar Singh" 
; "Anjali Gupta" ; "ankit 
malik" ; "ankit verma" ; "Ankit 
Yadav" ; "antriksh.c...@nic.in" 
; "Anurag Dak" ; "Anurag Kundu" 
; "anushree bhatt" <1594anush...@gmail.com>; "aparna 
roy" ; "arjun singh" ; "Arpan 
Saxena" ; "arushi paliwal" 
; "atam prakash" ; "Bhumika 
Sachdeva" ; "cyberbyte.literat...@gmail.com" 
; "danish.shab...@accenture.com" 
; "deep...@proteaminc.com" 
; "Deepali Garg" ; 
"dhruv_mech...@yahoo.co.in" ; "ekta dwivedy" 
; "fansofn...@gmail.com" ; "Gaurav 
Goel" ; "Gaurav Sharma" ; 
"Gaurav Walia" ; "gnee...@amazon.com" 
; "Helios NITK" ; 
"helios.nitk2...@gmail.com" ; "Himsa Narzari" 
; "i...@chillomrecordsindia.com" 
; "infotechnit...@googlegroups.com" 
; "intern...@tctinfotech.com" 
; "invest...@naukri.com" ; 
"Jasmine Gambhir" ; "Jitender Kumar" 
; "jitenderchha...@gmail.com" 
; "kamal khandelwal" ; 
"Kanika Bansal" ; "Kashish Mittal" 
; "khurana.prach...@yahoo.in" 
; "kriti.j...@99acres.com" ; 
"Kunal Kapoor" ; "Kunsana Tab" 
; "larry.guill...@rackspace.com" 
; "LOKESH GUPTA" ; 
"Madhuresh Srivastava" ; "Mamta Kayest" 
; "Manish Dhall" ; 
"manishkam...@rediffmail.com" 
Subject: [algogeeks] Yo! Help me make a Music Video

Waddup guys,

Hope everything is fine at your end. So this is a personal mail, I'm sending 
out. I've recently started my IndieGogo Crowdfunding Campaign for a hip hop 
music video. I'm now taking my passion for rapping to another level. It's just 
that I'm little short of funds. I need around 1000 to 1400 $ to come out with a 
good concept music video and hire promoters to do the same. 


The details of  the campaign can be found at this link. 
https://www.indiegogo.com/projects/indian-hiphop-single-music-video/x/9462122


If you all believe in me, donate a dollar or two; that's mere ~Rs 120. People 
smoke this much amount in one day. 




PS: If you think am begging for money, then please you don't have to pay 
anything. Don't even open the link and you can happily remove me from your 
circle. Because am a friend asking for help from friends . Nothing else.






Regards
Shrey Choudhary

Mobile: +919953029023



"The future belongs to those who believe in the beauty of their dreams" - 
Eleanor Roosevelt

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] C++ initialization list

2014-09-28 Thread saurabh singh
Here you go
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2012/n3337.pdf
The c++ standard itself. Refer to section 8.5.4 page no. 213.
Looks like even this int a[10] = {2} is not guaranteed to initialize all
the elements of the array. Sure gcc provides this but then it becomes a
compiler specific thing. The language doesn't advocates it.

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com

On Sun, Sep 28, 2014 at 3:47 PM, sagar sindwani 
wrote:

> Thanks Deepak and Rahul for the reply.
>
> Do you guys have any standard document or any standard book which defines
> this?  I totally agree with these answers but I don't have any formal
> written text.
>
> In my example 1, the object is on stack and this lead to a1[0].z to be
> un-initialized. But as the specified in example 2, Why every element of arr
> is initialized, it is also on the stack ? Any source to answer this
> question ?
>
> Thanks
> Sagar
>
>
>
> On Sun, Sep 28, 2014 at 2:26 PM, Rahul Vatsa 
> wrote:
>
>>
>> http://stackoverflow.com/questions/3127454/how-do-c-class-members-get-initialized-if-i-dont-do-it-explicitly
>>
>> On Sun, Sep 28, 2014 at 12:22 PM, Deepak Garg 
>> wrote:
>>
>>> Hi
>>>
>>> In example 1, member z will have a garbage value (i.e. 0 in your case )
>>>
>>> Thanks
>>> Deepak
>>> On Sep 28, 2014 11:29 AM, "sagar sindwani" 
>>> wrote:
>>>
>>>> I am working on How compilers handle initialization list. I came across
>>>> a case where I am not sure what should be the compiler behaviour.
>>>>
>>>> *Example 1:-*
>>>>
>>>> #include 
>>>>
>>>> class A
>>>> {
>>>> public:
>>>> int x,y,z;
>>>> };
>>>>
>>>> int main()
>>>> {
>>>> A a1[2] =
>>>> {
>>>> { 1,2 },
>>>> { 3,4 }
>>>> };
>>>>
>>>> std::cout << "a1[0].z is " << a1[0].z << std::endl;
>>>>
>>>> return 0;
>>>> }
>>>>
>>>> In above case a1[0].z is ? g++ shows it as 0 ( zero ). It is exactly 0
>>>> or garbage value, I am not sure on that.
>>>>
>>>> I tried lot of books and some documents , no where I found what C++
>>>> says for initialization of class objects.
>>>>
>>>> You can find handling of below case in almost every book.
>>>>
>>>> *Example 2:- *
>>>>
>>>> int arr[6] = {0};
>>>>
>>>> In Example 2,  compilers will auto-fill all members with 0. It is
>>>> mentioned in books. But when it comes to User-defined datatypes nothing is
>>>> mentioned.
>>>>
>>>>
>>>> Please share your thoughts on this. If you find any document related to
>>>> this, please share it as well.
>>>>
>>>> Thanks
>>>> Sagar
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] DP problems

2014-06-05 Thread Saurabh Paliwal
T[i][j] = 0 (i < 0 || j >=n || i >= j || s[i] != s[j])

T[i][j] = 1 + T[i-1][j+1]




On Fri, Jun 6, 2014 at 12:19 AM, kumar raja 
wrote:

> If i get u correctly, this is the recurrence relation ( i feel this makes
> many people to understand the solution rather than looking at the code)
>
>
> T[i..j] indicates the length of longest even length palin string ( not
> exactly palin but i think u know what i am saying) with i as begin and j as
> ending point.
>
> T[i,j] = 0 if i>=j
>T[i+1,j-1]+1 if s[i]==s[j]
>   0else
>
> And u find max value in the table which is the answer
>
> So time complexity  = space complexity = O(n^2).
>
> Correct me if i am wrong
>
>
>
> On 5 June 2014 23:44, Saurabh Paliwal  wrote:
>
>> And now I get what you meant when you said "palindrome". You should have
>> explained that if that was "not exact palindrome"
>>
>> So yes, your solution seems correct but that is the brute force approach.
>> It runs in O(n*n*n) as there are n*n substrings and every check is linear.
>> DP solution helps save time by memoization.
>>
>>
>> On Thu, Jun 5, 2014 at 11:37 PM, Saurabh Paliwal <
>> saurabh.paliwa...@gmail.com> wrote:
>>
>>> Ok! So I guess now we are talkng my solution. What i do is maintain two
>>> pointers i and j, i is the end of the first string and j is the beginning
>>> of the second. If both the character match, I calculate the answer for
>>> pointers i-1,j+1 and add 1 to the answer for i,j. If they don't match, I
>>> simply mark 0 as the answer for i,j. So my table if filled top-down like
>>> this. Finally, I return the maximum entry in the table.
>>> Need I explain further? If so, feel free. Should I explain what those
>>> methods do?
>>>
>>
>>
>>
>> --
>>  -Saurabh Paliwal
>>
>>B-Tech. Comp. Science and Engg.
>>
>>IIT ROORKEE
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] DP problems

2014-06-05 Thread Saurabh Paliwal
And now I get what you meant when you said "palindrome". You should have
explained that if that was "not exact palindrome"

So yes, your solution seems correct but that is the brute force approach.
It runs in O(n*n*n) as there are n*n substrings and every check is linear.
DP solution helps save time by memoization.


On Thu, Jun 5, 2014 at 11:37 PM, Saurabh Paliwal <
saurabh.paliwa...@gmail.com> wrote:

> Ok! So I guess now we are talkng my solution. What i do is maintain two
> pointers i and j, i is the end of the first string and j is the beginning
> of the second. If both the character match, I calculate the answer for
> pointers i-1,j+1 and add 1 to the answer for i,j. If they don't match, I
> simply mark 0 as the answer for i,j. So my table if filled top-down like
> this. Finally, I return the maximum entry in the table.
> Need I explain further? If so, feel free. Should I explain what those
> methods do?
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] DP problems

2014-06-05 Thread Saurabh Paliwal
Ok! So I guess now we are talkng my solution. What i do is maintain two
pointers i and j, i is the end of the first string and j is the beginning
of the second. If both the character match, I calculate the answer for
pointers i-1,j+1 and add 1 to the answer for i,j. If they don't match, I
simply mark 0 as the answer for i,j. So my table if filled top-down like
this. Finally, I return the maximum entry in the table.
Need I explain further? If so, feel free. Should I explain what those
methods do?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] DP problems

2014-06-05 Thread Saurabh Paliwal
Dude! That is what I just posted. Also your logic is wrong, Palindrome
thing is just not working. Think for a while on this problem.


On Thu, Jun 5, 2014 at 11:18 PM, kumar raja 
wrote:

> Yes i agree that my recurrence relation is wrong. I have checked it some
> inputs, it did not work. But i think the brute force solution is possible
> in O(n^3) solution. We have O(n^2) combination of end points. we can check
> for the maximum possible even length palin string in O(n). So that will
> give O(n^3). Anyone has solution about O(n^2)?
>
>
> On 5 June 2014 22:25, Saurabh Paliwal  wrote:
>
>> Hi all!
>> Well, I agree with Shashwat in that Kumar is wrong with his solution. For
>> example a string " kumarxyzramuk " will tell you why.
>> I have a solution which runs in O(n*n) time. It is top-down dynamic
>> programming approach. Let me know if you don't understand something or if
>> there is some glitch in the solution. I think it is correct.
>>
>> Link to the C++ code  - http://ideone.com/Qzs990
>>
>>
>> On Thu, Jun 5, 2014 at 7:13 PM, Shashwat Anand  wrote:
>>
>>> Code ?
>>>
>>>
>>> On Thu, Jun 5, 2014 at 7:08 PM, kumar raja 
>>> wrote:
>>>
>>>> U have two dimensions for the table ( has O(n^2) entries.) and to check
>>>> whether string is palindrome or not it will take O(n) . So it is O(n^3)
>>>> solution.
>>>>
>>>> I have checked it manually for some inputs, and it works.
>>>>
>>>>
>>>> On 5 June 2014 18:53, Shashwat Anand  wrote:
>>>>
>>>>> I am not too sure about your O (N^3) solution even.  Can you link the
>>>>> working code ?
>>>>>
>>>>>
>>>>> On Thu, Jun 5, 2014 at 6:48 PM, kumar raja 
>>>>> wrote:
>>>>>
>>>>>> This is a very good collection of DP problems.
>>>>>>
>>>>>> I want the answers for problem 2(e)
>>>>>> and problem 14.
>>>>>>
>>>>>> for problem 14 the recurrence relation
>>>>>> that i have is
>>>>>>
>>>>>> T[i,j] = 0 if i>=j
>>>>>>1 if j=i+1 and s[i]=s[j]
>>>>>>0 if j=i+1 and s[i]!=s[j]
>>>>>>j-i+1/2 if s[i..j] is even length palindrome
>>>>>>j-i/2  if s[i..j] is odd length palindrome
>>>>>>max{T[i+1,j],T[i,j-1]} else
>>>>>>
>>>>>> But this is O(n^3) solution. Could not
>>>>>> find out solution of order O(n^2).
>>>>>> If someone knows please share the answers for them.
>>>>>>
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to algogeeks+unsubscr...@googlegroups.com.
>>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>
>>
>> --
>>  -Saurabh Paliwal
>>
>>B-Tech. Comp. Science and Engg.
>>
>>IIT ROORKEE
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] DP problems

2014-06-05 Thread Saurabh Paliwal
Hi all!
Well, I agree with Shashwat in that Kumar is wrong with his solution. For
example a string " kumarxyzramuk " will tell you why.
I have a solution which runs in O(n*n) time. It is top-down dynamic
programming approach. Let me know if you don't understand something or if
there is some glitch in the solution. I think it is correct.

Link to the C++ code  - http://ideone.com/Qzs990


On Thu, Jun 5, 2014 at 7:13 PM, Shashwat Anand  wrote:

> Code ?
>
>
> On Thu, Jun 5, 2014 at 7:08 PM, kumar raja 
> wrote:
>
>> U have two dimensions for the table ( has O(n^2) entries.) and to check
>> whether string is palindrome or not it will take O(n) . So it is O(n^3)
>> solution.
>>
>> I have checked it manually for some inputs, and it works.
>>
>>
>> On 5 June 2014 18:53, Shashwat Anand  wrote:
>>
>>> I am not too sure about your O (N^3) solution even.  Can you link the
>>> working code ?
>>>
>>>
>>> On Thu, Jun 5, 2014 at 6:48 PM, kumar raja 
>>> wrote:
>>>
>>>> This is a very good collection of DP problems.
>>>>
>>>> I want the answers for problem 2(e)
>>>> and problem 14.
>>>>
>>>> for problem 14 the recurrence relation
>>>> that i have is
>>>>
>>>> T[i,j] = 0 if i>=j
>>>>1 if j=i+1 and s[i]=s[j]
>>>>0 if j=i+1 and s[i]!=s[j]
>>>>j-i+1/2 if s[i..j] is even length palindrome
>>>>j-i/2  if s[i..j] is odd length palindrome
>>>>max{T[i+1,j],T[i,j-1]} else
>>>>
>>>> But this is O(n^3) solution. Could not
>>>> find out solution of order O(n^2).
>>>> If someone knows please share the answers for them.
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Solving equation

2014-01-27 Thread Saurabh Paliwal
Ws
On 27 Jan 2014 17:02, "saurabh singh"  wrote:

> ^ No its not invalid. It just represents an equation with infinitely many
> correct solutions depending on the domain of x.
>
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
> On Mon, Jan 27, 2014 at 4:21 PM, Amol Sharma wrote:
>
>> i din't get ur question.
>>
>> isn't the equation "*(x - 7) + 7 = (x + 1) - 5*"  invalid ?
>>
>> --
>> Thanks and Regards,
>> Amol Sharma
>>
>>
>>
>> On Wed, Jan 15, 2014 at 3:34 AM, Arpit Sood  wrote:
>>
>>> Equivalent to solving an infix expression using stack with a pair (first
>>> variable, second constant) as the element
>>>
>>>
>>> On Sat, Jan 11, 2014 at 6:50 AM, atul anand wrote:
>>>
>>>> Hello,
>>>>
>>>> How to solve an equation with one unknown variable ?
>>>> operator allowed are : + , -
>>>>
>>>> for eg .  input could be :-
>>>> x + ( 5 + 4 ) = 6
>>>> (x - 7) + 7 = (x + 1) - 5
>>>>
>>>> If operator also allows " * " (multiply) , then what change in
>>>> algorithm is required.
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Solving equation

2014-01-27 Thread saurabh singh
^ No its not invalid. It just represents an equation with infinitely many
correct solutions depending on the domain of x.

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com


On Mon, Jan 27, 2014 at 4:21 PM, Amol Sharma  wrote:

> i din't get ur question.
>
> isn't the equation "*(x - 7) + 7 = (x + 1) - 5*"  invalid ?
>
> --
> Thanks and Regards,
> Amol Sharma
>
>
>
> On Wed, Jan 15, 2014 at 3:34 AM, Arpit Sood  wrote:
>
>> Equivalent to solving an infix expression using stack with a pair (first
>> variable, second constant) as the element
>>
>>
>> On Sat, Jan 11, 2014 at 6:50 AM, atul anand wrote:
>>
>>> Hello,
>>>
>>> How to solve an equation with one unknown variable ?
>>> operator allowed are : + , -
>>>
>>> for eg .  input could be :-
>>> x + ( 5 + 4 ) = 6
>>> (x - 7) + 7 = (x + 1) - 5
>>>
>>> If operator also allows " * " (multiply) , then what change in algorithm
>>> is required.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] coloring problem Dynamic programming

2013-12-28 Thread Saurabh Paliwal
@atul your understanding of my recurrences are fine but of the question are
not. You cannot have 3 adjacent houses with same colour. GGY is a fine case
for this problem.
On 28 Dec 2013 20:44, "atul anand"  wrote:

> @saurabh : i did not get your algo for modified ques i.e "No 3 adjacent
> houses should get same color"
>
> according to your recurrence
>
> answer[i][j][1] = min(answer[i-1][t][0],answer[i-1][t][1]) + colorvalue[j] for
> all t from 1 to k except j.
>
>
> now suppose in some case *answer[i-1][t][0] *is found minimum in
> above recurrence .
> *answer[i-1][t][0] *means that i - 2 and i - 1 are of same color say for
> eg color green.
>
> answer[i][j][1] is not colored same as i-1 house (green in this case)
> ...now say it is colored with color yellow.
>
> hence,
> answer[i][j][1] is sum of house with color green+green+yellow.
>
> i am not able to understand , how it is taking care that 3 adjacent are
> colored
> different.
>
> could you please clarify my doubt.
>
>
>
> On Thu, Dec 26, 2013 at 5:25 PM, Saurabh Paliwal <
> saurabh.paliwa...@gmail.com> wrote:
>
>> @atul anand :- no, we need not use all the colors.
>>
>> @kumar raja :- sorry dude for replying this late. Continuing with the
>> previous idea, I extend the solution for the modified problem as
>>
>> 1. let answer[i][j][0] represent minimum cost of coloring i houses when
>> ith house is colored with jth color and so is the (i-1)th house.
>>
>> 2. let answer[i][j][1] represent minimum cost of coloring i houses when
>> ith house is colored with jth color and (i-1)th is not.
>>
>> The recurrence will be
>>
>> 3. *answer[i][j][0] = answer[i-1][j][1] + colorvalue[j]*
>>
>> 4. *answer[i][j][1] = min(answer[i-1][t][0],answer[i-1][t][1]) +
>> colorvalue[j]* for all t from 1 to k except j.
>>
>> // In the first problem, I mistakenly wrote colorvalue[t] here. It will
>> be colorvalue[j] there. ( sorry for the confusion )
>>
>> 5. finally solution will be min(answer[n][j][0], answer[n][j][1]) for all
>> j from 1 to k.
>>
>> 6. initial settings -: answer[1][j][0] = answer[1][j][1] = colorvalue[j].
>>
>>
>> Also now that I read the problem, I guess colorvalue is not fixed for
>> every color, so that will be a 2-D matrix as well.
>>
>> *replace every colorvalue[j] with colorvalue[i][j] in the above
>> recurrences*. ( i is the house number, j is the color number )
>>
>>
>>  On Wed, Dec 18, 2013 at 10:16 PM, atul anand wrote:
>>
>>> @kumar :  i have one doubt regarding this question.Do we have to use all
>>> K colors[K] to color all building.
>>>
>>> for example :-
>>>
>>> color[3]={1,2,10};
>>>
>>>  now if we have to color 6 building then i can use only 1st 2 color to
>>> color all building and never 10 ...is this allowed ???
>>> building[N]={1,2,1,2,1,2}
>>>
>>>
>>>  On Sun, Dec 15, 2013 at 12:44 AM, kumar raja 
>>> wrote:
>>>
>>>> You have 'n' houses and 'k' colors. The cost of coloring a house with
>>>> one of the 'k' colors is different from coloring another house with same
>>>> color.  The cost of coloring the house with different colors are different.
>>>> So now how to colour the 'n' houses such that no two adjcent houses will
>>>> get the same color and the total coloring cost for 'n' houses is minimized.
>>>>
>>>>
>>>>
>>>> Regards,
>>>> Kumar Raja.
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>
>>
>> --
>>  -Saurabh Paliwal
>>
>>B-Tech. Comp. Science and Engg.
>>
>>IIT ROORKEE
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] coloring problem Dynamic programming

2013-12-26 Thread Saurabh Paliwal
@atul anand :- no, we need not use all the colors.

@kumar raja :- sorry dude for replying this late. Continuing with the
previous idea, I extend the solution for the modified problem as

1. let answer[i][j][0] represent minimum cost of coloring i houses when ith
house is colored with jth color and so is the (i-1)th house.

2. let answer[i][j][1] represent minimum cost of coloring i houses when ith
house is colored with jth color and (i-1)th is not.

The recurrence will be

3. *answer[i][j][0] = answer[i-1][j][1] + colorvalue[j]*

4. *answer[i][j][1] = min(answer[i-1][t][0],answer[i-1][t][1]) +
colorvalue[j]* for all t from 1 to k except j.

// In the first problem, I mistakenly wrote colorvalue[t] here. It will be
colorvalue[j] there. ( sorry for the confusion )

5. finally solution will be min(answer[n][j][0], answer[n][j][1]) for all j
from 1 to k.

6. initial settings -: answer[1][j][0] = answer[1][j][1] = colorvalue[j].


Also now that I read the problem, I guess colorvalue is not fixed for every
color, so that will be a 2-D matrix as well.

*replace every colorvalue[j] with colorvalue[i][j] in the above recurrences*.
( i is the house number, j is the color number )


On Wed, Dec 18, 2013 at 10:16 PM, atul anand wrote:

> @kumar :  i have one doubt regarding this question.Do we have to use all K
> colors[K] to color all building.
>
> for example :-
>
> color[3]={1,2,10};
>
> now if we have to color 6 building then i can use only 1st 2 color to
> color all building and never 10 ...is this allowed ???
> building[N]={1,2,1,2,1,2}
>
>
> On Sun, Dec 15, 2013 at 12:44 AM, kumar raja wrote:
>
>> You have 'n' houses and 'k' colors. The cost of coloring a house with one
>> of the 'k' colors is different from coloring another house with same color.
>>  The cost of coloring the house with different colors are different. So now
>> how to colour the 'n' houses such that no two adjcent houses will get the
>> same color and the total coloring cost for 'n' houses is minimized.
>>
>>
>>
>> Regards,
>> Kumar Raja.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] coloring problem Dynamic programming

2013-12-16 Thread Saurabh Paliwal
I think that can be done by having 2 different values at every position in
the answer matrix. One when the previous house is of same color and one
when it does not. Answer[n][k][2] will be the new dimensions.

I can explain in detail if you don't get this. ☺
On Dec 15, 2013 4:43 PM, "kumar raja"  wrote:

> What can be the recurrence relation if the condition is changed to "No 3
> adjacent houses should get same color"?
>
>
> On 15 December 2013 16:26, kumar raja  wrote:
>
>> No need for the explanation ,got it man thanks.
>>
>>
>> On 15 December 2013 16:20, kumar raja  wrote:
>>
>>> Saurabh your solutions seems right , but can u explain me how did u
>>> arrive at the time and space complexity with some proof /pseudocode/
>>> explanation?
>>>
>>>
>>> On 15 December 2013 09:47, Saurabh Paliwal 
>>> wrote:
>>>
>>>> what is the issue with the usual recurrence :-
>>>>
>>>> Let answer[i][j] represent minimum cost of coloring i houses with ith
>>>> house colored with jth color.
>>>>
>>>> answer[i][j] = min(answer[i-1][t]) + colorvalue[t] where t varies from
>>>> 1 to k except j.
>>>>
>>>> initial setting :-  answer[1][j] = colorvalue[j]
>>>>
>>>> final answer is min(answer[n][j]) for all j from 1 to k.
>>>>
>>>> Time complexity = O(n*k*k)
>>>> Space complexity = O(k) if only 2 rows are taken ( effectively only 2
>>>> are required ).
>>>>
>>>>
>>>> On Sun, Dec 15, 2013 at 12:44 AM, kumar raja 
>>>> wrote:
>>>>
>>>>> You have 'n' houses and 'k' colors. The cost of coloring a house with
>>>>> one of the 'k' colors is different from coloring another house with same
>>>>> color.  The cost of coloring the house with different colors are 
>>>>> different.
>>>>> So now how to colour the 'n' houses such that no two adjcent houses will
>>>>> get the same color and the total coloring cost for 'n' houses is 
>>>>> minimized.
>>>>>
>>>>>
>>>>>
>>>>> Regards,
>>>>> Kumar Raja.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>  -Saurabh Paliwal
>>>>
>>>>B-Tech. Comp. Science and Engg.
>>>>
>>>>IIT ROORKEE
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>
>>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] coloring problem Dynamic programming

2013-12-14 Thread Saurabh Paliwal
what is the issue with the usual recurrence :-

Let answer[i][j] represent minimum cost of coloring i houses with ith house
colored with jth color.

answer[i][j] = min(answer[i-1][t]) + colorvalue[t] where t varies from 1 to
k except j.

initial setting :-  answer[1][j] = colorvalue[j]

final answer is min(answer[n][j]) for all j from 1 to k.

Time complexity = O(n*k*k)
Space complexity = O(k) if only 2 rows are taken ( effectively only 2 are
required ).


On Sun, Dec 15, 2013 at 12:44 AM, kumar raja wrote:

> You have 'n' houses and 'k' colors. The cost of coloring a house with one
> of the 'k' colors is different from coloring another house with same color.
>  The cost of coloring the house with different colors are different. So now
> how to colour the 'n' houses such that no two adjcent houses will get the
> same color and the total coloring cost for 'n' houses is minimized.
>
>
>
> Regards,
> Kumar Raja.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] variation of LIS problem

2013-10-25 Thread Saurabh Paliwal
if all the elements are positive then we can reverse the array and multiply
all of them by -1. Now apply LIS algorithm O(nlog(n)) and since it gives
the answer for all k<=n with the minimum sum, this will be the answer
multiplied by -1.


On Sat, Oct 26, 2013 at 12:12 AM, kumar raja wrote:

> I think O(nlogn) solution is possible for this problem.  First  find the
> largest increasing subsequence in O(nlogn) time.
>
> http://en.wikipedia.org/wiki/Longest_increasing_subsequence#Efficient_algorithms
>
> From this one u have LIS array M and parent array P. Now traverse through
> the array M and for all the length values >= k , u can print the "k"
> elements using Parent array P. I guess the step of printing the array
> elements wont be greater than O(n logn).
>
> So it is bounded by O(nlogn) .  In the worst case it might go up to
> O(n^2). But i am not sure of this.
>
>
> On 25 October 2013 00:17, atul anand  wrote:
>
>> OK, i got now why you were using min-heap.
>>
>> now consider this example :-
>>
>> 200,12,33,1,55,100
>>
>> K=3
>>
>> insert 200
>> 12 < 200...cannot insert
>> 33 < 200...cannot insert
>> .
>> .
>> .
>> 100<200 cannot insert
>>
>> output : 200 (not lenght of k)
>> output should be : 33,55,100
>>
>>
>> On 10/24/13, pankaj joshi  wrote:
>> > Max-heap should not used in this case,
>> > why min heap? -- this is because program has to decide the smallest
>> element
>> > in k-group.
>> > in your example if i consider k =3 than
>> >
>> > insert 1
>> > insert 2
>> > insert 5
>> > insert 10
>> > size of heap ==4 so delete root of min- heap (which is 1),
>> > insert 100
>> > 30 cant insert because temp = 100 and 30> > insert 8 cant insert temp = 100 and 8> > (500>temp)size of heap ==4 so delete root of min-heap(which is 2)
>> > insert 555
>> >
>> > now if i check the heap elements
>> > {5, 10, 100 , 555}
>> >
>> >
>> >
>> > On Thu, Oct 24, 2013 at 11:25 PM, atul anand
>> > wrote:
>> >
>> >> in your updated algo , you should be using max-heap not min-heap.
>> >>
>> >> check your algo for :-
>> >>
>> >> 1,2,5,10,100,30,8,555
>> >>
>> >> let me know if it work fine.If it is working fine then i need more
>> >> clarity of your algo
>> >>
>> >> On 10/24/13, pankaj joshi  wrote:
>> >> > @Saurabh:
>> >> > As per the question the elements of sub-sequence  should be
>> increasing,
>> >> > so the solution will be {5} and as per the program.
>> >> > * but as written longest sub-sequence of k =2, so it should be {2,3}
>> >> > for
>> >> > this case. (there should be backtrack in this case.)
>> >> >
>> >> > @atul: increasing sub sequence is checked by condition, not by
>> >> > Min-heap,
>> >> > but min heap is used for storing the largest elements.
>> >> > So it is preferable DS,
>> >> >
>> >> >
>> >> > On Thu, Oct 24, 2013 at 8:35 PM, atul anand > >
>> >> > wrote:
>> >> >
>> >> >> @pankaj : how can you maintain increasing sub-sequence using
>> >> >> heapyour soln is for finding finding K largest element in the
>> >> >> array...so it wont work.
>> >> >>
>> >> >> On 10/24/13, Saurabh Paliwal  wrote:
>> >> >> > check for {5,2,3} and K = 2.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > On Thu, Oct 24, 2013 at 7:41 PM, pankaj joshi <
>> joshi10...@gmail.com>
>> >> >> wrote:
>> >> >> >
>> >> >> >> @ Saurabh,
>> >> >> >>
>> >> >> >> I have done a correction on algo
>> >> >> >>
>> >> >> >> temp =0
>> >> >> >> loop n to a[]
>> >> >> >>  if a[i]>temp
>> >> >> >>if min-heap(root) < a[i]
>> >> >> >>  if min-heap(count)==k
>> >> >> >> delete root in min- heap
>> >> >> >>  inseart a[i] in min - heap
>> >> >> >>
>> >> >> >> As i have made the condition: min-heap, (condition

Re: [algogeeks] variation of LIS problem

2013-10-24 Thread Saurabh Paliwal
check for {5,2,3} and K = 2.



On Thu, Oct 24, 2013 at 7:41 PM, pankaj joshi  wrote:

> @ Saurabh,
>
> I have done a correction on algo
>
> temp =0
> loop n to a[]
>  if a[i]>temp
>if min-heap(root) < a[i]
>  if min-heap(count)==k
> delete root in min- heap
>  inseart a[i] in min - heap
>
> As i have made the condition: min-heap, (condition size should be always
> k) for this particular case.
>
> And in the example {5,2,1,10,9,30,8,55} if K =3
>
> insert 5
> 2 is less so do nothing
> 1 is less so do nothing
> insert 10
> 9 is less so do nothing
> insert 30
> 8 is less so do nothing
> insert 55 (before inserting 50 delete the root of heap as count of heap ==
> 3), deleted root was - 5
> so the output will be
> {10,30,55}
>
> and if k is 4
> than
> {5, 10, 30 , 55)
>
>
> On Thu, Oct 24, 2013 at 6:20 PM, Saurabh Paliwal <
> saurabh.paliwa...@gmail.com> wrote:
>
>> You must be mistaken in the definition of heaps, or maybe the question,
>> look at the updated question I put up there.
>>
>>
>> On Thu, Oct 24, 2013 at 5:48 PM, pankaj joshi wrote:
>>
>>>
>>> hi all,
>>>
>>> nlog(k) is the solution i think.
>>> can anyone suggest more optimal?
>>> solution:
>>> create a min-heap, (condition size should be always k)
>>>
>>> temp =0
>>> loop n to a[]
>>>  if a[i]>temp
>>>if min-heap(root) < a[i]
>>>  delete root in min- heap
>>>  inseart a[i] in min - heap
>>>
>>> at the end of main loop the min-heap will contain the final sequence.
>>>
>>> On Thu, Oct 24, 2013 at 8:50 AM, atul anand wrote:
>>>
>>>> @Saurabh Paliwal : yes
>>>>
>>>> On 10/24/13, Saurabh Paliwal  wrote:
>>>> > Do you mean
>>>> > *of all the increasing subsequences of length k in this array, find
>>>> the one
>>>> > with maximum sum ?*
>>>>  >
>>>> >
>>>> >
>>>> > On Wed, Oct 23, 2013 at 10:52 PM, atul anand
>>>> > wrote:
>>>> >
>>>> >> Given an array with N elements and integer K . Find sum of longest
>>>> >> increasing sub-sequence of length  K elements such that sub-sequence
>>>> >> found
>>>> >> is maximum among all K max su-sequence.
>>>> >>
>>>> >> Eg arr[]={5,2,1,10,9,30,8,55}
>>>> >>
>>>> >> K = 3
>>>> >> output : 10,30,55sum = 10+30+55 = 95
>>>> >>
>>>> >> if K=4
>>>> >> output : 5,10,30,55   sum = 5+10+30+55 =100
>>>> >>
>>>> >> --
>>>> >> You received this message because you are subscribed to the Google
>>>> Groups
>>>> >> "Algorithm Geeks" group.
>>>> >> To unsubscribe from this group and stop receiving emails from it,
>>>> send an
>>>> >> email to algogeeks+unsubscr...@googlegroups.com.
>>>> >>
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> >  -Saurabh Paliwal
>>>> >
>>>> >B-Tech. Comp. Science and Engg.
>>>> >
>>>> >IIT ROORKEE
>>>> >
>>>> > --
>>>> > You received this message because you are subscribed to the Google
>>>> Groups
>>>> > "Algorithm Geeks" group.
>>>> > To unsubscribe from this group and stop receiving emails from it,
>>>> send an
>>>> > email to algogeeks+unsubscr...@googlegroups.com.
>>>> >
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>>
>>>
>>>
>>>
>>> --
>>>  Regards,
>>>
>>> Pankaj Kumar Joshi
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>>
>>
>>
>>
>> --
>>  -Saurabh Paliwal
>>
>>B-Tech. Comp. Science and Engg.
>>
>>IIT ROORKEE
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>
>
> --
>  Regards,
>
> Pankaj Kumar Joshi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] variation of LIS problem

2013-10-24 Thread Saurabh Paliwal
You must be mistaken in the definition of heaps, or maybe the question,
look at the updated question I put up there.


On Thu, Oct 24, 2013 at 5:48 PM, pankaj joshi  wrote:

>
> hi all,
>
> nlog(k) is the solution i think.
> can anyone suggest more optimal?
> solution:
> create a min-heap, (condition size should be always k)
>
> temp =0
> loop n to a[]
>  if a[i]>temp
>if min-heap(root) < a[i]
>  delete root in min- heap
>  inseart a[i] in min - heap
>
> at the end of main loop the min-heap will contain the final sequence.
>
> On Thu, Oct 24, 2013 at 8:50 AM, atul anand wrote:
>
>> @Saurabh Paliwal : yes
>>
>> On 10/24/13, Saurabh Paliwal  wrote:
>> > Do you mean
>> > *of all the increasing subsequences of length k in this array, find the
>> one
>> > with maximum sum ?*
>>  >
>> >
>> >
>> > On Wed, Oct 23, 2013 at 10:52 PM, atul anand
>> > wrote:
>> >
>> >> Given an array with N elements and integer K . Find sum of longest
>> >> increasing sub-sequence of length  K elements such that sub-sequence
>> >> found
>> >> is maximum among all K max su-sequence.
>> >>
>> >> Eg arr[]={5,2,1,10,9,30,8,55}
>> >>
>> >> K = 3
>> >> output : 10,30,55sum = 10+30+55 = 95
>> >>
>> >> if K=4
>> >> output : 5,10,30,55   sum = 5+10+30+55 =100
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Algorithm Geeks" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> an
>> >> email to algogeeks+unsubscr...@googlegroups.com.
>> >>
>> >
>> >
>> >
>> > --
>> >  -Saurabh Paliwal
>> >
>> >B-Tech. Comp. Science and Engg.
>> >
>> >IIT ROORKEE
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an
>> > email to algogeeks+unsubscr...@googlegroups.com.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>
>
> --
>  Regards,
>
> Pankaj Kumar Joshi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] variation of LIS problem

2013-10-23 Thread Saurabh Paliwal
Do you mean
*of all the increasing subsequences of length k in this array, find the one
with maximum sum ?*



On Wed, Oct 23, 2013 at 10:52 PM, atul anand wrote:

> Given an array with N elements and integer K . Find sum of longest
> increasing sub-sequence of length  K elements such that sub-sequence found
> is maximum among all K max su-sequence.
>
> Eg arr[]={5,2,1,10,9,30,8,55}
>
> K = 3
> output : 10,30,55sum = 10+30+55 = 95
>
> if K=4
> output : 5,10,30,55   sum = 5+10+30+55 =100
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Need an optimized solution.

2013-10-20 Thread Saurabh Paliwal
I submitted the solution on hackerrank and got Accepted. There is a change
though, there may be more terms like Term (r+1)
but this can also be done using O(1).

Term (r+2) : (2*n+1 - (r+2)*k)/2 and so forth until numerator becomes zero.
You can use the same technique to get this sum as well.

Sorry for the inconvenience.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Need an optimized solution.

2013-10-18 Thread Saurabh Paliwal
there is a minor correction in definition of r, actually r is the maximum
of all the numbers i such that *i*k-1<=n.*


On Fri, Oct 18, 2013 at 2:38 PM, Saurabh Paliwal <
saurabh.paliwa...@gmail.com> wrote:

> I think I have an O(1) solution to this problem.
>
> I think we can use the idea of summing the pairs of all the values which
> are divisible by k.
>
> The answer will have r+1 terms ( I define r below )
> Term 1 : floor((k-1)/2) will give us the value of pairs who have sum k.
> Term 2 : floor((2*k-1)/2) will give us the value of pairs who have sum 2*k.
> ...
> ...
> ...
> Term r : floor((r*k-1)/2) will give us the value of pairs who have sum r*k.
>
> where r is the maximum of all the numbers i such that i*k<=n
> hence r = floor((n+1)/k)
>
> the last term will contain the number of pairs who have sum (r+1)*k
> Hence,
>
> Term r+1 : floor((2*n-(r+1)*k+1)/2). (why?)
>
> Now the only thing which remains is summing the r terms defined above.
> I used the idea that floor(X/2) = (X-(X%2))/2
>
> Case 1 : k is even. Then all the numerators in r terms are odd, and the
> summation can be easily proved to be equal to ((r*(r+1)/2)*k - 2*r)/2.
> Case 2 : k is odd. Then half(actually floor of half) the numerators in r
> terms are odd, and the summation will be (r*(r+1)/2*k-r-floor(r/2))/2.
>
> The final answer can be stated as :-
>
> Even k : answer = ((r*(r+1)/2)*k - 2*r)/2 + floor((2*n-(r+1)*k+1)/2)
> Odd k  : answer = (r*(r+1)/2*k-r-floor(r/2))/2 + floor((2*n-(r+1)*k+1)/2)
>
> where r = floor((n+1)/k).
>
> Let me know if there is a flaw, or if you don't understand anything.
>
>
>
> On Fri, Oct 18, 2013 at 7:15 AM, pankaj joshi wrote:
>
>> HI All,
>>
>> Puzzle: (This puzzle is of hacker rank)
>>
>> Harvey gives two numbers N and K and defines a set A.
>>
>> *A = { x : x is a natural 
>> number<https://en.wikipedia.org/wiki/Natural_number> ≤
>> N }*
>> (i.e), A = {1,2,3,4,5,6,…., N}
>>
>> Mike has to find the total number of pairs of elements A[i] and A[j]
>> belonging to the given set such that i < j and their sum is divisible by K
>>
>>
>> Solution:- (I am facing a problem of time exceed. can you tell me an
>> optimize solution)
>>
>> the complexity of below solution is O(M*N) {M is numbers and N is Div}
>>
>> static long Occurances(int Number, int Div)
>> {
>> long retVal = 0;
>> for (int i = 1; i <= Number; i++)
>> {
>> int cout = 1;
>> int result = Div * cout - i;
>> cout = (result > 0) ? cout : i / Div;
>> result = Div * cout - i;
>> while (result <= Number)
>> {
>> if (result > i)
>> {
>> retVal++;
>> }
>> else
>> {
>> cout = 2 * i / Div;
>> }
>> cout++;
>> result = Div * cout - i;
>> }
>> }
>> return retVal;
>> }
>>
>> Test conditions are, so take care of space also.
>> K<=N<=109
>> 1<=K<=1
>>
>>  Regards,
>>
>> Pankaj Kumar Joshi
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>>
>
>
>
> --
>  -Saurabh Paliwal
>
>B-Tech. Comp. Science and Engg.
>
>IIT ROORKEE
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Need an optimized solution.

2013-10-18 Thread Saurabh Paliwal
I think I have an O(1) solution to this problem.

I think we can use the idea of summing the pairs of all the values which
are divisible by k.

The answer will have r+1 terms ( I define r below )
Term 1 : floor((k-1)/2) will give us the value of pairs who have sum k.
Term 2 : floor((2*k-1)/2) will give us the value of pairs who have sum 2*k.
...
...
...
Term r : floor((r*k-1)/2) will give us the value of pairs who have sum r*k.

where r is the maximum of all the numbers i such that i*k<=n
hence r = floor((n+1)/k)

the last term will contain the number of pairs who have sum (r+1)*k
Hence,

Term r+1 : floor((2*n-(r+1)*k+1)/2). (why?)

Now the only thing which remains is summing the r terms defined above.
I used the idea that floor(X/2) = (X-(X%2))/2

Case 1 : k is even. Then all the numerators in r terms are odd, and the
summation can be easily proved to be equal to ((r*(r+1)/2)*k - 2*r)/2.
Case 2 : k is odd. Then half(actually floor of half) the numerators in r
terms are odd, and the summation will be (r*(r+1)/2*k-r-floor(r/2))/2.

The final answer can be stated as :-

Even k : answer = ((r*(r+1)/2)*k - 2*r)/2 + floor((2*n-(r+1)*k+1)/2)
Odd k  : answer = (r*(r+1)/2*k-r-floor(r/2))/2 + floor((2*n-(r+1)*k+1)/2)

where r = floor((n+1)/k).

Let me know if there is a flaw, or if you don't understand anything.



On Fri, Oct 18, 2013 at 7:15 AM, pankaj joshi  wrote:

> HI All,
>
> Puzzle: (This puzzle is of hacker rank)
>
> Harvey gives two numbers N and K and defines a set A.
>
> *A = { x : x is a natural 
> number<https://en.wikipedia.org/wiki/Natural_number> ≤
> N }*
> (i.e), A = {1,2,3,4,5,6,…., N}
>
> Mike has to find the total number of pairs of elements A[i] and A[j]
> belonging to the given set such that i < j and their sum is divisible by K
>
>
> Solution:- (I am facing a problem of time exceed. can you tell me an
> optimize solution)
>
> the complexity of below solution is O(M*N) {M is numbers and N is Div}
>
> static long Occurances(int Number, int Div)
> {
> long retVal = 0;
> for (int i = 1; i <= Number; i++)
> {
> int cout = 1;
> int result = Div * cout - i;
> cout = (result > 0) ? cout : i / Div;
> result = Div * cout - i;
> while (result <= Number)
> {
> if (result > i)
> {
> retVal++;
> }
> else
> {
> cout = 2 * i / Div;
> }
> cout++;
> result = Div * cout - i;
> }
> }
> return retVal;
> }
>
> Test conditions are, so take care of space also.
> K<=N<=109
> 1<=K<=1
>
>  Regards,
>
> Pankaj Kumar Joshi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Leaf nodes from inorder traversal

2013-03-16 Thread Saurabh Paliwal
I don't think so. If I understand your problem well, I have a
counter-example
take for example - >
Inorder Traversal - 1-2-3
this could mean a binary tree rooted at 2 with 2 leaf nodes 1 and 3
but this could also mean a binary tree rooted at 3 with 2 as its left child
which in-turn has 1 as its left child (the only leaf node).

On Sat, Mar 16, 2013 at 7:44 PM, Megha Agrawal wrote:

> Hello all,
>
> Is it possible to get leaf nodes from inorder traversal of a binary
> tree(not BST)?
>
> --
> Thank you
>
>   --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Print tree node which sum

2013-03-08 Thread Saurabh Paliwal
Further if there are parent pointers defined in the BST, I think the
approach takes O(1) space because, we greedily traverse the tree with 2
pointers.
(Of course the space needed for tree is excluded).

On Sat, Mar 9, 2013 at 9:46 AM, marti  wrote:

> Thank you!!!  Sir.
>
>
> On Tuesday, March 5, 2013 1:24:30 PM UTC+5:30, marti wrote:
>>
>> Given a value , print two nodes that sum to the value in a BST and normal
>> tree.. time:O(n), space O(logn).
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Print tree node which sum

2013-03-08 Thread Saurabh Paliwal
awesome approach :) (y)

On Sat, Mar 9, 2013 at 9:46 AM, marti  wrote:

> Thank you!!!  Sir.
>
>
> On Tuesday, March 5, 2013 1:24:30 PM UTC+5:30, marti wrote:
>>
>> Given a value , print two nodes that sum to the value in a BST and normal
>> tree.. time:O(n), space O(logn).
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Algo Question

2013-02-26 Thread Saurabh Paliwal
Please mention the initial condition.
I mean I wouldn't pay to any guard (assuming their demands are all positive
numbers)

On Wed, Feb 27, 2013 at 12:39 AM, marti  wrote:

> Sure..
> http://stackoverflow.com/questions/14686745/guards-and-demand
>
>
>
> On Monday, February 4, 2013 5:54:19 PM UTC+5:30, marti wrote:
>>
>> You have N guards in a line each with a demand of coins.You can skip
>> paying a guard only if his demand is lesser than what you have totally paid
>> before reaching him.Find the least number of coins you spend to cross all
>> guards.
>> I think its a DP problem but cant come up with a formula.Another approach
>> would be to binary search on the answer but how do I verify if no. of coins
>> is a possible answer?
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: FInd unique element.

2013-02-22 Thread Saurabh Paliwal
So far what atul mentioned is I think the best and the most intuitive
approach. O(nlog(n)).

On Fri, Feb 22, 2013 at 11:22 PM, Karthikeyan V.B wrote:

> @Aditya :
>
> Since k need to find the smallest number in the array and the corresponding index
> is the number that is repeated most number of times.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: FInd unique element.

2013-02-22 Thread Saurabh Paliwal
So far what aditya mentioned is I think the best and the most intuitive
approach. O(nlog(n)).

On Fri, Feb 22, 2013 at 11:22 PM, Karthikeyan V.B wrote:

> @Aditya :
>
> Since k need to find the smallest number in the array and the corresponding index
> is the number that is repeated most number of times.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: CODECRACKER 2013 [codecracker.in]

2013-02-01 Thread saurabh araiyer
I apologise, the contest is from 11:00 PM IST to 2:00 AM IST

On Fri, Feb 1, 2013 at 5:06 PM, saurabh araiyer  wrote:

> Hi,
> CodeCracker is an online programming contest with fully automated judge
> system. The main drive and motivation behind this platform is to inculcate
> the culture of programming among us, helping understand the importance of
> algorithms in problem solving and recognizing the power of GNU/Linux as a
> powerful programming platform. The judge is built using Open Source
> technologies by the students of NIT Durgapur.
>
> *Date: Saturday February 2, 2013
> *
> Time: *21:00 IST to 01:00 IST* [FOUR hours]. You can see your time Zone
> here<http://www.timeanddate.com/worldclock/fixedtime.html?msg=CODECRACKER&iso=20130202T21&p1=1993&ah=4>
>
> So come, code, challenge yourself... prove your intelligence and win
> recognition for yourself and your college. Prizes *over 400 USD* to be
> won.
>
> For details contact:
> tir...@mukti.in
> jasn...@mukti.in
> saur...@mukti.in
>
>
> --
> Regards,
> Saurabh Araiyer <http://saurabharaiyer.blogspot.com>
>  NIT Durgapur
> blog: saurabharaiyer.blogspot.com
>



-- 
Regards,
Saurabh Araiyer <http://saurabharaiyer.blogspot.com>
 NIT Durgapur
Phone: (91) 9002948106
blog: saurabharaiyer.blogspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] sortin 2D array

2013-01-08 Thread Saurabh Paliwal
but how does it use the fact that the matrix was initially sorted row-wise
and column-wise? that's far from efficient.

On Tue, Jan 8, 2013 at 11:44 PM, Amit Basak  wrote:

> Take a one dimensional array as the multiplication of both the dimensions
> of the two dimensional array and copy the two dimensional array elements in
> the one dimensional array.
> After that use an efficient sorting (e.g. quick sort) on this one
> dimensional array
>
> Regards,
> - Amit
> ---
> Sent from Nexus 4
> On Jan 8, 2013 11:30 PM, "Ravi Ranjan"  wrote:
>
>> You have a two dimensional array of size m*n. The
>> elements in the rows are sorted and every row has
>> unique elements means( in a row no two elements are same) but
>> the elements can repeat across the rows.
>> For example:
>> you have following 2-D array:
>> 2 5 7 9 14 16
>> 3 6 8 10 15 21
>> 4 7 9 15 22 35
>> 7 8 9 22 40 58
>> You are supposed to write an efficient function which
>> will take upper 2-D array as input and will return a
>> one-dimensional array with following properties:
>> a) the 1-D array must contain all the elements of above
>> 2-D array.
>> b) the 1-D array should not have any repeated elements.
>> c) all the elements should be in sorted order.
>> For example:
>> for the above 2-D array, the output should be:
>> A [ ] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 16, 21, 22, 35,
>> 40, 58 }
>>
>> --
>>
>>
>>
>  --
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 




Re: [algogeeks] perfect square condition checking....

2012-12-27 Thread saurabh singh
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com


On Sun, Dec 23, 2012 at 9:07 PM, Anil Sharma wrote:

> no matter how much large number is
>

still,how large?If it fits in long long int then using binary search we can
check this is O(log n) time.

-- 




Re: [algogeeks] Regex tester

2012-12-23 Thread saurabh singh
If you need to implement this for some project then python and java have a
very nice library


Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com


On Sun, Dec 23, 2012 at 7:48 PM, shady  wrote:

>
> http://stackoverflow.com/questions/13144590/to-check-if-two-strings-match-with-alphabets-digits-and-special-characters
>
> any solution for this. we need to implement such regex
> tester
>
> some complex cases :
> *string** regex *   ->   * status*
> *
> *
> reesd   re*.d  ->   match
> re*eed reeed ->   match
>
> can some one help with this ?
>
>  --
>
>
>

-- 




Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-21 Thread saurabh singh
**p; *
Explanation: By default C thinks everything is an int. So p is a global
variable of type *pointer to an int.*Now like other global variables it is
very very very very likely  that the compiler will associate p with an
address that is *0.*Or in terms of pointers it is  *NULL.* That is
printf("%d\n",p) should give 0.
**p=0;*
*
*
What happens when you do **(some_ptr)? *The address stored by some_ptr is
referred to. So when we try to do **p=0 the address pointed by p is
referred,which is NULL,and by the law of the land trying to read/write from
memory with address NULL is sin. *So you get segmentation fault.

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com


On Sat, Dec 22, 2012 at 10:52 AM, Saurabh Paliwal <
saurabh.paliwa...@gmail.com> wrote:

> I am afraid both of you are incorrect..
> 1. since the code modified by you will compile but give sigsegv anyway.
> 2. The statement " *p = 0; " has nothing to do with the " random address"
> you are talking about.
>
>
> On Mon, Dec 17, 2012 at 7:25 PM, Prakhar Jain wrote:
>
>> You are initialising random memory address with 0, which OS doesn't allow.
>>
>> On 12/17/12, Shubham Sandeep  wrote:
>> > how does this code achieve SIGSEGV
>> > code:
>> >  *p;main(){*p=0;}
>> >
>> > --
>> > Regards,
>> > SHUBHAM SANDEEP
>> > IT 3rd yr.
>> > NIT ALD.
>> >
>> > --
>> >
>> >
>> >
>>
>>
>> --
>> --
>> Prakhar Jain
>> IIIT Allahabad
>> B.Tech IT 4th Year
>> Mob no: +91 9454992196
>> E-mail: rit2009...@iiita.ac.in
>>   jprakha...@gmail.com
>>
>> --
>>
>>
>>
>
>
> --
>  -Saurabh Paliwal
>
>B-Tech. Comp. Science and Engg.
>
>IIT ROORKEE
>
> --
>
>
>

-- 




Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-21 Thread Saurabh Paliwal
I am afraid both of you are incorrect..
1. since the code modified by you will compile but give sigsegv anyway.
2. The statement " *p = 0; " has nothing to do with the " random address"
you are talking about.

On Mon, Dec 17, 2012 at 7:25 PM, Prakhar Jain  wrote:

> You are initialising random memory address with 0, which OS doesn't allow.
>
> On 12/17/12, Shubham Sandeep  wrote:
> > how does this code achieve SIGSEGV
> > code:
> >  *p;main(){*p=0;}
> >
> > --
> > Regards,
> > SHUBHAM SANDEEP
> > IT 3rd yr.
> > NIT ALD.
> >
> > --
> >
> >
> >
>
>
> --
> --
> Prakhar Jain
> IIIT Allahabad
> B.Tech IT 4th Year
> Mob no: +91 9454992196
> E-mail: rit2009...@iiita.ac.in
>   jprakha...@gmail.com
>
> --
>
>
>


-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 




Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-17 Thread Saurabh Paliwal
because p is a dangling pointer and that you can't modify what it's
pointing to.

On Mon, Dec 17, 2012 at 7:10 PM, Shubham Sandeep  wrote:

> how does this code achieve SIGSEGV
> code:
>  *p;main(){*p=0;}
>
> --
> Regards,
> SHUBHAM SANDEEP
> IT 3rd yr.
> NIT ALD.
>
>  --
>
>
>



-- 
 -Saurabh Paliwal

   B-Tech. Comp. Science and Engg.

   IIT ROORKEE

-- 




Re: [algogeeks] Re: Adobe Interview Question

2012-12-13 Thread saurabh singh
^ *Exactly,* Things are the *same all around the globe *in terms of
hiring procedure for programming positions. However I don't understand *this
is India  *part?
Kindly reply only *when you think you are contributing something to the
community.*

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Thu, Dec 13, 2012 at 10:27 AM, rahul  wrote:

> @don , becoz this is India...and shit happens everywhere
>
>
> On Wed, Dec 12, 2012 at 11:48 PM, Don  wrote:
>
>> I dislike interview questions which place arbitrary restrictions on
>> the solver.
>> It may be a good puzzle, but it's not a good interview question.
>>
>> "Print the numbers 1 to 100 without using a loop."
>>
>> Why would you want to do that?
>>
>> "Divide a number by 5 without using the divide operator."
>>
>> Again, why? Interview questions shouldn't be about silly little
>> tricks, but about showing that you can do a real-world job.
>>
>> Don
>>
>> On Dec 11, 10:23 pm, saurabh singh  wrote:
>> > I would have replied back with I am doing it with C programming language
>> > only. the read function that we use is not an actual system call. It
>> > is a *wrapper
>> > to a system call*. Any other function that we use usually ends up in
>> > calling some system call. The actual system call is called by low level
>> > routines.
>> > If he still disagreed I would have given him this solution:
>> >
>> > #include
>> > int main()
>> > {
>> > int ch;
>> > while((ch=getchar())!=-1) putchar(ch);
>> > return 0;
>> >
>> > }
>> >
>> > Would have run this as *./a.out < file_to_read*
>> > *
>> > *
>> > If he still disagreed I would have walked out :P
>> >
>> > Saurabh Singh
>> > B.Tech (Computer Science)
>> > MNNIT
>> > blog:geekinessthecoolway.blogspot.com
>> >
>> > On Tue, Dec 11, 2012 at 11:23 PM, manish untwal <
>> manishuntw...@gmail.com>wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > i answered with the...system call too..but he said...do it in C
>> > > programming language only don't use...system call here!!
>> >
>> > > On Tue, Dec 11, 2012 at 10:32 PM, saurabh singh > >wrote:
>> >
>> > >> stdin is a file pointer.
>> > >> freopen returns a file pointer..
>> > >> I suggest using read system call.
>> >
>> > >> For the second question it would be simply
>> > >> (len)!/((frequency_0)!*(frequency_1)!*(frequency_2)!...)
>> >
>> > >> However this will also contains permutations which begin with 0. So
>> > >> subtract the number of permutations that begin with 0 from this
>> number.
>> >
>> > >> Since any factorial in the denominator part will be less than or
>> equal to
>> > >> (len)! we can calculate and store them while calculating len! Hence
>> the
>> > >> overall operation will take O(len) time which would be O(log n)
>> where n is
>> > >> the number.
>> >
>> > >> Saurabh Singh
>> > >> B.Tech (Computer Science)
>> > >> MNNIT
>> > >> blog:geekinessthecoolway.blogspot.com
>> >
>> > >> On Tue, Dec 11, 2012 at 11:02 AM, amrit harry <
>> dabbcomput...@gmail.com>wrote:
>> >
>> > >>> 1st:
>> >
>> > >>> freopen("filename","r",stdin);
>> >
>> > >>> while(scanf("%s",str)!=-1)
>> > >>> {
>> > >>> printf("%s\n",str);
>> > >>> }
>> >
>> > >>> On Sun, Dec 9, 2012 at 3:22 PM, manish untwal <
>> manishuntw...@gmail.com>wrote:
>> >
>> > >>>> I gave this interview in August this year, two of the question i
>> was
>> > >>>> not able to answer properly
>> > >>>> 1) how to print the content of file in C without using the file
>> pointer.
>> > >>>> 2) count the total number of permutation of a number in order O(n)
>> >
>> > >>>> --
>> >
>> > >>> --
>> > >>> Thanks & Regards
>> > >>> Amritpal singh
>> >
>> > >>>  --
>> >
>> > >>  --
>> >
>> > > --
>> > > With regards,
>> > > Manish kumar untwal
>> > > Indian Institute of Information Technology
>> > > Allahabad (2009-2013 batch)
>> >
>> > >  --
>>
>> --
>>
>>
>>
>  --
>
>
>

-- 




Re: [algogeeks] Adobe Interview Question

2012-12-11 Thread saurabh singh
I would have replied back with I am doing it with C programming language
only. the read function that we use is not an actual system call. It
is a *wrapper
to a system call*. Any other function that we use usually ends up in
calling some system call. The actual system call is called by low level
routines.
If he still disagreed I would have given him this solution:

#include
int main()
{
int ch;
while((ch=getchar())!=-1) putchar(ch);
return 0;
}

Would have run this as *./a.out < file_to_read*
*
*
If he still disagreed I would have walked out :P


Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Tue, Dec 11, 2012 at 11:23 PM, manish untwal wrote:

> i answered with the...system call too..but he said...do it in C
> programming language only don't use...system call here!!
>
> On Tue, Dec 11, 2012 at 10:32 PM, saurabh singh wrote:
>
>> stdin is a file pointer.
>> freopen returns a file pointer..
>> I suggest using read system call.
>>
>> For the second question it would be simply
>> (len)!/((frequency_0)!*(frequency_1)!*(frequency_2)!...)
>>
>> However this will also contains permutations which begin with 0. So
>> subtract the number of permutations that begin with 0 from this number.
>>
>> Since any factorial in the denominator part will be less than or equal to
>> (len)! we can calculate and store them while calculating len! Hence the
>> overall operation will take O(len) time which would be O(log n) where n is
>> the number.
>>
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT
>> blog:geekinessthecoolway.blogspot.com
>>
>>
>>
>> On Tue, Dec 11, 2012 at 11:02 AM, amrit harry wrote:
>>
>>> 1st:
>>>
>>> freopen("filename","r",stdin);
>>>
>>> while(scanf("%s",str)!=-1)
>>> {
>>> printf("%s\n",str);
>>> }
>>>
>>>
>>> On Sun, Dec 9, 2012 at 3:22 PM, manish untwal 
>>> wrote:
>>>
>>>> I gave this interview in August this year, two of the question i was
>>>> not able to answer properly
>>>> 1) how to print the content of file in C without using the file pointer.
>>>> 2) count the total number of permutation of a number in order O(n)
>>>>
>>>> --
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Thanks & Regards
>>> Amritpal singh
>>>
>>>  --
>>>
>>>
>>>
>>
>>  --
>>
>>
>>
>
>
>
> --
> With regards,
> Manish kumar untwal
> Indian Institute of Information Technology
> Allahabad (2009-2013 batch)
>
>  --
>
>
>

-- 




Re: [algogeeks] Adobe Interview Question

2012-12-11 Thread saurabh singh
stdin is a file pointer.
freopen returns a file pointer..
I suggest using read system call.

For the second question it would be simply
(len)!/((frequency_0)!*(frequency_1)!*(frequency_2)!...)

However this will also contains permutations which begin with 0. So
subtract the number of permutations that begin with 0 from this number.

Since any factorial in the denominator part will be less than or equal to
(len)! we can calculate and store them while calculating len! Hence the
overall operation will take O(len) time which would be O(log n) where n is
the number.

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Tue, Dec 11, 2012 at 11:02 AM, amrit harry wrote:

> 1st:
>
> freopen("filename","r",stdin);
>
> while(scanf("%s",str)!=-1)
> {
> printf("%s\n",str);
> }
>
>
> On Sun, Dec 9, 2012 at 3:22 PM, manish untwal wrote:
>
>> I gave this interview in August this year, two of the question i was not
>> able to answer properly
>> 1) how to print the content of file in C without using the file pointer.
>> 2) count the total number of permutation of a number in order O(n)
>>
>> --
>>
>>
>>
>
>
>
> --
> Thanks & Regards
> Amritpal singh
>
>  --
>
>
>

-- 




Re: [algogeeks] Data structure and algorithm made easy by narasimha karumanchi

2012-12-06 Thread saurabh singh
itti achi hai to khareed lo jake..yaha na milegi :P
( If it is that good,go buy it.You won't get it here)


*No more posts on this thread.And please this is not torrent. Please dont
post such requests in future*

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Dec 7, 2012 at 10:37 AM, pradeepiiita wrote:

>
>- Any 1 having* Data structure and algorithm made easy by narasimha
>karumanchi* ?? plz forward me d full e book ... :)
>
>  --
>
>
>

-- 




Re: [algogeeks] VIDEO STREAMING

2012-11-24 Thread saurabh singh
You are trying the wrong place.try stackoverflow.the best place to go
when ur ass is on fire. :p

On 11/24/12, Prateek Gupta  wrote:
> @kartik +1:P :P
>
> PS : pardon the pun.
>
>
> On Sat, Nov 24, 2012 at 11:42 AM, Kartik Sachan
> wrote:
>
>>
>> hey anybody has any idea about video streaming using vlcj lib ??
>>
>>
>> --
>>
>> *WITH REGARDS,
>>
>> *KARTIK SACHAN
>>  B.Tech. Final Year
>> Computer Science And Engineering
>> Motilal Nehru National Institute of Technology,Allahabad
>> Phone No: +91-9451012943
>> E-mail: kartik.sac...@gmail.com
>>
>>
>>  --
>>
>>
>>
>
> --
>
>
>


-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com

-- 




Re: [algogeeks] Re: Loan

2012-11-13 Thread saurabh arora
u contact indian embassy man..they will help u ,we are also poor with no money!!

-- 
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-09 Thread saurabh singh
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Nov 9, 2012 at 10:00 AM, atul anand  wrote:

> @saurabh : correct..yes if you are considering recursive approach , so it
> will take O(n) space stack.But same can be done using Morris traversal then
> space will be constant.
>

-- 
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-08 Thread saurabh singh
^ To perform inorder traversal in  a binary tree without using stack space
the tree must be mutable. In other cases as far as I can think the space
complexity should be asymptotically O(n) where n are the number of nodes.

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Wed, Nov 7, 2012 at 10:09 AM, atul anand  wrote:

> @vaibhav : by not using extra space...i guess you mean that you were not
> allowed to use one extra pointer.bcozz space complexity will remain
> constant for inorder approch.
>
> On Tue, Nov 6, 2012 at 1:07 AM, vaibhav shukla wrote:
>
>> yes ofcourse... dats the easiest i suppose...
>> but in one of my interviews, i told this approach, but was then asked not
>> to use space (which i was ,to store inorder)
>> So for such cases, you must try other approaches as well. (DO
>> inorder,keep track of previously visited node and compare it with current
>> node for value greater,or less accordingly.)
>>
>>
>> On Tue, Nov 6, 2012 at 12:34 AM, shady  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.
>>>
>>
>>
>>
>> --
>> best wishes!!
>>  Vaibhav
>>
>>  --
>> 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] Re: Repeated values

2012-11-06 Thread Saurabh Kumar
yes, that was an implementation mistake but what I meant to say was- Adding
extra check of indirect xor'ing could have a pitfall too.
Try the case: [0 1 1 1 4 4]
http://ideone.com/3sreLZ


On 4 November 2012 10:13, Vikram Pradhan  wrote:

>  It should have caught in the first loop where i checked that condition if
> the first value (which is 3 in this case) is repeated or not ...but
> unfortunately i  implemented that wrong ...so now i've corrected that
> mistake ..i hope now it'll work fine ..
> http://ideone.com/MQ44Rt
>
> the whole idea of using xor is that we don't have to modify the array as
> i've seen this same question somewhere else where the condition was that
> the array is a read only array ..otherwise Don's method will work fine .
>
>
>
>
>
>
>
> Vikram Pradhan | B.Tech| Computer Science & Engineering | NIT Jalandhar
>>  | 9740186063 |
>>
>  --
> 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: Repeated values

2012-11-03 Thread Saurabh Kumar
@Vikram - sorry  to burst your bubble once again. try - [3 3 1 1]
even indirect xor'ing could not ensure anything useful.


On 2 November 2012 17:04, Vikram Pradhan  wrote:

> @Don :yeah sorry i misinterpreted the if condition ..it'll work fine .
>
> I've modified my previous sol. and in this sol we do not need to modify
> the array . Time complexity O(n) and constant space.
> http://ideone.com/s2kR24
>
>
>
>
>
> On Fri, Nov 2, 2012 at 1:14 AM, Don  wrote:
>
>> It won't enter an infinite loop in that case. In fact, it would
>> immediately return.
>> Don
>>
>> On Oct 31, 2:39 pm, Vikram Pradhan  wrote:
>> > @Don It will be an infinite loop for some cases  ...like try this i=1,
>> and
>> > a[1] = 5 , a[5] = 5
>> >
>> > *Solution:*
>> >
>> > As the numbers are from 0 to N-1 so we can xor the value with its index
>> in
>> > a loop . if the result is 0 then there is no repetition else there is
>> some
>> > repetition.
>> >
>> > *int result = 0;*
>> > *for(int i=0;i> > *{*
>> > *result ^= i ^ array[i];*
>> > *}*
>> > *
>> > *
>> > *if(result==0)*
>> > *There is no repetition.*
>> > *else*
>> > *There is some repetition.*
>> >
>> > Time complexity O(N)
>> > Space Complexity : constant
>> >
>> > check this :http://ideone.com/RXyynB
>> >
>> >  As the indexes are from 0 to N-1 and numbers are also from 0 to N-1 in
>> > random order. So if there is no repetition then there is exactly two
>> copies
>> > of same number in set of (values and index) and when we xor all the
>> indexes
>> > to all the numbers the result will be zero because xor of same no. is
>> zero.
>> >
>> > --
>> > Vikram Pradhan | B.Tech| Computer Science & Engineering | NIT Jalandhar
>>  |
>> > 9740186063 |
>>
>> --
>> 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.
>>
>>
>
>
> --
> Vikram Pradhan | B.Tech| Computer Science & Engineering | NIT Jalandhar  |
>  9740186063 |
>
> --
> 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] Ternary operators

2012-11-02 Thread Saurabh Kumar
What I meant is: in case1 parsing of :
*cout << test ? "A String" : 0 << endl;*
is messed up because operator '*<<*' has higher precedence than ternary (*?:
*) operator.

Firstly, *cout << test* will be parsed then, an attempt for *0 <<
endl*would be made, which will fail because, arguments are not
compatible! it
makes no sense to left-shift 0 by 'endl'.
If you change *endl* to *5*  that is,

* cout << test ? "A String" : 0 << 5;*

expression will compile and work but its' something not what you want.
ternary operator is totally wasted here.

*cout << test ? "A String" : 0 << 5;*
How this expression will work ? It will first execute *cout <<
test*(outputting 0) return value is a
*reference to cout object *itself.
secondly, left shift of 0 by 5, which will evaluate to 0 again.
Now, you have *cout(ref) ? "A String" : 0* which will evaluate to "A
String" since reference of cout will be *not NULL*. but this value "A
String" will be wasted as you are not doing anyting with it.

>>>>and why 0 is converted to base..i know exp3 is convertered to exp
to..so int to array..???base array comes in int???and what is 0??

In expression: *expr1 ? expr2 : expr3*

as you already know for the above expression: return type is determined by
type of *expr2* and if *expr3* is not the same type as *expr2* then
compiler will 'try' to convert it to type of *expr2*.
say, expr2 is float and expr3 is int. then expr3 will be converted to float.
if expr2 is int and expr3 is float, then expr3 will be converted to int.
if expr2 is char* and expr3 is float, error will be thrown because there is
no way compiler can interpret a float as an address.
if expr2 is char* and expr3 is int, again it will be an error except for 0.
as 0 stands for NULL pointer.

so, in-  *cout << test ? "A String" : 0*
0 is a special case pointing to NULL, that's why it works.

>>>>what if we have 1 in case of 0?
you'll again get an error because you cannot assign an int value of 1 to a
char* like that. (the exact procedure to assign is to cast it to (void*)
and so on... but you are skipping all those steps. hence, an error) or if
you use something like:
cout << test ? "A String" : (char*)1;
or, cout << test ? "A String" : (char*)0x1523; then it should work.

But generally you should avoid falling into these intricate details.
Points to note:
1. Always use braces() when in doubt.
2. Note how the return value type for ternary operator is determined.

On 2 November 2012 00:40, rahul sharma  wrote:

>
> I cant get to you..please explain...what will first statement expanded to
> during compilation..??.and why 0 is converted to base..i know exp3 is
> convertered to exp to..so int to array..???base array comes in int???and
> what is 0??what if we have 1 in case of 0?
>
> On Thu, Nov 1, 2012 at 5:20 PM, Saurabh Kumar wrote:
>
>> There's nothing to do with the type of "A String".
>> The reason for which the first code gives compilation error is: operator
>> (<<) has higher precedence than ternary operator (?:) so, without braces
>> your are actually messing up the parsing of "cout << << << "stream.
>>
>> * cout << test ? "A String" : 0 << endl;*
>>
>> consider removing the last "*<> error.
>>
>> * cout << test ? "A String" : 0;* // this compiles and runs fine with my
>> compiler(g++ 4.5), but as *cout << test* will take precedence, there is
>> no point of putting a ternary operator there, unless you use braces, of
>> course.
>>
>>
>> In teh second case however, reason given is valid:
>>  i.e. return type of ternary operator is determined by "A String" and the
>> expression 0 will be taken as address of a string location. Hence, there is
>> no guarantee of output.
>>
>>
>> On 31 October 2012 19:52, rahul sharma  wrote:
>>
>>> plz read carefully
>>>
>>>
>>> On Wed, Oct 31, 2012 at 10:18 AM, Tamanna Afroze wrote:
>>>
>>>> sorry for my last post, i didn't look carefully at the code. I think
>>>> without bracket the ternary expression is incomplete, that's why; first
>>>> code doesn't compile correctly.
>>>>
>>>>
>>>>
>>>> On Wed, Oct 31, 2012 at 9:51 AM, Tamanna Afroze wrote:
>>>>
>>>>> both codes are same. Where is the difference?
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Grou

Re: [algogeeks] Re: Repeated values

2012-11-01 Thread Saurabh Kumar
@Vikram - your approach fails for [4 1 1 1 1]

On 1 November 2012 00:09, Vikram Pradhan  wrote:

> @Don It will be an infinite loop for some cases  ...like try this i=1, and
> a[1] = 5 , a[5] = 5
>
> *Solution:*
>
> As the numbers are from 0 to N-1 so we can xor the value with its index in
> a loop . if the result is 0 then there is no repetition else there is some
> repetition.
>
> *int result = 0;*
> *for(int i=0;i *{*
> *result ^= i ^ array[i];*
> *}*
> *
> *
> *if(result==0)*
> *There is no repetition.*
> *else*
> *There is some repetition.*
>
> Time complexity O(N)
> Space Complexity : constant
>
> check this : http://ideone.com/RXyynB
>
>  As the indexes are from 0 to N-1 and numbers are also from 0 to N-1 in
> random order. So if there is no repetition then there is exactly two copies
> of same number in set of (values and index) and when we xor all the indexes
> to all the numbers the result will be zero because xor of same no. is zero.
>
>
> --
> Vikram Pradhan | B.Tech| Computer Science & Engineering | NIT Jalandhar  |
>  9740186063 |
>
> --
> 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] Pre/Post L and r value

2012-11-01 Thread Saurabh Kumar
Yes, you are right. Pre increment simply increments and returns
*reference*to same object.
somewhat like:

int& operator++(int &n){
n = n+1;
return n;
}

On 31 October 2012 02:08, rahul sharma  wrote:

> @saurabh..thnxplz provide me code snippet for pre increment also..it
> will help a lot..i can guess it will do n++ and return itself..plz give
> code snippet...
>
>
> On Mon, Oct 29, 2012 at 10:50 AM, Saurabh Kumar wrote:
>
>> Post increment returns temp object because it has to return the old value
>> of object not the new incremented one:
>> Simply put, the code for post increment somewhat goes like this:
>>
>> int operator++ (int &n){
>>  int temp = n;
>> n = n+1;
>> return temp;
>> }
>>
>> that's also the reason you cannot use it as a lvalue in an exprression,
>> as you would be assigning nowhere.
>>
>> On 27 October 2012 20:09, rahul sharma  wrote:
>>
>>> But y post returns temp. object
>>>
>>>
>>> On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar wrote:
>>>
>>>> i++: Post increment can't be a lvalue because Post increment internally
>>>> returns a temporary object (NOT the location of i) hence you cannot assign
>>>> anything to it. The result of i++ can be used only as a rvalue.
>>>>  ++i: whereas, in Pre-increment  value gets incremented and the same
>>>> location is returned back to you, hence can be used as lvalue in an
>>>> expression.(C++ allows this)
>>>> Both can be used as rvalues though.
>>>>
>>>> On 26 October 2012 18:54, rahul sharma  wrote:
>>>>
>>>>>  why pre inc. is l value and post is r value..please explain
>>>>>
>>>>> --
>>>>> 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.
>

-- 
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] Ternary operators

2012-11-01 Thread Saurabh Kumar
There's nothing to do with the type of "A String".
The reason for which the first code gives compilation error is: operator
(<<) has higher precedence than ternary operator (?:) so, without braces
your are actually messing up the parsing of "cout << << << "stream.

* cout << test ? "A String" : 0 << endl;*

consider removing the last "*< wrote:

> plz read carefully
>
>
> On Wed, Oct 31, 2012 at 10:18 AM, Tamanna Afroze wrote:
>
>> sorry for my last post, i didn't look carefully at the code. I think
>> without bracket the ternary expression is incomplete, that's why; first
>> code doesn't compile correctly.
>>
>>
>>
>> On Wed, Oct 31, 2012 at 9:51 AM, Tamanna Afroze wrote:
>>
>>> both codes are same. Where is the difference?
>>>
>>
>>  --
>> 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] what to modify in given code so that dublicate permutations should not come

2012-11-01 Thread Saurabh Kumar
You'd simply have to keep track of : has particular alphabet already been
used or not. You can do this by maintaining a 'used' array of 0/1 . Set and
unset the respective index before and after the recursion.
Here's the modified code:

#include
#include
#include
*void allLexicographicRecur (char *str, char* data, int *used, int last,
int index)*
{
int i, len = strlen(str);
// One by one fix all characters at the given index and recur for the
// subsequent indexes
for ( i=0; iwrote:

> void allLexicographicRecur (char *str, char* data, int last, int index)
> {
> int i, len = strlen(str);
>
> // One by one fix all characters at the given index and recur for the
> // subsequent indexes
> for ( i=0; i {
> // Fix the ith character at index and if this is not the last
> index
> // then recursively call for higher indexes
> data[index] = str[i] ;
>
> // If this is the last index then print the string stored in
> data[]
> if (index == last)
> printf("%s\n", data);
> else // Recur for higher indexes
> allLexicographicRecur (str, data, last, index+1);
> }
> }
>
> /* This function sorts input string, allocate memory for data (needed for
>   allLexicographicRecur()) and calls allLexicographicRecur() for printing
> all
>   permutations */
> void allLexicographic(char *str)
> {
> int len = strlen (str) ;
>
> // Create a temp array that will be used by allLexicographicRecur()
> char *data = (char *) malloc (sizeof(char) * (len + 1)) ;
> data[len] = '\0';
>
> // Sort the input string so that we get all output strings in
> // lexicographically sorted order
> qsort(str, len, sizeof(char), compare);
>
> // Now print all permutaions
> allLexicographicRecur (str, data, len-1, 0);
>
> // Free data to avoid memory leak
> free(data);
> }
>
> // Needed for library function qsort()
> int compare (const void * a, const void * b)
> {
> return ( *(char *)a - *(char *)b );
> }
>
> // Driver program to test above functions
> int main()
> {
> char str[] = "ABC";
> printf("All permutations with repetition of %s are: \n", str);
> allLexicographic(str);
> getchar();
> return 0;
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 Function Pointer(Typedef)

2012-10-30 Thread Saurabh Kumar
because, pFunc is just a typedef.
you'd have to instantiate a variable at least in order to call your
function.
like -
 typedef int (*pFunc) (int);
 pFunc fptr = func; //fptr is now a variable on stack which points to your
function.
 fptr(5); // call that function.

On 30 October 2012 01:41, rahul sharma  wrote:

> #include 
> #include 
>
>
> int func(int);
> int main(int count,char *argv[])
> {
>  typedef int (*pFunc) (int);
> pFunc=func;
> getchar();
> }
>
>
>
>
> Y itz not compiling?
>
> --
> 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

2012-10-30 Thread Saurabh Kumar
you are right.
k is the edit distance we are searching for and a critical parameter. In
short you can say- k represents how much error(in terms of edit-distance)
you want to tolerate for between document word 'w' and your suggestion.
since our data structure can answer queries for e.g. "Find all words with
k<=5)" I think we can do better as loading the tree and searching could be
costly so, instead of repeatedly firing queries many times for k=1, 2,
3,...
i think it's better to do it like:

1. for a given document word 'w': you could start k = 0 (for exact
matching, i.e. if w is present in dictionary or not) if returned
list.size() =1 then its' a valid word else, if it's NULL fire a query for
k=2.
>From the function return a list of all dictionary words which are
*<=2*distance from 'w' and return a sorted list based on edit
distance.
sometimes returned list could be large so you need to filter out the Best
possible Suggestions for 'w'.
like- you might wanna give preference to those words which were 1 distance
away than 2. and in that - those edits which have the edited 'alphabet
close to the mispelled one'... like the example- w = REDT [REST is more
likely than RENT as 'S' appears closer to 'D' on keyboard than 'N'] etc. or
they sound same based on some phoneme model etc.

2. if for k=2 returned list was NULL, you can query for k=5, and check if
there are any words with edit-distance *<=5*., again returned list could
possibly be NULL as well. you might want to limit your search for k (say
5). e.g. if document contains w = "ijljhflkjjiulgihh"  It's highly unlikely
that your dictionary will contain any word closer to this (unless ur
dictionary contains crazy volcano names from iceland):
so for cases like these, after k=5 you can return "No Suggestion".

It's actually experimentative. you could try any other way also but this
way you can limit your no. of queries/per word to 2.


A correction: I realize previously I've interchangeably used teh name
'KDTree' and 'bk-tree', both are metric trees but what I really meant was a
'bkTree'. where, a node has arbitrary no. of children and the parent-child
edge represents the corresponding Levenshtein distance between them. The
basic idea here is to store your dictionary in a data-structure whcih
facilitates searching of words based on their edit-distances.


On 27 October 2012 22:40, payal gupta  wrote:

>  the question mentioned is as it isi just copy pasted it here.
> @saurabh thanx for the explainaton of the cube problem i guess that is an
> appropriate soln for the question.
> and for the other question on detection of typos and  suggestion i would
> like to know to know what 'k' in your explaination stands for?how are the
> values allocated to it ? should it be for each wrong word not mentioned in
> the dictionary we got to check if the word exists with edit distance equal
> to 1 in dictioanry
> and so on until we get the correct word???
>
>
>
>
> on Sat, Oct 27, 2012 at 8:12 AM, Saurabh Kumar wrote:
>
>> could you please share the link? coz at first glance a Trie looks like a
>> bad choice for this task.
>>
>> I'd go with the Levenshtein distance and a kd-tree.
>> First implement the Levenshtein distance algorithm to calculate the edit
>> distance of two strings.
>> Second, since Levenshtein distance qualifies as a metric space we can use
>> a metric tree like BK-tree to populate it with our dictionary.
>> Choose a random word from dictionary as a root and subsequently insert
>> dictionary words(picking them up randomly) into the tree.
>> A node has arbitrary no. of children. The parent-child edge represents
>> the corresponding Levenshtein distance between them.
>>
>> Building the tree is one time process. Once the tree is built we can
>> devise a way to serialize it and store it.
>>
>> Using this tree we can find all the words with edit-distance less than or
>> equal to, say k.
>> Lets, define a function call in Tree class as: List KDTreeSearch(s, k);
>> which searches for all strings s' in the tree such that |s-s'| <= k i.e.
>> all strings which are less than or equal to an edit distance of k.
>> Searching:
>> Start with the Root and calculate the edit-distance of s from root. If
>> its', say d then we know exactly which children we need to descend to in
>> order to find the words with distance <=k.
>>
>> Looking for typos:
>> Scan the document and for each word 'w' make a call: list =
>> KDTreeSearch(w, 0);
>> if, list.size() = 1. //We have the word in dictionary.
>> else, list = KDTreeSearch(w, 2); // 

Re: [algogeeks] Pre/Post L and r value

2012-10-30 Thread Saurabh Kumar
Post increment returns temp object because it has to return the old value
of object not the new incremented one:
Simply put, the code for post increment somewhat goes like this:

int operator++ (int &n){
int temp = n;
n = n+1;
return temp;
}

that's also the reason you cannot use it as a lvalue in an exprression, as
you would be assigning nowhere.

On 27 October 2012 20:09, rahul sharma  wrote:

> But y post returns temp. object
>
>
> On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar wrote:
>
>> i++: Post increment can't be a lvalue because Post increment internally
>> returns a temporary object (NOT the location of i) hence you cannot assign
>> anything to it. The result of i++ can be used only as a rvalue.
>>  ++i: whereas, in Pre-increment  value gets incremented and the same
>> location is returned back to you, hence can be used as lvalue in an
>> expression.(C++ allows this)
>> Both can be used as rvalues though.
>>
>> On 26 October 2012 18:54, rahul sharma  wrote:
>>
>>>  why pre inc. is l value and post is r value..please explain
>>>
>>> --
>>> 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] Fork in c

2012-10-27 Thread saurabh singh
Yup
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Sat, Oct 27, 2012 at 8:21 PM, rahul sharma wrote:

> text 1 remains in buffer...nowwhen child reaches print f.it prints
> oldbuffer+newdata...m i ryt???
>
>
> On Sat, Oct 27, 2012 at 4:07 PM, saurabh singh wrote:
>
>> printf is line buffered. hence text1 remains in buffer when fork is
>> called.this is shared by both the child and the parent when fork is called.
>> Leaving the rest for u to conclude
>>
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT
>> blog:geekinessthecoolway.blogspot.com
>>
>>
>>
>> On Sat, Oct 27, 2012 at 2:25 PM, CHIRANJEEV KUMAR <
>> cse.chiranj...@gmail.com> wrote:
>>
>>> I think the output should be :
>>>
>>> text1text2
>>> text2
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Sat, Oct 27, 2012 at 2:22 PM, rahul sharma 
>>> wrote:
>>>
>>>> int main()  {
>>>> printf("text1");
>>>> fork();
>>>> printf("text2\n");
>>>> return 0;  }
>>>>
>>>>  the output  is:
>>>>
>>>> text1text2
>>>> text1text2
>>>>
>>>> Please explain o/p
>>>>
>>>>  --
>>>> 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.



Re: [algogeeks] Re: Random Number generation

2012-10-27 Thread Saurabh Kumar
@Don- Yes, I agree the choice of Random number generator algorithm should
very much depend on the underlying application.
Thanks, for bringing up the "Diehard" tests, those are some interesting
statistical tests. +1

On 26 October 2012 21:23, Don  wrote:

> How you chose from the wide array of pseudo-random generators
> available depends a lot on how you intend to use it. If you just need
> something that seems random in a video game, a LCG is probably fine.
> However, you could fill a large bookshelf with studies which were
> invalidated because they used randu for simulation. If you need good
> statistical properties for Monte Carlo simulation, don't use a LCG.
> Use a 64-bit multiply with carry as a minimum, and preferably use
> Mersenne Twister.
>
> George Marsaglia developed a very comprehensive set of tests of the
> quality of a stream of "random" data. The suite is called "Diehard".
> It measures statistical properties of a sample and determines if it
> varies too much from what would be expected of a truly uniform and
> random sample. Many LCG generators fail badly.
>
> If you are using the generator for simulation you also need to be
> aware of the generator's period. If you exhaust the period, you are re-
> using data, which defeats the purpose of Monte Carlo simulation.
>
> There are hardware devices which claim to produce true random output,
> usually based on some sort of noisy physical process. They are
> generally slower than Mersenne Twister or other deterministic methods.
> However, they tend to have bias or other issues.
>
> If you need to generate an integer in a certain range, don't just use
> mod n. That does not result in a uniform result unless n is divisible
> by the range of the generator. You need to use a rejection method.
>
> Don
>
> On Oct 25, 8:44 am, Saurabh Kumar  wrote:
> > Take a look at  Linear Congruential
> > Generator<http://en.wikipedia.org/wiki/Linear_congruential_generator>
> > algorithm
> > for generating pseudo random numbers.
> >
> > On 25 October 2012 16:58, bharat b  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > I heard that LINUX uses our past time mouse movement and keys pressed
> at
> > > time and something else to generate a random number.
> >
> > > On Thu, Oct 25, 2012 at 4:07 PM, Anuj Khandelwal <
> > > anuj.cool.khandel...@gmail.com> wrote:
> >
> > >> hey all,
> > >> Any idea to generate random number without using rand() function call
> ?
> > >> Any algorithms for random number generation ?
> >
> > >> --
> > >> Anuj Khandelwal
> > >> Final Year Undergraduate Student
> > >> Department of Computer Engineering
> > >> Malaviya National Institute of Technology, Jaipur
> > >> India
> > >> +91-9784678325
> >
> > >>  --
> > >> 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] INTERVIEW QUESTION

2012-10-27 Thread Saurabh Kumar
Firstly, that question is missing a lot of details.
In absence of those details I'm going to make soem assumptions:
1. cube is odd lengthed, so that we can define a unique center of cube.
2. While traversing from a cell(x, y, z) we can only move into any of the 6
adjacent cells[x(+-)1, y(+-)1, z(+-)1] or you can assume all 8 neighbours
also, accordingly change your function to get neighbours.
3. Traversing Paths to surface would be done in a manner such that you
cannot revisit a cell, else there can be infinite many possibilities.

Since there will be exponential no. of such paths so enumerating them will
take exponential amount of time.
Simple recursive implementation could go something like this:

Algorithm(x, y, z, Path, Visited): // 'Path' is a list of cells visited
till now starting from the center cell. 'Visited' is a boolean NxNxN array.
or, you can choose to drop the 'Visited' array and implement
IsAlreadyVisited(x, y, z) function by searching in teh list 'Path'.
If   current cell(x, y, z) is a surface cell.
 Report a Path found and output the 'Path'.
 return;
else for each of the 6 neighbours (unvisited): //(x' y' z') is an
unvisited neighbour of (x, y, z)
 Path.append(x', y', z')
 Visited(x', y', z') = true;
 Algorithm(x', y', z', Path, Visited)

Depth of recursion is O(N^3).
You can use the symmetry argument here and only count the paths ending on a
particular surface (say- Top surface) rest of the paths can be calculated
by mirroring them onto other surfaces easily, but this will not cut down
the asymptotic complexity of the solution. In fact paths ending on a
particular face will also exhibit symmetry.

On 27 October 2012 10:11, payal gupta  wrote:

>
>  Sorry ,posted the wrong question initially actually i needed the algo for
> this question. Thanx.
>
>
> On Saturday, October 27, 2012 7:04:10 AM UTC+5:30, raghavan wrote:
>
>> By any chance did you read the new blog post by Gayle Laakmaan..
>>
>> I guess to detect typos we can use some sort of Trie implementation..
>>
>>
>> On Fri, Oct 26, 2012 at 7:50 PM, payal gupta  wrote:
>>
>>>
>>>Given a cube with sides length n, write code to print all possible
>>> paths from the center to the surface.
>>>Thanx in advance.
>>>
>>>
>>>Regards,
>>>   PAYAL GUPTA,
>>>   NIT-B.
>>>
>>>
>>>
>>> --
>>> 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/-/ZaItRf_9A_IJ
>>> .
>>>
>>> To post to this group, send email to algo...@googlegroups.com.
>>> To unsubscribe from this group, send email to algogeeks+...@**
>>> googlegroups.com.
>>>
>>> For more options, visit this group at http://groups.google.com/**
>>> group/algogeeks?hl=en .
>>>
>>
>>
>>
>> --
>> Thanks and Regards,
>> Raghavan KL
>>
>>
>>   --
> 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/-/vVmz5r1gpIYJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Finite state automata accpt string of length 6

2012-10-27 Thread Saurabh Kumar
Since this is a small grid you can count it manually but in general problem
is to count no. of paths from bottom-left corner to top-right corner
(provided all the transition alphabets in the automata are distinct in
the respective dimensions e.g. here,  xyz in one  dimension and abc in
other)

You can view this problem as writing all permutations of strings of 3R's
and 3U's (for RIGHT movement and UP movement) RRRUUU which will take you to
the top right most corner.
All possible arrangements = (3+3)! / (3! * 3!)
In general: (m+n)! / (m! * n!) for a mxn grid.

On 27 October 2012 11:05, rahul sharma  wrote:

> should i take it how many ways are there to reach from start to  the top
> right destination...x,y,z,a,b,c, are i/p statexyzabc one stringabc
> xyz is another...if m ryt then is dere any formulla to calute or we have to
> do it manuall
>
>
> On Sat, Oct 27, 2012 at 11:02 AM, rahul sharma wrote:
>
>>
>> can u please elaborate...i am not able to understand the figure..plz
>> explainit would be of great help
>>
>> On Sat, Oct 27, 2012 at 5:57 AM, payal gupta  wrote:
>>
>>> should be 6C3 or 20 perhaps.
>>>
>>> On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma 
>>> wrote:
>>>
 Finite state automata accpt string of length 6

 what is total number of strings in set..please find the attahcment

 --
 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] Pre/Post L and r value

2012-10-27 Thread Saurabh Kumar
i++: Post increment can't be a lvalue because Post increment internally
returns a temporary object (NOT the location of i) hence you cannot assign
anything to it. The result of i++ can be used only as a rvalue.
++i: whereas, in Pre-increment  value gets incremented and the same
location is returned back to you, hence can be used as lvalue in an
expression.(C++ allows this)
Both can be used as rvalues though.

On 26 October 2012 18:54, rahul sharma  wrote:

> why pre inc. is l value and post is r value..please explain
>
> --
> 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] Sequence Point C with postincremented

2012-10-27 Thread Saurabh Kumar
You're right , && || all introduce a sequence point. In first case
evaluation proceeds like this:
j = (i++, i++);
>>  *i++* Post increment the i (i is now 11)
>>  *j = i++* Post increment the i (j is assigned 11 and i is now 12)

In second case, the whole of rvalue for = operator will be evaluated
first...
j = a++ && 1;
>> *a++ *a is Post incremented (a is now 1 but return value is 0)
>> *0 && 1* = 0 (which gets assigned to j)
Hence, j = 0, a = 1

On 26 October 2012 18:54, rahul sharma  wrote:

> Guys plz tell that postincremented variable is  incremented after sequence
> or after ;
>
> as we have && || comma and ; as sequence point
>
> so say we have
> int i=10;
> int j=(i++,i++);
> firstly i++ goes and as comma comes so ++ post inc. takes place and take
> to 11 ..now when next time the postincremented is done later after ;  and
> firstly the value 11 is assigned to j
>
> so after this statement we have j=11,i=12
>
> but if i write
> int a=0;
> int j=a++&&1;
> so when && comes so postincrement takes place and assign this to j...so at
> the point we reach && acc. to me a=1..But a remains 0 as this expression
> goes to false...can anybody tell me y so happens..when does the value in
> postincremented is incremented...i am sure about comm and ;...but what in
> case of && and  ||these are also sequence point...y post increment
> doesnt take place when we reach &&...please explain..
>
> --
> 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

2012-10-27 Thread Saurabh Kumar
could you please share the link? coz at first glance a Trie looks like a
bad choice for this task.

I'd go with the Levenshtein distance and a kd-tree.
First implement the Levenshtein distance algorithm to calculate the edit
distance of two strings.
Second, since Levenshtein distance qualifies as a metric space we can use a
metric tree like BK-tree to populate it with our dictionary.
Choose a random word from dictionary as a root and subsequently insert
dictionary words(picking them up randomly) into the tree.
A node has arbitrary no. of children. The parent-child edge represents the
corresponding Levenshtein distance between them.

Building the tree is one time process. Once the tree is built we can devise
a way to serialize it and store it.

Using this tree we can find all the words with edit-distance less than or
equal to, say k.
Lets, define a function call in Tree class as: List KDTreeSearch(s, k);
which searches for all strings s' in the tree such that |s-s'| <= k i.e.
all strings which are less than or equal to an edit distance of k.
Searching:
Start with the Root and calculate the edit-distance of s from root. If
its', say d then we know exactly which children we need to descend to in
order to find the words with distance <=k.

Looking for typos:
Scan the document and for each word 'w' make a call: list = KDTreeSearch(w,
0);
if, list.size() = 1. //We have the word in dictionary.
else, list = KDTreeSearch(w, 2); // searching for all words with edit
distance of 2 from w

returned 'list' can sometimes be large, we can subsequently filter it out
by narrowing down our definition of 'typos'
e.g. for typo w = REDT [REST is more likely than RENT] or maybe some
Phoneme model etc you should discuss this at length with the
interviewer.

On 27 October 2012 07:03, Raghavan  wrote:

> By any chance did you read the new blog post by Gayle Laakmaan..
>
> I guess to detect typos we can use some sort of Trie implementation..
>
>
> On Fri, Oct 26, 2012 at 7:50 PM, payal gupta  wrote:
>
>>
>>Given a cube with sides length n, write code to print all possible
>> paths from the center to the surface.
>>Thanx in advance.
>>
>>
>>Regards,
>>   PAYAL GUPTA,
>>   NIT-B.
>>
>>
>>
>> --
>> 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/-/ZaItRf_9A_IJ.
>>
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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 and Regards,
> Raghavan KL
>
>
>  --
> 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] Finite state automata accpt string of length 6

2012-10-27 Thread Saurabh Kumar
20 seems correct.
You can also view this as all permutations of xyzabc such that the ordering
x wrote:

> should be 6C3 or 20 perhaps.
>
>
> On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma wrote:
>
>> Finite state automata accpt string of length 6
>>
>> what is total number of strings in set..please find the attahcment
>>
>> --
>> 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] Fork in c

2012-10-27 Thread saurabh singh
printf is line buffered. hence text1 remains in buffer when fork is
called.this is shared by both the child and the parent when fork is called.
Leaving the rest for u to conclude

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Sat, Oct 27, 2012 at 2:25 PM, CHIRANJEEV KUMAR
wrote:

> I think the output should be :
>
> text1text2
> text2
>
>
>
>
> On Sat, Oct 27, 2012 at 2:22 PM, rahul sharma wrote:
>
>> int main()  {
>> printf("text1");
>> fork();
>> printf("text2\n");
>> return 0;  }
>>
>>  the output  is:
>>
>> text1text2
>> text1text2
>>
>> Please explain o/p
>>
>>  --
>> 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] Random Number generation

2012-10-25 Thread Saurabh Kumar
Take a look at  Linear Congruential
Generator
algorithm
for generating pseudo random numbers.

On 25 October 2012 16:58, bharat b  wrote:

> I heard that LINUX uses our past time mouse movement and keys pressed at
> time and something else to generate a random number.
>
>
> On Thu, Oct 25, 2012 at 4:07 PM, Anuj Khandelwal <
> anuj.cool.khandel...@gmail.com> wrote:
>
>> hey all,
>> Any idea to generate random number without using rand() function call ?
>> Any algorithms for random number generation ?
>>
>> --
>> Anuj Khandelwal
>> Final Year Undergraduate Student
>> Department of Computer Engineering
>> Malaviya National Institute of Technology, Jaipur
>> India
>> +91-9784678325
>>
>>  --
>> 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] .Given the binary form of a number in a string. WAP to find 2's complement in that string itself.[ADOBE]

2012-10-25 Thread Saurabh Kumar
I think this should do:

string s;
cin >> s;
int n = s.length(), i;
for(i=n-1; s[i]=='0'; --i);//find the fist set bit from right...
for(int j=--i; j>=0; --j){// complement rest of the bits...
if(s[j] == '0')
s[j] = '1';
else
s[j] = '0';
}
cout << s << endl;


On 26 October 2012 03:40, rahul sharma  wrote:

> Plz give a program 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.
>

-- 
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] permutations using stack

2012-10-21 Thread Saurabh Kumar
answer is right there in the strings: S = PPXXPXPXPPX...

Possible permutations = No. of ways to generate strings of P/X's  such that
in each sub-string S[0..i] no. of P's is always greater than or equal to
no. of X's.
You can also view this as - all possible strings of n balanced parentheses.
This turns out to be nothing but famous Catalan number = 1/(n+1) *
2nCn Heres' wikipedia link to a formal
proof
.

In case if you have duplicates you can discard the repitions easily after
calculating Cn.

On 21 October 2012 14:29, Shruti  wrote:

> we can generate permutations using stack. For example, if n=1,2,3 and
> Push() is denoted by "P", and Pop() by "X",
> then we can generate permutations as :
> PPPXXX = 321
> PPXXPX = 213
> PXPXPX = 123
> PXPPXX = 132
> PPXPXX = 231
>
> (note : at any point, #P's>=#X's and finally, #P's=#X's)
>
> ques :- Given n elements, find the number of permutations which are
> possible and which are not possible??
>
> --
> 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/-/8ZitrJFT4zUJ.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] test cases

2012-10-21 Thread Saurabh Kumar
Sorry, I couldn't find any test-case which could fail. I don't think there
is any logical error in that code. It works just fine.

You might be exceeding the time limit though.
Your approach is O(N^2) for N = 5 and 10 test-cases. it will be
nearly 10*5*5 calculations.

On 19 October 2012 15:33, w.s miller  wrote:

> @sourabh i applied the scenario as mentioned by u.but the problem is that
> it is still giving wrong answer for some test case.rest test cases are
> working fine.so can u help me out a bit here.
>
>
> On Thu, Oct 18, 2012 at 6:38 PM, Saurabh Kumar wrote:
>
>> Actually *fflush(stdin)* is the problem here, your reading of inputs is
>> all messed up, at least on my machine( and probably on the machine you are
>> submitting the code too).
>> Maybe it's working fine on your particular environment but generally
>> fflush() is only defined on output streams. (see this discussion -
>> http://stackoverflow.com/questions/2979209/using-fflushstdin )
>>
>> I recommend putting one more scanf("%c", &c).
>> Your logic looks fine. For better runtime you might wanna use a
>> data-structure though.
>>
>> On 18 October 2012 18:09, w.s miller wrote:
>>
>>> This code is failing only for a particular test case .can you plz
>>> suggest any such test case.
>>>
>>>
>>> On Thu, Oct 18, 2012 at 6:08 PM, w.s miller <
>>> wentworth.miller6...@gmail.com> wrote:
>>>
>>>> @Saurabh  kumar But i have used fflush(stdin),which flushes the
>>>> standard input fille. So there is nothing in stdin when i go to read the
>>>> character.so i dont think this is the problem.
>>>>
>>>>
>>>> On Wed, Oct 17, 2012 at 5:36 PM, Saurabh Kumar wrote:
>>>>
>>>>> The problem is with:
>>>>>
>>>>> scanf("%c",&c);
>>>>> scanf("%d%d",&k,&l);
>>>>>
>>>>> the first scanf goes on to read the '\n' character after you enter
>>>>> variable 't'.
>>>>> Try doing:
>>>>> scanf("%c",&c); // Read the '\n' or SPACE character between
>>>>> 't' and the next Q/U.
>>>>> scanf("%c",&c); // Read the 'Q' or 'U'
>>>>> scanf("%d%d",&k,&l);
>>>>>
>>>>> On 17 October 2012 17:09, w.s miller 
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> You are given N numbers. You have to perform two kinds of operations:
>>>>>> U x y - x-th number becomes equal to y.
>>>>>> Q x y - calculate the sum of distinct numbers from x-th to y-th. It
>>>>>> means that the sum for the set {1, 2, 3, 2, 7} will be equal to 13
>>>>>> (1+2+3+7).
>>>>>> Input
>>>>>>
>>>>>> The first line of input contains an integer N. 1<=N<=5
>>>>>> The second line consists of N numbers.
>>>>>> The third line consists of an integer Q. 1<=Q<=10
>>>>>> The following Q lines will consist of queries of the form described
>>>>>> in the task description.
>>>>>> All numbers in input will fit in the signed 32-bit type.
>>>>>> Output
>>>>>>
>>>>>> Output an answer for every query of the second type.
>>>>>> Here is my code .But it is giving the wrong answer.Can anybody
>>>>>> suggest me the test cases where it is giving Wrong Answer..
>>>>>>
>>>>>> #include
>>>>>> #include
>>>>>> int main()
>>>>>> {
>>>>>> int list[5],i,n,j,sum,k,l;char c;long t;
>>>>>> scanf("%d",&n);
>>>>>> for(i=0;i>>>>> {
>>>>>> scanf("%d",&list[i]);
>>>>>> }
>>>>>> scanf("%ld",&t);
>>>>>> while(t)
>>>>>> {
>>>>>> sum=0;
>>>>>> fflush(stdin);
>>>>>> scanf("%c",&c);
>>>>>> scanf("%d%d",&k,&l);
>>>>>>
>>>>>> if(c=='Q' && (k<=l))
>>>>>> {

Re: [algogeeks] Re: c code help!!!!

2012-10-21 Thread Saurabh Kumar
Sorry, I don't understand your question. *%.2x *is only a precision
specifier still.
(%.2x was used for neat formatting only, because you are printing the
values only 1 Byte long and a Byte can occupy at max 2digits in hex)

hex representated by 4 bits.
Yes hex is represented by 4 bits i.e. 1 Byte and that's what you are
reading with a char pointer*,  1 Byte each time and printing the values in
those Bytes.

total we have to represent 32 bits and 8 bits in eachplz xplain
Each output represents 32bits only. 1 Byte each (in total 4Bytes)

It's showing you the memory layout. You stored *i = 1; *and when probed it
using a char pointer. you found following four bytes written:  *01 00 00 00*
It shows that on your machine:
1. int is 4bytes long. (4x1Byte)
2. First byte stores the least significant value, hence you are working on
a Little endian machine.

similarly, for pointer:
char pointer reads 1 Byte at a time. It read 4Bytes in total i.e. 32 bits.
Hence, you are working on a 32 bit machine. (as pointer has value: *44 ff
28 00, *address of i)*.*
*
*
*
*
PS: This is an algorithm group, please refrain from asking such language
specific questions.

On 21 October 2012 00:19, rahul sharma  wrote:

> Actually i have taken form   http://www.geeksforgeeks.org/archives/730
> Please explain me o/p...as hex representated by 4 bitsthen how cum is
> following o/p
>  00 00 80 3f
>  01 00 00 00
>  44 ff 28 00
>  01 00 00 00
>
> total we have to represent 32 bits and 8 bits in eachplz xplain
>
> On Sun, Oct 21, 2012 at 12:05 AM, rahul sharma wrote:
>
>> void show_bytes(byte_pointer start, int len)
>> {
>>  int i;
>>  for (i = 0; i < len; i++)
>>printf(" %.2x", start[i]);
>>  printf("\n");
>> }
>>
>>
>>
>> byte_pointr is unsigned char *...typedef unsigned char * byte_pointer
>> plz tell me use of %.2x  i knowx is for hexadoes it mean print 8
>> bites of address in 4 hexa of 2 bits???i cant get xactly plz explain
>>
>
>  --
> 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: c code help!!!!

2012-10-21 Thread Saurabh Kumar
Sorry, about that.
Read it as:
Yes a hex digit is represented by 4 bits but 1 Byte is being read using a
char pointer* and you're printing the values in those Bytes.

On 21 October 2012 01:03, Saurabh Kumar  wrote:

> Sorry, I don't understand your question. *%.2x *is only a precision
> specifier still.
> (%.2x was used for neat formatting only, because you are printing the
> values only 1 Byte long and a Byte can occupy at max 2digits in hex)
>
> >>>>hex representated by 4 bits.
> Yes hex is represented by 4 bits i.e. 1 Byte and that's what you are
> reading with a char pointer*,  1 Byte each time and printing the values in
> those Bytes.
>
> >>>>total we have to represent 32 bits and 8 bits in eachplz xplain
> Each output represents 32bits only. 1 Byte each (in total 4Bytes)
>
> It's showing you the memory layout. You stored *i = 1; *and when probed
> it using a char pointer. you found following four bytes written:  *01 00
> 00 00*
> It shows that on your machine:
> 1. int is 4bytes long. (4x1Byte)
> 2. First byte stores the least significant value, hence you are working on
> a Little endian machine.
>
> similarly, for pointer:
> char pointer reads 1 Byte at a time. It read 4Bytes in total i.e. 32 bits.
> Hence, you are working on a 32 bit machine. (as pointer has value: *44 ff
> 28 00, *address of i)*.*
> *
> *
> *
> *
> PS: This is an algorithm group, please refrain from asking such language
> specific questions.
>
> On 21 October 2012 00:19, rahul sharma  wrote:
>
>> Actually i have taken form   http://www.geeksforgeeks.org/archives/730
>> Please explain me o/p...as hex representated by 4 bitsthen how cum is
>> following o/p
>>  00 00 80 3f
>>  01 00 00 00
>>  44 ff 28 00
>>  01 00 00 00
>>
>> total we have to represent 32 bits and 8 bits in eachplz xplain
>>
>> On Sun, Oct 21, 2012 at 12:05 AM, rahul sharma 
>> wrote:
>>
>>> void show_bytes(byte_pointer start, int len)
>>> {
>>>  int i;
>>>  for (i = 0; i < len; i++)
>>>printf(" %.2x", start[i]);
>>>  printf("\n");
>>> }
>>>
>>>
>>>
>>> byte_pointr is unsigned char *...typedef unsigned char * byte_pointer
>>> plz tell me use of %.2x  i knowx is for hexadoes it mean print 8
>>> bites of address in 4 hexa of 2 bits???i cant get xactly plz explain
>>>
>>
>>  --
>> 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 code help!!!!

2012-10-20 Thread Saurabh Kumar
It only means - If address in hexadecimal is less than 2 digits, it will
add extra padding 0's. If it's more than 2 digits it will simply print the
address as is.
i.e. suppose If address is *E* it will print: *0E* (padding an extra zero)
that's all.

On 21 October 2012 00:05, rahul sharma  wrote:

> void show_bytes(byte_pointer start, int len)
> {
>  int i;
>  for (i = 0; i < len; i++)
>printf(" %.2x", start[i]);
>  printf("\n");
> }
>
>
>
> byte_pointr is unsigned char *...typedef unsigned char * byte_pointer
> plz tell me use of %.2x  i knowx is for hexadoes it mean print 8
> bites of address in 4 hexa of 2 bits???i cant get xactly plz explain
>
> --
> 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] test cases

2012-10-18 Thread Saurabh Kumar
Actually *fflush(stdin)* is the problem here, your reading of inputs is all
messed up, at least on my machine( and probably on the machine you are
submitting the code too).
Maybe it's working fine on your particular environment but generally
fflush() is only defined on output streams. (see this discussion -
http://stackoverflow.com/questions/2979209/using-fflushstdin )

I recommend putting one more scanf("%c", &c).
Your logic looks fine. For better runtime you might wanna use a
data-structure though.

On 18 October 2012 18:09, w.s miller  wrote:

> This code is failing only for a particular test case .can you plz suggest
> any such test case.
>
>
> On Thu, Oct 18, 2012 at 6:08 PM, w.s miller <
> wentworth.miller6...@gmail.com> wrote:
>
>> @Saurabh  kumar But i have used fflush(stdin),which flushes the standard
>> input fille. So there is nothing in stdin when i go to read the
>> character.so i dont think this is the problem.
>>
>>
>> On Wed, Oct 17, 2012 at 5:36 PM, Saurabh Kumar wrote:
>>
>>> The problem is with:
>>>
>>> scanf("%c",&c);
>>> scanf("%d%d",&k,&l);
>>>
>>> the first scanf goes on to read the '\n' character after you enter
>>> variable 't'.
>>> Try doing:
>>> scanf("%c",&c); // Read the '\n' or SPACE character between 't'
>>> and the next Q/U.
>>> scanf("%c",&c); // Read the 'Q' or 'U'
>>> scanf("%d%d",&k,&l);
>>>
>>> On 17 October 2012 17:09, w.s miller wrote:
>>>
>>>> Hi,
>>>>
>>>> You are given N numbers. You have to perform two kinds of operations:
>>>> U x y - x-th number becomes equal to y.
>>>> Q x y - calculate the sum of distinct numbers from x-th to y-th. It
>>>> means that the sum for the set {1, 2, 3, 2, 7} will be equal to 13
>>>> (1+2+3+7).
>>>> Input
>>>>
>>>> The first line of input contains an integer N. 1<=N<=5
>>>> The second line consists of N numbers.
>>>> The third line consists of an integer Q. 1<=Q<=10
>>>> The following Q lines will consist of queries of the form described in
>>>> the task description.
>>>> All numbers in input will fit in the signed 32-bit type.
>>>> Output
>>>>
>>>> Output an answer for every query of the second type.
>>>> Here is my code .But it is giving the wrong answer.Can anybody suggest
>>>> me the test cases where it is giving Wrong Answer..
>>>>
>>>> #include
>>>> #include
>>>> int main()
>>>> {
>>>> int list[5],i,n,j,sum,k,l;char c;long t;
>>>> scanf("%d",&n);
>>>> for(i=0;i>>> {
>>>> scanf("%d",&list[i]);
>>>> }
>>>> scanf("%ld",&t);
>>>> while(t)
>>>> {
>>>> sum=0;
>>>> fflush(stdin);
>>>> scanf("%c",&c);
>>>> scanf("%d%d",&k,&l);
>>>>
>>>> if(c=='Q' && (k<=l))
>>>> {
>>>> for(i=k-1;i>>> {
>>>> for(j=i+1;j>>> {
>>>>if(list[i]==list[j])
>>>>   break;
>>>>else if((j==l-1) &&(list[i]!=list[j]))
>>>>{
>>>>   sum=sum+list[i];
>>>>}
>>>> }
>>>>  }
>>>>  printf("%d\n",sum+list[l-1]);
>>>>  }
>>>>  if(c=='U')
>>>>  {
>>>>  list[k-1]=l;
>>>>  }
>>>>  t--;
>>>> }
>>>> return 0;
>>>> }
>>>>
>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>  --
>>> 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] Virtual functions in constructor

2012-10-09 Thread Saurabh Kumar
In short: Call for virtual function in constructor is redirected to the
local function because, the derived part of the object has not being
initialized yet(remember you are still in Bases' constructor) and it makes
no sense to call a derived's implementation of a virtual function, which in
turn be using some (still uninitialized) non-static data members of derived
class.

You can read it in detail over here:
http://www.parashift.com/c%2B%2B-faq-lite/calling-virtuals-from-ctors.html

Also i recommend - *Inside the C++ Object Model* By Stanley B. Lippman.

Cheers,

On 10 October 2012 02:16, rahul sharma  wrote:

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

-- 
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] this pointer help c++

2012-10-09 Thread Saurabh Kumar
 So how will he be able to get
>>> it? Until I tell him my house structure, which in programming language like
>>> C++ is reference.
>>>
>>>I am saying sir, I have created a house (object) and here is
>>> the layout (referring to what I have created) so inorder to tell him about
>>> my layout I have to generate the return value which is NOT the house
>>> (object) but the reference to the house ( "pointer" pointing to what I have
>>> created ).
>>>
>>>  Now I am almost done here.. So Why  " ** this *" and not "*this
>>> *" is coz  "*this"*  gives the object directly to the the party who is
>>> calling me and the reference means a copy not the object itself whereas "
>>> ** this *"  is presenting you what you were looking for.
>>>
>>>   I hope now people are clear about all the above aspects.. I mean
>>> the very last question about returns full object or wat?? if you get all
>>> this.. U got all this.. :)
>>>
>>> Ciao,
>>> Prem
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Oct 10, 2012 at 12:23 AM, rahul sharma 
>>> wrote:
>>>
>>>> @saurabhif i look from the way that i need to return a
>>>> referencei.e. i mean object...i will ryt *this for this..i knew
>>>> thisbut i have read that reference is a const pointer so if
>>>> i look from this prespective then do i need to return
>>>> pointer(this)..
>>>> int * fun()//return pointer to int
>>>>
>>>> then what does return by reference mean if i return ( *this)..then what
>>>> actually returns...full object???or pointer to object...mix
>>>> questions ...plz clear me..
>>>>
>>>>
>>>> On Tue, Oct 9, 2012 at 11:26 PM, Saurabh Kumar wrote:
>>>>
>>>>> >> as we know reference is a const pointer
>>>>> That is Not quite true.
>>>>>
>>>>> >> our aim is ony to return pointer to circle
>>>>> No. our aim is to return a reference to circle.
>>>>>
>>>>> When you've to define a reference you do something like: *Circle &ref
>>>>> = c;*
>>>>> you *don't* do: *Circle &ref = &c;* Right ?
>>>>>
>>>>> Same is the case here, at the receiving end where the call was
>>>>> initiated a reference is waiting there to be initialized, so you pass the
>>>>> Object (*this) itself and NOT the pointer (this).
>>>>> [Also remember if you've a complex object, no copy constructors etc.
>>>>> are called when an object is sent for *reference receiving,* so no
>>>>> need of worries there.]
>>>>>
>>>>> References are not quite exactly same as pointers, they were
>>>>> introduced much later as a wrapper to pointers but there are some subtle
>>>>> differences between them when it comes to writing code, behaviorally, yes
>>>>> they are more or less the same.
>>>>>
>>>>> On 9 October 2012 22:54, SAMM  wrote:
>>>>>
>>>>>> This used for the following situation when   a=b=c=d  (Consider then
>>>>>> as the  objects of a particular class say X ).
>>>>>>
>>>>>>
>>>>>>  --
>>>>>> 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.
>

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

<<322.png>>

Re: [algogeeks] this pointer help c++

2012-10-09 Thread Saurabh Kumar
>> as we know reference is a const pointer
That is Not quite true.

>> our aim is ony to return pointer to circle
No. our aim is to return a reference to circle.

When you've to define a reference you do something like: *Circle &ref = c;*
you *don't* do: *Circle &ref = &c;* Right ?

Same is the case here, at the receiving end where the call was initiated a
reference is waiting there to be initialized, so you pass the Object
(*this) itself and NOT the pointer (this).
[Also remember if you've a complex object, no copy constructors etc. are
called when an object is sent for *reference receiving,* so no need of
worries there.]

References are not quite exactly same as pointers, they were introduced
much later as a wrapper to pointers but there are some subtle differences
between them when it comes to writing code, behaviorally, yes they are more
or less the same.

On 9 October 2012 22:54, SAMM  wrote:

> This used for the following situation when   a=b=c=d  (Consider then as
> the  objects of a particular class say X ).
>
>
>  --
> 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] Min Edges to be added to DAG to make it Strongly connected?

2012-10-09 Thread Saurabh Kumar
We are attempting for DAGs only.
Your graph is not acyclic.  :)

On 9 October 2012 21:57, Jaspreet Singh  wrote:

> What if this :-
> a-»b
> ^--' c
>
> here max of both is 1 but ans is 2.
> On Oct 8, 2012 11:38 PM, "Saurabh Kumar"  wrote:
>
>> You'd need:  max(#vertices-with-0in-degree, #vertices-with-0out-degree)
>> edges at least.
>>
>> On 8 October 2012 20:20, bharat b  wrote:
>>
>>> @jaspreet: take an ex:
>>>  B->A
>>> B->C
>>> B->D
>>> Here the no.of zero-indegree is one . But its not the correct ans.
>>>
>>>
>>> On Mon, Oct 8, 2012 at 1:19 AM, Jaspreet Singh <
>>> jassajjassaj...@gmail.com> wrote:
>>>
>>>> count the no. of nodes having 0 in-degree.
>>>>
>>>>
>>>> On Mon, Oct 8, 2012 at 12:44 AM, atul anand wrote:
>>>>
>>>>> yeah i read it wrongly .. i thought ques was asking to find total
>>>>> strongly connected component in the graph
>>>>>
>>>>> On 10/7/12, bharat b  wrote:
>>>>> > @atul : if there is no cut vertex, that doesn't mean that graph is
>>>>> strongly
>>>>> > connected ...
>>>>> >
>>>>> >
>>>>> > On Sat, Oct 6, 2012 at 7:37 PM, atul anand 
>>>>> wrote:
>>>>> >
>>>>> >> find no. of cut vertex in the DAGthat will be the ans.
>>>>> >> On 6 Oct 2012 19:33, "KK"  wrote:
>>>>> >>
>>>>> >>> Given a DAG(Directed Acyclic Graph). How to find out the minimum
>>>>> number
>>>>> >>> of edges that needs to be added so that the given graph becomes
>>>>> Strongly
>>>>> >>> Connected?
>>>>> >>>
>>>>> >>> --
>>>>> >>> 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/-/PbR3j9S5OXUJ.
>>>>> >>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> >>> To unsubscribe from 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.
>>>>

Re: [algogeeks] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread Saurabh Kumar
You'd need:  max(#vertices-with-0in-degree, #vertices-with-0out-degree)
edges at least.

On 8 October 2012 20:20, bharat b  wrote:

> @jaspreet: take an ex:
>  B->A
> B->C
> B->D
> Here the no.of zero-indegree is one . But its not the correct ans.
>
>
> On Mon, Oct 8, 2012 at 1:19 AM, Jaspreet Singh 
> wrote:
>
>> count the no. of nodes having 0 in-degree.
>>
>>
>> On Mon, Oct 8, 2012 at 12:44 AM, atul anand wrote:
>>
>>> yeah i read it wrongly .. i thought ques was asking to find total
>>> strongly connected component in the graph
>>>
>>> On 10/7/12, bharat b  wrote:
>>> > @atul : if there is no cut vertex, that doesn't mean that graph is
>>> strongly
>>> > connected ...
>>> >
>>> >
>>> > On Sat, Oct 6, 2012 at 7:37 PM, atul anand 
>>> wrote:
>>> >
>>> >> find no. of cut vertex in the DAGthat will be the ans.
>>> >> On 6 Oct 2012 19:33, "KK"  wrote:
>>> >>
>>> >>> Given a DAG(Directed Acyclic Graph). How to find out the minimum
>>> number
>>> >>> of edges that needs to be added so that the given graph becomes
>>> Strongly
>>> >>> Connected?
>>> >>>
>>> >>> --
>>> >>> 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/-/PbR3j9S5OXUJ.
>>> >>> To post to this group, send email to algogeeks@googlegroups.com.
>>> >>> To unsubscribe from 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.
>>
>
>  --
> 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] Nested Function C

2012-10-03 Thread Saurabh Kumar
It's compiler dependent. gcc comes from GNU project.
ANSI C doesn't allow nested function definitions.

On 3 October 2012 01:06, rahul sharma  wrote:

> Guys i have read that we cant define function in another function in c
> Then why this followung program running fine on gcc
>
> #include
> void abc()
> {
>  printf("bac");
>  void abf()
>  {
>  printf("bas");
>  getchar();
>  }
> }
> int main()
> {
> abc();
> 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.
>

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

2012-10-01 Thread saurabh agrawal
Do we need to handle cases when the same string will appear again??
In that case we can sort individual array and remove duplicates.

On Mon, Oct 1, 2012 at 9:54 AM, Rahul Singh  wrote:

> check this out..
>
> #include
> #include
> using namespace std;
>
> void print_sets(string *s,int pos,int n,char *to_print)
> {
> if(pos==n)
> {
> return;
> }
>
> for(int i=0;i {
> to_print[pos] =  s[pos][i];
> print_sets(s,pos+1,n,to_print);
> if(pos==n-1)
> {
> for(int j=0;j cout< }
> }
> return;
> }
> int main()
> {
> int n;
> cin>>n;
> string s[n];
>
> for(int i=0;i {
> cin>>s[i];
>  }
>  char *to_print = new char[n];
> print_sets(s,0,n,to_print);
> }
>
>  --
> 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: Make My Trip *URGENT*

2012-09-22 Thread saurabh arora
can anyone tell makemytrip for quality assurance look for coding 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.



Re: [algogeeks] Re: Snapdeal placement proceedure

2012-09-07 Thread saurabh arora
hiee. wat about the analyst profile procedure..plz 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.



Re: [algogeeks] LOGIC!!!

2012-08-30 Thread Saurabh Kumar
I think, if the Graph is 2-colorable (i.e. Bipartite) trip can be arranged.

On 30 August 2012 09:43, ashish mann  wrote:

> Q. A company organizes two foreign trips for its employees yearly. Aim of
> the trip is to increase interaction among the employees of the company and
> hence company wants each of his employee to see new people on the trip and
> not even a single person with whom he has worked in past. Therefore it is a
> rule in company that in any of the trips, all the employees should be new
> to each other and no two of them should have worked together in past.
>
>
> Given the work history of each employee (which people he has worked with
> sometimes in past), you have to tell whether all of the employees can be
> accommodated within trips without violating the above rule or not. Each
> employee is given a unique integer ID by which they are recognized. You can
> also assume that each employee has worked with at least one other employee
> in past.
>
>
>
> *Note: *No employee can be in both trips and every employee must be part
> of one trip.
>
>
> *Example: *
>
> i) Suppose the work history is given as follows: {(1,2),(2,3),(3,4)}; then
> it is possible to accommodate all the four employees in two trips (one trip
> consisting of employees 1& 3 and other having employees 2 & 4). Neither of
> the two employees in the same trip have worked together in past.
>
> ii) Suppose the work history is given as {(1,2),(1,3),(2,3)} then there is
> no way possible to have two trips satisfying the company rule and
> accommodating all the employees.
>
> --
> 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]

2012-08-09 Thread saurabh singh
Banning anyone henceforth who posts anything unrelated to algorithm. Any
users posting "me too" type posts will be banned
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Thu, Aug 9, 2012 at 9:59 PM, sahil gupta  wrote:

> Please wait for someone to reply.
> Then ask personally for paper through his or her email id.
> Stop spaming the group.
>
> Sahil Gupta.
>
>
> On Thu, Aug 9, 2012 at 9:56 PM, *$*  wrote:
>
>> Mail to me also plz
>> On Aug 9, 2012 9:55 PM, "rahul sharma"  wrote:
>>
>>> Mail to me alsothnx
>>>
>>> On Thu, Aug 9, 2012 at 2:28 PM, Piyush Khandelwal <
>>> piyushkhandelwal...@gmail.com> wrote:
>>>
>>>>
>>>>
>>>> Hi !
>>>> Google is visiting our campus tomorrow. Anyone having latest written
>>>> test paper of google, please mail it...
>>>> Thanx in advance!!!
>>>>
>>>>
>>>> *Piyush Khandelwal** | Placement Coordinator**,
>>>> Delhi Technological University
>>>> ( Delhi College of Engineering )*
>>>> Mobile: 91-8447229204
>>>> www.dce.edu
>>>>   Get a signature like this.
>>>> <http://r1.wisestamp.com/r/landing?promo=17&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_17>
>>>>  CLICK
>>>> HERE.<http://r1.wisestamp.com/r/landing?promo=17&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_17>
>>>>
>>>>
>>>> --
>>>> 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.



Re: [algogeeks] directi paper pattern

2012-08-02 Thread saurabh singh
Please stop this idiocity of " *me too,me too "*
You can send personal mails to the author,why spam the group?

No More Posts on this thread.

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.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] pls guy im need of a ebook named "Data Structures and algorithms made easy" details given below....

2012-07-20 Thread saurabh singh
Above users banned for violating group policy. NO MORE  POSTS ON THIS
THREAD.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Jul 20, 2012 at 11:39 PM, suresh kumar mahawar <
suresh.mahawar1...@gmail.com> wrote:

>
>
> On Fri, Jul 20, 2012 at 11:02 PM, sarath prasath 
> wrote:
>
>> Book: Data Structures And Algorithms Made Easy: Data Structure And
>> Algorithmic Puzzles
>> Author: Narasimha Karumanchi
>>  ISBN: 0615459811
>> ISBN-13: 9780615459813, 978-0615459813
>> Binding: Paperback
>> Publishing Date: 2011
>> Publisher: CareerMonk Publications
>> Edition: 2ndEdition
>> Number of Pages: 484
>> Language: English
>>
>>
>> pls guys if anyone having this book's pdf or something pls do share to my
>> email.
>>
>> my email id is prasathsar...@gmail.com , suresh.mahawar1...@gmail.com
>>  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/-/HOSKfo0wvRAJ.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Suresh Kumar Mahawar,
> CSE,ISM Dhanbad
>
>  --
> 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 the repeated element

2012-07-19 Thread Saurabh Yadav
@deepikaanand

(checksum  & 1<< 100) will it work ?

as i know int has only 32 bits !!



Thanks & Regards
Saurabh Yadav

-- 
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] Anagram problem

2012-07-18 Thread saurabh singh
^sorting a string would be o(n^2logn) if u use q.sort.count sort would be
better.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Wed, Jul 18, 2012 at 1:08 PM, vindhya chhabra
wrote:

> sort the list,sort the word(use quick sort(nlogn  time))- and den search
> using binary search(logn time)
> or we can evn do by hashing-hash the word,den for every word keep
> decreasing the counter,if the hash array is zero ,anagram,else reset the
> hash array for given input for the checking the next word.
>
>
> On Wed, Jul 18, 2012 at 2:07 AM, Navin Kumar wrote:
>
>> Assuming a preexisting list of 100 words, how would you efficiently see
>> if a word received from input is an anagram of any of the 100 words?
>>
>> --
>> 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/-/5kuxjymYEc4J.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Vindhya Chhabra
>
>
>
>
>  --
> 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 Coding Problem

2012-07-14 Thread saurabh singh
its from a running contest i believe.This is against the group policy as
well as against the ethics of programmers. The author of this post is
banned permanently from algogeeks. Kindly no more posts on this thread till
16th July (the date mentioned as end of contest in the given link).
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Sat, Jul 14, 2012 at 2:36 PM, Gobind Kumar Hembram
wrote:

>
> Please visit this 
> link<http://www.techgig.com/codehire/ZSAssociates/problem/35>.And
> help me in  solving this.
> --
> Thanks & Regards
> Gobind Kumar Hembram
> Contact no.-+91867450
>
>
>  --
> 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: [Google] Finds all the elements that appear more than n/3 times

2012-06-30 Thread saurabh singh
@above

>
> On Thursday, 28 June 2012 04:05:12 UTC+5:30, Navin Kumar wrote:
>>
>>
>> Design an algorithm that, given a list of n elements in an array, finds
>> all the elements that appear more than n/3 times in the list. The algorithm
>> should run in linear time
>>
>> ( n >=0 ).
>>
>> You are expected to use comparisons and achieve linear time. No 
>> hashing/excessive
>> space/ and don't use standard linear time deterministic selection algo.
>>
>>
> On Thursday, 28 June 2012 04:05:12 UTC+5:30, Navin Kumar wrote:
>>
>>
>> Design an algorithm that, given a list of n elements in an array, finds
>> all the elements that appear more than n/3 times in the list. The algorithm
>> should run in linear time
>>
>> ( n >=0 ).
>>
>> You are expected to use comparisons and achieve linear time. No
>> hashing/excessive space/ and don't use standard linear time deterministic
>> selection algo.
>>
>>
> On Thursday, 28 June 2012 04:05:12 UTC+5:30, Navin Kumar wrote:
>>
>>
>> Design an algorithm that, given a list of n elements in an array, finds
>> all the elements that appear more than n/3 times in the list. The algorithm
>> should run in linear time
>>
>> ( n >=0 ).
>>
>> You are expected to use comparisons and achieve linear time. No
>> hashing/excessive space/ and don't use standard linear time deterministic
>> selection algo.
>>
>>  --
> 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/-/0myz4OIStO8J.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Switch doubt in C

2012-06-29 Thread saurabh singh
the cases are simple lables they have nothing to do with the flow of
program.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar  wrote:

> Doubt, very trivial though:
> #include
> int main()
> {
> int x=3;
> switch(x)
> {
>  case 1:
> x=1;
> break;
>  case 2:
> x=2;
> break;
>  case 3:
> x=3;
> break;
>  default:
>  x=0;
>  break;
>  case 4:
> x=4;
> break;
> }
> printf("%d",x)
> return 0;
> }
> gives an output of 3. But,
> #include
> using namespace std;
> int main()
> {
> int x=3;
> switch(x)
> {
>  case 1:
> x=1;
>  case 2:
> x=2;
>  case 3:
> x=3;
>  default:
>  x=0;
>  case 4:
> x=4;
> }
>printf("%d",x);
> getch();
> return 0;
> }
> gives an output of 4.
> My doubt is, in spite of the missing break statements in the second case,
> how will it enter case 4, as it should check if x=4 before doing that,
> which is not true.
>
>  --
> 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] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread saurabh singh
duplicate of a previous post.Kindly refer to that post.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Jun 29, 2012 at 10:41 AM, raghavan M
wrote:

> Hi
> Question as in subject
>
> *No extra space (can use one extra space)-O(1) max
> *No order change allowed
> example:
>
> input : 1,-5,2,10,-100,-2
> output: -5,-10,-100,1,2
>
> input : -1,-5,10,11,15,-500,200,-10
> output : -1,-5,-10,-500,-10,10,11,15
>
>
> Thanks
> Raghavn
>
> --
> 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] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread saurabh singh
^ 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 wrote:

> whether it is in character array or integer array??
>
>
> On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel  wrote:
>
>>
>> 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.



Re: [algogeeks] Programming Question

2012-06-22 Thread saurabh singh
+1 to Trie

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Jun 22, 2012 at 3:50 PM, Karthikeyan V.B wrote:

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

2012-06-20 Thread saurabh singh
My bad...Sorry :(..Yes it certainly was not right

On Wed, Jun 20, 2012 at 8:56 PM, Navin Kumar wrote:

> @Saurabh:i was wrong in deciding space complexity. Yes, your algo will
> take O(1) time but you have to enqueue elements in reverse order.Not in the
> order you fetched. Think about it :). Then you have to take stack or some
> other data structure.
>
>
> On Wed, Jun 20, 2012 at 8:40 PM, saurabh singh wrote:
>
>> How ??
>> I am asking to manipulate the same queue.
>> Dequeue n-1 elements and enqueue them in order to you take out to the
>> same queue..Where is extra space involved ?
>>
>>
>> On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar wrote:
>>
>>> @saurabh : i want solution with space complexity of O(1) . your solution
>>> is right but it takes O(n) space.
>>>
>>>
>>> On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh 
>>> wrote:
>>>
>>>> Why will my proposed solution not work for you ???
>>>>
>>>>
>>>> On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar 
>>>> wrote:
>>>>
>>>>> @Kirubakaran : still space complexity is O(n) due to stack.Can it be
>>>>> solved in space complexity O(1).
>>>>>
>>>>>
>>>>> On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D <
>>>>> kirubakara...@gmail.com> wrote:
>>>>>
>>>>>> You could use recursion.
>>>>>>
>>>>>> def reverse_Q q
>>>>>> if !q.isEmpty?
>>>>>>   el = q.dequeue
>>>>>>   nQ = reverse_Q(q)
>>>>>>   nQ.enqueue el
>>>>>>   return nQ
>>>>>> end
>>>>>> return q
>>>>>> end
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote:
>>>>>>>
>>>>>>> Use only standard operation of Queue like: EnQueue, DeQueue,
>>>>>>> IsEmptyQueue etc
>>>>>>>
>>>>>>> On Wed, Jun 20, 2012 at 6:50 PM, amrit harry <
>>>>>>> dabbcomput...@gmail.com> wrote:
>>>>>>>
>>>>>>>> can we create other methods or we have to use only enqueue and
>>>>>>>> dequeue...? if yes then simply
>>>>>>>> for(i=0;i<=n/2;i++)
>>>>>>>> swap(i,n-i);
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar <
>>>>>>>> algorithm.i...@gmail.com> wrote:
>>>>>>>>
>>>>>>>>> @Saurabh: queue will be remain unchanged according to your
>>>>>>>>> algorithm. Because if you will delete an element from front and add 
>>>>>>>>> at rear
>>>>>>>>> no change will be there. After n iteration front will be pointing to 
>>>>>>>>> same
>>>>>>>>> element and rear will also point to same element.
>>>>>>>>>
>>>>>>>>> Correct me if i am wrong. :)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh <
>>>>>>>>> saurabh.n...@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> count the size of queue : O(n)
>>>>>>>>>> loop for n and do remove and add in queue : O(n)
>>>>>>>>>>
>>>>>>>>>> Total : O(n)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar <
>>>>>>>>>> algorithm.i...@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> How to reverse a Queue .
>>>>>>>>>>>
>>>>>>>>>>> Constraints: Time complexity O(n). space complexity: O(1)
>>>>>>>>>>>
>>>>>>>>>>>  --
>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>> Google Groups "Algorithm Geeks" group.
>>>>>>>>>>> To view this 

Re: [algogeeks] Reverse Queue

2012-06-20 Thread saurabh singh
How ??
I am asking to manipulate the same queue.
Dequeue n-1 elements and enqueue them in order to you take out to the same
queue..Where is extra space involved ?

On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar wrote:

> @saurabh : i want solution with space complexity of O(1) . your solution
> is right but it takes O(n) space.
>
>
> On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh wrote:
>
>> Why will my proposed solution not work for you ???
>>
>>
>> On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar wrote:
>>
>>> @Kirubakaran : still space complexity is O(n) due to stack.Can it be
>>> solved in space complexity O(1).
>>>
>>>
>>> On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D 
>>> wrote:
>>>
>>>> You could use recursion.
>>>>
>>>> def reverse_Q q
>>>> if !q.isEmpty?
>>>>   el = q.dequeue
>>>>   nQ = reverse_Q(q)
>>>>   nQ.enqueue el
>>>>   return nQ
>>>> end
>>>> return q
>>>> end
>>>>
>>>>
>>>>
>>>> On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote:
>>>>>
>>>>> Use only standard operation of Queue like: EnQueue, DeQueue,
>>>>> IsEmptyQueue etc
>>>>>
>>>>> On Wed, Jun 20, 2012 at 6:50 PM, amrit harry 
>>>>> wrote:
>>>>>
>>>>>> can we create other methods or we have to use only enqueue and
>>>>>> dequeue...? if yes then simply
>>>>>> for(i=0;i<=n/2;i++)
>>>>>> swap(i,n-i);
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar <
>>>>>> algorithm.i...@gmail.com> wrote:
>>>>>>
>>>>>>> @Saurabh: queue will be remain unchanged according to your
>>>>>>> algorithm. Because if you will delete an element from front and add at 
>>>>>>> rear
>>>>>>> no change will be there. After n iteration front will be pointing to 
>>>>>>> same
>>>>>>> element and rear will also point to same element.
>>>>>>>
>>>>>>> Correct me if i am wrong. :)
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh <
>>>>>>> saurabh.n...@gmail.com> wrote:
>>>>>>>
>>>>>>>> count the size of queue : O(n)
>>>>>>>> loop for n and do remove and add in queue : O(n)
>>>>>>>>
>>>>>>>> Total : O(n)
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar <
>>>>>>>> algorithm.i...@gmail.com> wrote:
>>>>>>>>
>>>>>>>>> How to reverse a Queue .
>>>>>>>>>
>>>>>>>>> Constraints: Time complexity O(n). space complexity: O(1)
>>>>>>>>>
>>>>>>>>>  --
>>>>>>>>> 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/-/kepls-8qRwgJ<https://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ>
>>>>>>>>> .
>>>>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>>> algogeeks+unsubscribe@**googlegroups.com
>>>>>>>>> .
>>>>>>>>> For more options, visit this group at http://groups.google.com/**
>>>>>>>>> group/algogeeks?hl=en<http://groups.google.com/group/algogeeks?hl=en>
>>>>>>>>> .
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Thanks & Regards,
>>>>>>>> Saurabh
>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>

  1   2   3   4   5   6   7   8   >