![]() |
java advanced tutorial part 2 - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Java, JVM, & JRE (https://sinister.ly/Forum-Java-JVM-JRE) +--- Thread: java advanced tutorial part 2 (/Thread-java-advanced-tutorial-part-2) |
java advanced tutorial part 2 - ICE_ - 02-13-2013 In this thread I will be going over some very advanced stuff, if you do not know java that well please go check my java-the bare basics tutorial or any of my other tutorials. Maze recursion Definition: maze recursion is fairly self-explanatory. it is recursion used to solve some sort of maze: example: X X X X X X X X S . . X . . . X X X . X . X . X X X . . . X . X X X . . . . . E X X X X X X X X maze recursion works by testing every possible move at every point. most of te time this involves checking up, down, left and right. depending n the constraints of the problem, however, you may have diagonals involved. Code: import java.util.*; Data Structures Definition: a data structure is a object design that stores data in a specific way. examples of a structures include java.util.list(arraylists and linkedlists), java.util.set(treeset and hashset), java.util.map(treemaps and hashmaps), trees, graphs Lists Definition: lists are defined by java.util.list interface. a list will have any method contained in that interface. a few of these include add(object), remove(object),size(), isEmpty(). for a complete set of methods, view the java API online. ArrayLists are the most common type of lists. they essentially serve as dynamic arrays, allowing indexing and the setting and getting of objects at a particular index. Lined lists are less common but are faster. in a linkedList every element is linked to the one following it. linkedlists can only add/remove from the beginning or end and have no indexing sets Definition: any class that implements the java.util.set. sets DO NOT allow duplicated ad upon adding to a set, java checks each element using it's defined equals() method. if no equals() method has been created for a given class then object's equals method is used. to acessess the values in a set, one must use an iterator. an easy way to do so is with a for-each loop: Code: TreeSet<String> myset = new TreeSet<string>(); Hashsets are sets in which the elements are stored based on an instance-specific hash code. more often than not, this hash code is simply determined by object's hashcode() method. trees Definition: a darta structure in which every element is stored in a node and each node has link to 2 child nodes. O <--- Node O O <--- children O O O O <--- Leaves (LEAVES HAVE NO CHILDREN) There are 4 main types of trees: 1) an unsorted/unorganized tree. the items in the tree have no particular sort applied and no real structure other than the basic tree structure 2) binary trees. in binary trees, each parent node's datum is greater than the datum of its left child and less than the datum of its right child. equal data can fall on either side depending on the implementation 3) min-heap every parent node datum is less than the datum of the parent node's children 4) max-heap. every parent node datum is greater than the date of the parent node's children A Balanced Binary Tree 6 4 8 3 5 7 9 A Balanced min-heap 3 4 7 6 5 8 9 A balanced max-heap 9 8 7 6 5 4 3 Min heap: heeps_of_sheeps_with_peeps_that_sleeps class Code: import java.util.ArrayList; Code: import java.util.Arrays; |