Objective in JAVA (Please show output and have the avergae number of checks also.):
Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE number of times the loop is ran or the number of times the recursive method is called) needs to be counted and at the end the total number of checks should be averaged.
A few notes
Each algorithm (linear search and binary search) is ran 20 times
Each time a new sorted array of whole numbers is created and populated with random values from 0-999
A value to be searched in the said array is randomly selected from the range 0-999
Each algorithm must display if that number was successfully found
Each algorithm must display the number of checks it took to determine the above answer
It is advisable to create a method that returns the sorted array
Populate the array with random numbers
Search the array next
Return whether or not the value was found in the array
Implement both searches as a method
However instead of returning whether or not it found the number it should return the number of checks.
Whether the value is or is not found can be printed in the method
Binary search is fairly simple to create using recursion
Do not count the out of bounds or stopping index as a check
Example:
Welcome to the search tester. We are going to see which algorithm performs the best out of 20 tests
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 753
Binary Checks: 8
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 834
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 515
Binary Checks: 6
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 757
Binary Checks: 7
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 395
Binary Checks: 9
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 117
Binary Checks: 7
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 334
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 521
Binary Checks: 9
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 901
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 626
Binary Checks: 8
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 361
Binary Checks: 9
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 630
Binary Checks: 9
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 443
Binary Checks: 7
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 818
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 288
Binary Checks: 7
The average number of checks for 20 were:
Linear Search 664
Binary Search 8
In: Computer Science
In: Computer Science
Requirements Specification (this is a fictional scenario)
A large business, with several medical practices, contacted your company to create a database design. You received the task to investigate if there is a need for a hierarchy based on the specifications below, and to create the hierarchy analysis if needed. You must not create the entire analysis but only the aspects related to the hierarchy as described in the instructions, class lectures and sample examples. This is the relevant fragment from the requirements specification related to your task.
In the practice we have medical doctors, nurses, staff and other employees (e.g. cleaners for which we just keep contact information: name, SSN, phone).
For the doctors we keep the name, SSN, phone, email, main specialty, medical school. A doctor may have appointments and write prescripions. For nurses we keep the name, SSN, phone, and nurse program they completed. A nurse will prepare the patient during the visit and may collect various data. For staff we keep the name, SSN, phone and their role (e.g. receptionist, scheduler, accountant). Based on the practice policies, a nurse will not be allowed to perform staff duties.
The company wants to keep a log with who was working daily, between what hours and in which role. The company also wants to fast identify the role of a person in the organization (e.g. doctor, nurse, ...), based on the last name or id.
In: Computer Science
Generate a random list NUMBERS of size 100.
Sort NUMBERS using QUICKSORT until the sublist has size 15 or less; then use INSERTIONSORT on the sublist.
In: Computer Science
In: Computer Science
System Analysis and Design
please simple your answers as you can and don't copy.
Question One
What are the roles of a project sponsor and the approval committee during the different SDLC phases?
Question Two
As the project sponsor, you suggested that your company that runs multiple local supermarkets should provide an online shopping service to increase sales during COVID-19 pandemic. Write a system request to propose this project.
System request |
|
Project Sponsor |
|
Business Need |
|
Business Requirements |
|
Business Value |
|
Special Issues or Constraints |
Question Three
Assume the following scenario:
A small company needs to develop an information system for the Finance and Accounting Department. As an analyst which process model would you prefer and why?
Question Four
There are three techniques which help users discover their needs for the new system, list and compare these techniques in terms of impactful changes. Also, explain BPR.
In: Computer Science
# How do you select the the vector c(7, 8, 9) using the following four approaches
# (1) Using the [[]] operator once and only once # Your code below
(2) Using the [] operator once # Your code below
(3) Using the $ operator # Your code below
(4) Using a column vector name without using the $ operator # Your code below
In: Computer Science
Write a method that will have a C++ string passed to it. The string will be an email address and the method will return a bool to indicate that the email address is valid.
Email Validation Rules: ( These rules are not official.)
1) No whitespace allowed
2) 1 and only 1 @ symbol
3) 1 and only 1 period allowed after the @ symbol. Periods can exist before the @ sign.
4) 3 and only 3 characters after the period is required.
*****************************
Program will prompt for an email address and report if it is valid or not according to the rules posted above. The program will loop and prompt me to continue.
*****************************
In: Computer Science
QUESTION 1:
Imagine that the IRA is giving a stimulus package in the COVID-19
season. The package amount is determined by the number of adults in
the family and the total amount of salary the family gets.
Each adult will get 1200 dollars if the total salary is 100000 or less.
Each adult will get 800 dollars if the total salary is 150000 or less.
Write a python program to ask the user the number of adults in the family and the total number of family salary and determine the total amount of stimulus package the IRA will provide for that family.
QUESTION 2:
Write a program that will ask the user length and width of a right triangle and find the area of the right-angled triangle. The formula for finding the area of a right-angle triangle is
ab/2. Also, find out the result if you calculate as (ab)/2. Is it the same? If it is same, why it is the same. If it is not the same, why it is not the same.
In: Computer Science
Please note that this problem have to use sstream library in c++
(1) Prompt the user for a title for data. Output the title. (1
pt)
Ex:
Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored
(2) Prompt the user for the headers of two columns of a table.
Output the column headers. (1 pt)
Ex:
Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels
(3) Prompt the user for data points. Data points must be in this
format: string, int. Store the information before the
comma into a string variable and the information after the comma
into an integer. The user will enter -1 when they have finished
entering data points. Output the data points. Store the string
components of the data points in a vector of strings. Store the
integer components of the data points in a vector of integers. (4
pts)
Ex:
Enter a data point (-1 to stop input): Jane Austen, 6 Data string: Jane Austen Data integer: 6
(4) Perform error checking for the data point entries. If any of
the following errors occurs, output the appropriate error message
and prompt again for a valid data point.
Ex:
Enter a data point (-1 to stop input): Ernest Hemingway 9 Error: No comma in string. Enter a data point (-1 to stop input): Ernest, Hemingway, 9 Error: Too many commas in input. Enter a data point (-1 to stop input): Ernest Hemingway, nine Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Ernest Hemingway, 9 Data string: Ernest Hemingway Data integer: 9
(5) Output the information in a formatted table. The title is right
justified with a setw() value of 33. Column 1 has a setw() value of
20. Column 2 has a setw() value of 23. (3 pts)
Ex:
Number of Novels Authored Author name | Number of novels -------------------------------------------- Jane Austen | 6 Charles Dickens | 20 Ernest Hemingway | 9 Jack Kerouac | 22 F. Scott Fitzgerald | 8 Mary Shelley | 7 Charlotte Bronte | 5 Mark Twain | 11 Agatha Christie | 73 Ian Flemming | 14 J.K. Rowling | 14 Stephen King | 54 Oscar Wilde | 1
(6) Output the information as a formatted histogram. Each name is
right justified with a setw() value of 20. (4 pts)
Ex:
Jane Austen ****** Charles Dickens ******************** Ernest Hemingway ********* Jack Kerouac ********************** F. Scott Fitzgerald ******** Mary Shelley ******* Charlotte Bronte ***** Mark Twain *********** Agatha Christie ************************************************************************* Ian Flemming ************** J.K. Rowling ************** Stephen King ****************************************************** Oscar Wilde *
In: Computer Science
in javascript OR JAVA
You are given two numbers n and m representing the dimensions of an n × m rectangular board. The rows of the board are numbered from 1 to n, and the columns are numbered from 1 to m. Each cell has a value equal to the product of its row index and column index (both 1-based); in other words, board[i][j] = (i + 1) * (j + 1).
Initially, all the cells in the board are considered active, though some of them will eventually be deactivated through a sequence of queries - specifically, you will be given an array queries, where each query is of one of the following 3 types:
Given the dimensions n, m, and the array of queries, your task is to return an array consisting of calculated values (results of the queries of the 0th type), in the order in which they were calculated.
In: Computer Science
1) Translate the following C program to Pep/9 assembly language. Please attach screenshot of Pep/9 simulator running the program.
#include <stdio.h.>
int main() {
int numitms,j,data,sum;
scanf("%d", &numitms);
sum=0;
for (j=1;j<=numitms;j++) {
scanf("%d", &data);
sum+=data;
}
printf("sum: %d\n",sum);
return0;
}
In: Computer Science
In: Computer Science
1, Create a class Car. The class has four instance fields:
Provide
2. Create a class CarFactory
It provides just one method public static Car createRandomCar() which creates a random car instance with value chosen from the admissible set/range.
In: Computer Science
INFIX2POSTFIX.CPP
#include "stack.hpp"
using namespace std;
// Auxiliary method, you probably find it useful
// Operands are all lower case and upper case characters
bool isOperand(char c){
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
// Auxiliary method, you probably find it useful
int precedence(char c)
{
if(c == '+' || c == '-'){
return 0;
}
if(c == '*' || c == '/'){
return 1;
}
if(c == '^'){
return 2;
}
return -1;
}
int main(){
freopen("input_infix2postfix.txt", "r", stdin);
string input;
string solution;
int line_counter = 0;
while(cin >> solution){
cin >> input;
Stack<char> stack;
string result;
//The input file is in the format "expected_solution infix_expression",
//where expected_solution is the infix_expression in postfix format
for(int i=0; i<input.length(); ++i){
// WRITE CODE HERE to store in 'result' the postfix transformation of 'input'
}
// You need to do some extra stuff here to store in 'result' the postfix transformation of 'input'
// Checking whether the result you got is correct
if(solution == result){
cout << "line " << line_counter << ": OK [" << solution << " " << result << "]" << endl;
}else{
cout << "line " << line_counter << ": ERROR [" << solution << " " << result << "]" << endl;
}
line_counter++;
}
}
Implement a stack and solutions to the following problems: balancing parenthesis, evaluating postfix expressions and transforming infix expressions into postfix expressions.
infix2postfix.cpp
- create main method to transform an infix expression into postfix
In: Computer Science