Re: [algogeeks] Permutation of Array.

2010-08-20 Thread BALARUKESH SIVARAMAN
@Nikhil I am clear with your first 2 algos but not with the change u introduced ie., adding a check. please give a working example -- 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

Re: [algogeeks] Longest Palindromic Substring

2010-08-20 Thread Chonku
I definitely meant a suffix Tree and not a trie. Apologize for that. :) On Fri, Aug 20, 2010 at 8:47 PM, Nikhil Jindal wrote: > @chonku > As i understand, a trie is used when we have a lot of strings (such as a > dictionary). > Here we just have a single string. The resultant trie will be: > > a

Re: [algogeeks] Re: Array Problem

2010-08-20 Thread Chonku
Its easier to look at a property of numbers. It will be interesting to evaluate/prove if two different arrays have same value for sum of elements and sum of squares of the elements. On Fri, Aug 20, 2010 at 9:38 AM, Nikhil Agarwal wrote: > Check this new algo: plz provide counter eg.(if any) > > s

Re: [algogeeks] Re: Adobe Questions

2010-08-20 Thread Stanley Cai
this one is not very right... public void solution(String str) { int t = Integer.parseInt(str, 2); System.out.printf(Integer.toBinaryString((int)((1l<<32) - t))); } Still for this issue, it could be hard if the string is very long, length is more than 32 On Fri, Aug 20, 2010 at 6:46 PM, GOB

Re: [algogeeks] Permutation of Array.

2010-08-20 Thread Nikhil Agarwal
I have corrected my msb algo please have a look. On Fri, Aug 20, 2010 at 10:59 PM, Nikhil Agarwal wrote: > > > On Fri, Aug 20, 2010 at 10:06 PM, Nikhil Agarwal < > nikhil.bhoja...@gmail.com> wrote: > >> The solution for the above problem will be, >> >> 1.First convert all the smaller nos of by co

Re: [algogeeks] Re: Adobe Questions

2010-08-20 Thread Rahul Singhal
I think u r right lucky On Sat, Aug 21, 2010 at 11:45 AM, luckyzoner wrote: > With reference to the first question...I would say that both the > statements were given seperately. > The answer to the question is : Hello Hello...as i have tried it out. > The reason for the output as i think is tha

[algogeeks] Re: Adobe Questions

2010-08-20 Thread luckyzoner
SPIRAL Traversal a /\ b c /\ /\ d e f g Output : abcgfed -- 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

[algogeeks] Re: Adobe Questions

2010-08-20 Thread luckyzoner
With reference to the first question...I would say that both the statements were given seperately. The answer to the question is : Hello Hello...as i have tried it out. The reason for the output as i think is that the class functions are allocated the memory even if no object of the class has been

[algogeeks] Re: Adobe Questions

2010-08-20 Thread Debajyoti Sarma
what is actually spiral traversal ??? can any please give sample tree and spiral traversal . -- 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

Re: [algogeeks] Re: Array Problem

2010-08-20 Thread Nikhil Agarwal
Check this new algo: plz provide counter eg.(if any) step 1 : count the no. of elements,0s,1s,2s,3s in arr1 and arry2.if yes proceed to step 2 else print fail step2: if(sum of the elements and product of the non zero elements are same in both arrays ) print arrays are same else print fail. On F

Re: [algogeeks] Permutation of Array.

2010-08-20 Thread Nikhil Agarwal
On Fri, Aug 20, 2010 at 10:06 PM, Nikhil Agarwal wrote: > The solution for the above problem will be, > > 1.First convert all the smaller nos of by concatenating 9 at the end > suppose 23,333 -> (239,333) to the size of the maximum digit. > 2.Sort the numbers; > 3.remove the 9 from the nos where w

[algogeeks] kth smallest element in a heap < x

2010-08-20 Thread Ashim Kapoor
Dear All, I found this in the book by skeina. Problem: Given an array-based heap on n elements and a real number x, efficiently determine whether the kth smallest element in the heap is greater than or equal to x. Your algorithm should be O(k) in the worst-case, independent of the size of the hea

Re: [algogeeks] Permutation of Array.

