Skip to main content
8 of 13
deleted 297 characters in body
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
What is the relation between algorithms and OOP? Are they two independent topics?

Algorithms are about how to solve a problem, OOP is about how to formulate our problem and solution. They can be related when the formulation of a problem affects its solution.

An algorithm can be described in natural language or in assembly language, but the concepts we have in a natural language help us to write and understand it better. For example the algorithm for bubble-sort could be:

bubbleSort(Array A)
  for (n=A.size; n>1; n=n-1){
    for (i=0; i<n-1; i=i+1){
      if (A[i] > A[i+1]){
        A.swap(i, i+1)
    } 
  } 
}

To hide the details of swap and to relate it to the A we used an OOP syntax and feature, then OO makes the algorithm closer to our natural language and understanding.

Are there some problems which can only be presented and solved by OOP?

No, if you consider that any program (or algorithm) on a computer will be translated to a set of instructions executed on CPU (Turing Machine proof) and if we regard these instructions as the ultimate algorithm which solves the problem on a computer, then OOP can't do something further. It just makes it closer to the human understanding and reasoning.

How OOP can help algorithms? Or in which direction it can affect it?

It may help to state or formulate an algorithm easier or more understandable. It can hide details and provide a big picture of the solution.

Ahmad
  • 1.9k
  • 3
  • 21
  • 36