20
Binary Search Trees and Rare Super Cars By Cole P.

Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Binary Search Trees

and Rare Super Cars By Cole P.

Page 2: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Definition

� A node-based data structure that compares keys in order to tell where a node goes

Page 3: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Ferrari P4/5

� Total Amount: 1

� Release Year: 2006

� Base Price: $4,000,000

Info From:https://freeaddon.com/top-10-rarest-supercars-never-see/

Page 4: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

What does a node contain?

� Key

� Value

� Left Link

� Right Link

Page 5: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

How it works

� The data structure takes the key from the data set and compares it to the “root” and continues from there

Page 6: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

McLaren F1 LM

� Total Amount: 5

� Release Year: 1995

� Base Price: $1,000,000

Info From:https://freeaddon.com/top-10-rarest-supercars-never-see/

Page 7: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Insert

� We would use a recursive method, so it compares the key to the key of each node and determines where to go, left is lower and right is greater.

Page 8: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Example (Insertion)

Page 9: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Pagani Zonda Revolucion

� Total Amount: 5

� Release Year: 2014

� Base Price: $2,900,000

Info From:https://freeaddon.com/top-10-rarest-supercars-never-see/

Page 10: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Delete

� To delete a node you CAN find the successor of the node being deleted in the right tree and replace it

� BUT there are other methods for deleting nodes

Page 11: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Example (Deletion)

� In order to do this you would need to find the smallest value in the right branch of the node being deleted

Page 12: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Methods and Variables

Binary Search Tree

• Int Root

• Search(n)• Insert(n)• Minimum• Maximum• Delete(n)• Floor• Ceiling• Selection• Rank

Page 13: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Run Time

� The search tree all runs in O(log n) because it depends on how many objects are in the structure

� Slower than O(1)

� Faster than O(n)

Page 14: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Different Cases

Page 15: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Lamborghini Veneno

� Total Amount: 5

� Release Year: 2013

� Base Price: $4,000,000

Info From:https://freeaddon.com/top-10-rarest-supercars-never-see/

Page 16: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Implementation

� Keep track of the root, the left, and right links then the rest of the tree is found from there

HLeft, Less than

Right,Greater than

Root

Page 17: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Applications of Search Trees

� Used in search applications

� 3D games for rendering

Page 18: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

What’s the Point?

� Search trees CAN be more reliable than arrays and are faster than 0(n)

� It is O(log n) meaning it must search, but not through all objects ideally

Page 19: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Koenigsegg One

� Total Amount: 6

� Release Year: 2015

� Base Price: $2,400,000

Info From:https://freeaddon.com/top-10-rarest-supercars-never-see/

Page 20: Binary Search Trees and Rare Super Carswtkrieger.faculty.noctrl.edu › csc210-spring2020 › docs › pk03_bst.pdf · Implementation Keep track of the root, the left, and right links

Overview

� O(log n)

� Adds items through simple method

� Less than Greater than operation

Quick and Reliable

(not the fastest)