Solution for Data Structures and Algorithms Task
- 24th Nov, 2022
- 17:09 PM
In order to make genealogy software. We need data structures for better and more efficient handling of data. To deal with these types of problems we have to discuss either the data structure first and then the problem or discuss the problem first then we can discuss the data structure most suitable for the problem.
I think we first need to discuss the need for data structures and the kind of problems they help us to solve.
Data structures solve the problem of handling and storing data which have a sequential, hierarchical and structural relationship with each other.
What is the significance of the relationship between data elements?
Relationship plays an important role in categorizing, generalizing and specializing the data
categorized data helps us to see the trends in the data. And most importantly it makes our communication about and of the data easier.
For example, there are millions of species on this planet and most of us have known at least a few hundred species.
How we can take account of these species and their property, the answer is by categorization and generalization of these species we know some species are plants and some are animals, some are cats and some cats specialize are lions or tigers.
Another example, there are many incidents in the history of this planet and we account for those events by a sequential events list.
How does this accounting happen in our brains I think we are implementing data structures in some weird way in our brains.
What are the basic challenges in representing these relationships and elements?
The challenge of representing these relationships is they can be modified or a new relationship can be added.
There can be a new element with some other relationship added and recalling those relationships and elements
these challenges are known as insertion deletion and searching in computer science. our goal is to be most efficient in solving these challenges
Now, let's discuss our problem :
1. Representation of a person (node): this can be dealt with by using a class which I think is a structural data structure in which we define each person and his properties. We can identify each person's properties as a bundle of attributes defined in various categories.
2. Relationships: in this problem relationship is many to many. for example, a child has more than one parent and a parent can have more than one child. To solve this problem, we have to use graphs instead of trees as one node can't have more than one parent in the tree so we have to use graphs, which can be described as a network of nodes connected with edges called relationships.
3. Dealing with data assertion: data assertion can be enforced by defining methods or variables which account for the assertion.
4. A person cannot marry themself: we can have a named variable which accounts for the name of each person in the class definition.
To identify each person's name must be distinct to ensure that we need to have a function which checks for the name duplicacy. if the above is mentioned correctly we should not marry a person with the same name.to check this we need to define a method
5. A person cannot create offspring themself: to deal with this problem we have to define the problem more accurately first, a person who has a married variable as none have a variable called natural offspring list must be none;
6. A single parent can adopt A child this can be accounted for by using the adaptation list which accounts for adopted children for both married and unmarried persons.
7. A same-sex person cannot create offspring: this problem is can be dealt with by having gender variables. if a married couple has the same gender then the natural offspring list must be none.
8. Sibling marriage: this can be dealt with by using a method which ensures the marriage of two people with the same parent can't possibly.
NOTE: marriage between distant-related aunt or cousin is considered valid.
9. now types of relationship: parents of parents must be grandparents, persons with same parents are siblings, persons with different parents but are on the same level are cousins, persons with the same level(height) as parents are uncle or aunt.
Note: In this problem, nodes do not form cycles.