Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7624941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:07:34+00:00 2026-05-31T05:07:34+00:00

I have an assignment where I have a tree where all the parent nodes

  • 0

I have an assignment where I have a tree where all the parent nodes contain yes or no questions and the leaf nodes contain an answer. There are two children per parent node, a yes node and a no node. This tree needs to be serialized and stored in a file via RandomAccessFile so that the whole tree isn’t written out to the file every time. If the leaf node doesn’t contain the answer the user is looking for, the user submits a new answer and a question to differentiate between the leaf’s answer and the answer he was thinking of. Then this leaf becomes a parent with its own question and two children a “yes” node and a “no” node (these two nodes are new leafs). This process is what’s giving me trouble because if a leaf is already written out to the file how can I overwrite the leaf without spilling into another node’s data (since the byte size of a leaf node changes when it becomes a parent). Note that the program can be killed at any time and its tree structure should still remain intact. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:07:36+00:00Added an answer on May 31, 2026 at 5:07 am

    having a process write to a file, having in mind that the process can be killed at any time … -> journaling

    the byte size of a node changes when it becomes a parent? let’s see …

    a parent node has a question (reference to a string)
    a parent node has a yes node (reference to a node)
    a parent node has a no node (reference to a node)

    a leaf node has an answer (reference to a string)
    a leaf node may have 2 unused references to other nodes …

    so a node has a string reference and 2 node references …

    if both node refs are NULL, it’s a leaf node and the string ref is an answer … else it’s a parent node and the string ref is a question …

    when you serialize that to a file:

    you know a node has a fixed length: 3 pointers(references)
    so your new string reference will be current position + 3 pointer length
    write that address as string ref …
    write 2 null references for now … (we don’t know yet where those nodes will be written)
    write the string

    traverse your tree and keep in mind that you have to update the skipped 2 node references when you know the position of the node in your file …

    when you update a node (leaf becomes parent):

    write the new question string to the file, and store it’s address
    store the address of the current answer string …
    replace the string reference in the old node with the new question string address
    write a new node for the old answer (string ref is the stored address for the current answer) and update one of the old nodes node-references (yes or no, accordingly)
    write a new node for the other answer (string reference can be stored 3 pointers later, so address is known)
    write the new answer string
    update the old nodes other node reference

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there exceptions for types which can't have thier assignment operator overloaded? Specifically, I'm
I'm working on an AVL tree assignment and I have a quick question about
I have this assignment to prove that this problem: Finite alphabet £, two strings
I have an assignment on optimal binary search trees and some questions came up
for a programming assignment, I have to load a tree into an array in
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
I have an assignment in a language-independent class, and part of it is using
I have an assignment to create a GUI using MATLAB GUIDE and am having
I have an assignment about fftw and I was trying to write a small
So I am being taught assembly and we have an assignment which is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.