CSCI 1300
Lecture Notes


12/2/97

Administrative Stuff 



Administrative Stuff

  • Tuesday 12/2: Advanced data structures and algorithms
  • Thursday 12/4 Advanced data structures and algorithms
  • Tuesday 12/9: Programming assignment #9 due, Quiz #5
  • No final exam



    Trees (chapter 17)

    With arrays:
  • The size of the data set cannot be changed once the array is created
  • It is costly to move elements around (add, delete, rearrange)
  • Linear search is inefficient, but works
  • Binary search is more efficient
  • With linked lists:
  • The size of the data set can change
  • Moving elements around is efficient (add, delete, sort, etc.)
  • Linear search is still relatively inefficent, but works
  • Binary search is very inefficient
  • Trees are a kind of data structure in which the information is stored so as to reflect the ways in which it will be used.

    Like linked lists, trees are implemented with pointers.

    In a linked list, each node has a pointer to the element that comes after it in the list

    In a tree, each node has pointers to all of the nodes that come below it, called its children.

    Nodes that have no children are called the leaves of the tree.

    Examples:
  • Family tree
  • Animal taxonomies
  • File system directory structure

  • Binary trees

    In some trees, all nodes have the same number of children.

    In other trees, the number of children may vary

    Binary trees are trees in which all non-leaf nodes have either one of two children

    Binary trees are useful for storing information that will be accessed via a set of binary decisions

    Examples:
  • Greater-than/Less-than decisions (Binary search)
  • Anything else with two choices (Morse code example)

  • Morse code

    Morse code is a system for representing the alphabet in which each letter of the alphabet is represented by a short sequence of dots and dashes.

    In Morse code
  • A = dot-dash
  • B = dash-dot-dot-dot
  • C = dash-dot-dash-dot
  • D = dash-dot-dot
  • E = dot
  • etc.
  • Morse code can be represented by a tree as follows:

    To find out what letter is represented by a particular sequence of dots and dashes, you just start at the top of the tree and follow the links indicated by the sequence. Wherever you stop, that's the letter.


    Binary search trees

    Binary trees can also be used to hold dynamic lists of numbers.

    Adding to a binary tree

    Deleting from a binary tree

    Searching for an element in a binary tree


    Recursion in binary trees

    Subtrees


    Binary tree code


    Tree search algorithms

  • Depth-First Search (DFS)

  • Breadth-First Search (BFS)