MySQL Forums
Forum List  »  Newbie

Re: Teaching mysql to teens
Posted by: Rick James
Date: March 01, 2011 11:17PM

For teaching INDEXes, ...

Bring in a telephone directory or dictionary. (I mean the old fashioned paper kind.) That can be handy for explaining binary tree search. Open to the middle. Ask whether the name is before or after what is on that page. Then split the first (or last) half of the book. Repeat until you find your name.

If they have had logarithms, have them count the steps. Then do the math to take log (base 2) of the number of entries. Note that that is how many steps they took (or at least very close). That may be the only real application of logs they will every hear of. (That is "complexity" of the problem. It is "order log N" or "O(logN)".)

A binary tree is close to the way a BTree works, which most database engines use.

Find your name in a phone book -- note that your last name is most useful.
Now find your name given only your first name -- not efficient -- "O(N)"
Search by your phone number -- yuck! Then talk about "reverse directories".

To get more complex, look for all person(s) with last name = 'James' and first initial = 'R'. See how many such names there are. Note how efficient this 'range' query is.
Now look for 'Rick J.' -- back to being very inefficient.

Other thoughts:

Ask them what these do:
SELECT first_name, last_name FROM phone_book ORDER BY first_name, last_name;
SELECT first_name, last_name, phone_number FROM phone_book ORDER BY phone_number;
SELECT first_name, last_name, phone_number FROM phone_book WHERE phone_number LIKE '212%';
SELECT first_name, last_name FROM phone_book WHERE address LIKE '%Main St%';

Exercise:
Write a SELECT to find out how many other people in the phone book have the same first name as you do.

Note that the parts of a SELECT are done in the same order that the syntax requires:
FROM
WHERE
GROUP BY
HAVING
ORDER BY
LIMIT

Options: ReplyQuote


Subject
Written By
Posted
March 01, 2011 05:26AM
Re: Teaching mysql to teens
March 01, 2011 11:17PM
March 02, 2011 01:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.