Class VectorSum

java.lang.Object
topics.divideconquer.VectorSum

public class VectorSum extends Object
DIVIDE AND CONQUER PROBLEM: CALCULATE THE SUM OF n ELEMENTS IN A VECTOR
Author:
vicegd
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    sum1(int[] v)
    This method iteratively calculates the sum with a linear complexity O(n)
    int
    sum2(int[] v)
    This method recursively calculates the sum with a linear complexity O(n).
    int
    sum3(int[] v)
    This method recursively calculates the sum with a linear complexity O(n).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VectorSum

      public VectorSum()
  • Method Details

    • sum1

      public int sum1(int[] v)
      This method iteratively calculates the sum with a linear complexity O(n)
      Parameters:
      v - Array to be used for the addition
      Returns:
      Addition of all the elements of the array
    • sum2

      public int sum2(int[] v)
      This method recursively calculates the sum with a linear complexity O(n). DandC by subtraction with a=1,b=1,k=0 - O(n)
      Parameters:
      v - Array to be used for the addition
      Returns:
      Addition of all the elements of the array
    • sum3

      public int sum3(int[] v)
      This method recursively calculates the sum with a linear complexity O(n). DandC by division with a=2,b=2,k=0 - O(n)
      Parameters:
      v - Array to be used for the addition
      Returns:
      Addition of all the elements of the array