Re: [algogeeks] amazon

2012-05-29 Thread rahul patil
Here is a constant time formula, LetterRankInSortedString is index of
alphabate if all characters in string are sorted lexographically starting
from 1.

Index = 0;
For(i=0; i  LengthOfString; i++)
{
 Letter = string[i];
 Index + = (LetterRankInSortedString(Letter) - 1)  *
(TotalPermutationsPossible/ (LengthOfString-i));
}


On Mon, May 28, 2012 at 12:26 AM, saurabh agrawal saurabh...@gmail.comwrote:

 @atul:
  i dont agree that baa should come once or twice is arguable.
 It definitely have to be one time only..
 we are supposed to get all lexicographic combinations (which implicitly
 means no two strings will be same..)

 On Mon, May 28, 2012 at 12:23 AM, atul anand atul.87fri...@gmail.comwrote:

 @saurabh : i kinda assumed that string will not contain
 repeated character. reason being if string has repeated character , say in
 your case baa then baa will be repeated
 twice hence it would be difficult to justify the output for this
 input answer could be say 2 or 3 or both are correct.

 On Mon, May 28, 2012 at 12:16 AM, saurabh agrawal 
 saurabh...@gmail.comwrote:

 @atul:
 if i have understood ..
 ur solution will break when the string has repeated characters.

 e.g. for baa

 On Tue, May 22, 2012 at 3:43 PM, partha sarathi Mohanty 
 partha.mohanty2...@gmail.com wrote:

 sorry it was treeset Here is the code..

 public class asd1 {


  public static TreeSetString t = new TreeSetString();
  public static int j = 0;
 public static void main(String args[]) {




 String s= edcba;
 permute(, s);
 System.out.println(t.toString());
 int length=t.size();
 String[] arr=(String[]) t.toArray(new String[length]);
 for(int i =0;ilength;i++)
 {
 System.out.println(arr[i]);
 if(arr[i].equals(s)){
 System.out.println(i+1);
 break;
 }
 }
 }

 public static void permute(String st, String chars) {
 if (chars.length() = 1)
 t.add(st+chars);
 else
 for (int i = 0; i  chars.length(); i++) {
 try {
 String newString = chars.substring(0, i)
 + chars.substring(i +
 1);
 permute(st + chars.charAt(i),
 newString);
 } catch (Exception e) {
 e.printStackTrace();
 }
 }

 }
 }

 On Tue, May 22, 2012 at 2:19 PM, partha sarathi Mohanty 
 partha.mohanty2...@gmail.com wrote:

 Java has something call treeMap. it stores strings lexographically.. u
 can always do permutations and store them in a treeMap. and get the rank
 then... just the idea.. will post the solution once i am done.. what do u
 guys think.abt the idea???


 On Tue, May 22, 2012 at 9:46 AM, atul anand 
 atul.87fri...@gmail.comwrote:

 actually we can think of above approach as follows :-

 input : cabd

 sort(input) = abcd

 find first element of the input i.e 'c' in the sorted form i.e abcd

 'c' is at found_index=3 ( index starting from 1 )

 so permutaion stating from 'c' will come after temp_rank=(found_index
 - start_index) * (total_lentgh - 1) !

 now after temp_rank we know that permutation starting with 'c' will
 come.

 so to find out the exact index sort(input-1)  i.e removing 1st
 character ('c') from the input(cadb) we will get abd

 now permute string abd and compare with input - 1 character i.e
 (abd).

 and keep inc the counter , if match is found then you have to add
 this counter to temp_rank.

 so for the input = cabd

 temp_rank = (3 - 1) * (4-1) !
 =  2 * 3!
 =  12

 counter found c = 1;
 rank = 12 + c = 13

 but i dont think this would be good solution as be have to permute
 string and then compare at last...yes we did some optimization.
 i was wondering if instead of permuting at the end , we can calculate
 minimum number of swaps required to convert input - 1 to sorted input -1
 (removing 1st character )using edit distance ...will this work?? .


 On Mon, May 21, 2012 at 11:33 PM, atul anand atul.87fri...@gmail.com
  wrote:

 consider string input = cabd
 now sort this string = abcd

 now search 1st character from original string(cabd) in  sorted
 string abcd... index found = 3 (index starting from 1 )

 now you can arrange left elements from found index i.e index-1
 elements in (index-1) ! and right elements from found index in 
 (lastIndex -
 index)! before character 'c' occurs at index 0. similarly find for other
 characters and at the end subtract it from n! (n = length of the string 
 )
 to find rank


 On Mon, May 21, 2012 at 11:02 PM, rahul venkat 
 rahul911...@gmail.com wrote:

 Given a string. Tell its rank among all its permutations sorted
 lexicographically.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, 

