I am attending coursera scala course for parallel programming. I have an assignment to solve paranthesis balancer both sequential and parallel. I have solved the sequential function. For the parallel function I have doubts as to how I can maintain the current paranthesis data across parallel threads.
Here is my sequential function:
def balance(chars: Array[Char]): Boolean = {
def helper( arr: Array[Char], acc: Int): Boolean = {
if (arr.isEmpty && acc ==0)
true
else if (arr.isEmpty || arr.head == ')' && acc <=0)
false
else if (arr.head == '(')
helper( arr.tail, acc +1)
else if (arr.head == ')' )
helper( arr.tail, acc - 1)
else
helper(arr.tail, acc)
}
helper(chars, 0)
}
now, my whole logic is based on acc value. When I will run these across multiple threads, what should I be focusing on? The parallel method will have range start and end index. The only thing I have understood so far is that aggregate of all these operations should be acc==0.
Please let me know some pointers in this direction.
Thanks