Hey today I was in a job interview where they gave us a tree with unknown structure(could b not binary) and i was asked to insert it to a database in a certain order where I could turn back the db into tree and show I have done it using ER model, every node in the tree has two data members data1 and data2
can someone answer or give me an hint for how it's done ?
EDIT: what I wrote is because every child has a father we should add relation between the nodes father and son because son has onley one father the son has a arrow one to one to his father ' i gave for everyy one of them a开发者_高级运维n index and every sun had his father pointer and what does it got to do with the ER model ' i dont knoww too this is why i asked it here.
One thing you can do is to label en entire branch with an index (say 1,2,3..) and now the whole branch with a particular index can be taken as a record. Look over entire tree and try to find some relation between the data and assign some attribute name to every node at each level of that tree. Now once u have done this you can separate out what those attributes are.. and make an entity which could represent those attributes(or properties). Now once you your entity is decided you can make an entity and attributes in an ERD(Entity Relationship Diagram)
if you have gone through network model of designing database then you could get some more hint
start thinking from bottom level,then proceed towards the solution,
Good Luck
What was the position you interviewed for ?
There is no such technical term as an "ER model", it is a lay descriptive term. There are technical terms:
- Data Model
- the Relational Model (RM)
- Entity Relation Diagram (ERD)
Which is the Entities and Relations only; the Data Model minus the columns and datatypes
Fair enough, it has been bastardised into "ER model" in some parts of the world.
If they actually asked you to provide an "ER model", they are not on the ball. But if they were on the ball, they would ask for EITHER a Data Model (unlikely for an interview) OR a ER Diagram (likely).
I think, these days, if anyone talks database, and they do not specify the type, Relational is expected.
If you talked "pointer" and "index" at the ER Diagram stage in an interview with me, I would be showing you the door. Thvia the FK e first demonstrates no understanding of the Relational Model; the second is too much detail at that high level of modelling. "Father/son" demonstrates that you do not understand B-Trees ("every member has two nodes") and Relational (the child references the parent anyway, you do not need additional work or "pointer")
When you have been give a clear acceptance/rejection notice for the job that you interviewed for, post again, I will supply the answer.
精彩评论