[algogeeks] Tree/Graph implementation

2012-05-29 Thread prakash y
How to implement complex data structures like trees (with unknown no.of
subtrees) and graphs efficiently in C/Java?
I have implemented binary trees in Java as it always contains two nodes.
But I don't know about graphs.
I am not able to solve these problems in coding contests because of this.
Can anyone please suggest me?

Thanks in advance.
~Prakash.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Tree/Graph implementation

2012-05-29 Thread Hassan Monfared
you can use adjacency matrices for spare graphs and two dimensional  array
for non-spare graphs

On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.com wrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two nodes.
 But I don't know about graphs.
 I am not able to solve these problems in coding contests because of this.
 Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

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


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



[algogeeks] Re: Tree/Graph implementation

2012-05-29 Thread Gene
I'm interested to see problems where tree implementation causes a
performance problem.  Example?

Choice of graph data structures is very problem-dependent. An
adjacency matrix will probably be fastest and simplest for dense
graphs.  For sparse ones there are many, many answers.

An efficient way to do n-ary trees (which are usually sparse graphs)
in C:

typedef struct node_s {
 // Use a fixed size array of NODE* if you know
 // the maximum number of children in advance.
 // Here we assume this isn't true.
 struct node_s **children;
 int n_children;
 ...
} NODE;

NODE *make_node(int max_children)
{
  // Allocate nodes in a single array if you know the max
  // number in advance.  Here we assume this isn't true.
  NODE *node = safe_malloc(sizeof *node);
  node-children = safe_malloc(max_children * sizeof *node-children);
  node-n_children = 0;
  return node;
}

void add_child(NODE *parent, NODE *child)
{
  parent-children[parent-n_children++] = child;
}

void walk

On May 29, 6:17 am, prakash y yprakash@gmail.com wrote:
 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two nodes.
 But I don't know about graphs.
 I am not able to solve these problems in coding contests because of this.
 Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Tree/Graph implementation

2012-05-29 Thread Ashish Goel
Gene: why do you say that adjacency list is not a good solution for sparse
matrix? what other alternates are you looking at?

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


On Tue, May 29, 2012 at 9:09 PM, Gene gene.ress...@gmail.com wrote:

 I'm interested to see problems where tree implementation causes a
 performance problem.  Example?

 Choice of graph data structures is very problem-dependent. An
 adjacency matrix will probably be fastest and simplest for dense
 graphs.  For sparse ones there are many, many answers.

 An efficient way to do n-ary trees (which are usually sparse graphs)
 in C:

 typedef struct node_s {
  // Use a fixed size array of NODE* if you know
  // the maximum number of children in advance.
  // Here we assume this isn't true.
  struct node_s **children;
  int n_children;
  ...
 } NODE;

 NODE *make_node(int max_children)
 {
  // Allocate nodes in a single array if you know the max
  // number in advance.  Here we assume this isn't true.
  NODE *node = safe_malloc(sizeof *node);
  node-children = safe_malloc(max_children * sizeof *node-children);
  node-n_children = 0;
  return node;
 }

 void add_child(NODE *parent, NODE *child)
 {
  parent-children[parent-n_children++] = child;
 }

 void walk

 On May 29, 6:17 am, prakash y yprakash@gmail.com wrote:
  How to implement complex data structures like trees (with unknown no.of
  subtrees) and graphs efficiently in C/Java?
  I have implemented binary trees in Java as it always contains two nodes.
  But I don't know about graphs.
  I am not able to solve these problems in coding contests because of this.
  Can anyone please suggest me?
 
  Thanks in advance.
  ~Prakash.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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: Tree/Graph implementation

