Amarbir Singh

Greenhorn
+ Follow
since Jun 26, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Amarbir Singh

Hi Pankaj,

You are refering to the static inner class... and anything which is in the static context has Class level scope.

so, when you are changing the value of "i" which is a memeber of the static class and hence is in the static context, therefore in fact you are altering a static member value and the same"ll be reflected to all the instances.

I hope it clarifies your doubt.

"The Art Of People Is The True Mirror Of Their Minds...!"
Thank you James...!

I'll try this out.

" The Art Of People Is The True Mirror Of Their Minds........! "
16 years ago
Hi Friends,

I need little guidance/help ...regarding Binary Search Tree
I have to write an algorithm to :-
1) Create a Biary Search Tree.
2) Find the Nth smallest Element of the tree.

I have solved this problem earlier but just got stuck as I'm implementing this using recursion.

This is the helper method that I'm using...

public void nthSmallest(int n)
{
Node tNode = nthSmallest(root , n);
}
private Node nthSmallest(Node node , int n)
{
Node tempNode = node;
if(tempNode == null)
{
System.out.println(" Tree is Empty hence no data returned....! ");
return node ;
}

if( (counter < n) && (tempNode.left != null) )
{
tempNode = nthSmallest(tempNode.left , n);
counter++;
System.out.println( " left counter < n "+ counter );
}

if(counter < n )
{
counter++;
}

if( (counter < n) && (tempNode.right!=null) )
{
tempNode = nthSmallest(node.right,n);
counter++;
}

if(counter == n)
{
System.out.println(" The Required Element is "+tempNode.data);
}

return tempNode;
}

Node{
int data;
Node left;
Node right;
}

How can I use this type of BST to find nth smallest element...
16 years ago
Thanks James,

Your algorithm will be of great help. Marking the nodes as Visited/Unvisited should help make it work perfectly fine.

Thanks everybody for your guidance.

"The Art Of People Is The True Mirror Of Their Minds."
16 years ago
I'm using two variables to control the number of iterations in the while loop that gets changed when we do i--/j--/j++ etc....
16 years ago
I wrote following two functions to increment/decrement based on flag...
now the issue is how to call these symmetrically in loop so that parameter values are correctly passed.

Is there any symmetry that i can follow in loop to call these functions for desired output.


[ added code tags - Jim ]
[ October 05, 2007: Message edited by: Jim Yingst ]
16 years ago
Hi Frnz..Thank you very much....for your guidance..
what i was looking for ... Is there any mathematical algorithm for handling M*N matrix ... to parse it on the periphery...!

or do we need to go through 4-different loops.....?

thnks in advance...!
cheers

" Art of people is the true mirror of their minds...! "
16 years ago
Hi All,

I have this query of parsing an M*N matrix on periphery...
e.g we are given 4*4 matrix as below...

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

We need to parse it to display output in the sequence as shown....

1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10.

Please guide me to write the algorithm generic for the same....!

Thank you very much.
cheers
Amar
16 years ago
Thnx guys I have managed to write an algorithm for finding Nth largest element without sorting with average complexity linear....
1) Compare the first array element with rest of the elements and whenever the next element is greater than the first element increment the counter...and break whenever the counter is == N-1... Repeat the process untill the counter == N-1.

cheers
16 years ago
Thanks guys....

Dear Ashok,

We are not allowed to use any inbuilt function or utility ..... like collections....

and I have executed your code...it runs fine...but the complexity is cubic...
16 years ago
Dear Bart,

If you can provide the pseudo code... or more details ...code level..because there are many theoretical solutions but when puting them to practice....It becomes very complicated ....

thnks ... cheers
16 years ago
Dear Manuel,

your code'll work but we have to think of the best possible solution like...
If you want to use another array you can keep the size n where n = no of largest element that we have to find.

Dear All,
Think of something like searching the 1st , 2nd ... nth largest and subsequently add them to some array or stack...

The concept is clear in my mind the only problem i am facing is How to keep the complexity in average case to LINEAR ....
16 years ago
Dear Ashok,

Your code'll work but the complexity is cubic ... So we have to find more efficient solution...

e.g If we could find First , Second , Third ... largest element upto the value user has asked for e.g 4th largest etc..

Than either we can put this in the stack or in array .....and the last inserted will be our result....

Think in this context... Thnks in advance
cheers
16 years ago
Dear Bianchi ,

This code'll return the 1st Largest element ... and our requirement is to get the nth largest element of the array without sorting the array....
16 years ago
Dear vanlalhmangaiha,

The prerequisite is you are not allowed to explicitly sort the array...you have to do it without sorting...
16 years ago