Divide And Conquer
Minimum Spanning Tree
What is the difference between Algorithm and Pseudo code ?
Is a finite set of instructions that if followed accomplishes a particular task.
One needs basic programming knowledge to understand an algorithm.
Meant to be the blueprint of a code/program.
Is an English-like statement that follows a loosely defined syntax and are used to convey the design of an algorithm.
One doesnâ€™t need any knowledge in programming to understand a given pseudo code.
Can be called to be blueprint of an algorithm.
What is an algorithm and what are the properties of an algorithm?
An algorithm refers to a computable set of steps commonly used in mathematics, computing, linguistic and related disciplines to carry out certain calculations or data processing. It is an effective method which uses a list of well-defined instructions to complete a task, starting from a given initial state to achieve the desired end state.
There are five key properties for an algorithm to be called as an algorithm which are as follows :
Input can be any data considered for processing in an algorithm on which operations are being performed which are basically considered from an external file.
Output is the result data of an algorithm.
It is the quantity produced at the conclusion of an algorithm.
It is the property which tells about the unambiguousness of an instruction in the given algorithm.
Each instruction (line of code) must be as clear as possible.
An algorithm must be terminate after a finite number of steps, i.e., after number of set of instructions.
It is the property which deals about how successful an algorithm in making the user to understand, i.e., tells about the level of user-friendly nature.
What are the steps that need to follow while designing an algorithm ?
Steps required while designing an algorithm:
1. Obtain the description of the problem statement for which the algorithm is meant to be designed.
2.Analyze the given problem statement.
3.Develop the algorithm.
4.Refine and review the algorithm until it is considered to be the best one.
What are the parameters that help in deciding the best possible algorithm for a problem ?
The criteria for judging algorithms that have a more direct relationship to perform are computing the time and storage requirements.
Also called as Performance Analysis which helps one to judge the effectiveness of an algorithm.
Performance Analysis considers two most important criteria as parameters in judging, namely:
1) Time Complexity:
Time taken by a program is nothing but the collective time at both run-time and compile-time.
2) Space Complexity:
Space complexity of an algorithm is the amount of memory required to complete the execution given piece of code, i.e., program.
What do you understand by constant time complexity ?
A given algorithm is said to be taking constant time complexity if and only if the algorithms takes the same amount of time irrespective of the input data.
Searching an element in a hash table.
Printing the first element of a given array
Here, irrespective of length and type of array, it takes constant time to print the very first element.
Explain with example the concept of linear space complexity?
The instance where the space quantity required by an algorithm is proportional to the amount of the input data, i.e., the space consumed by an algorithm increases as the data of input increases, is said to be linear space complexity.
An array of elements.
Explanation: Here, the space consumed by the algorithm depends upon the number of elements, i.e., more the number of elements in the input array, greater the space consumed by the algorithm.
What do you understand by order of growth?
Order of growth is the set of functions which best describes the complexity of an algorithm (both space and time), in an asymptotic notation.
These are nine set of functions, in total.
The priority is given either on top-down or left-right order.
Higher priority is given to the topmost or left-most function and the priority decreases as one move towards down/left the chart.
An algorithm is said to be optimal if it is taking constant function for both time and space complexities.
Following is the left-right chart of order of growth: Name Constant Logarithmic Square-Root Linear Multiple Logarithmic Quadratic Cubic Exponential Factorial
Function 1 Log(n) n^(1/2) n N*Log(n) n^2 n^3 2^n n!
Explain lower bound and upper bound of an algorithm?
As the terms suggest, lower & upper bound refers to lower and upper boundary.
For an algorithm, Big Omega asymptotic function is considered to be the lower bound and Big Oh function is considered to be the upper bound.
Explain the difference between Big o, Small o notations with example.
Big Oh notation as well as small o notations varies in terms of exactness / displacement towards the upper bound.
Here, small o notation is not tight to the upper bound where as the Big o notation gives an upper bound with relation of a constant factor.
Finding the sum of elements in a given array.
Here, small O notation can be considered to be o(n) for the time complexity as it takes time to process n elements and some miscellaneous time to carry out the algorithm, where as Big o notation can be considered as O(n)+c, where c is some constant time that can be considered for that missed out extra time other than the time taken to process n elements of the array .
Differentiate Big-omega and little-omega.
Omega is considered to be the best case of a function.
Little omega and Big omega do keenly differ in terms of precision, i.e., little omega is considered to be a rough estimate of the mentioned order of growth, where as the Big-omega represents the exact order of growth.