2012-05-29 Thread saurabh singh
^ A list representation 
consider a graph with 1 million nodes..and at a time only 2  nodes will be
connected...Compare the difference in the two representations...
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Tue, May 29, 2012 at 10:00 PM, Ashish Goel ashg...@gmail.com wrote:

 Gene: why do you say that adjacency list is not a good solution for sparse
 matrix? what other alternates are you looking at?

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



 On Tue, May 29, 2012 at 9:09 PM, Gene gene.ress...@gmail.com wrote:

 I'm interested to see problems where tree implementation causes a
 performance problem.  Example?

 Choice of graph data structures is very problem-dependent. An
 adjacency matrix will probably be fastest and simplest for dense
 graphs.  For sparse ones there are many, many answers.

 An efficient way to do n-ary trees (which are usually sparse graphs)
 in C:

 typedef struct node_s {
  // Use a fixed size array of NODE* if you know
  // the maximum number of children in advance.
  // Here we assume this isn't true.
  struct node_s **children;
  int n_children;
  ...
 } NODE;

 NODE *make_node(int max_children)
 {
  // Allocate nodes in a single array if you know the max
  // number in advance.  Here we assume this isn't true.
  NODE *node = safe_malloc(sizeof *node);
  node-children = safe_malloc(max_children * sizeof *node-children);
  node-n_children = 0;
  return node;
 }

 void add_child(NODE *parent, NODE *child)
 {
  parent-children[parent-n_children++] = child;
 }

 void walk

 On May 29, 6:17 am, prakash y yprakash@gmail.com wrote:
  How to implement complex data structures like trees (with unknown no.of
  subtrees) and graphs efficiently in C/Java?
  I have implemented binary trees in Java as it always contains two nodes.
  But I don't know about graphs.
  I am not able to solve these problems in coding contests because of
 this.
  Can anyone please suggest me?
 
  Thanks in advance.
  ~Prakash.

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


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


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



[algogeeks] Re: Cpp problem

2012-05-29 Thread Navin Gupta
Here the const specifies that this is a const memeber function.
It means it does not modify its arguments.
It means it can be called for const data members.
However since a const member function is more generic than non-const member 
function,it can also be called on non-const data.

On Monday, 28 May 2012 00:23:39 UTC+5:30, amrit harry wrote:

 complex_number const  operator =(complex_number  temp) const
 {
 return *this;
 }


 what is the job of marked 'const'???


-- 
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/-/60kdIXtTPO8J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] problem with increment operator

2012-05-29 Thread ashish pant
#includestdio.h
int main()
{
  int a=4;
  printf(%d\n,++a + ++a + a++);
  return 0;
}

according to me output should be 17, but it is coming out to be 18.
plz explain it??

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



[algogeeks] find error

2012-05-29 Thread amrit harry
#includeiostream
using namespace std;
class complex_number
{
public: int x,*ptr;

  ostream  operator (ostream out, complex_number c)
{
outsize=c.xendl;
for(int i=0;ic.x;i++)
outc.ptr[i] ;
out\n;
return out;
}

complex_number(int a)
{
x=a;
ptr=(int *) malloc(a*sizeof(int));
for(int i=0;i5;i++)
ptr[i]=i;
}
};

int main()
{
complex_number p(5);
coutp;
}
above code show error operator  must take only one argument
and when i change code to

#includeiostream
using namespace std;
class complex_number
{
public: int x,*ptr;

   friend ostream  operator (ostream out, complex_number c);
complex_number(int a)
{
x=a;
ptr=(int *) malloc(a*sizeof(int));
for(int i=0;i5;i++)
ptr[i]=i;
}
};
ostream  operator (ostream out, complex_number c)
{
outsize=c.xendl;
for(int i=0;ic.x;i++)
outc.ptr[i] ;
out\n;
return out;
}

int main()
{
complex_number p(5);
coutp;
}
 then there is no error why so...?

-- 
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/-/_s8SKLlcB5UJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Tree/Graph implementation

2012-05-29 Thread Jeevitesh
We can use the following data structure for Graphs:-
- Adjacency Lists(More generally used)
- Adjacency Matrix(Takes a lot of space but good for dense graph)

For Trees:-
We can model a node such that it has two pointers one of which points to
its first child while the other points to the next peer or sibling.

On Tue, May 29, 2012 at 4:03 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 you can use adjacency matrices for spare graphs and two dimensional  array
 for non-spare graphs


 On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.com wrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two nodes.
 But I don't know about graphs.
 I am not able to solve these problems in coding contests because of this.
 Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

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


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




-- 
*Thanks,
Jeevitesh Shekhar Singh.*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] problem with increment operator

2012-05-29 Thread MeHdi KaZemI
At first the value of a is calculated for the statement, that is 6, and
then statement is evaluated with a=6
so it is 6 + 6 + 6 = 18
and as you know after that the value of a becomes 7 for the rest of the
program.

On Mon, May 28, 2012 at 10:02 AM, ashish pant asheesh...@gmail.com wrote:

 #includestdio.h
 int main()
 {
   int a=4;
   printf(%d\n,++a + ++a + a++);
   return 0;
 }

 according to me output should be 17, but it is coming out to be 18.
 plz explain it??

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




-- 
   MeHdi KaZemI

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] problem with increment operator

2012-05-29 Thread Prateek Jain
how is it 6?
++a(5) + ++a(6) + a++(6) it shud be 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.



Re: [algogeeks] problem with increment operator

2012-05-29 Thread Hassan Monfared
I implemented ++ for a simple class and got 17.
class A
{
public :
int val;
A(int v):val(v){}
int operator++()
{
cout empty arg called\n;
return ++val;
}
int operator++(int x)
{
cout x:arged arg called\n;
return val++;
}
};
--
A b(4);
cout ++a + ++a +a++endl;

17
but  story is different for your sample.
let me tell the fact with a simpler  problem :
int b=4;
cout  ++b + ++b ;
will print 12 instead of 11!
amazing huh ?
what happens from right to left is :
in the right statement  : b becomes 5:
in the left statement : b becomes 6 ( now be is 6 in both sides !)
so right_b + left_b = 6+6 = 12

Regards


On Tue, May 29, 2012 at 11:43 PM, Prateek Jain prateek10011...@gmail.comwrote:

 how is it 6?
 ++a(5) + ++a(6) + a++(6) it shud be 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.



Re: [algogeeks] problem with increment operator

2012-05-29 Thread rahul ranjan
it first calculates from right to left and then performs addition
so after a++ its still 4(with a promise to increment in next
statement). then ++a makes it 5. then further ++a makes it 6
now the addition phase comes into play value of a is 6 now so total
18 if it wud hav been a++ + a++ + a++ sum wud hav been 12
and for next statement 'a' wud hav been 7

On Wed, May 30, 2012 at 1:32 AM, Hassan Monfared hmonfa...@gmail.comwrote:

 I implemented ++ for a simple class and got 17.
 class A
 {
 public :
 int val;
 A(int v):val(v){}
  int operator++()
 {
 cout empty arg called\n;
  return ++val;
 }
 int operator++(int x)
  {
 cout x:arged arg called\n;
 return val++;
  }
 };
 --
 A b(4);
 cout ++a + ++a +a++endl;
 
 17
 but  story is different for your sample.
 let me tell the fact with a simpler  problem :
 int b=4;
 cout  ++b + ++b ;
 will print 12 instead of 11!
 amazing huh ?
 what happens from right to left is :
 in the right statement  : b becomes 5:
 in the left statement : b becomes 6 ( now be is 6 in both sides !)
 so right_b + left_b = 6+6 = 12

 Regards


 On Tue, May 29, 2012 at 11:43 PM, Prateek Jain 
 prateek10011...@gmail.comwrote:

 how is it 6?
 ++a(5) + ++a(6) + a++(6) it shud be 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.



Re: [algogeeks] Tree/Graph implementation

2012-05-29 Thread prakash y
@all,
when we use a 2D array/matrix to implement graphs, how can we traverse
efficiently from starting node to ending node?

