General info
Download
1 / 34

General Info - PowerPoint PPT Presentation


  • 317 Views
  • Updated On :

General Info. Check out gilgarn.org. QUIZ. DO YOU: Love CSC 171 ? Want a job? Like to exert power over others? Want to improve CSC education @ UR? DID YOU: Do well (A or B) in 171? Think Workshops were helpful? CAN YOU: Stand looking at me for another semester?. IF YOU:.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'General Info' - Sharon_Dale


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
General info l.jpg
General Info

  • Check out gilgarn.org


Slide2 l.jpg
QUIZ

  • DO YOU:

    • Love CSC 171 ?

    • Want a job?

    • Like to exert power over others?

    • Want to improve CSC education @ UR?

  • DID YOU:

    • Do well (A or B) in 171?

    • Think Workshops were helpful?

  • CAN YOU:

    • Stand looking at me for another semester?


If you l.jpg
IF YOU:

  • Answered “YES” to most of the above questions

  • THEN:

    • Consider serving as a WORKSHOP LEADER

  • BENEFITS:

    • FAME, MONEY, POWER

    • LOOKS GOOD ON YOUR RESUME

    • DO SOMETHING GOOD FOR HUMANITY

  • INTEREST MEETING:

    • THURS (3/25) 5:15PM

    • LAS, basement of Lattimore


Trees l.jpg

Trees

CSC 172

SPRING 2004

LECTURE 14


Lists l.jpg

Lists

We have seen lists:

public class Node {

Object data;

Node next;

}


Trees6 l.jpg

Trees

Now, look at trees:

public class Node {

Object data;

Node left;

Node right;

}


Rooted trees l.jpg
Rooted Trees

Collection of nodes, one of which is the root

Nodes != root have a unique parent node

Each non-root can reach the root by following parent links one or more times


Definitions l.jpg
Definitions

If node p is the parent of node c

then c is a child of p

Leaf : no children

Interior node : has children

Path : list of nodes (m1,m2,…,mk) such that each is the parent of the following

path “from m1 to mk”

Path length = k-1, number of links, not nodes


Slide9 l.jpg

If there is a path from m to n, then m is an ancestor of n and n is a descendant of m

Note m == n is possible

Proper ancestors, descendants : m != n

Height of a node n is the length of the longest path from n to a leaf

Height of a tree is the height of its root

Depth of a node is the length of the path from the root to n

Subtree rooted at n is all the descendants of n


Slide10 l.jpg

The children of any given note are often ordered “from the left”

Child c1 is to the left of c2 then all the nodes in the subtree rooted at c1 are “to the left” of those in the subtree rooted at c2

Nodes may have labels, which are values associated with the nodes


Example unix file systems l.jpg

left”

/bin

/dev

/usr

.

/dev/term

/dev/sound

/dev/tty01

/usr/anna

/usr/jon

/usr/ted

Example: UNIX File Systems

/


Example expression trees l.jpg
Example: Expression Trees left”

Labels are operands or operators

Leaves : operands

Interior nodes : operators

Children are roots of sub-expressions to which the operator is applied


X 1 x y 4 l.jpg

* left”

+

-

4

x

1

-

x

y

(x+1)*(x-y+4)


Recursion on trees l.jpg
Recursion on Trees left”

Many algorithms to process trees are designed with a basis (leaves) and induction (interior nodes)

Example: If we have an expression tree we can get

infix

(operator between operands - common)

prefix

(operator before operands – like function calls)

postfix

(operator after operands – good for compilers)


Expression tree to postfix l.jpg
Expression Tree to Postfix left”

Basis

For a leaf, just print the operand

Induction:

For an interior node

apply algorithm to each child from left

print the operator


X 1 x y 416 l.jpg

* left”

+

-

4

x

1

-

x

y

(x+1)*(x-y+4)

x 1 + x y – 4 - *


General trees l.jpg

left”

General Trees

Some trees are binary:

public class Node {

Object data;

Node left;

Node right;

}


Some trees are not binary l.jpg

left”

/bin

/dev

/usr

.

/dev/term

/dev/sound

/dev/tty01

/usr/anna

/usr/jon

/usr/ted

Some trees are not binary

/

How do we implement

such trees?


Lmc rs l.jpg
LMC-RS left”

Leftmost-Child, Right-Sibling Tree Representation

Each node has a reference to

  • It’s leftmost child

  • It’s right sibling – the node immediately to the right having the same parent

    Advantage: represents trees without limits or pre-specified number of children

    Disadvantage: to find the ith child of node n, you must traverse a list n long


Lmc rs20 l.jpg

left”

LMC-RS

public class Node {

Object data;

Node l_child;

Node r_sibling;

}


Structural induction l.jpg
Structural Induction left”

Basis = leaves (one-node trees)

Induction = interior nodes (trees with => 2 nodes)

Assume the statement holds for the subtrees at the children of the root and prove the statement for the whole tree


Tree proof example l.jpg

left”

Tree Proof Example

Consider a LMC-RS tree

S(T): T has one more  reference than it has nodes

Basis: T is a single node – 2  references


Induction l.jpg
Induction left”

T has a root r and one or more sub trees T1, T2,…,Tk

BTIH: each of these trees, by itself has one more  than nodes

How many nodes all together?

How many  references?

How many nodes do I add to make one tree?

How many  references do we reduce to make one tree?


Slide24 l.jpg

T left”1

n1 nodes

n1+1 

T2

n2 nodes

n2+1 

Tk

nk nodes

nk+1 

?

?

?

One more node

One more 

Still “k” extra


Slide25 l.jpg

T left”1

n1 nodes

n1+1 

T2

n2 nodes

n2+1 

Tk

nk nodes

nk+1 

?

?

?

One more node

One more 

Still “k” extra

How many less?


Example pair quiz l.jpg
Example: Pair Quiz left”

S(T): A full binary tree of height h

has (2h+1 – 1) nodes

Basis?

Induction?


Example l.jpg
Example: left”

S(T): A full binary tree of height h has 2h+1 – 1 nodes

Basis?

Nodes = 1, height == 0, 20+1-1 = 1

Induction?


Slide28 l.jpg

T left”1

h height

2 h+1-1 nodes

T2

h height

2 h+1-1 nodes

Height = h+1


Why structural induction l.jpg
Why Structural Induction? left”

  • Q: Why do I want you to draw the pictures?

  • A: We know you can do the algebra. As you move on, the difficult part of the proofs is “setting up” the proof, from some situation. Sure, if someone sets it up for you, it’s just an “exercise” to solve. The real value is in being able to reason about a situation so as to set up a proof.


Process l.jpg
Process left”

Real world

phenomena

or artifact

Formal

Representation

“set up” of proof

Rigorous

Knowledge

Formal

techniques:

induction,

algebra

Informal

reasoning

abstraction

analysis


Kraft s inequality l.jpg
Kraft’s Inequality left”

  • Suppose that a binary tree has leaves {l1,l2,..lM} at depths {d1,d2,...,dM}, respectively.

  • Prove:



How do you set this up33 l.jpg
How do you set this up? left”

  • Basis:

  • In a tree with zero nodes, the sum is zero

  • In a tree with one node

    • One leaf, depth 0


Slide34 l.jpg

T left”1

∑1<=1

T2

∑2<=1

Same number of total leaves, all depths increase by 1

So, in new Tree ∑1<=1/2 && ∑2<=1/2


ad