DATA STRUCTURE
1. Define Algorithm
It is a set of explicit and unambiguous finite step which, when carried out for a given set of initial conditions, produce the corresponding output and terminate in finite time.
2. What are the steps involved in problem solving aspects
-
Problem definition phase -
Getting started on a problem -
Use of specific examples -
Similarities among problems -
Working backwards from the solution -
General problem solving strategies
3. Define top down design or step (or) step wise refinement
A technique for algorithm design that tries to accommodate a very limited span of logic or instruction, It builds solutions to a problem in a step wise fashion.
4. What are the steps involved in top-down design
-
Breaking a problem into sub problem -
Choice of a suitable data structure -
Construction of loops -
Establishing initial condition for loops -
Find the iterative construct -
Termination of loops
5. What are the points to be considered during implementation of algorithms
-
use of procedure to emphasize modularity -
Choice of variable names -
Documentation of programs -
Program testing
6. What types of strategy is used in binary search? Give its analysis
Divide and conquer strategy. Analysis is n/2-O(log n)
7. What types of strategy is used in linear search? Give its analysis.Brute force approach ie., Finds the solution directly without considering the time and memory consumption. Analysis is n- O(n)
8. Define program verificationIt refers to application of mathematical proof technique to establish that the results obtained by the execution of a program with arbitray inputs are in accord with formally defined output specification.9. What are the steps involved in program verification
Computer model for program execution
Input and Output assertion
Implications and symbolic executions
Verification of straight-line program segments
Verification of program segments with branches
Verification of program segments with loops
Verification of program segments that employ array
Proof of termination.
10. What are the steps involved in efficiency of algorithm
Avoiding redundant computation
Inefficiency due to late terminations
Referencing array elements
Early diction of desired output conditions
Trading storage for efficiency gain
11. What are the steps involved in analysis of algorithm
Computational complexity
The order notation
Worst and average case behaviour
Probabilistic average case analysis
12. How will you swap two values A,BT=A;A=B;B=T; Here T is a temporary storage variable
13. Write an algorithm to find the total number of students passed in a subject
Read the number of marks
Initialize count=0
While there are still marks do
Read next mark
If it is a pass(>=50) then add one to count
Write the total number of passes=count
14. Design an algorithm to compute the average of n numbers
Read the number
Initialize sum=0
While less than n numbers have been summed do
a. Read next numberb. Compute sum=sum +number4. Write out the sum n numbers
15. Design an algorithm for e=1/0! + 1/1! + ½! +…….Long int factorial(int n){If(n<=1)Return 1;elseReturn n*factorial (n-1)}Long int series (int n){Sum=0;For(i=0;iSum=sum+1/factorial(i);print sum;}
16. Design an algorithm for sin(x)=x/1! – x^3/3! + x^5/5!-…….
Function sin(float x)
Term=x;
Tsin=x;
I=1;
X2=x*x;
While abs(term)>error do
i=i+2
term=term*x2/(j*(j-1));
tsin=tsin+term;
Print sine series as t sin
17. Design an algorithm for Fibonacci sequence
Get the n value
Initialise=0,b=1;
While i
Print the value of a&b
a=a+b;
b=a+b;
i=i+2;
Print the value of a and b
18. Design an algorithm to find the reverse the digits of an integer
Function findreverse(int n)
Initalise reverse=0
While n>0 do
reverse=reverse*10+n mod 10;
n=n div 10;
Print the reverse value
19. Design an algorithm to convert a decimal integer to octal representation
Establish the new base and initialize the quotient to the decimal number to be converted
Set the new digit count n digit to zero
Repeatedly
Compute the next most significant digit (octal) form the current quotient q as the reminder r after division by new base
Covert r to appropriate ASCII value
Increment new digit count n digit and store r in output array newrep
Compute the next quotient q from its predecessor using integer division by new base
Until the quotient is zero
20. Design an algorithm to convert integer to decimal format
Establish the character string for conversion to decimal and its length initialize decimal value to zero
Set base 0 value to ASCII or ordinal value of 0
While less than n characters have been examined do
Convert next character to corresponding decimal digit
Shift current decimal value to the left one digit and add in digit for current character
Return decimal integer corresponding to input character representation
21. Design an algorithm for factorial using recursionLong int factorial(int n){If(n<=1)Return 1;elsereturn n*factorial(n-1)}
22. Define computational complexity or time and space complexityIt is a quantitative measure (time & memory consumption) of an algorithm performance, which is necessary to step up a computational model that reflects its behaviour under specific input conditions.
23. Define worse case complexityIt is a quantitative measure of an algorithms performance for a given problem of size n corresponds to maximum complexity encountered among all problems of size n.
24. Give the analysis of nested for loopsAnalysis O (n^2)
25. Define Big OhT(N)=O(f(N)) if there are positive constants c and no such thatT(N)>=cf(N) where N>=n0
No comments:
Post a Comment