Entry
Database: Relational: Normalization: Simple: Algorithm: How to do normalization using BBCBASIC?
Dec 24th, 2003 16:59
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 25 December 2003 - 01:44 am -------------------
Database: Relational: Normalization: Simple: Algorithm: How to do
normalization using BBCBASIC?
---
employee
|
+-------------------+----------+
| |
jobhistory offspring
|
salaryhistory
---
---
Steps: Overview:
1. -Store the given tree
2. -Create an output
2. -Run the algorithm
---
---
Steps: Worked out:
1. -Store the given tree in an array
INPUT
--------------------------------------------------------
1. employee# | jobhistory | offspring | -1 |
--------------------------------------------------------
2. jobhistory# | salaryhistory | -1 | |
--------------------------------------------------------
3. salaryhistory# | -1 | | |
--------------------------------------------------------
4. offspring# | -1 | | |
--------------------------------------------------------
This is one of the easiest ways to store the tree.
---
Each row contains a node,
with on the right of it all its children,
---
Followed by -1
(to indicate that there are no more childs for that node)
---
You indicate that that node has a key, by putting a '#' at the end
of its name.
---
2. -Create some output structure in an array
OUTPUT
--------------------------------------------------------
1.
--------------------------------------------------------
2.
--------------------------------------------------------
3.
--------------------------------------------------------
4.
--------------------------------------------------------
3. -Store initially all keys in the output
OUTPUT
--------------------------------------------------------
1. [employee#]
--------------------------------------------------------
2. [jobhistory#]
--------------------------------------------------------
3. [salaryhistory#]
--------------------------------------------------------
4. [offspring#]
--------------------------------------------------------
2. -Run the algorithm: in general
1. Start with the current node equal to the root
employee#
---
1. For the current node
employee#
---
1. If the current node has no children anymore:
1. Return
---
1. For first to last child of that node
1. Add all the keys of the current node to that child
(e.g. put it in front)
OUTPUT
--------------------------------------------------------
1. [employee#]
--------------------------------------------------------
2. employee# [jobhistory#]
--------------------------------------------------------
3. [salaryhistory#]
--------------------------------------------------------
4. employee# [offspring#]
--------------------------------------------------------
2. Next child
---
3. Repeat the above steps for all the childs of the current node
---
---
1. For the current node
jobhistory
---
1. If the current node has no children anymore:
1. Return
---
1. For first to last child of that node
1. Add all the keys of the current node to that child
(e.g. put it in front)
OUTPUT
--------------------------------------------------------
1. [employee#]
--------------------------------------------------------
2. employee# [jobhistory#]
--------------------------------------------------------
3. employee# jobhistory# [salaryhistory#]
--------------------------------------------------------
4. employee# [offspring#]
--------------------------------------------------------
2. Next child
---
3. Repeat the above steps for all the childs of the current node
---
---
1. For the current node
offspring
---
1. If the current node has no children anymore:
1. Return
---
---
1. For the current node
salaryhistory
---
1. If the current node has no children anymore:
1. Return
---
---
So the final result is:
OUTPUT
--------------------------------------------------------
1. [employee#]
--------------------------------------------------------
2. employee# [jobhistory#]
--------------------------------------------------------
3. employee# jobhistory# [salaryhistory#]
--------------------------------------------------------
4. employee# [offspring#]
--------------------------------------------------------
---
---
Internet: see also:
---
Database: Relational: Normalization: Simple: How to do normalization?
http://www.faqts.com/knowledge_base/view.phtml/aid/27720/fid/147
----------------------------------------------------------------------