2010-08-20 Thread Nikhil Agarwal
The solution for the above problem will be, 1.First convert all the smaller nos of by concatenating 9 at the end suppose 23,333 -> (239,333) to the size of the maximum digit. 2.Sort the numbers; 3.remove the 9 from the nos where we had concatenated. 4.concatenate the string eg1. 55 31 312 33 -> 5

Re: [algogeeks] linked list

2010-08-20 Thread Raj Jagvanshi
#include #include #include using namespace std; struct node { void *name; struct node *next; }; typedef struct node Node; void createList(Node **head ) { char *str= (char*)malloc(20*sizeof(char)); char *p; cout<<"Enter a String: " ; gets (str) ; p = str; if((strl

Re: [algogeeks] Longest Palindromic Substring

2010-08-20 Thread Nikhil Jindal
@chonku As i understand, a trie is used when we have a lot of strings (such as a dictionary). Here we just have a single string. The resultant trie will be: a \ b \ c \ l \ e \ v \ e \ l

[algogeeks] Re: Adobe Questions

2010-08-20 Thread sachin
The answer for first question would be a segmentation fault...since none of a or b has been allocated any memory. Had it been A *a=new A; then the call to a->print() would not result into a segmentation fault. I think the purpose of this question was to know about this pointer concept about dynami

[algogeeks] transitive closure algorithm for graph

2010-08-20 Thread Raghava
Hi all, In terms of runtime, what is the best known transitive closure algorithm for directed graphs? I am currently using Warshall's algorithm but its O(n^3). Although, due to the graph representation my implementation does slightly better (instead of checking all edges, it only checks all out g

[algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-20 Thread bittu
@ Rahul in Tejus Can u provide solution base conversion problem discussed above -- 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 al

[algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-20 Thread bittu
can u provide solution of base conversion problem discussed abpve -- 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+unsubs

Re: [algogeeks] Permutation of Array.

2010-08-20 Thread Sakshi Handa
@srinivas Following your method won't the answer be 31 312 33 55, which is not the smallest concatenated no. here? On Fri, Aug 20, 2010 at 3:05 AM, srinivas reddy wrote: > @Divya chandrasekhar your algorithm doesn't satisfy the condition like > {130,11} > we can give so many examples like this so

[algogeeks] Re: Adobe Questions

2010-08-20 Thread ramu
this is the code for question 2 sort array havin 0,1,2 in one pass. #include using namespace std; int main() { int arr[]={2,0,1,1,1,0,0,2,2,0,1,2,0,1,2},a,b,c; a=b=c=-1; for (int i=0;i<15;i++) { if (arr[i]==0) { if (b==-1 && c==-1) arr[++a]=0; else if (b==-1) { ar

[algogeeks] Re: How to find two missing numbers from an unsorted continuous natural numbers array [only use O(1) space and O(n) time]

2010-08-20 Thread rahul patil
do we know the range of nos in array? is it possible that negative nos are in array? On Aug 12, 6:50 pm, Dave wrote: > @ashish. The product will overflow for even moderate n, so instead, > form the sum and the sum of the squares of the numbers. If a and b are > the missing numbers, they satisfy

[algogeeks] Re: How to find two missing numbers from an unsorted continuous natural numbers array [only use O(1) space and O(n) time]

2010-08-20 Thread rahul patil
Is there any restriction that array must be start from 0 or 1 ? or it can start from any no ? On Aug 12, 6:50 pm, Dave wrote: > @ashish. The product will overflow for even moderate n, so instead, > form the sum and the sum of the squares of the numbers. If a and b are > the missing numbers, th

Re: [algogeeks] Re: 0's and 1's yet again!!!

2010-08-20 Thread Ashutosh Tamhankar
Here is a C++ version of the algorithm to solve this problem. #include #define TRUE 1 #define FALSE 0 typedef struct Binarr{ int iNumber; }; class binaryarr{ Binarr * arr; public: int iHead; int iSize; int iZeroes; int iOnes; int iTail; binaryarr(void); ~bi

Re: [algogeeks] Re: Adobe Questions

2010-08-20 Thread GOBIND KUMAR
This is the code for question no-4 #include #include using namespace std; int main(){ char str[20]; char *sp=str; int n=0; int count=0;int carry=1; gets(str); //cout<<"\n"