Course Name : Data Structures & Algorithms

1 of
Published on Video
Go to video
Download PDF version
Download PDF version
Embed video
Share video
Ask about this video

Page 1 (0s)

Course Name : Data Structures & Algorithms. Bharat Deshpande Computer Science & Information Systems.

Page 2 (8s)

What is a program?. Algorithm An algorithm is a step-by-step procedure for solving a problem in a finite amount of time. Data Structures Is a systematic way of organizing and accessing data, so that data can be used efficiently. Algorithms + Data Structures = Program.

Page 3 (22s)

Algorithmic problem. 3. Specification of output as a function of input Specification of input ? ???.

Page 4 (38s)

Algorithmic Solution. 4. Specification of input ? Specification of output ALGORITHM.

Page 5 (52s)

What is good algorithm?. Resources Used Running time Space used Resource Usage Measured proportional to (input) size.

Page 6 (1m 2s)

Measuring the running time. Write a program implementing the algorithm. Run the program with inputs of varying size and composition. Use a method like System.currentTimeMillis () to get an accurate measure of the actual running time..

Page 7 (1m 15s)

Limitations of experimental studies. Implementation is a must. Execution is possible on limited set of inputs. If we need to compare two algorithms we need to use the same environment (like hardware, software etc).

Page 8 (1m 29s)

Analytical model to analyze algorithm. Algorithm should be analyzed by using general methodology. This approach uses: High level description of the algorithm. Takes into account all possible inputs. Allows one to evaluate the efficiency of any algorithm in a way that is independent of the hardware and the software environment..

Page 9 (1m 45s)

Pseudo-code. A mixture of natural language and high level programming concepts that describes the main ideas behind a generic implementation of a data structure and algorithms..

Page 10 (2m 3s)

Pseudo-code. Is structured than usual prose but less formal than a programming language. Expressions Use standard mathematical symbols to describe numeric and Boolean expressions. Uses for assignment. Use = for the equality relationship. Method declaration Algorithm name(param1,param2…).

Page 11 (2m 17s)

11. Assumptions. Individual statement considered as “unit” time Not applicable for function calls and loops Individual variable considered as “unit” storage Often referred to as “algorithmic complexity”.

Page 12 (2m 29s)

Complexity Example [1]. Example 1 (Y and Z are input) X = Y * Z; X = Y * X + Z; // 2 units of time and 1 unit of storage // Constant Unit of time and Constant Unit of storage.

Page 13 (2m 41s)

13. Complexity Example [2]. Example 2 (a and N are input) j = 0; while (j < N) do a[j] = a[j] * a[j]; b[j] = a[j] + j; j = j + 1; endwhile ; // 3N + 1 units of time and N+1 units of storage // time units prop. to N and storage prop. to N.

Page 14 (2m 56s)

14. Complexity Example [3]. Example 3 (a and N are input) j = 0; while (j < N) do k = 0; while (k < N) do a[k] = a[j] + a[k]; k = k + 1; endwhile ; b[j] = a[j] + j; j = j + 1; endwhile ; // ??? units of time and ??? units of storage // time prop. to N 2 and storage prop. to N.

Page 15 (3m 12s)

Example of sorting. 15. Output a Permutation of input of numbers b 1 ,b 2 ,b 3 ,…, b n 1,2.4.6.8 Input Sequence of numbers a 1 , a 2 ,a 3 ,…,a n 8,4,6,2,1 Sort.

Page 16 (3m 41s)

16. Order Notation. Purpose Capture proportionality Machine independent measurement Asymptotic growth (i.e. large values of input size N).

Page 17 (3m 51s)

17. Motivation for Order Notation. Examples 100 * log 2 N < N for N > 1000 70 * N + 3000 < N 2 for N > 100 10 5 * N 2 + 10 6 * N < 2 N for N > 26.

Page 18 (4m 1s)

Asymptotic Analysis. Goal: To simplify analysis of running time of algorithm .eg 3n 2 =n 2 . Capturing the essence: how the running time of the algorithm increases with the size of the input in the limit..

Page 19 (4m 15s)

Asymptotic Notation. The big O notation Definition Let f and g be functions from the set of integers to the set of real numbers. We say that f(x) is in O(g(x)) if there are constants C > and k such that |f(x)| ≤ C |g(x)|, w henever x > = k. This is read as f(x) is big-oh of g(x) Note : Pair of C and k is never unique..

Page 20 (4m 34s)

20. Order Notation. Examples g(n) = 17*N + 5 lim n   g(n) / f(n) = c lim n   (17*N +5)/N = 17. The asymptotic complexity is O(N) g(n) = 5*N 3 + 10*N 2 + 3 lim n   (5*N 3 + 10*N 2 + 3) / N 3 = 5. The asymptotic complexity is O(N 3 ) g(n) = C1* N k + C2*N k-1 + … + Ck*N + C lim n   (C1* N k + C2*N k-1 + … + Ck*N + C) / N k = C1 . The asymptotic complexity is O( N k ) 2 N + 4*N 3 + 16 is O(2 N ) 5*N*log(N) + 3*N is O(N*log(N)) 1789 is O(1).

Page 21 (4m 56s)

21. Linear Search. function search (X, A, N) j = 0; while (j < N) if (A[j] == X) return j; j++; endwhile ; return “Not-found”;.

Page 22 (5m 7s)

22. Linear Search - Complexity. Time Complexity “if” statement introduces possibilities Best-case: O(1) Worst case: O(N) Average case: ???.

Page 23 (5m 17s)

23. Binary Search Algorithm. Assume: Sorted Sequence of numbers low = 1; high = N; while (low <= high) do mid = (low + high) /2; if (A[mid] = = x) return x; else if (A[mid] < x) low = mid +1; else high = mid – 1; endwhile ; return Not-Found;.

Page 24 (5m 31s)

24. Binary Search - Complexity. Best Case O(1) Worst case: Loop executes until low <= high Size halved in each iteration N, N/2, N/4, … 1 How many steps ?.

Page 25 (5m 44s)

25. Binary Search - Complexity. Worst case: K steps such that 2 K = N i.e. log 2 N steps is O(log(N)).