lecture15

lecture15 - Wednesday,March3 rd Tables HashTables...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Wednesday, March 3 rd    Tables Hash Tables Review Challenge
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Big-OH Craziness Consider a binary search tree that holds  N  student records, all indexed by  their  name . Each student record contains a linked-list of the  classes  that they have  taken while at UCLA. What is the big-oh to determine if a  student has taken a class?  bool HasTakenClass( b name class ) Name: Rick Classes: Left Right Class: CS31 Next: Name: Linda Classes: Left Right Class: CS31 Next: Class: EE10 Next: Name: Sal Classes: Left Right Class: Math31 Next: Class: Math31 Next: NULL Class: EE100 Next: NULL NULL NULL NULL NULL NULL
Background image of page 2
Tables A table is a data structure that allows us to store a number of  records  and  efficiently  lookup those records using one or more  key fields . Examples:  1. UCLA:  Store  student records  and look them up by the student’s  last  name . 2. DMV:  Store  vehicle records  and look them up by the  Vehicle ID  Number  (VIN) 3. Phone company:  Store  customer records  and look them up by the  customer’s phone #   or   last name .
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Tables Definition : A  record  is basically a struct/class  variable with a bunch of information. struct  CarRecord {    string make;    string model;    int year;    int horsepower;    int VehicleIDNum; }; Definition : A  key field  is a specially designated  field in the struct that the user of the table can  search by. idnum {    for (int i=0;i<table.size(); i++)       if ( idnum  == table[i]. VehicleIDNum )       {           out = table[i];           return(true);       }     return(false); }
Background image of page 4
Can anyone think of any  data structures  that allow us to search quickly? Tables This is a perfectly valid table!  However, often times we want to make it  more  efficient  to search our table. In the previous example, we used an  array  to hold our table and a  linear search   to find the proper car by its  ID #. Right!  We can use a  Binary Search Tree  to organize our records by the key  field.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
 using Binary Trees name: Carey GPA: 3.62 ID: 400655312 name: Linda GPA: 3.99 ID: 000317312 name: Alex GPA: 2.05 ID: 712424512 null Consider this table of students.  Here we use the  student’s name  as the  key  field . name: Abe GPA: 4.00 ID: 987654321 name: Zelda GPA: 3.43 ID: 641632128 name: Jason GPA: 1.55 ID: 105405118 null null null null null null What if we wanted to use the  student ID  # as the  key field ? We order our BST by the 
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 45

lecture15 - Wednesday,March3 rd Tables HashTables...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online