SlideShare a Scribd company logo
Data Structures in
Java
Session 7
Instructor: Bert Huang
http://www1.cs.columbia.edu/~bert/courses/3134
Announcements
• Homework 2 released on website
• Due Oct. 6th at 5:40 PM (7 days)
• Homework 1 solutions posted
• Post homework to
Shared Files, Homework #2
Review
• Review of scope
• Stack applications examples
• Stack implementation (easy)
• Queue ADT definition and
implementation
Todayʼs Plan
• Lists, Stacks, Queues in Linux
• Introduction to Trees
• Definitions
• Tree Traversal Algorithms
• Binary Trees
Lists, Stacks, Queues
in Linux
• Linux:
• processes stored in Linked List
• FIFO scheduler schedules jobs using queue
• function calls push memory onto stack
Drawbacks of Lists
• So far, the ADTʼs weʼve examined have been
linear
• O(N) for simple operations
• Can we do better?
• Recall binary search: log N for find :-)
• But list must be sorted. N log N to sort :-(
Trees
• Extension of Linked List structure:
• Each node connects to multiple nodes
• Example usages include file systems,
Java class hierarchies
• Fast searchable collections
Tree Terminology
• Just like Linked Lists, Trees are
collections of nodes
• Conceptualize trees upside down (like
family trees)
• the top node is the root
• nodes are connected by edges
• edges define parent and child nodes
• nodes with no children are called leaves
More Tree
Terminology
• Nodes that share the
same parent are siblings
• A path is a sequence of
nodes such that the next
node in the sequence is a
child of the previous
More Tree
Terminology
• a nodeʼs depth is the
length of the path from
root
• the height of a tree is
the maximum depth
• if a path exists between
two nodes, one is an
ancestor and the other
is a descendant
Tree Implementation
• Many possible implementations
• One approach: each node stores a list of
children
• public class TreeNode<T> {
T Data;
Collection<TreeNode<T>> myChildren;
}
Tree Traversals
• Suppose we want to print all nodes in a tree
• What order should we visit the nodes?
• Preorder - read the parent before its children
• Postorder - read the parent after its children
Preorder vs.
Postorder
• // parent before children
preorder(node x)
print(x)
for child : myChildren
preorder(child)
• // parent after children
postorder(node x)
for child : myChildren
postorder(child)
print(x)
Binary Trees
• Nodes can only have two children:
• left child and right child
• Simplifies implementation and logic
• public class BinaryNode<T> {
T element;
BinaryNode<T> left;
BinaryNode<T> right;
}
• Provides new inorder traversal
Inorder Traversal
• Read left child, then parent, then right child
• Essentially scans whole tree from left to right
• inorder(node x)
inorder(x.left)
print(x)
inorder(x.right)
Binary Tree
Properties
• A binary tree is full if each node has
2 or 0 children
• A binary tree is perfect if it is full and
each leaf is at the same depth
• That depth is O(log N)
Expression Trees
• Expression Trees are yet another way to
store mathematical expressions
• ((x + y) * z)/300
• Note that the main mathematical
operators have 2 operands each
• Inorder traversal reads back infix notation
• Postorder traversal reads postfix notation
*
+
x y
z
/
300
Hungry?
Enough money?Do nothing
Chicken and Rice Subsconscious
Decision Trees
• It is often useful to design decision
trees
• Left/right child represents yes/no
answers to questions
Reading
• This class: Weiss 4.1-4.2
• Next class: Weiss 4.3

More Related Content

PPT
Hub102 - Lesson4 - Data Structure
PDF
Presentation of OpenNLP
PDF
Corpus studio Erwin Komen
PPTX
Streams&amp;io
PDF
Graph databases & data integration v2
PPTX
Clojure/conj 2017
ODP
The eXtensible Catalog Drupal Toolkit
PDF
dipLODocus[RDF]: Short and Long-Tail RDF Analytics for Massive Webs of Data
Hub102 - Lesson4 - Data Structure
Presentation of OpenNLP
Corpus studio Erwin Komen
Streams&amp;io
Graph databases & data integration v2
Clojure/conj 2017
The eXtensible Catalog Drupal Toolkit
dipLODocus[RDF]: Short and Long-Tail RDF Analytics for Massive Webs of Data

What's hot (20)

PPTX
NLP and LSA getting started
PDF
Another RDF Encoding Form
PPTX
Flow control, variable types
PDF
Programming for Performance
ODP
Meet the-other-elephant
PDF
The List Data Model
PPTX
SWT Lecture Session 8 - Rules
PPTX
Data and Donuts: Data cleaning with OpenRefine
PDF
Knowledge Patterns for the Web: extraction, transformation, and reuse
PDF
Data quality in Real Estate
PPTX
R language
PDF
Federated data stores using semantic web technology
PPTX
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
PDF
Practical NLP with Lisp
PDF
Python 45 minutes hangout #3
PPTX
ISOcat and RELcat, two cooperating semantic registries
PPT
linked list in c++
NLP and LSA getting started
Another RDF Encoding Form
Flow control, variable types
Programming for Performance
Meet the-other-elephant
The List Data Model
SWT Lecture Session 8 - Rules
Data and Donuts: Data cleaning with OpenRefine
Knowledge Patterns for the Web: extraction, transformation, and reuse
Data quality in Real Estate
R language
Federated data stores using semantic web technology
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
Practical NLP with Lisp
Python 45 minutes hangout #3
ISOcat and RELcat, two cooperating semantic registries
linked list in c++
Ad

Similar to DATA STRUCTURE (20)

PPTX
Skillwise - Enhancing dotnet app
PDF
Data Structures and Algorithm - Week 4 - Trees, Binary Trees
PPTX
Data science and Hadoop
PPTX
DAA-Week-9-1dsad;jglrjglkdfjglfdkfsada0.pptx
PPTX
Infinispan, a distributed in-memory key/value data grid and cache
PDF
Intro to Big Data - Spark
PPT
Agile Data Science: Hadoop Analytics Applications
PPTX
MapReduce and Hadoop
PDF
OU RSE Tutorial Big Data Cluster
DOC
Advanced c c++
PPT
Agile Data: Building Hadoop Analytics Applications
PPT
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
PPT
Agile Data Science: Building Hadoop Analytics Applications
PDF
Introduction to libre « fulltext » technology
PDF
DL4J at Workday Meetup
PDF
How to choose a database
PPTX
CPP19 - Revision
PPTX
Embed, Encode, Attend, Predict – applying the 4 step NLP recipe for text clas...
PDF
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Skillwise - Enhancing dotnet app
Data Structures and Algorithm - Week 4 - Trees, Binary Trees
Data science and Hadoop
DAA-Week-9-1dsad;jglrjglkdfjglfdkfsada0.pptx
Infinispan, a distributed in-memory key/value data grid and cache
Intro to Big Data - Spark
Agile Data Science: Hadoop Analytics Applications
MapReduce and Hadoop
OU RSE Tutorial Big Data Cluster
Advanced c c++
Agile Data: Building Hadoop Analytics Applications
Agile Data Science by Russell Jurney_ The Hive_Janruary 29 2014
Agile Data Science: Building Hadoop Analytics Applications
Introduction to libre « fulltext » technology
DL4J at Workday Meetup
How to choose a database
CPP19 - Revision
Embed, Encode, Attend, Predict – applying the 4 step NLP recipe for text clas...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Ad

Recently uploaded (20)

PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PDF
Introduction to Business Data Analytics.
PDF
Fluorescence-microscope_Botany_detailed content
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
Business Acumen Training GuidePresentation.pptx
PDF
Launch Your Data Science Career in Kochi – 2025
PPTX
Global journeys: estimating international migration
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPT
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
PPT
Quality review (1)_presentation of this 21
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
Computer network topology notes for revision
PPTX
Database Infoormation System (DBIS).pptx
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Introduction to Business Data Analytics.
Fluorescence-microscope_Botany_detailed content
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Business Acumen Training GuidePresentation.pptx
Launch Your Data Science Career in Kochi – 2025
Global journeys: estimating international migration
STUDY DESIGN details- Lt Col Maksud (21).pptx
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
Quality review (1)_presentation of this 21
Supervised vs unsupervised machine learning algorithms
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Computer network topology notes for revision
Database Infoormation System (DBIS).pptx

DATA STRUCTURE

  • 1. Data Structures in Java Session 7 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134
  • 2. Announcements • Homework 2 released on website • Due Oct. 6th at 5:40 PM (7 days) • Homework 1 solutions posted • Post homework to Shared Files, Homework #2
  • 3. Review • Review of scope • Stack applications examples • Stack implementation (easy) • Queue ADT definition and implementation
  • 4. Todayʼs Plan • Lists, Stacks, Queues in Linux • Introduction to Trees • Definitions • Tree Traversal Algorithms • Binary Trees
  • 5. Lists, Stacks, Queues in Linux • Linux: • processes stored in Linked List • FIFO scheduler schedules jobs using queue • function calls push memory onto stack
  • 6. Drawbacks of Lists • So far, the ADTʼs weʼve examined have been linear • O(N) for simple operations • Can we do better? • Recall binary search: log N for find :-) • But list must be sorted. N log N to sort :-(
  • 7. Trees • Extension of Linked List structure: • Each node connects to multiple nodes • Example usages include file systems, Java class hierarchies • Fast searchable collections
  • 8. Tree Terminology • Just like Linked Lists, Trees are collections of nodes • Conceptualize trees upside down (like family trees) • the top node is the root • nodes are connected by edges • edges define parent and child nodes • nodes with no children are called leaves
  • 9. More Tree Terminology • Nodes that share the same parent are siblings • A path is a sequence of nodes such that the next node in the sequence is a child of the previous
  • 10. More Tree Terminology • a nodeʼs depth is the length of the path from root • the height of a tree is the maximum depth • if a path exists between two nodes, one is an ancestor and the other is a descendant
  • 11. Tree Implementation • Many possible implementations • One approach: each node stores a list of children • public class TreeNode<T> { T Data; Collection<TreeNode<T>> myChildren; }
  • 12. Tree Traversals • Suppose we want to print all nodes in a tree • What order should we visit the nodes? • Preorder - read the parent before its children • Postorder - read the parent after its children
  • 13. Preorder vs. Postorder • // parent before children preorder(node x) print(x) for child : myChildren preorder(child) • // parent after children postorder(node x) for child : myChildren postorder(child) print(x)
  • 14. Binary Trees • Nodes can only have two children: • left child and right child • Simplifies implementation and logic • public class BinaryNode<T> { T element; BinaryNode<T> left; BinaryNode<T> right; } • Provides new inorder traversal
  • 15. Inorder Traversal • Read left child, then parent, then right child • Essentially scans whole tree from left to right • inorder(node x) inorder(x.left) print(x) inorder(x.right)
  • 16. Binary Tree Properties • A binary tree is full if each node has 2 or 0 children • A binary tree is perfect if it is full and each leaf is at the same depth • That depth is O(log N)
  • 17. Expression Trees • Expression Trees are yet another way to store mathematical expressions • ((x + y) * z)/300 • Note that the main mathematical operators have 2 operands each • Inorder traversal reads back infix notation • Postorder traversal reads postfix notation * + x y z / 300
  • 18. Hungry? Enough money?Do nothing Chicken and Rice Subsconscious Decision Trees • It is often useful to design decision trees • Left/right child represents yes/no answers to questions
  • 19. Reading • This class: Weiss 4.1-4.2 • Next class: Weiss 4.3