Tutorial 10 - Binary Trees A binary tree is a linked data structure - - PowerPoint PPT Presentation

tutorial 10 binary trees
SMART_READER_LITE
LIVE PREVIEW

Tutorial 10 - Binary Trees A binary tree is a linked data structure - - PowerPoint PPT Presentation

Tutorial 10 - Binary Trees A binary tree is a linked data structure where each element has a link to at most two child nodes There is a root node that is not the child of any other node There are leaf nodes which have no children 1 CS


slide-1
SLIDE 1

Tutorial 10 - Binary Trees

  • A binary tree is a linked data structure where each element has

a link to at most two child nodes

  • There is a root node that is not the child of any other node
  • There are leaf nodes which have no children

CS 136 Spring 2020 Tutorial 10

1

slide-2
SLIDE 2

Root Node Leaf Nodes

CS 136 Spring 2020 Tutorial 10

2

slide-3
SLIDE 3

Binary Search Trees

  • A binary search tree is a binary tree where each element is

associated with a value

  • The left child and all of its descendants have values that are

lower than it’s parent’s value

  • The right child and all of its descendants have values that are

higher than it’s parent’s value

CS 136 Spring 2020 Tutorial 10

3

slide-4
SLIDE 4

CS 136 Spring 2020 Tutorial 10

4

slide-5
SLIDE 5

Binary Search Trees

  • Binary search trees represent collections of data that can be
  • rdered
  • We can check whether or not a value is stored in the binary

search tree using binary search

CS 136 Spring 2020 Tutorial 10

5

slide-6
SLIDE 6

CS 136 Spring 2020 Tutorial 10

6

slide-7
SLIDE 7

CS 136 Spring 2020 Tutorial 10

7

slide-8
SLIDE 8

CS 136 Spring 2020 Tutorial 10

8

slide-9
SLIDE 9

CS 136 Spring 2020 Tutorial 10

9

slide-10
SLIDE 10

Exercise: Implement a Binary Search Tree

  • 1. Implement a binary search tree in C.
  • 2. Provide a method called push for adding new nodes to a tree.
  • 3. Provide a method called find that checks whether some

value is contained in the binary tree. Use binary search.

  • 4. Provide a method called print that prints a binary search tree.

CS 136 Spring 2020 Tutorial 10

10