Question

In: Computer Science

In C#. Explain the technique of fusing loop.Give example.

In C#. Explain the technique of fusing loop.Give example.

Solutions

Expert Solution

Loop fusion is done inorder to reduce loop overhead and improve run time complexity. It is a programming technique where two or more loops are combined to one loop.

Example in C# Language :

Not Fusing Loop :

using System;
class FUSE{
  static void Main() 
  {
      int a=0,b=0;
      for(int i=0;i<10;i++)
      {
          a=a+i;
      }
      for(int j=0;j<10;j++)
      {
          b=b-j;
      }
      Console.WriteLine("value of a : "+a);
      Console.WriteLine("value of b : "+b);
  }
}

Here we can see, we have two for loops

Fusing Loop :


using System;
class FUSE{
  static void Main() 
  {
      int a=0,b=0;
      for(int i=0;i<10;i++)
      {
          a=a+i;
          b=b-i;
      }
      Console.WriteLine("value of a : "+a);
      Console.WriteLine("value of b : "+b);
  }
}

Here we can see, we have one loop. The two loops in the above example are merged.

Output for both the codes:


Related Solutions

1. Which of the following is not an example of a risk transfer technique? a. the...
1. Which of the following is not an example of a risk transfer technique? a. the purchase of insurance from a commercial insurance company b. the purchase of a futures contract to hedge against an increase in the price of a commodity c. a firm’s decision to self-insure the costs of medical expense benefits owed to workers injured on the job d. all the above are examples of risk transfer techniques
Explain the main disadvantage of scheduling with preemption. (b) Describe and explain an example. (c) Is...
Explain the main disadvantage of scheduling with preemption. (b) Describe and explain an example. (c) Is the Five Philosophers Problem a synchronization problem? Explain.
Explain a fraud technique in relation to the revenue cycle. How can this fraud technique be...
Explain a fraud technique in relation to the revenue cycle. How can this fraud technique be identified?
A. Explain what is climate zone B. Explain an example for a normal climate zone C....
A. Explain what is climate zone B. Explain an example for a normal climate zone C. Describe how it shifts due to global warming?
Explain the following terms a) Eavesdropping b) Identity theft c) Salami technique d) Scavenging e) Hacking...
Explain the following terms a) Eavesdropping b) Identity theft c) Salami technique d) Scavenging e) Hacking f) Skimming g) Social engineering h) Trojan horse i) Worm j) Vishing
Explain how the nonprobability technique of quota sampling can be used to mimic the probability technique...
Explain how the nonprobability technique of quota sampling can be used to mimic the probability technique of stratified random sampling. Give an example.
Describe an example of using the executive coaching technique to improve employee performance.
Describe an example of using the executive coaching technique to improve employee performance.
Clinical experience of 1 example of Therapeutic Communication Technique use and 1 Non Therapeutic Technique use (verbal or non verbal)
Clinical experience of 1 example of Therapeutic Communication Technique use and 1 Non Therapeutic Technique use (verbal or non verbal), and identify the technique that was been used . 
Genetics: Using molecular hybridization: fully explain the technique and discuss one application of that technique used...
Genetics: Using molecular hybridization: fully explain the technique and discuss one application of that technique used in scientific research.
Using an example of your own, explain the difference between the calculations ₈C₃ ₈P₃?
Using an example of your own, explain the difference between the calculations ₈C₃ ₈P₃?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT