Here are some basic rules for calculating the Big O for some T(n) or an algorithm.
1. Only the highest degree of n matters. For example T(n) = n^3 + 5n^2 + 107 → O(n^3 ) since once n becomes super-massively huge, the other terms just stop mattering.
2. Constant factors don’t matter. T(n) = 500n and T(n) = 0.005n both O(n). Again, as n becomes bigger, these constants stop mattering; what matters is the rate of growth. Example: T(n) = 50n^3 − 2n^2 + 400 → O(n^3 )
3. Counting the number of nested loops usually works.
Please provide your work with the answers.
In: Computer Science
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Each process is assigned a numerical priority,with a higher number indicating a higher relative priority. The scheduler will execute the highest-priority process. For processes with the same priority, a round-robin scheduler will be used with a time quantum of 10 units. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue.
Process Burst Time Arrival Time Priority
P1 15 0 8
P2 20 0 3
P3 20 20 4
P4 20 25 4
P5 5 45 5
P6 15 55 5
What is the average turnaround time of these processes?
What is the average waiting time of these processes?
In: Computer Science
The program should be written in C++ with comments
Write a program that takes graduation rates (per 1000 of the population) for North, South, East, West and Central United States. Input the number from each of the regions in a function returning an int with the graduation rate to the main program. Also figure out which region has the highest graduation rate in another function and display the result from inside that particular function.
So your function prototypes should be something like:
int gradrate( );
void highestgrad(double n, double south, double east, double west,
double central);
So you are using gradrate to read in the value of 0 to 1000 to give it to the north, south, east, west or central variables like: north = gradrate() / 1000.0;
In: Computer Science
Flow this Code to answer question below
#include <iostream>
using std::cout;
struct Node {
int data;
Node *link;
Node(int data=0, Node *p = nullptr) { //Note, this constructor combines both default and parameterized constructors. You may modify the contructor to your needs
this->data = data;
link = p;
}
};
class linked_list
{
private:
Node *head,*current;
public:
//constructor
linked_list() {
head = nullptr;//the head pointer
current = nullptr;//acts as the tail of the list
}
//destructor - IMPORTANT
~linked_list() {
current = head;
while( current != nullptr ) {//the loop stops when both current and head are NULL
head = head->link;
delete current;
current = head;
}
}
void addLast(int n) {// to add a node at the end of the list
if(head == nullptr){
head = new Node(n);
current = head;
} else {
if( current->link != nullptr)
current = current->link;
current->link = new Node(n);
current = current->link;//You may decide whether to keep this line or not for the function
}
}
void print() { // to display all nodes in the list
Node *tmp = head;
while (tmp != nullptr) {
cout << tmp->data << std::endl;
tmp = tmp->link;
}
}
};
int main() {
linked_list a;
a.addLast(1);
a.addLast(2);
a.print();
return 0;
}
Question:
Create the node structure and the linked list class. The sample class has implemented the following member methods:
o constructor
o destructor
o print(),
o addLast()
2. Implement the following member methods:
▪ addFirst (T data) // Adds a node with data at the beginning of the list
▪ pop() // Removes the first node of the list. Note: Don't forget to delete/reallocate the removed dynamic memory
▪ contains(T data) // Returns true or false if a node contains the data exists in the list
▪ update(T oldDate, T newData) // Updates the oldData of a node in the list with newData.
▪ size() // Returns the number of nodes in the list
▪ remove( T data) //Removes the node that contains the data. Note, you will need to check if the node exists. Again, don't forget to delete/re-allocate the dynamic memory
3. (Extra Credit Part) Implement the following additional member methods
▪ insertAfter(int n, T data) //Adds a node after the n-th node. Note, you will need to check if the n th node exists, if not, do addLast().
▪ merge(const LinkedList &linkedlist) //Merges this object with linkedlist object. In other words, add all nodes in linkedlist to this object.
In: Computer Science
In: Biology
Which of the following compounds has the highest pka?
a. NH3
b. H2O
c. HCl
d. CH4
In: Chemistry
In: Nursing
a diffraction grating has 650 slits/mm. what is the highest order that contains the entire visible spectrum?
In: Physics
During periods of normal credit market conditions, which financing strategy will result in the highest borrowing costs?
In: Finance
Why would a monopolist not charge the highest price possible? Include appropriate terminology that supports your reasoning.
In: Economics