Re: [algogeeks] Re: sortin 2D array

2013-01-12 Thread Piyush Raman
Use a set ADT ( C++ STL). Traverse the entire 2d matrix and keep on adding
each element to the set. The set ADT stores, sorts and removes redundant
data values and you get sorted list after traversal. Now again traverse the
set ADT and store it in an array.

On Wed, Jan 9, 2013 at 4:53 PM, Karthikeyan V.B  wrote:

> Merge pairs of rows until u get a single row, while merging remove the
> duplicates
>
> --
>
>
>

-- 




Re: [algogeeks] Pointers Usage

2013-01-12 Thread Piyush Raman
For simple reasons according to me:
1- It reduces overhead drastically,thus more efficient execution time is
achieved. Consider a recursive function call having array parameters ->
func (int a[100][100], int b[100][100]).. Now instead if we use pointers->
func(int **a, int **b), the overhead on the stack of the language decreases
drastically and thus further reducing the execution time of the code!!

2- It allows dynamic memory storage. If you do not know the amount of
memory needed, then using dynamic allocaton using pointer is the best way.
Consider we have an array -> arr[1000], but we actually need to use only
10,5, or even 2 sized array! This will lead to huge memory wastage..
instead we can do size_type *arr= new size_type[size]. thus this leads to
more space efficient code and avoid chances of memory overflow.

3- Access to an entity via pointer is faster!! :P
Hope this helps!

On Thu, Jan 3, 2013 at 7:49 PM, Debabrata Das <
debabrata.barunhal...@gmail.com> wrote:

> @ arun... 8 byte may be for 64 bit application or far pointer ...
>
> On Thu, Jan 3, 2013 at 6:29 PM, Arun Vishwanathan
>  wrote:
> > @atul/shady: why is it that pointer takes 8 bytes ? So the takes a memory
> > location whose value is the address of the element it points to. Why does
> > the pointer value have to take 8 bytes? I am sorry if I am missing
> something
> > silly here.
>
> --
>
>
>

-- 




Re: [algogeeks] Re: Amazon Dynamic Programming problem

2013-01-12 Thread kumar anurag
yes the below logic is correct
1-> 1st(1)
2-> 1st(2)
3-> 2nd(1,2 or 2,1)
4-> 1st (1,2,1 or 1,1,2)
5->1st(2, 1, 2 or 2, 2, 1)
6-> 2nd(2, 1, 3) or 1, 2,3)) 2nd will win
7-> 1st(1, 1, 2, 3 or 1, 2, 1,3  or .,.
8-> 1st (2, 1, 2, 3 or 2, 2,1, 3 or ..

In above 3 can be (1,2) or (2,1)

Thanks
Kumar Anurag

On Sat, Jan 12, 2013 at 10:11 PM, Lucifer  wrote:

>
> @siva..
>
> if (n%3 == 0)
>   "Player 1 will lose"
> else
>   "Player 1 will win. The no. of balls picked in the first turn will
> be n%3"
>
> --
>
>
>



-- 
Kumar Anurag

-- 




[algogeeks] Re: Amazon Dynamic Programming problem

2013-01-12 Thread Lucifer

@siva..

if (n%3 == 0) 
  "Player 1 will lose"
else
  "Player 1 will win. The no. of balls picked in the first turn will be 
n%3" 

-- 




[algogeeks] Re: Amazon Dynamic Programming problem

2013-01-12 Thread Lucifer
@siva..

if (n%3 == 0) 
  "Player 1 will lose"
else
  "Player 1 will win. The no. of balls picked in the first turn will be 
n%3" 


On Saturday, 12 January 2013 18:33:45 UTC+5:30, siva wrote:
>
> consider there are N balls in a basket. 2 players play the turns 
> alternatively ..AT each turn,the player 
>
> can take 1 or 2 balls from the basket. the first player starts the game.. 
> Both the players play optimally. 
>
>i)   Given N,tell whether the 1st player win or loss ?
>
>ii) If player 1 wins, how many balls he should take at this first 
> turn(1 or 2) ?
>

-- 




Re: [algogeeks] Amazon Dynamic Programming problem

2013-01-12 Thread siva
The player who plays the last turn and finishes the game wins ... 

I think the approach would be similar to this .. 
http://www.spoj.com/problems/TWENDS/

.. @vamshi .. Can't get your question? .. what you refer to hit or fail 
case in picking up a ball?..

 At the end any of the 2 players can win 

On Saturday, 12 January 2013 19:12:19 UTC+5:30, raunak wrote:
>
>
> how is winning going to decided 
>
> On Sat, Jan 12, 2013 at 6:33 PM, siva  >wrote:
>
>> consider there are N balls in a basket. 2 players play the turns 
>> alternatively ..AT each turn,the player 
>>
>> can take 1 or 2 balls from the basket. the first player starts the game.. 
>> Both the players play optimally. 
>>
>>i)   Given N,tell whether the 1st player win or loss ?
>>
>>ii) If player 1 wins, how many balls he should take at this first 
>> turn(1 or 2) ?
>>
>> -- 
>>  
>>  
>>
>
>

-- 




Re: [algogeeks] Amazon Dynamic Programming problem

2013-01-12 Thread vamshi palakurti
Are we supposed to assume that every ball played is a hit? Or should we
consider a hit or a fail case??


On Sat, Jan 12, 2013 at 7:12 PM, Raunak Gupta wrote:

>
> how is winning going to decided
>
> On Sat, Jan 12, 2013 at 6:33 PM, siva  wrote:
>
>> consider there are N balls in a basket. 2 players play the turns
>> alternatively ..AT each turn,the player
>>
>> can take 1 or 2 balls from the basket. the first player starts the game..
>> Both the players play optimally.
>>
>>i)   Given N,tell whether the 1st player win or loss ?
>>
>>ii) If player 1 wins, how many balls he should take at this first
>> turn(1 or 2) ?
>>
>> --
>>
>>
>>
>
>  --
>
>
>

-- 




Re: [algogeeks] Amazon Dynamic Programming problem

2013-01-12 Thread Raunak Gupta
how is winning going to decided

On Sat, Jan 12, 2013 at 6:33 PM, siva  wrote:

> consider there are N balls in a basket. 2 players play the turns
> alternatively ..AT each turn,the player
>
> can take 1 or 2 balls from the basket. the first player starts the game..
> Both the players play optimally.
>
>i)   Given N,tell whether the 1st player win or loss ?
>
>ii) If player 1 wins, how many balls he should take at this first
> turn(1 or 2) ?
>
> --
>
>
>

-- 




[algogeeks] Amazon Dynamic Programming problem

2013-01-12 Thread siva
consider there are N balls in a basket. 2 players play the turns 
alternatively ..AT each turn,the player 

can take 1 or 2 balls from the basket. the first player starts the game.. 
Both the players play optimally. 

   i)   Given N,tell whether the 1st player win or loss ?

   ii) If player 1 wins, how many balls he should take at this first turn(1 
or 2) ?

--