"How can I implement Graph/Tree algorithms in java ?"
-
I can implement all the algorithms like DFS/BFS/Dijkstra and can implement data structures like BST, AVL, RB Tree in C. But I donot know how to implement them using "Java" as there are no pointers available or Am I missing something ? I want to implement them from scratch even if these are already implemented.
-
Answer:
Java object references are the equivalent of pointers. For example, a binary tree might have a node structure like this: class Node<T> { T value; Node<T> left; Node<T> right; } (If they don't teach parameterized types in your class... then boo on them. Just omit <T> and use Object value instead.)
Joshua Engel at Quora Visit the source
Other answers
If you are able to implement something in C you should be able to implement in Java as well. The only reason I can think of why you are not able to do it is due to lack of sufficient knowledge of the java language. You don't have pointers available in Java but all objects are accessed by references so you could create self referential structures in java as well. Look at these codes to see how the self referential data structures are coded BST - http://algs4.cs.princeton.edu/32bst/BST.java.html Red Black Trees - http://algs4.cs.princeton.edu/33balanced/RedBlackBST.java.html Further have a look at http://algs4.cs.princeton.edu/code/ this page has most of the standard algorithms implemented in Java if while implementing you are stuck at some point you can refer to their implementation and try to re implement on your own with out seeing it.
Praveen Reddy Vaka
A detailed explanation about graphs, trees and their representations including Java code is available at http://sadakurapati.wordpress.com/2014/01/06/graph-tree-algorithms/
Sada Kurapati
Prateek Rathore
Related Q & A:
- How can I make a Spinner only by java?Best solution by stackoverflow.com
- How can I implement an atomic incr and decr on top of an eventually consistent key-value store?Best solution by Stack Overflow
- How can I implement idle timeout in android?Best solution by Stack Overflow
- how can I listen for database changes using java?Best solution by Stack Overflow
- How can I implement a multilayer social network in R?Best solution by Computational Science
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.