Find the first value in the binary tree [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
where each node has a pointer to a sibling and a child.
Say that every node is either True or False, and you want to find the first node that is True (first means the shallowest).
How would you solve this? You are given the node to the head of the tree
can solve in java/c++.

As a hint, if you want to find the shallowest node in a tree with some property, you can use breadth-first search starting from the root.
The tree representation shouldn't be too much of an issue here, since when doing a BFS you would want to insert all of a node's children into the queue. The only difference between the normal representation and this representation is how you find the children.
I'll leave all the details to you, including doing the research to learn what these basic terms and definitions are, as an exercise. Your question is clearly some form of assignment or interview question and it would be terribly dishonest of me to just give you code.
Hope this helps!

Related

Largest area in matrix [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've been aksed to write a program that finds the largest area of equal neighbour elements in a rectangular matrix and prints its size. I tried to construct a 2d array with some numbers but I think that I should switch to using a tree or something in order to solve this problem. Chould somebody suggest a possible way of solving it?
For example:
"Hint: use the algorithm Depth-first search or Breadth-first search."
Sounds like a standard maze search problem. I suggest you use recursion to find all the elements which you haven't been to before which have the same number as the one you have found. You can either update the matrix as you go or create a copy to keep track of the cells you have visited. So you don't need a tree or even an additional complex data structure.
use the algorithm Depth-first search or Breadth-first search
These are two types of recursive searches. I suspect you could implement both of these to see how they behave.

How to implement an already well implemented module(like stack) in java using a linked list [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm trying to implement an stack using a linked list in Java, But I'm not sure which methods I have to implement(stack is a simple example here), How can I somehow get the methods and then extend my linked list class to implement my own class of stack
I know that somehow I have to use some kind of interface but it would be a great help if someone could guide me here.
A stack at its simplest just has Push() and Pop(). They map directly to the LinkedList methods push and pop already present!
So in order to implement a stack on top of a linked list you need to do....nothing :)

Java-like .hasNext() method in Ruby? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Is there a similar syntax to Java's .hasNext() method in Ruby? I've been trying to get inputs in one line and then making it as integers and getting the absolute value.
It sounds like you want to see if there are more elements left in an iteration. Ruby's equivalent to that is peek:
From the docs:
Returns the next object in the enumerator, but doesn’t move the internal position forward. If the position is already at the end, StopIteration is raised.
But, in Ruby we usually rely on each or map to walk an iterable collection. There's no "figuring out" whether there's another element remaining, because Ruby does that for us.
ansh0l is right, gets is the most likely equivalent to hasNext() assuming that you're reading from the keyboard or any other I/O stream.

Value of the String [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have just come across a string variable in my application code where the value is assigned as follows
String YEAR="${year}";
What does the value of the String variable here?
Without being interpolated, just ${year}.
I can almost guarantee that String is going to be interpolated elsewhere in the code.
Maven, for example, uses this syntax to inject variable values into it's configuration settings.
Use an IDE such as IntelliJ and do a find usage on this variable. An extended find (search/find in path) may also yield results.
As others here have suggested, It is most likely being interpolated somewhere else.

Edit distance in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a list of names (surnames) and a simple search mechanism. I would like to have words with minor changes (typos) shown in search results.
Example search text: braniecka
Example result: Branicka, Kraniecka, Braniecki
Any help appreciated.
You can implement the Levenshtein distance. It is a widely used algorithm.
You could also consider upgrading your solution to Lucene, especially if you are doing any production work. Lucene handles your requirement in an extremely performant way (no brute-force exhaustive search).
Try using simmetrics.
Is a library for measuring string similarity and implements many algorithms.
http://sourceforge.net/projects/simmetrics/

Categories

Resources