27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Solutions</strong> to Chapter 15 | Databases<br />

15.4 Draw an entity-relationship diagram for a database with companies, people, <strong>and</strong> professionals<br />

(people who work for companies).<br />

SOLUTION<br />

pg 80<br />

People who work for companies are Professionals. So <strong>the</strong>re is an ISA (is a) relationship between<br />

People <strong>and</strong> Professionals (or we could say that a Professional is derived from People).<br />

Each Professional has additional information such as degree, work experiences, etc, in addition<br />

to <strong>the</strong> properties derived from People.<br />

A Professional works for one company at a time, but Companies can hire many Professionals,<br />

so <strong>the</strong>re is a Many to One relationship between Professionals <strong>and</strong> Companies. This “Works<br />

For” relationship can store attributes such as date of joining <strong>the</strong> company, salary, etc. These<br />

attributes are only defined when we relate a Professional with a Company.<br />

A Person can have multiple phone numbers, which is why Phone is a multi-valued attribute.<br />

PName<br />

Sex<br />

DOB<br />

Phone<br />

PID<br />

Address<br />

People<br />

ISA<br />

Date of<br />

Joining<br />

CID<br />

CName<br />

Professional<br />

N<br />

Works For<br />

1<br />

Companies<br />

Degree<br />

Experience<br />

Salary<br />

Address<br />

2 3 5<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Knowledge Based

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!