What are the advantages of a using a linked list rather than a conventional array in Java? and when would it be more efficient to use an array rather than a linked list? Explain your answer.
In: Computer Science
Create a table with a list of five project management software programs available on the market today (Microsoft Project and ProjectLibre are two examples). List two benefits and two drawbacks for each program.
In: Operations Management
List at least three ways that gang attempts to mitigate the externalities it generates from the sale of drugs. In addition list at least three externalities that gang activities generate within the local community
In: Economics
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are divisible by 3. Arrange these numbers in a list called “result”.
Hint: similar to page 9 in the slides.
In: Computer Science
I need to create a linked list that contains a fixed arraylist. Each new entry is added to array list. If the arraylist is full, create a new arraylist and add to the linklist. In java please.
In: Computer Science
You are provided with a partial implementation of a templated singly-linked list in LinkedList.h, with some missing functionality. It contains a templated Node class and a templated LinkedList class. Do not modify the class definitions.
The linked list class contains the following methods:
• LinkedList – Constructor of a linked list with a head pointing to null (implemented).
• ~LinkedList – Destructor of a linked list.
• deleteFromHead – Removes and returns content of the first node of the list. (If the list is empty, does nothing.)
• deleteFromTail – Removes and returns content of last node of the list. (If the list is empty, does nothing.)
• deleteNode – Removes node with provided data from the list.
• InsertToHead – Inserts node with provided data at the head (implemented).
• InsertToTail – Inserts node with provided data at the tail. • getSize – Returns the number of nodes in the linked list.
• print - Prints the linked list (implemented).
Notice that while the declaration and implementation of classes are typically split between .cpp and .h files, some compilers cannot handle templates in separate files, which is why we include both the declaration and implementation in a single .h file. The main.cpp file consists of sample test code for each of the tasks below. Your code, which should be added to the provided LinkedList.h will be compiled and run with variations of this file. Submit your modified LinkedList.h file only
LinkedList.h:
#ifndef LinkedList_h
#define LinkedList_h
#include <iostream>
using namespace std;
template <class T = int>
class Node {
public:
Node(); // default constructor
Node(const T& data, Node<T>* next = nullptr); // donstructor
T data; // node data
Node<T>* next; // node next pointer
};
template <class T = int>
class LinkedList {
public:
LinkedList(); // constructor
~LinkedList(); // destructor
T deleteFromHead(); // removes and returns content of head
T deleteFromTail() // removes and returns content of tail
void deleteNode(T data) // removes node with specified data
void InsertToHead(T data); // insert node with data at the head
void InsertToTail(T data); // insert node with data at the tail
int getSize(); // returns size of linked list
void print(); // prints linked list
private:
Node<T>* head; // head of linked list
};
/******* From here down is the content of the LinkedList.cpp file: ***********************/
/* Implementation of Node */
// default constructor
template<class T>
Node<T>::Node()
{
}
// constructor
template<class T>
Node<T>::Node(const T& data, Node<T>* next)
{
this->data = data;
this->next = next;
}
/* Implementation of linked list */
// constructor
template <class T>
LinkedList<T>::LinkedList()
{
head = nullptr;
}
// destructor
template <class T>
LinkedList<T>::~LinkedList()
{
/*** to be implemented ***/
}
template <class T>
T LinkedList<T>::deleteFromHead()
{
/*** to be implemented ***/
}
template <class T>
T LinkedList<T>::deleteFromTail()
{
/*** to be implemented ***/
}
template <class T>
void LinkedList<T>::deleteNode(T data)
{
/*** to be implemented ***/
}
template <class T>
void LinkedList<T>::InsertToHead(T data)
{
Node<T> * newNode = new Node<T>(data, nullptr);
if (head == nullptr)
head = newNode;
else
{
newNode->next = head;
head = newNode;
}
}
template <class T>
void LinkedList<T>::InsertToTail(T data)
{
/*** to be implemented ***/
}
template <class T>
int LinkedList<T>::getSize()
{
/*** to be implemented ***/
}
template <class T>
void LinkedList<T>::print()
{
if (head == nullptr)
{
cout << "Linked list is empty" << endl;;
return;
}
cout << head->data << " ";
if (head->next == nullptr)
{
cout << endl;
return;
}
Node<T>* currNode = head->next;
Node<T>* prevNode = head;
while (currNode->next != nullptr)
{
cout << currNode->data << " ";
prevNode = currNode;
currNode = currNode->next;
}
cout << currNode->data << endl;
return;
}
#endif /* LinkedList_h */In: Computer Science
In short, you’re going to implement a linked-list class for storing integers, using a provided main program to help you interact and test your work. You’ll want to build the linked-list class function by function, working in “Develop” mode to test out each function you write.
main.cpp is a read only file
linkedlist.h is the file to work on.
main.cpp
#include
#include
#include "linkedlist.h"
using namespace std;
int main()
{
linkedlist LL;
string cmd;
int value, key;
//
// user can enter commands to manipulate the LL:
//
// p w => push w onto the end
// i x y => insert x after y (y must exist in the list)
// r z => remove the first instance of z
// o => output the list
// q => quit
//
//cout << "Enter a command> ";
cin >> cmd;
while (cmd != "q")
{
if (cmd == "p")
{
// push:
cin >> value;
LL.push_back(value);
}
else if (cmd == "i")
{
// insert:
cin >> value;
cin >> key;
LL.insert(value, key);
}
else if (cmd == "r")
{
// remove:
cin >> value;
LL.remove(value);
}
else if (cmd == "o")
{
// output:
LL.output();
}
else
{
cout << "**Invalid command, try p, i, r, o or q" <<
endl;
cout << endl;
}
//cout << "Enter a command> ";
cin >> cmd;
}
return 0;
}
linkedlist.h
/*linkedlist.h*/
#pragma once
#include <iostream>
using namespace std;
class linkedlist
{
private:
struct NODE
{
int Data;
struct NODE* Next;
};
struct NODE* Head; // first node in list (or nullptr)
struct NODE* Tail; // last node in list (or nullptr)
int Size; // # of elements (i.e. nodes) in list
public:
//
// default constructor
//
// Creates an empty list.
//
linkedlist()
{
Head = nullptr;
Tail = nullptr;
Size = 0;
}
//
// size
//
// Returns the # of elements in the list.
//
int size()
{
return Size;
}
//
// push_back
//
// Pushes value onto the end of the list.
//
void push_back(int value)
{
struct NODE* newNode = new struct NODE();
newNode->Data = value;
newNode->Next = nullptr;
//
// TODO: a new node containing the value was created
// above. Add this new node to the end of the list.
//
//
// HINT #2: don't forget to increment size
//
}
//
// insert
//
// Inserts the given value in the list *after* the key. If
// the key cannot be found, nothing happens; if the key
occurs
// multiple times, value will be inserted after the first
// instance.
//
void insert(int value, int key)
{
// allocate a new node to hold the value:
struct NODE* newNode = new struct NODE();
newNode->Data = value;
newNode->Next = nullptr;
//
// TODO: a new node containing the value was created
// above. Insert this new node after the node containing
// the given key (assume the key appears only once).
// If the key cannot be found (or the list is empty), do
// nothing and just return (or delete newNode and return).
//
t.
//
// HINT #2: don't forget to increment size
//
}
//
// remove
//
// Removes the first instance of value from the list; if
// the value cannot be found, nothing happens.
//
void remove(int value)
{
//
// TODO: remove the first node that contains value; if value
// is not found, do nothing. You'll need to search the list
// for the value, and then unlink that node from the list.
// Don't worry about freeing the memory, you can ignore that
// for now (or use delete ptrToNode; if you want to free).
//
//
// HINT #2: don't forget to decrement size
//
}
//
// output
//
// Outputs the size, followed by the elements one by one on
// the same line.
//
void output()
{
cout << "Size: " << Size << endl;
cout << "Elements: ";
//
// TODO: output elements with a space after each one
// (including a space after last element). Output all
// on the same line, save the end-of-line for after
// the traversal loop is over.
//
.
//
cout << endl;
}
};
In: Computer Science
The following SinglyLinkedList class is available:
class SinglyLinkedList:
class _Node:
"""Lightweight, nonpublic class for storing a singly linked node."""
__slots__ = 'element', 'next' # streamline memory usage
def __init__(self, element, next): # initialize node's fields
self.element = element # reference to user's element
self.next = next # reference to next node
def __init__(self): # initialize list's fields
self._head = None # head references to None
def printList(self, label):
print(label, end=' ')
curr = self._head
while curr != None:
print(curr.element, end=" -> ")
curr = curr.next
print("/")
#########################################################
# Only this method is required for your solution
def computeStats(self):
# Your code goes here
#########################################################
def main():
# Create a list object for testing purpose
sList = SinglyLinkedList()
# Create list 2 -> 4 -> -1 -> 8 -> -5
sList._head = sList._Node(2, sList._Node(4, sList._Node(-1, sList._Node(8, sList._Node(-5, None)))))
sList.printList("before:")
# Call computeStats method
sList.computeStats()
# And see if it worked!
sList.printList("after :")
if __name__=="__main__":
main()
Assume you have a singly-linked list of integers, some positive and some negative. Write a Python method that traverses this list to calculate both the average and the count (ie, number) of the odd values only. Once calculated, add the average to a new node at the front of the list, and the count to a new node at the end of the list. You may assume that the list will always contain at least one odd value.
Your method will be have the following method signature:
def computeStats(self):
You may use only the SinglyLinkedList class; no other methods (like size(), etc) are available.
For example, if the list initially contains:
2 → 4 → -1 → 8 → -5
the resulting list will contain:
-3.0 → 2 → 4 → -1 → 8 → -5 → 2
In: Computer Science
Do students reduce study time in classes where they achieve a higher midterm score? In a Journal of Economic Education article (Winter 2005), Gregory Krohn and Catherine O’Connor studied student effort and performance in a class over a semester. In an intermediate macroeconomics course, they found that “students respond to higher midterm scores by reducing the number of hours they subsequently allocate to studying for the course.” Suppose that a random sample of n = 8 students who performed well on the midterm exam was taken and weekly study times before and after the exam were compared. The resulting data are given in Table 10.6. Assume that the population of all possible paired differences is normally distributed. Table 10.6 Weekly Study Time Data for Students Who Perform Well on the MidTerm Students 1 2 3 4 5 6 7 8 Before 15 19 12 17 16 15 11 16 After 11 18 9 10 8 9 11 10 Paired T-Test and CI: Study Before, Study After Paired T for Study Before - Study After N Mean StDev SE Mean StudyBefore 8 15.1250 2.5877 .9149 StudyAfter 8 10.7500 3.1053 1.0979 Difference 8 4.37500 2.87539 1.01660 95% CI for mean difference: (1.97112, 6.77888) T-Test of mean difference = 0 (vs not = 0): T-Value = 4.30, P-Value = .0036 (a) Set up the null and alternative hypotheses to test whether there is a difference in the true mean study time before and after the midterm exam. H0: µd = versus Ha: µd ≠ (b) Above we present the MINITAB output for the paired differences test. Use the output and critical values to test the hypotheses at the .10, .05, and .01 level of significance. Has the true mean study time changed? (Round your answer to 2 decimal places.) t = We have evidence. (c) Use the p-value to test the hypotheses at the .10, .05, and .01 level of significance. How much evidence is there against the null hypothesis? There is against the null hypothesis. 02_16_2018_QC_CS-118501
In: Statistics and Probability
One may organize cost data and their distribution among
stakeholders in various ways to assess overall project viability,
and cost distribution to analyse the project’s attractiveness to
various stakeholders. One approach to organizing such data is to
identify the various categories for the project inputs in column
(1), then show the total value of each input in column (2) and use
subsequent columns to show the various stakeholders’ contribution.
Similar to the case we did in class, consider the following project
designed to train 100 low-income workers for a year.
Costs
The sponsoring NGO spends GHS 200,000 on Rental of Premises a year,
after Students and their Families have contributed labour to
prepare the project site, thus lowering the rental costs by GHS
50,000. In addition, Students and their Families pay for the
services of a part-time worker, valued at GHS 25,000 a year. The
NGO pays GHS 225,000 as salaries of two full-time skilled staff.
Further, a Private firm donates computers valued at GHS 20,000. The
cost of material and supplies are an additional GHS 20,000, of
which the sponsoring NGO bears GHS 8,000 and the rest are donated
by a private entity. The sponsoring NGO bears half the costs of
utilities; Government bears the other half. Total utilities are
estimated at GHS 50,000. For the period they are in training,
Students incur GHS 2,000 each in lost income and Government loses
GHS 200 per student.
Gains of the Project
When students complete, they are expected to earn GHS 100 each per
month more than they would otherwise have earned for 5 years and
Government will earn GHS 30 extra from each of them as tax The
opportunity cost of this project to Students and Government is 24%
p.a.
Questions
i. Present the data in a tabular form for ease of analysis showing
benefits and costs to each stakeholder and on Society. Consider all
private sector contributions to the project as one stakeholder,
called PRIVATE.
ii. Calculate the proportion of total cost being borne by each
stakeholder.
iii. Do you advise that this Project be undertaken? Explain.
In: Accounting