Skip to main content
Tweeted twitter.com/StackSoftEng/status/1196941380381237248
Just explained why my question should stand.
Source Link
Jesse Q
  • 251
  • 2
  • 6

Pseudo code and comments to explain:

// first select companies to process from db

foreach (company) {
    // select the employees
    foreach (employee of company) {
        // select items they can access
        foreach (item) {
           // do some calculation and save

I believe this will be O(n^3) time complexity, please correct me if I am wrong - Big O has always given me a headache. My question is if you introduce Parallel processing at the first level, what does it become? What if we introduce a second parallel.foreach() for the second iteration as well?

Edit: It was suggested that What is O(...) and how do I calculate it? would address my question, however I am more interested in whether Parallel.Foreach impacts time complexity so I believe the question is sufficiently different to stand on its own.

Pseudo code and comments to explain:

// first select companies to process from db

foreach (company) {
    // select the employees
    foreach (employee of company) {
        // select items they can access
        foreach (item) {
           // do some calculation and save

I believe this will be O(n^3) time complexity, please correct me if I am wrong - Big O has always given me a headache. My question is if you introduce Parallel processing at the first level, what does it become? What if we introduce a second parallel.foreach() for the second iteration as well?

Pseudo code and comments to explain:

// first select companies to process from db

foreach (company) {
    // select the employees
    foreach (employee of company) {
        // select items they can access
        foreach (item) {
           // do some calculation and save

I believe this will be O(n^3) time complexity, please correct me if I am wrong - Big O has always given me a headache. My question is if you introduce Parallel processing at the first level, what does it become? What if we introduce a second parallel.foreach() for the second iteration as well?

Edit: It was suggested that What is O(...) and how do I calculate it? would address my question, however I am more interested in whether Parallel.Foreach impacts time complexity so I believe the question is sufficiently different to stand on its own.

Became Hot Network Question
Source Link
Jesse Q
  • 251
  • 2
  • 6

Time Complexity of Parallel.ForEach

Pseudo code and comments to explain:

// first select companies to process from db

foreach (company) {
    // select the employees
    foreach (employee of company) {
        // select items they can access
        foreach (item) {
           // do some calculation and save

I believe this will be O(n^3) time complexity, please correct me if I am wrong - Big O has always given me a headache. My question is if you introduce Parallel processing at the first level, what does it become? What if we introduce a second parallel.foreach() for the second iteration as well?