1

I have the following python program for Linear Search algorithm:

import numpy as np

a, item = [2.6778716682529704, 8.224004328108661, 8.819020166860604, 25.04500044837642, 
114.6788167136755, 147.21744952331062, 109.1213882924877, 123.36405515780437, 10.113059020720906, 
59.01217380179232, 97.07159649653909, 9.010298414811622, 18.749094869496762, 75.27074394937102, 
85.75441597903486, 67.06650469807076, 59.193039503175825, 53.617565239895384, 13.945783254008596, 
130.41570895088282, 47.71407473246193, 51.903813982574384, 102.21910956684476, 106.99206485108651, 
80.95491815609066, 128.1883746500615, 29.40146119124661, 36.67058053312906, 124.22796860099373, 
46.14312646522846, 88.17789802786112, 10.952449565320403, 109.91937529687375, 124.20305335555281, 
12.389516472883905, 123.44886155581098, 17.421503974572637, 56.70857063455636, 71.00168946472502, 
103.07336370249966, 133.12218972160733, 88.57270183072094, 62.44720049852278, 19.689835681780934, 
57.274235858675404, 11.4949075513903, 32.06572223098081, 16.85725643503054, 147.75304767222545, 
73.03273121662845], 73.03273121662845

# Want to compute the Flops for the below 'for' loop
for i in range(50):
    if a[i] == item:
        print("item found")

I have the following questions:

  1. Since the above program lacks any basic floating point operations (such as +, -, *, /) and only has a comparison (relational) operator (==), should there be any Flops defined for the above linear search program?
  2. Regarding 1), if Flops should not be undefined then what should be the Flops of the for loop written in the above program?

I tried exploring PyPI to seek if any python package can be used to compute the Flops for the above program but found none. Moreover, attempted to find any solution for this, however, had no great fate in this regard.

user16217248
  • 3,119
  • 19
  • 19
  • 37
Andy s
  • 11
  • 2
  • 1
    Can you at least attempt a solution to your problem in the code? – ryanwebjackson Apr 16 '23 at 15:12
  • 1
    Maybe see https://stackoverflow.com/questions/68790128/understanding-linux-perf-fp-counters-and-computation-of-flops-in-a-c-program – AKX Apr 17 '23 at 05:47
  • 1
    Floating {Point Operations Per Second (FLOPS) is generally employed to define the computational power of a processor not a program. The computational complexity of a program is typically defined using Big O terminology (i.e. O(n) or O(log n), etc.). – itprorh66 Apr 17 '23 at 18:03

0 Answers0