In each of these exercises, consider the relation, CKs, and FDs. Determine if the relation is in BCNF, and if not in BCNF give a non-loss decomposition into BCNF relations. The last 5 questions are abstract and give no context for the relation nor attributes.
1. Consider a relation Player which has information about
players for some sports league. Player has attributes id, first,
last, gender. id is the only CK and the FDs are:
idfirst
idlast
idgender
Player-sample data
ID | First | Last | gender |
1 | Jim | Jones | Male |
2 | Betty | Smith | Female |
3 | Jim | Smit | Male |
4 | Lee | Mann | Male |
5 | Samantha | McDonald | Female |
2.Consider a relation Employee which has information about
employees in some company. The employee has attributes id, first,
last, sin (social insurance number) where id and sin are the only
CKs, and the FDs are:
idfirst
idlast
sinfirst
sinlast
idsin
sinid
Employee – sample data
ID | First | Last | SIN |
1 | Jim | Jones | 111222333 |
2 | Betty | Betty | 333333333 |
3 | Jim | Smith | 456789012 |
4 | Lee | Mann | 123456789 |
5 | Samantha | McDonald | 987654321 |
In: Computer Science
a/ write 4 numbers from your choice
b/ Write a java code to create a linked list containing the 4 numbers
In: Computer Science
/*
* bitCount - returns count of number of 1's in word
* Examples: bitCount(5) = 2, bitCount(7) = 3
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 40
* Rating: 4
*/
int bitCount(int x) {
return 2;
}
Can you please complete this code in C language without the use of any loops such as if, do, while, for, switch, etc., macros, other operations, such as &&, ||, -, or ?: .
In: Computer Science
In: Computer Science
using python/IDLE
(1) Prompt the user to enter a string of their choosing. Store
the text in a string. Output the string. (1 pt)
Ex:
Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue!
(2) Implement a print_menu() function, which has a string as a
parameter, outputs a menu of user options for analyzing/editing the
string, and returns the user's entered menu option and the sample
text string (which can be edited inside the print_menu() function).
Each option is represented by a single character.
If an invalid character is entered, continue to prompt for a
valid choice. Hint: Implement the Quit menu option before
implementing other options. Call print_menu() in the main
section of your code. Continue to call print_menu() until the user
enters q to Quit. (3 pts)
Ex:
MENU c - Number of non-whitespace characters w - Number of words f - Fix capitalization r - Replace punctuation s - Shorten spaces q - Quit Choose an option:
(3) Implement the get_num_of_non_WS_characters() function.
get_num_of_non_WS_characters() has a string parameter and returns
the number of characters in the string, excluding all whitespace.
Call get_num_of_non_WS_characters() in the print_menu() function.
(4 pts)
Ex:
Number of non-whitespace characters: 181
(4) Implement the get_num_of_words() function. get_num_of_words()
has a string parameter and returns the number of words in the
string. Hint: Words end when a space is reached except for the
last word in a sentence. Call get_num_of_words() in the
print_menu() function. (3 pts)
Ex:
Number of words: 35
(5) Implement the fix_capitalization() function.
fix_capitalization() has a string parameter and returns an updated
string, where lowercase letters at the beginning of sentences are
replaced with uppercase letters. fix_capitalization() also returns
the number of letters that have been capitalized. Call
fix_capitalization() in the print_menu() function, and then output
the the edited string followed by the number of letters
capitalized. Hint 1: Look up and use Python functions
.islower() and .upper() to complete this task. Hint 2: Create an
empty string and use string concatenation to make edits to the
string. (3 pts)
Ex:
Number of letters capitalized: 3 Edited text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
(6) Implement the replace_punctuation() function.
replace_punctuation() has a string parameter and two keyword
argument parameters exclamation_count and
semicolon_count. replace_punctuation() updates the
string by replacing each exclamation point (!) character with a
period (.) and each semicolon (;) character with a comma (,).
replace_punctuation() also counts the number of times each
character is replaced and outputs those counts. Lastly,
replace_punctuation() returns the updated string. Call
replace_punctuation() in the print_menu() function, and then output
the edited string. (3 pts)
Ex:
Punctuation replaced exclamation_count: 1 semicolon_count: 2 Edited text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here, our hopes and our journeys continue.
(7) Implement the shorten_space() function. shorten_space() has a
string parameter and updates the string by replacing all sequences
of 2 or more spaces with a single space. shorten_space() returns
the string. Call shorten_space() in the print_menu() function, and
then output the edited string. Hint: Look up and use Python
function .isspace(). (3 pt)
Ex:
Edited text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue!
In: Computer Science
For m=4 bits, using the signed two’s complement representation, (neatly) construct a table consisting of all possible 4 bit sequences along with their base 10 values.
In: Computer Science
There is a lot of repeating data in the file example below in the form of key names being in each and every record. This is a tradeoff to allow each record to have a different mix of (or even entirely different) keys. CSV files generally have one record (the first one in the file) which is simply a record of each headers (or "key") for each column and every record has the same fields and keys.
My tsv2json utility has but one argument: tsv2json [-c | --compact]
This lets you use the CSV approach when you know every record contains the same fields.
What are the plusses and minuses of each approach? Also, what are your thoughts on redundancy and size, and processing-convenience in file formats?
File Example:
[ { "type": "act", "line_id": 1, "play_name": "Henry IV", "speech_number": "", "line_number": "", "speaker": "", "text_entry": "ACT I" }, … { "type": "line", "line_id": 111396, "play_name": "A Winters Tale", "speech_number": 38, "line_number": "", "speaker": "LEONTES", "text_entry": "Exeunt" } ]
In: Computer Science
Which of the following statements are true for both bubble sort and heapsort?.
a) Largest values accumulate on the right
b) Both must be implemented with arrays
c) Largest values accumulate on the left
d) This is a trick question, there is nothing in common. Heapsort uses heaps, which is a tree.
e) Smallest values accumulate on the left
In: Computer Science
1) (chapter 3)What is a sticky form?
2)What is the purpose of using the following statements:
if ($_SERVER['REQUEST_METHOD'] = = 'POST') {
// Handle the form.
} else {
// Display the form.
}
3) (PHP Chapter 2) PHP programming: POST and GET methods of a form, how to retrieve the input in the submission php code. $_POST, $_GET(), which way is more secure than the other? Why?
4) You can find how many records get affected in php Which
function to use?
In: Computer Science
Using your knowledge of the college environment, determine the functional dependencies that exist in the following table. After determining the functional dependencies convert this table to an equivalent collection of tables that are in third normal form.
Student (StudentNum, StudentName, NumCredits, AdvisorNum,AdvisorName,
DeptNum, DeptName, AdvisorNum, AdvisorName, DeptNum, DeptName, (CourseNum, Description, Term, Grade))
In: Computer Science
Write a method that takes an array of integers as input. The method should find and display two indices m and n such that if you sort the elements from index m to index n the entire array would be sorted. The method should minimize m − n, that is it should find the smallest subsection for the array that needs to be sorted. For example,
int[] a = {2, 4, 6, 7, 9, 8, 12, 15, 5, 13, 18, 20}
get_unsorted_section(a); // prints 2 and 9
Please use Java. Thanks!
In: Computer Science
Write a program:
For this assignment, you will need to write three source code files as well as two header files. Each of these files is relatively short, but many inexperienced programmers are overwhelmed by the idea of writing a program as multiple files. "Where do I start?!!" is a common refrain. This assignment sheet attempts to walk you through the steps of writing a multi-file program.
The steps outlined below should not be thought of as a purely linear process, but rather an iterative one - For example, work a little on Step 1, then a little on Step 2, then test what you've written (Step 3).
Step 1: Write the CreditAccount class declaration
The CreditAccount class represents information about a credit card account. The code for the CreditAccount class will be placed in two separate files, which is the norm for non-template C++ classes.
The header file for a class contains the class declaration, including declarations of any data members and prototypes for the methods of the class. The name of the header file should be of the form ClassName.h (for example, CreditAccount.h for the header file of theCreditAccount class).
A skeleton for the CreditAccount.h file is given below. As shown, a header file should begin and end with header guards to prevent it from accidentally being #included more than once in the same source code file (which would produce duplicate symbol definition errors). The symbol name used in the header guards can be any valid C++ name that is not already in use in your program or the C/C++ libraries. Using a name of the format CLASSNAME_H (like CREDIT_ACCOUNT_H in the code below) is recommended to avoid naming conflicts.
#ifndef CREDIT_ACCOUNT_H #define CREDIT_ACCOUNT_H //***************************************************************** // FILE: CreditAccount.h // AUTHOR: your name // LOGON ID: your z-ID // DUE DATE: due date of assignment // // PURPOSE: Contains the declaration for the CreditAccount class. //***************************************************************** class CreditAccount { // Data members and method prototypes for the CreditAccount class go here . . . }; #endif
Data Members
The CreditAccount class should have the following private data members:
an account number (a char array with room for 19 characters PLUS the null character, i.e. 20 elements total)
a customer name (a char array with room for 20 characters PLUS the null character)
a credit limit (a double variable)
a current account balance (a double variable)
Note: Make that sure you code your data members in THE EXACT ORDER LISTED ABOVE and with THE EXACT SAME DATA TYPES. If you use float instead of double or only make the name array 20 characters long instead of 21, your final program will not work correctly!
C++11 Initialization Option for Data Members
C++11 adds the ability to initialize the non-static data members of a class at the time you declare them using a "brace-or-equal" syntax. This is very convenient, and can eliminate most or all of the code from your default constructor. Here are a few examples of the kind of initializations you can do in a class declaration:
class Foo { // Data members private: int x = 0; // Initialize x to 0 double y = 9.9; // Initialize y to 9.9 char text[21]{}; // Initialize text to an // empty string char name[11]{'J', 'o', 'h', 'n', '\0'}; // Initialize name to "John" string s{"Hello"}; // Initialize s to "Hello" etc. };
Feel free to use this option if you want to.
Method Prototypes
The CreditAccount class declaration should (eventually) contain public prototypes for all of the methods in the CreditAccount.cpp source code file described in Step 2 below.
Step 2: Write the CreditAccount class implementation
The source code file for a class contains the method definitions for the class. The name of the source code file should be of the form ClassName.cpp or ClassName.cc (for example, CreditAccount.cpp for the source code file of the CreditAccount class).
The CreditAccount class implementation should (eventually) contain definitions for all of the methods described below. Make sure to #include "CreditAccount.h" at the top of this file.
CreditAccount default constructor - This "default" constructor for the CreditAccount class takes no parameters. Like all C++ constructors, it does not have a return data type.
This method should set the account number and customer name data members to "null strings". This can be done by copying a null string literal ("") into the character array using strcpy() or by setting the first element of the array to a null character ('\0'). The credit limit and account balance data members should be set to 0.
(If you're working in C++11 and you initialized the data members at declaration as described above under C++11 Initialization Option for Data Members, this method's body can be empty. You still need to code the method though, even though it won't actually do anything.)
Alternate CreditAccount constructor - Write another constructor for the CreditAccount class that takes four parameters: 1) a character array that contains a new account number, 2) a character array that contains a new customer name, 3) a double variable that contains a new credit limit, and 4) a double variable that contains a new balance. DO NOT GIVE THESE PARAMETERS THE SAME NAMES AS YOUR DATA MEMBERS.. Like all C++ constructors, this constructor does not have a return data type.
Use strcpy() to copy the new account number parameter into the account number data member and the new customer name parameter into the customer name data member. The new credit limit and new account balance parameters can be assigned to the corresponding data members.
getAccountNumber() - This accessor method takes no parameters. It should return the account number data member. In C++, the usual return data type specified when you are returning the name of a character array is char* or "pointer to a character" (since returning an array's name will convert the name into a pointer to the first element of the array, which in this case is data type char.
getName() - This accessor method takes no parameters. It should return the customer name data member.
getLimit() - This accessor method takes no parameters. It will have a return data type of double. It should return the credit limit data member.
getBalance() - This accessor method takes no parameters. It will have a return data type of double. It should return the account balance data member.
processPayment() - This method takes one parameter, a double payment amount. It returns nothing. The payment amount should be subtracted from the current account balance data member. (Note that it is possible to have a negative balance on an account as a result of overpayment.)
processCharge() - This method takes one parameter, a double charge amount. It returns a Boolean value. If the charge amount plus the current account balance is greater than the credit limit, the method should return false without altering the balance (because this charge has been declined). Otherwise, the charge amount should be added to the account balance and the method should return true.
print() - This method takes no parameters and returns nothing. The method should print the values of the data members for the account in a format similar to the following:
Account Number: 1938-2348-3843-9683 Name: John Smith Credit Limit: $5000.00 Current Balance: $127.65 CR
If the balance is negative, it should be printed as a positive number but followed by the letters "CR" (for credit). For example, the sample output shown above is for an account with a balance of -127.65.
Step 3: Test and debug the CreditAccount class
As you write your declaration and implementation of the CreditAccount class, you should begin testing the code you've written. Create a basic main program called assign2.cpp that tests your class. This is not the final version of assign2.cpp that you will eventually submit. In fact, you'll end up deleting most (or all) of it by the time you're done with the assignment. An example test program is given below.
You do not have to have written all of the methods for the CreditAccount class before you begin testing it. Simply comment out the parts of your test program that call methods you haven't written yet. Write one method definition, add its prototype to the class declaration, uncomment the corresponding test code in your test program, and then compile and link your program. If you get syntax errors, fix them before you attempt to write additional code. A larger amount of code that does not compile is not useful - it just makes debugging harder! The goal here is to constantly maintain a working program.
#include <iostream> #include "CreditAccount.h" using std::cout; using std::endl; int main() { char code1[20] = "1111-1111-1111-1111"; char name1[21] = "Jermaine Arnold"; char code2[20] = "2222-2222-2222-2222"; char name2[21] = "Vanessa Long"; // Test default constructor CreditAccount account1; // Test alternate constructor CreditAccount account2(code1, name1, 1000.00, 520.25); // Account with negative balance CreditAccount account3(code2, name2, 1500.00, -62.95); // Test print() method and whether constructors // properly initialized objects cout << "Printing account1\n\n"; account1.print(); cout << endl; cout << "Printing account2\n\n"; account2.print(); cout << endl; cout << "Printing account3\n\n"; account3.print(); cout << endl; // Test accessor methods cout << "Testing accessor methods for account2\n\n"; cout << account2.getAccountNumber() << endl; cout << account2.getName() << endl; cout << account2.getLimit() << endl; cout << account2.getBalance() << endl << endl; // Test the processCharge() method with a successful charge bool chargeAccepted = account2.processCharge(400.00); if (chargeAccepted) cout << "Charge of $400.00 accepted, new balance on account2 is $" << account2.getBalance() << endl; else cout << "Charge of $400.00 on account2 declined\n"; cout << endl; // Test the processCharge() method with a failed charge chargeAccepted = account2.processCharge(620.00); if (chargeAccepted) cout << "Charge of $620.00 accepted, new balance on account2 is $" << account2.getBalance() << endl; else cout << "Charge of $620.00 on account2 declined\n"; cout << endl; // Test the processPayment() method cout << "Payment of $500.00 on account2\n\n"; account2.processPayment(500.00); account2.print(); cout << endl; // Test the processPayment() method by overpaying - should now have a // credit on the account cout << "Payment of $750.00 on account2\n\n"; account2.processPayment(750.00); account2.print(); return 0; }
Once your CreditAccount class has been thoroughly tested and debugged, it's time to write the second class for this assignment.
Step 4: Write the AccountDB class declaration
The AccountDB class represents a database of CreditAccount objects. Like the CreditAccount class, the code for this class will be placed in two separate files.
Place the class declaration in a header file called AccountDB.h. Like the file CreditAccount.h you wrote in Step 1, this file should begin and end with header guards to prevent it from accidentally being #included more than once in the same source code file.
After the header guard at the top of the file but before the class definition, make sure to #include "CreditAccount.h".
Data Members
The AccountDB class should have the following two private data members:
An array of 20 CreditAccount objects
An integer that specifies the number of CreditAccount objects actually stored in the array
Note: Once again, make sure you code your data members in THE EXACT ORDER LISTED ABOVE and with THE EXACT SAME DATA TYPES.
Method Prototypes
The AccountDB class declaration should (eventually) contain public prototypes for all of the methods in the AccountDB.cpp source code file described in Step 5 below.
Step 5: Write the AccountDB class implementation
The AccountDB class implementation should (eventually) contain definitions for all of the methods described below. Make sure to #include "AccountDB.h" at the top of this file.
AccountDB default constructor - This "default" constructor for the AccountDB class takes no parameters. Like all C++ constructors, it does not have a return data type.
This constructor is called to create an empty database, so this method should set the number of accounts data member to 0.
(As with the CreditAccount class, if you initialize the number of accounts data member to 0 when you declare it, this method's body can be empty. You still need to code the method with an empty body.)
Alternate AccountDB constructor - Write a second constructor for the AccountDB class that takes one parameter: a C++ string that contains the name of an existing database file. Like all C++ constructors, this constructor does not have a return data type.
This constructor should do the following:
Declare an input file stream variable (the code below assumes it is named inFile).
Open the file stream for binary input. Check to make sure the file was opened successfully as usual.
Read the database file into your AccountDB object. You can do this with a single statement:
inFile.read((char*) this, sizeof(AccountDB));
Close the file stream.
print() - This method takes no parameters and returns nothing.
This method should first print a descriptive header line (e.g., "Credit Card Account Listing"). It should then loop through the array of CreditAccount objects and print each of the elements that contains account data, with a blank line between each account. Here we see some of the power of object-oriented programming: since each element of the array is an object, we can call a method for that object. We've already written a print() method for the CreditAccount class, so printing an element of the account array is as easy as calling print() for the array element. The syntax for calling a method using an array element that is an object is pretty straightforward:
arrayName[subscript].methodName(arguments);
Step 6: Write the main program
Since most of the logic of the program is embedded in the two classes you wrote, the main() routine logic is extremely simple.
Create an AccountDB object using the alternate constructor you wrote. Pass the filename string literal "accounts" as an argument to the constructor.
Call the print() method for the AccountDB object.
Part 2:
For this part of the assignment, you'll need to write one new file and then modify two of the files you wrote for Part 1.
Step 1: Write a makefile
The file named makefile tells the make utility how to build the final executable file from your collection of C++ source code and header files. The makefile for this assignment is given in its entirety below. Makefiles for future assignments will follow this basic pattern.
IMPORTANT NOTE: The commands that appear in the makefile below MUST be indented as shown. Furthermore, the indentation MUST be done using a tab character, not spaces. If you don't indent your makefile commands, or indent using spaces, your makefile WILL NOT WORK.
# # PROGRAM: assign2 # PROGRAMMER: your name # DATE DUE: due date of program # # Compiler variables CCFLAGS = -Wall -std=c++11 # Rule to link object code files to create executable file assign2: assign2.o CreditAccount.o AccountDB.o g++ $(CCFLAGS) -o assign2 assign2.o CreditAccount.o AccountDB.o # Rules to compile source code files to object code assign2.o: assign2.cpp AccountDB.h g++ $(CCFLAGS) -c assign2.cpp CreditAccount.o: CreditAccount.cpp CreditAccount.h g++ $(CCFLAGS) -c CreditAccount.cpp AccountDB.o: AccountDB.cpp AccountDB.h g++ $(CCFLAGS) -c AccountDB.cpp # The AccountDB class depends on the CreditAccount class AccountDB.h: CreditAccount.h # Pseudo-target to remove object code and executable files clean: -rm *.o assign2
Once you've written the file makefile, try using the make utility to compile and link your program.
Step 2: Add the following methods to the AccountDB class
sortAccounts() - This method takes no parameters and returns nothing.
This method should sort the array of CreditAccount objects in ascending order by account number using the insertion sort algorithm.
The sort code linked to above sorts an array of integers called numbers of size size. You will need to make a substantial number of changes to that code to make it work in this program:
This will be a method, not a function. Change the parameters for the method to those described above.
In the method body, change the data type of bucket to CreditAccount. This temporary storage will be used to swap elements of the array of CreditAccount objects.
In the method body, change any occurrence of numbers to the name of your array of CreditAccount objects and size to numAccounts (or whatever you called the data member that tracks the number of valid CreditAccount objects stored in the array).
The comparison of accountArray[j-1] and bucket will need to use the C string library function strcmp() to perform the comparison. Also, you'll need to use the getAccountNumber() method to access the accountNumber data member within each CreditAccountobject. The final version of the inner for loop should look something like this:
for (j = i; (j > 0) && (strcmp(accountArray[j-1].getAccountNumber(), bucket.getAccountNumber()) > 0); j--) ...
It is legal to assign one CreditAccount object to another; you don't need to write code to copy individual data members.
Add a call to the sortAccounts() method to the end of the alternate constructor you wrote for the AccountDB class. This will sort the array of CreditAccount objects that were read in from the input file.
searchForAccount() - This method should take one parameter: a character array containing the account number code of the CreditAccount to search for (searchNumber). The method should return an integer.
The logic for this method is a variation of the binary search of a sorted list strategy.
int low = 0; int high = number of valid CreditAccount objects in the array - 1; int mid; while (low <= high) { mid = (low + high) / 2; if (searchNumber is equal to accountNumber data member of accountArray[mid]) return mid; if (searchNumber is less than accountNumber data member of accountArray[mid]) high = mid - 1; else low = mid + 1; } return -1;
As usual, you'll need to use strcmp() to perform the comparison of account numbers.
processTransactions() - This method should take one parameter: a C++ string containing the name of a file of credit card transaction data. The method should return nothing.
The method should open the specified transaction file for input (not binary input - this file is a text file). Make sure to test that the file was opened successfully; if it wasn't, print an error message and exit the program.
Before reading any transactions, the function should print a report header and column headers. The function should then read transaction data from the file until end of file is reached. A typical transaction is shown below. The first field on the transaction record is the date of the transaction, followed by an account number, then the transaction type ('C' for charge or 'P' for payment), and finally a transaction amount.
06/19 1111-1111-1111-1111 C 430.00
Once all of the data for a given transaction has been read, call the searchForAccount() method to search the accounts array for the account number given in the transaction. If the account number is present in the array, then the transaction may be processed. For a payment, simply call the processPayment() method for the object that contains a matching account number, passing it the transaction amount. For a charge, call the processCharge() method for the object that contains a matching account number, passing it the transaction amount.
For each transaction record processed, print a line in a transaction report with the data from the record and the updated balance for that account. If the balance is negative, it should be printed as a positive number but followed by the letters "CR". If the transaction account number was not found in the account array or if a charge exceeded the account's credit limit (i.e., if the processCharge() method returned false), print an appropriate error message instead of the account balance.
After all transactions have been processed, close the transaction file.
Step 3: Add two method calls to the main program
The main() routine logic will now look like this:
Create an AccountDB object using the alternate constructor you wrote. Pass the filename string "accounts" as an argument to the constructor.
Call the print() method for the AccountDB object.
Call the processTransactions() method for the AccountDB object. Pass the filename string "transactions.txt" as an argument to the method.
Call the print() method for the AccountDB object.
This completes the project.
In: Computer Science
Complete the Tree class within the following program: BalancingTrees.zip. There are three two classes and one driver in this program. You just need to complete or add the Tree class code.
In java please.
The code for tree class:
public class Tree {
Node root;
public Tree() {
root = null;
}
public int getHeight(Node node) {
if (node == null)
return 0;
return node.height;
}
public Node insertANDbalance(Node node, int element) {
// base case
if (node == null)
return (new Node(element));
// inserting new elements into tree following Binary tree
rules
if (element < node.key)
node.left = insertANDbalance(node.left, element);
else if (element > node.key)
node.right = insertANDbalance(node.right, element);
else
return node;
// updating heights of left and right
if (getHeight(node.left) > getHeight(node.right))
node.height = 1 + getHeight(node.left);
else
node.height = 1 + getHeight(node.right);
// balance tree as each new element is added to it
int balance;
if (node == null)
balance = 0;
else
balance = getHeight(node.left) -
getHeight(node.right);
// left -> left
if (balance > 1 && element < node.left.key)
return rightRotate(node);
// right -> right
else if (balance < -1 && element >
node.right.key)
return leftRotate(node);
// left -> right
else if (balance > 1 && element > node.left.key)
{
node.left = leftRotate(node.left);
return rightRotate(node);
}
// right -> left
else if (balance < -1 && element < node.right.key)
{
node.right = rightRotate(node.right);
return leftRotate(node);
}
return node;
}
public Node rightRotate(Node root) {
Node newRoot = root.left;
Node Temp = newRoot.right;
// Rotate
newRoot.right = root;
root.left = Temp;
// Update
if (getHeight(root.left) >
getHeight(root.right))
root.height =
getHeight(root.left)+1;
else
root.height =
getHeight(root.right)+1;
if (getHeight(newRoot.left) >
getHeight(newRoot.right) + 1)
newRoot.height =
getHeight(newRoot.left)+1;
else
newRoot.height =
getHeight(newRoot.right)+1;
return newRoot;
}
public Node leftRotate(Node root) {
Node newRoot = root;
// for students to complete for an
assignment
return newRoot;
}
public static void printTree(Node node, int n) {
n += 5;
// Base case
if (node == null)
return;
printTree(node.right, n);
for (int i = 5; i < n; i++)
System.out.print(" ");
System.out.println(node.key);
printTree(node.left, n);
}
}
The code for node class:
public class Node {
protected int key, height;
protected Node left, right;
public Node(int item) {
key = item;
height = 1;
left = right = null;
}
}
The driver:
public class TreeDriver{
public static void main(String[] args) {
Tree tree = new Tree();
/* 6
* / \
* 2 7
* / \
* 1 4
* / \
* 3 5
*
*/
tree.root =
tree.insertANDbalance(tree.root, 6);
tree.root = tree.insertANDbalance(tree.root, 2);
tree.root = tree.insertANDbalance(tree.root, 1);
tree.root = tree.insertANDbalance(tree.root, 4);
tree.root = tree.insertANDbalance(tree.root, 3);
tree.root = tree.insertANDbalance(tree.root, 5);
tree.root = tree.insertANDbalance(tree.root, 7);
tree.printTree(tree.root, 0);
}
}
In: Computer Science
sleep data analysis:
a) What is the dataset “sleep” in R? and its description?
b) Draw boxplots for two drug groups in ONE plot.
c) Set up a hypothesis (null and alternative) for testing whether there exists an effect difference between two drugs. Using both words and symbols for hypothesis settings. (Hint: this is a paired sample test, rather than a general two sample t test.)
d) Use an appropriate formula to calculate the test statistic and find its p-value for part c) and draw a conclusion at the significance level α=0.05.
e) Check the function “t.test”in R, i.e, read the description of this function and its usage, values, and even play the examples provided at the end of the help page. What is the function description?
f) Use the function “t.test” in R to answer c) with the significance level α=0.05. (Hint: you need to change the “paired” status from FALSE to TRUE) g) Compare the conclusions in d) and f) Attach all the R code you used for this problem.
In: Computer Science
Java Program
Make an interface called interface1 that has tow data fields- default_length=1 and Pi=3.14
Make a second interface called interface2 that has one method: double getPerimeter(),
Make an abstract class GeometricObject that implements the 2 interfaces. And make one method getArea as an abstract method.
Make a subclass of GeometricObject called Square. The square class will inherit the superclass methods and implements the required abstract methods.
Make a subclass of GeometricObject called Triangle. (This is an equilateral triangle.) Triangle class will inherit the superclass methods and implements the required abstract methods.
In another class called test,using polymorphism call, declare 6 objects. The objects should be enclosed in an ArrayList of GeometricObject.
GeometricObject obj1=new Square(2);
Geometric Object obj2= new Triangle(4);
ArrayList<GeometricObject> arr=new ArrayList();
Write a for loop to extract the objects and print out their data.
In: Computer Science