You are on page 1of 8

1) What is a Computer Algorithm?

An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time. 2) What are the features of an algorithm? More precisely, an algorithm is a method or process to solve a problem satisfying the following properties: Finiteness terminates after a finite number of steps Definiteness Each step must be rigorously and unambiguously specified. -e.g., stir until lumpy Input Valid inputs must be clearly specified. Output can be proved to produce the correct output given a valid can be proved to produce the correct output given a valid input. Effectiveness Steps must be sufficiently simple and basic. 3) Show the notion of an algorithm.

4) What are different problem types?

5) What are different algorithm design techniques/strategies?

Brute force Divide and conquer Decrease and conquer Transform and conquer Space and time tradeoffs Greedy approach Dynamic programming Backtracking Branch and bound

6) What are fundamental data structures? list array linked list string stack queue priority queue graph tree set and dictionary

7) What are the sequence of steps in designing and analyzing the algorithm? Fundamentals of Algorithmic Problem Solving Understanding the problem Asking questions, do a few examples by hand, think about special cases, etc. Deciding on Exact vs. approximate problem solving Appropriate data structure Design an algorithm Proving correctness Analyzing an algorithm Time efficiency : how fast the algorithm runs Space efficiency: how much extra memory the algorithm needs. Coding an algorithm

8) What is algorithm analysis framework? Analysis of algorithms means to investigate an algorithms efficiency with respect to resources: running time and memory space Time efficiency: how fast an algorithm runs. Space efficiency: the space an algorithm requires. Typically, algorithms run longer as the size of its input increases We are interested in how efficiency scales wrt input size Analysis Framework Measuring an inputs size Measuring running time Orders of growth (of the algorithms efficiency function) Worst-base, best-case and average-case efficiency 9) How the running time of an algorithm is measured? Units for Measuring Running Time

Count the number of times an algorithms basic operation is executed. Basic operation: the operation that contributes the most to the total running time. For example, the basic operation is usually the most time-consuming operation in the algorithms innermost loop. 10) How time effieciency is analysed? Time efficiency is analyzed by determining the number of repetitions of the basic operation as a function of input size.

input size

running time

T(n) copC (n)


execution time for the basic operation Number of times the basic operation is executed

11) What is orders of growth? Orders of Growth

12) What are Worst-Case, Best-Case, and Average-Case Efficiency ? Worst case Efficiency Efficiency (# of times the basic operation will be executed) for the worst case input of size n. The algorithm runs the longest among all possible inputs of size n. Best case Efficiency (# of times the basic operation will be executed) for the best case input of size n. The algorithm runs the fastest among all possible inputs of size n.

Average case: Efficiency (#of times the basic operation will be executed) for a typical/random input of size n. NOT the average of worst and best case How to find the average case efficiency? 13) What are asymptotic notations? Explain in detail. Asymptotic Growth Rate Three notations used to compare orders of growth of an algorithms basic operation count O(g(n)): class of functions f(n) that grow no faster than g(n) (g(n)): class of functions f(n) that grow at least as fast as g(n) (g(n)): class of functions f(n) that grow at same rate as g(n) O-notation Formal definition A function t(n) is said to be in O(g(n)), denoted t(n) O(g(n)), if t(n) is bounded above by some constant multiple of g(n) for all large n, i.e., if there exist some positive constant c and some nonnegative integer n0 such that t(n) cg(n) for all n n0

-notation Formal definition

A function t(n) is said to be in (g(n)), denoted t(n) (g(n)), if t(n) is bounded below by some constant multiple of g(n) for all large n, i.e., if there exist some positive constant c and some nonnegative integer n0 such that t(n) cg(n) for all n n0

-notation Formal definition A function t(n) is said to be in (g(n)), denoted t(n) (g(n)), if t(n) is bounded both above and below by some positive constant multiples of g(n) for all large n, i.e., if there exist some positive constant c1 and c2 and some nonnegative integer n0 such that c2 g(n) t(n) c1 g(n) for all n n0

12) What are basic efficiency classes? Basic Efficiency classes 1 log n n n log n n2 Basic Efficiency classes n3 2n n! constant logarithmic linear n log n quadratic cubic exponential factorial

13) Give an example for basic operations. Input size and basic operation examples Problem Input size measure Basic operation Key comparison

Searching for key in a Number of lists items, list of n items i.e. n

Multiplication of two Matrix dimensions or Multiplication of two matrices total number of elements numbers Checking primality of ansize = number of digits Division given integer n (in binary representation) Typical graph problem #vertices and/or edges Visiting a vertex or traversing an edge

14) Write an algorithm for counting binary digits for a decimal number.

15) Write an algorithm for matrix multiplication.

You might also like