Basics of Algorithms in Swift

minal kewat
3 min readFeb 5, 2024

--

Algorithm is the set of rules or instruction to solve any given problem effectively and efficiently.

Why writing algorithm is important ?

  1. Algorithm help us to write a solution for complex problem effectively and efficiently.
  2. It provide optimised process to solve any problem.
  3. Algorithms are faster and easy to perform. we can write algorithm in any language .
  4. Algorithms are human readable.

Required elements to write an standard algorithm :-

  1. Algorithm’s each steps should be clear and precise.
  2. Algorithm must terminate after a finite time.
  3. An Algorithm should be simple and feasible, it can be executed with available resources.
  4. Algorithm’s input and output should be well defined.
  5. Algorithm should zero or more input.
  6. An Algorithm must produce at least one output.

Types of algorithm -

  1. Searching Algorithm
  2. Sorting Algorithm
  3. Greedy Algorithm
  4. Mathematical Algorithm
  5. Geometric Algorithm
  6. Bitwise Algorithm
  7. Randomized Algorithm
  8. Dynamic Programming
  9. Recursion
  10. Backtracking
  11. Divide and Conquer
  12. Branch and Bound

Searching Algorithm

Searching algorithm is used to search for the data or retrieve the data, stored in the any data structure.

Sorting Algorithm

Sorting algorithm is used to arrange the list data in a particular manner(Increasing or Decreasing).

Bitwise Algorithm

Bitwise Algorithm is used to perform operation on data represented in binary form(0 or 1). This algorithm allow us to perform operation on bit level which is very faster and efficient.

Randomized Algorithm

Randomized Algorithm is uses the random number to get the immediate benefit to as part of its logic. This algorithm always depend on a random number to perform an operation and to find a solution for any problem.

Dynamic Programming

Dynamic Programming is useful to find a optimal solution for any problem if it exist. It will break the problems into subproblems and store the result for the future purpose so that we don’t have to perform calculation again to get the result. This approach provide the optimised solution for recursive call for the inputs.

Recursion

Recursive algorithm use the recursion technique find the solution for problem where a problem subparts will call the same function again and again.

Backtracking Algorithm

Backtracking Algorithm name itself suggest that we are going back and coming forward. If is satisfied the condition then return success or else go back again to find the next solution and continue the process till we find next solution.

Divide and Conquer Algorithm

In Divide and Conquer Algorithm, we breaks the problem into subproblems and find the solution for subproblems then merge the solution to find a final solution.

Branch and Bound Algorithm

Branch and Bound Algorithm is a technique to find the optimal solution for optimised problem by breaking down the problem into smaller sub problems and using the bounding function to eliminate the sub problem that can not have optimal solution.

Thanks for reading. Hope this blog has helped you to understand core basic concept of Algorithms. In my next blog, I will explain each algorithm and their type in detail with example written in Swift language 🙂🙂🙂.

--

--

minal kewat

iOS Dev | Tech Writer| Personal Wellness Writer | Discovering the wonders of technology and living 👾💃🌼