The union of two non-seasonal and insoluble trees

That's right, I study CS and finish the lab in C, everything went well, but now I hit something that seems impossible for bonus tags. I have been doing this for a day or two and just can't find the right way to complete this.

Introduction

Summary of tasks so far:

Build the game in lizards, where the computer stores questions and objects in a tree structure. The game works as follows: you are thinking about an object, and the computer is trying to guess what you are thinking about, asking you a series of yes / no questions. If the computer correctly guesses, it wins. If you manage to trick him, you will win, but then you must provide the computer with a question that will allow him to correctly guess the next time. That is all that is needed.

An example of a tree structure that you fall into (from left to right):

Tree / Is it made of wood? \ Grass / Is it green? \ Pangolin / Does it have a legs? \ Computer / Is it larger than a microwave? \ Laptop / Does it have a keyboard? \ Desk 

If it is made from the following structure:

 typedef struct node { char* object_name; // object-name (which may be NULL) char* question; // question (which may be NULL) struct node *yesNode; // where if yes (NULL) struct node *noNode; // where if no (NULL) } node; 

If the specified tree is stored in the following file:

 Is it green? Does it have a legs? Does it have a keyboard? Desk Is it larger than a microwave? Laptop Computer Pangolin Is it made of wood? Grass Tree 

Problem

The bonus is as follows:

Make your program an arbitrary number of input files, and graft them together to make a huge tree. Share your files with friends and get a huge collection of pointless questions. To do this correctly you need to scan duplicate records (you cannot do it perfectly, but it should at least weed out obvious duplicates and plant trees in a reasonable way.)

Or it sums up:

Take two tree structures (or files representing tree structures) and combine them together to create a larger tree, removing duplicates.

My problem:

  • How can I remove two unsorted trees?
  • Is it possible to remove duplicates without manually checking all nodes?
  • How do you even loop around to the end of each node and compare it to another tree?

My best idea:

  • Look for a second tree for objects that are in the first tree as well
  • Replace these objects with a pangolin object
  • Find all occurrences of pangolin in the first
  • Place the parent on top of the second tree instead

But this destroys the tree structure and potentially leads to a game break (for example, the main question in the first tree was red), and the second tree was attached to no node and all the elements in the second tree were red?

My main questions are:

  • Do you have any ideas on how you solve this? Or a hack that will work?
  • How can you find duplicates in two trees?
  • How do you connect trees together?
  • How do you lay the bottom of each tree?
+4
source share
1 answer

I think the easiest way to join all your trees is to recreate a minimal entropy decision tree, for example:

  • Consider all the elements.
  • Create a new node.
  • For node, select the question that distinguishes most of the elements in the current set of elements:
    • note that the number of elements that distinguish a question is equal to the sum of all the elements in question in each tree where the question arises.
  • Divide the set of elements according to the question.
  • Repeat recursively from step 2 for each of the two new sets.

When it comes to communicating logically identical, but linguistically different questions ... which is an extremely complex problem in natural language. Without analyzing the language, you could do something simple, for example, compare question strings, ignoring case, punctuation, and spacing.

+3
source

Source: https://habr.com/ru/post/1386304/


All Articles