Big-O notation is a way to describe a function that represents the n amount of times a program/function needs to be executed.
(I'm assuming that := is a typo and you mean just =, by the way)
In your case, you have two loops, nested within each other, and both loop to n (inclusive, meaning, that you loop for when i or j is equal to n), and both loops iterate by 1 each loop.
This means that both loops will therefore execute an n amount of times. Now, if the loops were NOT nested, our big-O would be O(2n), because 2 loops would run an n amount of times.
HOWEVER, since the j-loop is nested within i-loop, the j-loop executes every time the i-loop <span>ITERATES.
</span>
As previously mentioned, for every i-loop, there would be an n amount of executions. So if the i-loop is called an n amount of times by the j loop (which executes n times), the big-O notation would be O(n*n), or O(n^2).
(tl;dr) In basic, it is O(n^2) because the loops are nested, meaning that the i-loop would be called n times, and for each iteration, it would call the j-loop n times, resulting in n*n runs.
A way to verify this is to write and test program the above. I sometimes find it easier to wrap my head around concepts after testing them myself.
import java.util.Scanner;
public class JavaApplication77 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a sentence:");
String sentence = scan.nextLine();
String [] arr = new String[sentence.length()];
arr = sentence.split(" ");
System.out.println("There are "+arr.length+" words in the sentence.");
int count = 0;
for(int i = 0; i < arr.length; i++){
count += arr[i].length();
}
System.out.println("The average length of a word in your sentence is "+(count/arr.length)+" characters");
count = 0;
System.out.println("Your sentence is "+sentence.length()+" characters long.");
}
}
For the length of a sentence, I included spaces as characters but I did not do this for the length of a word. I hope this helps!
Answer:
Transport layer:
- data packets are segment to smaller chunks.
- gives sequence number to segment.
- identifies the source and destination port number.
- initiates data transmission between nodes.
- rearrange and identifies the application, the transmitted data is meant for.
Explanation:
The transport layer is the fourth layer in the OSI network model. Protocols like TCP and UDP are found in this layer. It segment data packets and for a connection oriented protocol like TCP, it creates an established session between source and destination host (the session layer can also do this, but it is more defined in the transport layer).
The network and data-link layer can also transmit data packets.
Answer:
The answer is A or C. I hope this helps narrow down your answers.