take a look at of these problems
Graph problem:
https://www.interviewstreet.com/challenges/dashboard/#problem/4f40dfda620c4
Tree Problem:
https://codeninja.interviewstreet.com/challenges/dashboard/#problem/4f75c32310103

How can we implement such problems efficiently in a language like Java?

On Tue, May 29, 2012 at 4:07 PM, Jeevitesh jeeviteshshekha...@gmail.comwrote:

 We can use the following data structure for Graphs:-
 - Adjacency Lists(More generally used)
 - Adjacency Matrix(Takes a lot of space but good for dense graph)

 For Trees:-
 We can model a node such that it has two pointers one of which points to
 its first child while the other points to the next peer or sibling.


 On Tue, May 29, 2012 at 4:03 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 you can use adjacency matrices for spare graphs and two dimensional
 array for non-spare graphs


 On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.comwrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two nodes.
 But I don't know about graphs.
 I am not able to solve these problems in coding contests because of
 this. Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

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


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




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] problem with increment operator

2012-05-29 Thread atul anand
@all : no need to argue on this ...output is compiler dependent ... it
violates sequence point rule :) :).

On Wed, May 30, 2012 at 2:26 AM, rahul ranjan rahul.ranjan...@gmail.comwrote:

 it first calculates from right to left and then performs addition
 so after a++ its still 4(with a promise to increment in next
 statement). then ++a makes it 5. then further ++a makes it 6
 now the addition phase comes into play value of a is 6 now so total
 18 if it wud hav been a++ + a++ + a++ sum wud hav been 12
 and for next statement 'a' wud hav been 7


 On Wed, May 30, 2012 at 1:32 AM, Hassan Monfared hmonfa...@gmail.comwrote:

 I implemented ++ for a simple class and got 17.
 class A
 {
 public :
 int val;
 A(int v):val(v){}
  int operator++()
 {
 cout empty arg called\n;
  return ++val;
 }
 int operator++(int x)
  {
 cout x:arged arg called\n;
 return val++;
  }
 };
 --
 A b(4);
 cout ++a + ++a +a++endl;
 
 17
 but  story is different for your sample.
 let me tell the fact with a simpler  problem :
 int b=4;
 cout  ++b + ++b ;
 will print 12 instead of 11!
 amazing huh ?
 what happens from right to left is :
 in the right statement  : b becomes 5:
 in the left statement : b becomes 6 ( now be is 6 in both sides !)
 so right_b + left_b = 6+6 = 12

 Regards


 On Tue, May 29, 2012 at 11:43 PM, Prateek Jain prateek10011...@gmail.com
  wrote:

 how is it 6?
 ++a(5) + ++a(6) + a++(6) it shud be 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.



Re: [algogeeks] Tree/Graph implementation

2012-05-29 Thread atul anand
simple DFS can be used to traverse nodes in the graph

On Wed, May 30, 2012 at 10:12 AM, prakash y yprakash@gmail.com wrote:

 @all,
 when we use a 2D array/matrix to implement graphs, how can we traverse
 efficiently from starting node to ending node?

 take a look at of these problems
 Graph problem:
 https://www.interviewstreet.com/challenges/dashboard/#problem/4f40dfda620c4
 Tree Problem:
 https://codeninja.interviewstreet.com/challenges/dashboard/#problem/4f75c32310103

 How can we implement such problems efficiently in a language like Java?

 On Tue, May 29, 2012 at 4:07 PM, Jeevitesh 
 jeeviteshshekha...@gmail.comwrote:

 We can use the following data structure for Graphs:-
 - Adjacency Lists(More generally used)
 - Adjacency Matrix(Takes a lot of space but good for dense graph)

 For Trees:-
 We can model a node such that it has two pointers one of which points to
 its first child while the other points to the next peer or sibling.


 On Tue, May 29, 2012 at 4:03 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 you can use adjacency matrices for spare graphs and two dimensional
 array for non-spare graphs


 On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.comwrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two
 nodes. But I don't know about graphs.
 I am not able to solve these problems in coding contests because of
 this. Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

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


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




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.