For the 2nd ques, wat i think is the interviewer has kept the restriction of
not moving the data since you may have a linked list about which you donot
have much information about the structure of the node of the list(only know
about the next pointer) and hence you cannot move the data. For that, y
ignore my last post :(
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, v
we can merge the 2 arrays in sorted manner. Now from the 2nd last number,we
can have the first pair (last,second last).From the 3rd last,we can have 2
pairs (last,3rd last) and (2nd last,3rd last). similarly we will keep on
taking till we get n pairs.
time complexity: O(2n+n)-> O(n)
space comp
we can do one thing. compare first element with all others. if it matches
with any of them, we have found our number, else leave the first number and
now the required number is available (n/2)+1 times in the rest of the array,
which can be found in O(n)
--
You received this message because you ar
@Amir: how you have found this relation
dp[i][j]=dp[i-1][j]+dp[i][j-1]
i am not able to understand it. Plz explain it.
thanx
On Tue, Jul 13, 2010 at 3:39 AM, Amir hossein Shahriari <
amir.hossein.shahri...@gmail.com> wrote:
> dp[i][j] is the number of strings that have i As and j Bs
>
>
> dp[
i dont think counting sort can be applied since its time cpmplexity is
O(n+k) where numbers are in the range 1...k and here k=O(n^2). so the
overall complexity will again go to O(n^2) :(
On Mon, Aug 2, 2010 at 10:22 AM, Apoorve Mohan wrote:
> Counting Sort.
>
>
> On Mon, Aug 2, 2010 at 6:15
int num_of_BST(int n)
{
int sum=0;
int left,right,root;
if(n<=1)
return 1;
else
{
for(root=1;root<=n;root++)
{
left=num_of_BST(root-1);
right=num_of_BST(n-root);
sum+=left*right;
}
}
return sum;
}
On Thu, Jul 29, 2010 at 9:56 PM, amit wrote:
> Given the numbers from 1 to n, write an algorithm to
@souravsain: In the method suggested by anand, he was first reversing the
second part of the array i.e. a[k+1]a[n] and then applying bitonic sort.
Both the parts are initially sorted in same direction.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Ge
@anand: this code will not work when n is not power of 2.
check for this example:
{2, 4, 55, 25, 15}
Output was:
0 4
0 2
1 3
0 1
2 3
2 4 25 55 15 0 0 0
ascending order
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group,
Given an array of n elements and an integer k where khttp://groups.google.com/group/algogeeks?hl=en.
10 matches
Mail list logo