Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the description of the assignment: - Implement an AVL tree of ints stored in a random access file. - Duplicates can be entered

Here is the description of the assignment: - Implement an AVL tree of ints stored in a random access file. - Duplicates can be entered in the tree and will be recorded with a count value like we did in class - The implementation MUST NOT load the whole tree in memory. Each operation only makes copies of the nodes it needs for that operation. Modified nodes must be written to the file. - You must create a main method to test your code. Here is an example of the random access file: image text in transcribed //IMPLEMENT THE FOLLOWING METHODS

import java.io.*;

import java.util.*;

public class AVLTree {

/*

Implements a ALV tree of ints stored in a random access file.

Duplicates are recorded by a count field associated with the int

*/

public static final int CREATE = 0;

public static final int REUSE = 1;

private RandomAccessFile f;

private long root; //the address of the root node in the file

private long free; //the address in the file of the first node in the free list

private class Node {

private long left;

private long right;

private int data;

private int count;

private int height;

private Node(long L, int d, long r) {

//constructor for a new node

this.left = L;

this.data = d;

this.right = r;

}

private Node(long addr) throws IOException {

// constructor for a node that exists and is stored in the file

}

private void writeNode(long addr) throws IOException {

// writes the node to the file at location addr

}

}

public AVLTree(String fname, int mode) throws IOException {

//if mode is CREATE a new empty file is created

//if mode is CREATE and a file with file name fname exists the file with

// fname must be deleted before the new empty file is created

//if mode is REUSE an existing file is used if it exists otherwise a new empty

// file is created

}

public void insert(int d) throws IOException {

//insert d into the tree

//if d is in the tree increment the count field associated with d

}

public int find(int d) throws IOException {

//if d is in the tree return the value of count associated with d

//otherwise return 0

return 0;

}

public void removeOne(int d) throws IOException {

//remove one copy of d from the tree

//if the copy is the last copy remove d from the tree

//if d is not in the tree the method has no effect

}

public void removeAll(int d) throws IOException {

//remove d from the tree

//if d is not in the tree the method has no effect

}

public void close() {

//close the random access file

//before closing update the values of root and free if necessary

}

}

Contents Address Root0 128 Free8 72 212 16 150 1 44 184 72 240 100 10 0 128 80 23 156 300 4 0 184 0 212 175 2 0 240 44 268 200 2 296125 3 0 324 50 21 296 324 268 156 100 Data Count Height Left Right Contents Address Root0 128 Free8 72 212 16 150 1 44 184 72 240 100 10 0 128 80 23 156 300 4 0 184 0 212 175 2 0 240 44 268 200 2 296125 3 0 324 50 21 296 324 268 156 100 Data Count Height Left Right

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

Students also viewed these Databases questions