Basics of Algorithms in Swift
Algorithm is the set of rules or instruction to solve any given problem effectively and efficiently.
Why writing algorithm is important ?
- Algorithm help us to write a solution for complex problem effectively and efficiently.
- It provide optimised process to solve any problem.
- Algorithms are faster and easy to perform. we can write algorithm in any language .
- Algorithms are human readable.
Required elements to write an standard algorithm :-
- Algorithm’s each steps should be clear and precise.
- Algorithm must terminate after a finite time.
- An Algorithm should be simple and feasible, it can be executed with available resources.
- Algorithm’s input and output should be well defined.
- Algorithm should zero or more input.
- An Algorithm must produce at least one output.
Types of algorithm -
- Searching Algorithm
- Sorting Algorithm
- Greedy Algorithm
- Mathematical Algorithm
- Geometric Algorithm
- Bitwise Algorithm
- Randomized Algorithm
- Dynamic Programming
- Recursion
- Backtracking
- Divide and Conquer
- 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 🙂🙂🙂.