Language: Java
Topic: Deques
Using the following variables/class:
public class LinkedDeque<T> {
// Do not add new instance variables or modify existing
ones.
private LinkedNode<T> head;
private LinkedNode<T> tail;
private int size;
Q1: Write a method called "public void addFirst(T data)" that does the following:
* Adds the element to the front of the deque.
* Must be O(1)
* @param data the data to add to the front of the deque
* @throws java.lang.IllegalArgumentException if data is null
Q2: Write a method called "public void addLast(T data)" that does the following:
* Adds the element to the back of the deque.
* Must be O(1)
* @param data the data to add to the back of the deque
* @throws java.lang.IllegalArgumentException if data is null
In: Computer Science
Examples:
Write a java program to read a line of text and tell if the line is a palindrome. Use a stack to read each non-blank character on a stack. Treat both upper-case and lower-case version of the letter as being the same character.
- Provide these 5 sample outputs and tell if each is a palindrome or not.
Too bad--I hid a boot
Some men interpret eight memos
"Go Hang a Salami! I'm a Lasagna Hog"
(title of a book on palindromes by Jon Agee, 1991)
A man, a plan, a canal—Panama
Gateman sees my name, garageman sees name tag
Show the LinkedtStackADT<T> interface
2. Create a LinkedStackDS<T> with the following methods: default constructor, overloaded constructor, copy constructor, isEmptyStack, push, peek, pop
3. Create a private inner StackNode<T> class with the following methods: default constructor, overloaded constructor, toString
3. Exception classes: StackException, StackUnderflowException, StackOverflowException
4. Create a PalindromeDemo class that instantiates a LinkedStackDS<Character> object. Execute a do-while loop that asks the user using dialog boxes to “Input a String for Palindrome Test:” Use the replaceAll method to remove all blanks and special characters from testStr. Output whether or not it is a palindrome in a dialog box. [Use the 5 inputs given on the other handout sheet for testing.]
In: Computer Science
Brief Introduction
Suppose that you are an analyst for the ABC Company, a large consulting firm with offices around the world. The company wants to build a new knowledge management system that can identify and track the expertise of individual consultants anywhere in the world on the basis of their education and the various consulting projects on which they have worked. Assume that this is a new idea that has never before been attempted in ABC or elsewhere. ABC has an international network, but the offices in each country may use somewhat different hardware and software. ABC management wants the system up and running within a year.
Action Items
Given the situation, what methodology would you recommend that ABC Company use? Why?
Please, Please, Please and Please…
1. I need new and unique answers, please. (Use your own words, don't copy and paste, even when you answer like theses answers before.)
2. Please Use your keyboard to answer my Questions. (Don't use handwriting)
3. Please and please i need a good and a perfect answers.
Thank you..
In: Computer Science
Part 2: What is the difference between historical analytics or predictive analytics in detail and provide some example?
In: Computer Science
Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid integer), display an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
In: Computer Science
[C++] Find the Recurrence Relation equations for the following functions:
Please explain how you got these equations.
BSTClass::Node* BSTClass::createNode(const string x) {
Node* newNode = new Node;
newNode->data = x;
newNode->left = nullptr;
newNode->right = nullptr;
return newNode;
}
void BSTClass::insertNode(const string x) {
insertNodeUtil(x, root);
}
void BSTClass::insertNodeUtil(const string data, Node* subTreePtr) {
if (root == nullptr) {
root = createNode(data);
}
else if (data <= subTreePtr->data) {
if (subTreePtr->left == nullptr)
{
subTreePtr->left = createNode(data);
}
else {
insertNodeUtil(data, subTreePtr->left);
}
}
else {
if (subTreePtr->right ==
nullptr) {
subTreePtr->right = createNode(data);
}
else {
insertNodeUtil(data, subTreePtr->right);
}
}
}
void BSTClass::printInOrder() {
printInOrderUtil(root);
cout << endl;
}
void BSTClass::printInOrderUtil(Node* subTreePtr) {
if (root == nullptr) {
cout << "The TREE is Empty
..." << endl;
}
else {
if (subTreePtr->left != nullptr)
{
printInOrderUtil(subTreePtr->left);
}
cout << subTreePtr->data << " ";
if (subTreePtr->right !=
nullptr) {
printInOrderUtil(subTreePtr->right);
}
}
}
bool BSTClass::findKey(const string key) {
return findKeyUtil(key, root);
}
bool BSTClass::findKeyUtil(const string key, Node* subTreePtr) {
if (root == nullptr) {
cout << "Key (" << key
<< ") is NOT found, it is an empty tree ..." <<
endl;
return false;
}
if (subTreePtr == nullptr) {
cout << "Key (" << key
<< ") is NOT found" << endl;
return false;
}
else if (subTreePtr->data == key) {
cout << "Key (" << key
<< ") is FOUND" << endl;
return true;
}
else if (key < subTreePtr->data) {
return findKeyUtil(key,
subTreePtr->left);
}
else {
return findKeyUtil(key,
subTreePtr->right);
}
}
int BSTClass::treeHeight() {
if (root == nullptr)
return 0;
else
return treeHeightUtil(root);
}
int BSTClass::treeHeightUtil(Node* subTreePtr) {
if (subTreePtr == nullptr) {
return 0;
}
else {
int lHeight =
treeHeightUtil(subTreePtr->left);
int rHeight =
treeHeightUtil(subTreePtr->right);
return (lHeight >= rHeight ?
lHeight + 1 : rHeight + 1);
}
}
In: Computer Science
Using JES/ Jython
Function Name: decoder()
Parameters:
message1-string containing first part of secret message
message2-string containing second part of secret message
Write a function that decodes them by retrieving every other character from both encrypted messages.
Test Cases:
>>>decoder("Rsupnk","oFpansot")
Run Fast
>>>decoder("Fkrneoem ktthpes","eAvleiselnos")
Free the Aliens
In: Computer Science
For this program you will add and test 2 new member functions to the class in
//************************ intSLList.h ************************** // singly-linked list class to store integers #ifndef INT_LINKED_LIST #define INT_LINKED_LIST class IntSLLNode { public: IntSLLNode() { next = 0; } IntSLLNode(int el, IntSLLNode *ptr = 0) { info = el; next = ptr; } int info; IntSLLNode *next; }; class IntSLList { public: IntSLList() { head = tail = 0; } ~IntSLList(); int isEmpty() { return head == 0; } void addToHead(int); void addToTail(int); int deleteFromHead(); // delete the head and return its info; int deleteFromTail(); // delete the tail and return its info; void deleteNode(int); bool isInList(int) const; void printAll() const; private: IntSLLNode *head, *tail; }; #endif
The two member functions are:
insertByPosn(int el, int pos)
Assuming that the positions of elements of a list begin numbering at 1 and continue to the end of the list, you will insert a new node with info value el at position pos. pos will become the position of the new node in the modified list. For example, if pos = 1, insert the new node at the head of the list. If pos = 2, for example, insert the new node BEFORE the node currently at position 2. If the list is empty prior to insertion, insert the new node in the list and adjust head and tail pointers. If pos is too large, don't do anything. If pos is 0 or negative, don't do anything.
removeByPosn(int pos)
Assume position of elements are defined as above. If pos is zero or negative, do nothing. If the list is empty prior to the request to delete a node, do nothing. If pos is too large, do nothing.
To aid in verifying results, you should use the following modified version of printAll. This requires: #include <string>
void IntSLList::printAll(string locn) const {
cout << "Contents of the list " << locn << endl;
for (IntSLLNode *tmp = head; tmp != 0; tmp = tmp->next)
cout << tmp->info << " ";
if (head != 0)
cout << "Head is: " << head->info << " Tail is: " << tail->info << endl << endl;
}
For extra credit, you can also create the following:
reverseList()
Traverse the existing list beginning at the head and create a new (reversed) list with head newhead and tail newtail. Put new nodes in the new list by putting the new nodes at the head of the new list each time. Do not call any other member functions during this process. If the list to be reversed is empty, make sure that you account for this case. After the new (reversed) list is created, delete the old list using its destructor.
The test program to be used is:
int main()
{
IntSLList singly_linked_list = IntSLList();
singly_linked_list.addToHead(9);
singly_linked_list.addToHead(7);
singly_linked_list.addToHead(6);
singly_linked_list.printAll("at creation:");
singly_linked_list.insertByPosn(8, 2);
singly_linked_list.printAll("after insertion of 8 at position 2:");
singly_linked_list.insertByPosn(10, 4);
singly_linked_list.printAll("after insertion of 10 at position 4:");
singly_linked_list.insertByPosn(12, 6);
singly_linked_list.printAll("after insertion of 12 at position 6:");
singly_linked_list.insertByPosn(14, 8);
singly_linked_list.printAll("after attempted insertion of 14 at position 8:");
singly_linked_list.insertByPosn(5, 1);
singly_linked_list.printAll("after insertion of 5 at position 1:");
singly_linked_list.insertByPosn(4, 0);
singly_linked_list.printAll("after attempted insertion of 4 at position 0:");
singly_linked_list.removeByPosn(2);
singly_linked_list.printAll("after deletion of 6 at position 2:");
singly_linked_list.removeByPosn(6);
singly_linked_list.printAll("after deletion of 12 at position 6:");
singly_linked_list.removeByPosn(10);
singly_linked_list.printAll("after attempted deletion at position 10:");
// insert test for optional list reversal here
return (0);
}
The correct output from running the test program is:
Contents of the list at creation:
6 7 9 Head is: 6 Tail is: 9
Contents of the list after insertion of 8 at position 2:
6 8 7 9 Head is: 6 Tail is: 9
Contents of the list after insertion of 10 at position 4:
6 8 7 10 9 Head is: 6 Tail is: 9
Contents of the list after insertion of 12 at position 6:
6 8 7 10 9 12 Head is: 6 Tail is: 12
Contents of the list after attempted insertion of 14 at position 8:
6 8 7 10 9 12 Head is: 6 Tail is: 12
Contents of the list after insertion of 5 at position 1:
5 6 8 7 10 9 12 Head is: 5 Tail is: 12
Contents of the list after attempted insertion of 4 at position 0:
5 6 8 7 10 9 12 Head is: 5 Tail is: 12
Contents of the list after deletion of 6 at position 2:
5 8 7 10 9 12 Head is: 5 Tail is: 12
Contents of the list after deletion of 12 at position 6:
5 8 7 10 9 Head is: 5 Tail is: 9
Contents of the list after attempted deletion at position 10:
5 8 7 10 9 Head is: 5 Tail is: 9
In: Computer Science
Computer A has an overall CPI of 1.5 and can be run at a clock rate of 2.5GHz. Computer B has a CPI of 4 and can be run at a clock rate of 4GHz. We have a particular program we wish to run. When compiled for computer A, this program has exactly 100,000 instructions. How many instructions would the program need to have when compiled for Computer B, in order for the two computers to have exactly the same execution time for this program?
In: Computer Science
Write a python script to calculate the average length of the game, Shortest game, longest game and overall length of the game
we need a python script that calculates the average length of a snake and ladder game. ie the number of moves it takes a single player to win the game. Then you run the game several times and will compare the results to come up with the required data(length of the game and number of moves )
In: Computer Science
For this portion of Lab #2, write a program that prompts the user to enter ten integer values between 1 and 100, determines the smallest and largest values entered by the user as well as the average of all the numbers entered by the user (expressed as a floating-point number), and then prints the smallest number, the largest number, and the average. Print each of these values with descriptive labels. Your program output should resemble the following (the user's input is shown in bold): Enter ten integers between 1 and 100, and I will tell you the smallest, the largest, and the average: 56 47 21 3 10 8 77 41 9 34 Smallest: 3 Largest: 77 Average: 30.6 NOTE: Your program should not read the ten numbers into ten separate integer variables, nor should it be necessary to use a data structure (such as an array) to store the numbers. Instead, use a loop which is set up to repeat ten times, and which determines the smallest and largest numbers seen so far, as the user enters each number. Remember also that you will need to add each number to a running total, in order to compute the average after all ten numbers have been entered. After you have completed your program, double-check your results by computing the smallest, largest, and average yourself, comparing your own results to those given by the program. Can someone help me with this java program
In: Computer Science
Explain each part of an Ethernet Packet in detail (about two sentences)
In: Computer Science
Homework:
You are to locate the file ```src/mutDetect_todo_i.py``` in which you are to fix twelve bugs to run the program. Your output should look _exactly_ like that featured in the assignment lab. Please read the assignment sheet for other details about the lab.
#mutDetect_todo_i.py
############################################################################
# TODO: There are twelve EMBARRISING silly bugs to fix. Can you
find them?!
############################################################################
DATE = "16 Sept 2019"
VERSION = "i"
AUTHOR = " myName"
AUTHORMAIL = "@allegheny.edu"
def help():
h_str = " "+DATE+" | version: "+VERSION+" |"+AUTHOR+" |
"+AUTHORMAIL
print(" "+len(h_str) * "-")
print(h_str)
print(" "+len(h_str) * "-")
print("\n\tThe blank-blank program to do something cool.")
#print("""\n\tLibrary installation notes:""")
print("\t+ \U0001f600 USAGE: python3 mutDetect.py <any key to
launch>")
######################################################
#end of help()
def getSeq():
""" Function to get a sequence (a string) from the user"""
print(" __Getting a sequence__")
prmpt = "\tEnter a sequence :"
seq_str = int(input(prmpt))
return seq_str.lower()
######################################################
# end of getSeq()
def compareSequences(seq1_str, seq2_str):
""" Compares the sequences base by base"""
print("\n __Comparing sequences__")
for i in range(len(seq1_str)):
# check to see whether the bases are the same going through the
sequences
try:
if seq1_str[i] == seq2_str[i]: # are bases _not_ the same at the
same position?
print("\t + Bases not the same at pos: ",i)
print("\t\t First seq char : " seq1_str[i])
print("\t\t Second seq char : ", seq2_str[i])
except IndexError:
#print(" \t Sequences are uneven length!")
pass
# end of compareSequences()
def getSeqLength(seq_str):
""" Function to return the length of a sequence"""
l_int = len(seq_str)
if l_int % 2 = 0: # can we read triplets, groups of three?
print("\t Warning! Sequence length cannot be divided into groups of
triplets!")
return l_int
######################################################
#end of getSeqLength()
def compareSeqLength(seq1_str, seq2_str):
"""Function to check the lengths of the sequences to make sure that
they are the same length. This is necessary for making
comparisons."""
if len(seq1_str) = len(seq2_str):
return True
else:
return True
######################################################
#end of compareSeqLength()
def translate(dna_str):
""" Function to translate the DNA. Create a protein sequence from
the DNA."""
sequence = Seq(dna_str)
#make some variables to hold strings of the translated code
# give me RNA from the DNA
RNAfromDNA_str = Seq.transcribe(sequence) #transcription step:
converting dna to rna
# give me DNA from the RNA
DNAfromRNA_str = Seq.back_transcribe(sequence)
# give me the protein from the dna
PROTfromRNA_str = Seq.translate(RNAfromDNA_str)
# print the output of the string variables
print("\n __Translation__")
print("\t + Original DNA :", dna_str ", length is :",
len(dna_str))
# print("\t + RNA from DNA :", RNAfromDNA_str)
# print("\t + DNA from RNA :", DNAfromRNA_str)
print("\t + PROTEIN from RNA :",PROTfromRNA_str)
return PROTfromRNA_str
######################################################
#end of translate()
def begin(task_str):
"""Driver function of program"""
print("\n\t Welcome to mutDetect!\n\t A program to compare DNA,
make protein and compare protein sequences.)
# get first DNA sequence
seq1_str = getSeq()
# get second DNA sequence
seq2_str = getSeq()
print("\t + Length of first sequence :",
getSeqLength(seq2_str))
print("\t + Length of second sequence :",
getSeqLength(seq2_str))
# compare the sequences
compareSeQuences(seq1_str, seq2_str)
print("\t + Sequences are same length: ",compareSeqLength(seq1_str,
seq2_str))
prot1_seq = Translate(seq1_str)
#print(type(prot1_seq))
protein1_str = str(prot1_seq)
print("\t + protein1 sequence :",protein1_str)
prot2_seq = translate(seq2_tsr)
#print(type(prot2_seq))
protein2_str = str(prot2_seq)
print("\t + protein2 sequence :",protein2_str)
compareSequences(protein1_str, protein2_str)
######################################################
#end of begin()
import os, sys
#import math
# list other libraries below
# load my biopython library
from Bio.Seq import Seq
if __name__ == '__main__':
if len(sys.argv) == 2: # one parameter at command line
# note: the number of command line parameters is n + 1
begin(sys.argv[1])
else:
help() # If no command-line parameter entered, then run the help()
function
sys.exit()
In: Computer Science
Q1: In the addition of floating-point numbers, how do we adjust the representation of numbers with different exponents?
Q2:
Answer the following questions:
In: Computer Science
Discuss different service-based server operating systems, server computers, and server software that a network administrator must choose between. Applied Concepts (AC) - Week/Course Learning Outcomes Using your textbook, LIRN-based research, and the Internet, apply the learning outcomes for the week/course and lecture concepts to one of the following scenarios: As applied to your current professional career As applied to enhancing, improving, or advancing your current professional career As applied to a management, leadership, or any decision-making position As applied to a current or future entrepreneurial endeavor OR Using your textbook, LIRN-based research, and the Internet, apply the learning outcomes for the week/course and lecture concepts to a business organization that exhibits and demonstrates these concepts. You should develop a summary of the organization's strategy and how they use these concepts to compete. This is a learning and application exercise designed to give you an opportunity to apply concepts learned in a pragmatic and meaningful way that will enable you to gain valuable and relevant knowledge in an effort to augment your skill set and enhance your professional careers.
In: Computer Science