Question

Please Help ASAP. 1Consider the below code which iterates over a linked list of n nodes...

Please Help ASAP.

1Consider the below code which iterates over a linked list of n nodes (assume the list has at least 1 node). How many lines of output will it write?

Node *thisNode = headPtr;
while (thisNode != null) {
    cout << thisNode->item << endl;
    thisNode = thisNode->next;
}

1.n

2.1

3.n2

4.n / 2

5.2 * n

2The below algorithm contains nested loops.  

for (int total = 1; total <= n; total++) {
    for (int samples = 0; samples < n; samples++) {
        for (int location = 1; location < n; location++) {
            ...
        }
    }
}


This algorithm has __________ complexity.

Group of answer choices

1.O(n log n)

2.O(1)

3.O(n)

4.O(n2)

5.O(n3)

3Consider an algorithm that requires the following number of operations (time units) for these input sizes (n). The algorithm is ___________ .

Input size Operations
100 20,000
400 320,000
1600 5,120,000

Group of answer choices

1.O(n log n)

2.O(2n)

3.O(n2)

4.O(n)

5.O(n3)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 n

Node *thisNode = headPtr;
while (thisNode != null) {
    cout << thisNode->item << endl;
    thisNode = thisNode->next;
}

this is code for traversing the node and printing the each node date so if there are n node then it will print each node data so it will execute O(n)

2  O(n3)

3 3.O(n2)

explanation :-

for this input size and operation the recurrence relation is

T(n) = 2 n2

 
Add a comment
Know the answer?
Add Answer to:
Please Help ASAP. 1Consider the below code which iterates over a linked list of n nodes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer ASAP Thank You 1Consider an algorithm that requires the following number of operations (time...

    Please answer ASAP Thank You 1Consider an algorithm that requires the following number of operations (time units) for these input sizes (n). The algorithm is ___________ . Input size Operations 100 100,000 400 100,000 1600 100,000 Group of answer choices 1.O(n2) 2.O(n) 3.O(log n) 4.O(n3) 5.O(1) 2The below algorithm contains nested loops. for (int total = 1; total <= n; total++) { for (int samples = 0; samples < n; samples++) { for (int location = 1; location < 10;...

  • Consider the following loop nest: int sum = 0; for(int j = 0; j < N...

    Consider the following loop nest: int sum = 0; for(int j = 0; j < N * N; j += 2) for(int i = 2*N; i > 0; i--) sum++; What is the Big-O behavior? Group of answer choices O(1) O(log N) O(N) O(N log N) O(N2) O(N3) 2.Consider the following loop nest: int sum = 0; for(int j = 1; j < N; j *= 2) for(int i = 0; i < N; i += 2) sum++; What is...

  • Assume you are given two linear lists of size n each; consider the problem of determining...

    Assume you are given two linear lists of size n each; consider the problem of determining whether any element of one list is an element of the other (not value, element). Derive a lower bound for this problem and design an algorithm for this problem. Derive its time complexity. It should be as close the lower bound as possible. My work so far: //Copy list n1 into n3 int n3[n]; for(int I = 0; I < n; i++)n3[i] = n1[i];...

  • Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for...

    Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for a list of size N? Group of answer choices O(1) O(log N) O(N) O(N log N) Flag this Question Question 21 pts Java's ArrayList class represents a basic array. As a convenience for the user, when the capacity of the backing array is exceeded, the class handles creating a new larger array and copying over the existing items. Its add(int index, E element) method...

  • In this assignment, you will use a Hashtable to determine the common elements in all the...

    In this assignment, you will use a Hashtable to determine the common elements in all the lists. If an element appears more than once in one or more lists, the algorithm should capture the instances the element is present in all the lists. You are given a code that implements a Hashtable as an array of linked lists. You are also given a main function that will create an array of Lists using the input variable values that you enter....

  • Please answer in C++. Derive a class called Stack from the linked list described in Assignment...

    Please answer in C++. Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions...

  • Question 13 pts (TCO 4) Which of the following functions grows at a slower rate than...

    Question 13 pts (TCO 4) Which of the following functions grows at a slower rate than the rest? n2 n log n n3 Flag this Question Question 23 pts (TCO 4) Algorithms can be described using pseudo-code. assignment and arithmetic operations. loops and decision statements. All of the above Flag this Question Question 33 pts (TCO 4) The running time of an algorithm is the time, in milliseconds, it takes to complete its execution. the running time of its implementation....

  • Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time...

    Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...

  • Question 2 (3 points) Given the following singly linked list (a list with four nodes), what...

    Question 2 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the last node when the following operations are executed? head->1111-151->11011->1211 Node curr = head; while(curr next !=null) { curr.item = curritem-head. item; curr = cur next; اسرة Node newNode = new Node(8): curr.next = newNode: 23 O 12 OS O21 Question 3 (3 points) Given a recursive method as shown below, what is the return value for P(5)...

  • I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I...

    I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I have right now. ************city.h**************** #ifndef city_h #define city_h #include <string> using namespace std; class City{ public: City () { name = "N/A"; population = 0; } City (string nm, unsigned int pop){ name = nm; population = pop; } void setName (string name) { this -> name = name; } void setPopulation (unsigned int population){ this -> population = population; } string getName() const...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT