1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Shalnov [3]
3 years ago
4

Write an iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse in O(N) time. You can use as m

uch extra space as you need. The original list pointers CAN NOT BE MODIFIED. State in big-O notation how much extra space is used by this algorithm.NOTE: The reason you are not allowed to implement the algorithms recursively, is due to the additional space requirements of recursive calls. Around N recursive calls has an additional space complexity of O(N) as each recursive call is placed on a call-stack that requires memory to keep track of.Write another iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse using O(1) extra space. The original list pointers CAN NOT BE MODIFIED. This algorithm can have any runtime (it will be worse than the algorithm in part a). State the runtime of your algorithm in big-O notation.NOTE: The reason you are not allowed to implement the algorithms recursively, is due to the additional space requirements of recursive calls. Around N recursive calls has an additional space complexity of O(N) as each recursive call is placed on a call-stack that requires memory to keep track of.
Computers and Technology
1 answer:
aleksklad [387]3 years ago
8 0

Answer:

Printing a singly linked-list in reverse in O(N) time

Step 1. Create an empty stack.

Step 2. Traverse each element of linked-list and push it in stack. O(N)

Step 3. Pop stack and print the element untill stack gets empty. O(N)

O(N) + O(N) = O(N)

This algorithm will take O(N) extra space for maintaining the stack.  

    class Node {

       int data;

       Node next;

}

Stack<Integer> st = new Stack<Integer>();

current = head; // head is starting point of linked-list

while(current != NULL)

{

st.push(current.data);

current = current.next;

}

while( ! st.empty())

{

System.out.println( st.pop() + " ");

}

Explanation:

You might be interested in
Imagine that a team of scientists test a certain hypothesis, and the experimental results show that it is false.
andrew-mc [135]

Answer:

They would have had to retry and go back to experimenting.

4 0
3 years ago
Chemical reaction rates are proportional to a rate constant, k, which changes with temperature according to the Arrhenius equati
Vanyuwa [196]

Answer:

see answer below

Explanation:

the equation is given by

k=ko* e^(-Q/RT)

then replacing the known values

k=1200 min⁻¹ e^[-8000 cal/mole/ (1.987 cal/mole K *T)]

then replacing values of T every 50 K from 100 to 500 K we get the series of values

\left[\begin{array}{ccc}T&k\\100&3.924*10^{-15} min ^{-1} \\150&2.643*10^{-9} min ^{-1} \\200&2.17*10^{-6} min ^{-1} \\250&1.216*10^{-4} min ^{-1} \\300&1.781*10^{-3} min ^{-1} \\350&0.012 min ^{-1} \\400&0.051 min ^{-1} \\450&0.156 min ^{-1} \\500&0.382 min ^{-1} \end{array}\right]

7 0
3 years ago
Libby wrote an email to her friend. She pressed Shift and the number key 2 together to enter the email address. Which symbol did
exis [7]

When Libby wrote the email to her friend, she typed the '@' symbol. When pressing SHIFT and 2 together, it pastes this aforementioned symbol. However, there isn't any specific name for the symbol. As a matter as fact, there are several names that this symbol goes by.

The most famous name this symbol is called is the "at symbol" or the "at sign". In terms of a formal name, "commercial at" would be a good one.

Here's an example with the symbol:

[email protected]

This is essentially telling the email server where to send your email. From this, they'll know it's located at brainly.com! It's pretty neat.

4 0
4 years ago
Read 2 more answers
BRIANLIEST!!!!!!!!!!!!!!!!
oksano4ka [1.4K]

Answer:

First Line indent

Explanation:

should be correct

4 0
3 years ago
Read 2 more answers
Having reviewed dod wireless stig (ver6, release 1), sarah learns she may only utilize secnet 54 and ______________ for transmit
xeze [42]
<span>Sarah learns she may only utilize SecNet 54 and SecNet 11 for transmitting classified information up to top secret.
</span>

SecNet 11 Plus is a family of encrypted <span>802.11b wi-fi <span>networking products. The Army has also approved</span></span> SecNet 11<span> as part of the classified Navy Marine Corps Intranet (NMCI) wireless solution. There are many products in SecNet 11 family, such as SecNet 11 Plus PC card, the SecNet 11 Wireless ridge, and the SecNet 11 Key Fill Cable etc.</span>

7 0
3 years ago
Other questions:
  • Which change signaled a musical progression toward rock and roll?
    14·1 answer
  • Why is it a mistake to put e-mail address of people who don't know each other in the "to:" field
    9·2 answers
  • In this part, you have to implement a linked list that maintains a list of integers in sorted order. Thus, if the list contains
    13·1 answer
  • All of the following are strategies to help you prepare for standardized test except <br>​
    5·1 answer
  • The Coins class was created to hold all your loose change, kind of like a piggy bank! For this exercise, you are going to simula
    15·1 answer
  • Place the steps in order to link and place text into the document outline, effectively creating a master document.
    8·1 answer
  • The _______ of a secondary storage device indicates how much data the storage medium can hold.
    13·1 answer
  • What is HTML? (list down any 5 points)
    12·1 answer
  • If the starting address location changes, in which of the following cases, the program has to be recompiled? Select one: a. Both
    12·1 answer
  • You want to add a caption to a table. which tab contains this option?.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!