source: cse 214 – computer science ii trees

Download Source:  CSE 214 – Computer Science II Trees

If you can't read please download the document

Upload: alexis-oconnor

Post on 18-Jan-2018

221 views

Category:

Documents


0 download

DESCRIPTION

If you didn’t do well in HW 1 Now’s the time to panic, not in December By panic, I mean work hard to catch up and do your best in HW 2 & Coding Exam 1 Three things I don’t do as an instructor: –give incompletes –grade under the Christmas tree –give extra credit assignments at the end of the semester

TRANSCRIPT

Source:CSE 214 Computer Science II Trees HW 2 Has Been Posted You must define: 3 Iterators 10 other methods GenericDoublyLinkedList We use this list in 2 different ways Try to get started early If you didnt do well in HW 1 Nows the time to panic, not in December By panic, I mean work hard to catch up and do your best in HW 2 & Coding Exam 1 Three things I dont do as an instructor: give incompletes grade under the Christmas tree give extra credit assignments at the end of the semester Every year I go to GDC Want to guess what won 2008 Game of the Year? Fable II (Lionhead Studios)Fable II LittleBigPlanet (Media Molecule)LittleBigPlanet Fallout 3 (Bethesda Game Studios)Fallout 3 Left 4 Dead (Valve Software)Left 4 Dead Grand Theft Auto IV (Rockstar North)Grand Theft Auto IV What do I learn while at GDC? Data structures, data structures, data structures, shading, data structures, data structures, data structures, physics, data structures, data structures, graphics, data structures, data structures, data structures, memory management, data structures, data structures, & data structures Why is this true? Because custom data structures can be invented to solve specific problems more efficiently games draw to the screen frames per second Large Hadron Collider computers record images at 40,000,000 frames per second Researchers are always looking for improved performance Now that we know linked lists Lets think about arranging nodes differently Washington (1) Madison (4) Adams (2) Monroe (5) Jefferson (3) Now that we know linked lists Lets think about arranging nodes differently Why would we do that? efficiency! Washington (1) Madison (4) Adams (2) Monroe (5) Jefferson (3) Adams (6) Jackson (7) Now that we know linked lists Whats the worst case scenario for accessing a node? log N TREES ARE GREAT FOR REDUCING A PROBLEM!!! to get the most of trees, we typically keep them sorted How many operations to find Monroe? Washington (1) Madison (4) Adams (2) Monroe (5) Jefferson (3) Adams (6) Jackson (7) What might we put in those nodes? Lots of fun stuff Databases love trees Games really love trees If you learn trees you could work for SpeedTree Ref: Trees are really upside down trees Root is at top Tree Application: Scene Graphs Tree with all the visible game objects Each frame of animation we go through the tree If a node is not visible, all of its child nodes are also not visible, so we can ignore all of them Ex: House is node, whats inside the house can be ignored if player is outside Octrees Tree with all collidable game objects Nodes represent regions of the game world During collision detection, if 2 objects are not in the same region, we dont test if they are colliding with each other Octree Source: Class Exercise Just like linked lists, well make tree-managing classes Just like linked lists, well make inner node classes Exercises: define a binary scene graph managing class (but no methods, except the constructors) instance variables & node class Define an octree managing class (but no methods, except the constructors) instance variables & node class public class BinarySceneGraph { private BinaryTreeNode root = null; public BinarySceneGraph() {} class BinaryTreeNode { protected Object data = null; protected BinaryTreeNode leftNode = null; protected BinaryTreeNode rightNode = null; BinaryTreeNode(Object initData, BinaryTreeNode initLeftNode, BinaryTreeNode initRightNode) { data = initData; leftNode = initLeftNode; rightNode = initRightNode; } Whats inside data? Whatever we want to put there, even other data structures public class Octree { private OctreeNode root = null; public Octree() {} class OctreeNode { protected Object data = null; protected OctreeNode node0,node1,node2,node3 = null; protected OctreeNode node4,node5,node6,node7 = null; BinaryTreeNode(Object initData, OctreeNode initNode0, , OctreeNode initNode7) { data = initData; node0 = initNode0; node7 = initNode7; } Whats inside data? Whatever we want to put there, even other data structures Next Time Well add methods to our list managing classes to: add data (thus nodes) remove data retrieve data rearrange data etc. By the way, well start with easier trees than octrees