Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I uploaded that question 3 time, ut no one solve or any comment, is there anyone, any expert who can solce this question? or there

I uploaded that question 3 time, ut no one solve or any comment, is there anyone, any expert who can solce this question? or there really is not such a person (i will %100 thumbs up if anyone do)

image text in transcribed

public class BST, Value> { private Node root; // root of BST // Inner class private class Node { private Key key; // key private Value val; // associated value private Node left, right; // links to subtrees public Node(Key key, Value val) { this.key = key; this.val = val; } public String toString(){return " ("+key+ ":"+ val + ") ";} } //////////////////////////////////////////////////////////////////////////// public String getRoot(){ return root.toString(); } /////////////////////////////////////////////////////////////////////////// //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// /** * deleteMin(). * we go left until finding a Node * that has a null left link and then replace the link to that node by * its right link (simply by returning the right link in the recursive * method). */ public void deleteMin(){root = deleteMin(root);} private Node deleteMin(Node x){ if (x.left == null) return x.right; // min is the node without left child x.left = deleteMin(x.left); // advance untill min is found return x; } public void delete(Key key){ root = delete(root, key); } private Node delete(Node x, Key key) { // node to be deleted can not found if (x == null) { return null; } int cmp = key.compareTo(x.key); if (cmp  0) { // if greater go right x.right = delete(x.right, key); } else { // x is the node to be deleted // easy case zero or one child if (x.right == null) {// maybe one child at left, return it or null return x.left; } if (x.left == null) {// maybe one child at right, return it or null return x.right; } // hard case two childs Node t = x; // t and x are the nodes to be deleted x = min(t.right); // x is min at the right subtree x.right = deleteMin(t.right); // x.right becomes a new subtree after removal of its min x.left = t.left; // nobody is pointing to t } return x; } //////////////////////////////////////////////////////////////////////////// //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// // Recursive Show: inorder traversal. public void show(){ show(root); System.out.println(); } public void show(Node x){ if(x == null) return; show(x.left); System.out.print(" ("+x.key+ ":"+ x.val + ") "); show(x.right); } //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// public Node min(){ return min(root); } public Node min(Node x){ if(x.left == null) return x; return min(x.left); } //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// //////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// public String max(){ return max(root); } public String max(Node x){ if(x.right== null) return " ("+x.key+ ":"+ x.val + ") "; return max(x.right); } //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// // public search calls for private search public Value get(Key key) { // search inside the tree from the root. // Note that: (private) root is invisible outside the tree return get(root, key); } /** * Private Search: Recursive Search Algorithm * Return value associated with key in the subtree rooted at x * @param x : root node of the subtree * @param key : search key * @return : value if key is found, null otherwise */ private Value get(Node x, Key key) { // return null if subtree is empty if (x == null) { return null; } int cmp = key.compareTo(x.key); // search recursively in the appropriate subtree // if less, go left if (cmp  0) { return get(x.right, key); // move right subtree, if key is smaller } // if found, return value else { return x.val; // return value if found at the root of the subtree } } //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// // public insert call public void put(Key key, Value val) { root = put(root, key, val); } /** * Public insert call: * Recursive logic: * if empty, return new node to the call * ow compare with node x, update x's left or right link * @param x : root node of the subtree * @param key : key-value pair to be inserted * @param val : key-value pair to be inserted * @return */ private Node put(Node x, Key key, Value val) { // Insertion occurs only at the bottom, return new node if (x == null) { return new Node(key, val); // node count N is 1 } // compare search key against the root node x int cmp = key.compareTo(x.key); // update link from parent x to its child if (cmp  0) { // set right link, to the resulting right subtree after insertion x.right = put(x.right, key, val); } else { // update already-existing key with new value x.val = val; } return x; } //\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\// //////////////////////////////////////////////////////////////////////////// } 
Inner BST Following 9 movie names will be the key . Star Wars, The Dark Knight, Gladiator . Up, Wall-E, Superman, . Titanic, Amelie, Casablanca Corresponding values will be rating scores. Outer BST Following 3 person wl be the key . Ahmet, Berk, Selin, Corresponding values wll be Inner BST described above. You are given the code for a Binary Search Tree. Use this code to implement nested BST. In the outer BST, names of a person will be the key for an inner BST. Inner BST will store name of the movies as keys and scores given to them by the person (key of outer BST) as values. 1. Create a client BST, fill the nested BST as follows and print key value pairs Ahmet: (Amelie:1.0) (Casablanca:1.0) (Gladiator:5.0) (Star Wars:5.0) (Superman:3.0) (The Dark Knight:5.0) (Titanic:1.0) (Up:3.0) (Wall- E:3.0) Berk: (Amelie:1.0) (Casablanca:1.0) (Gladiator:3.0) (Star Wars:3.0) (Superman:5.0) (The Dark Knight:3.0) (Titanic:1.0) (Up:5.0) (Wall- E:5.0) . Selin: (Amelie:5.0) (Casablanca:5.0) (Gladiator:1.0) (Star Wars:1.0) (Superman:3.0) (The Dark Knight:1.0) (Titanic:5.0) (Up:3.0) (Wall- E:3.0) 2. Write a function in the client, that computes the similarity between the preferences of two people a and b. Calculate similarities for all pairs as follows. sim (a, b) -1 + film(score(a, fil (b. film))2 m) - score Inner BST Following 9 movie names will be the key . Star Wars, The Dark Knight, Gladiator . Up, Wall-E, Superman, . Titanic, Amelie, Casablanca Corresponding values will be rating scores. Outer BST Following 3 person wl be the key . Ahmet, Berk, Selin, Corresponding values wll be Inner BST described above. You are given the code for a Binary Search Tree. Use this code to implement nested BST. In the outer BST, names of a person will be the key for an inner BST. Inner BST will store name of the movies as keys and scores given to them by the person (key of outer BST) as values. 1. Create a client BST, fill the nested BST as follows and print key value pairs Ahmet: (Amelie:1.0) (Casablanca:1.0) (Gladiator:5.0) (Star Wars:5.0) (Superman:3.0) (The Dark Knight:5.0) (Titanic:1.0) (Up:3.0) (Wall- E:3.0) Berk: (Amelie:1.0) (Casablanca:1.0) (Gladiator:3.0) (Star Wars:3.0) (Superman:5.0) (The Dark Knight:3.0) (Titanic:1.0) (Up:5.0) (Wall- E:5.0) . Selin: (Amelie:5.0) (Casablanca:5.0) (Gladiator:1.0) (Star Wars:1.0) (Superman:3.0) (The Dark Knight:1.0) (Titanic:5.0) (Up:3.0) (Wall- E:3.0) 2. Write a function in the client, that computes the similarity between the preferences of two people a and b. Calculate similarities for all pairs as follows. sim (a, b) -1 + film(score(a, fil (b. film))2 m) - score

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago