slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Unit III : Introduction To Data Structures and Analysis Of Algorithm PowerPoint Presentation
Download Presentation
Unit III : Introduction To Data Structures and Analysis Of Algorithm

Loading in 2 Seconds...

play fullscreen
1 / 30

Unit III : Introduction To Data Structures and Analysis Of Algorithm

0 Vues Download Presentation
Télécharger la présentation

Unit III : Introduction To Data Structures and Analysis Of Algorithm

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Unit III : Introduction To Data Structures and Analysis Of Algorithm Contents : Introduction to Data Structures: Concept of data, Data object, Data structure, Abstract Data Types, realization of ADT in 'C'. Concept of Primitive and non-primitive, linear and Non-linear, static and dynamic, persistent and ephemeral data structures. Analysis of algorithm: frequency count and its importance in analysis of an algorithm, Time complexity & Space complexity of an algorithm, Big 'O', 'Ω' and 'Θ' notations, Best, Worst and Average case analysis of an algorithm.and basic operations on file, functions used for text and binary file handling in C. Objective : • To understand primitive storage structures and types • To understand the concept of abstraction. • To understand how good or bad the algorithm is. • To understand the parameter to measure the goodness of algorithm.

  2. Contents • 1.Basic concepts • Data • Data object • Data structure • Abstract data type

  3. Contents • 2.Types Of Data Structure • Primitive and Non-Primitive • Linear and Non-Linear • Static and Dynamic • Persistent and Ephemeral

  4. Contents • 3.Analysis of Algorithm • Frequency Count • Time and Space Complexity of Algorithm • Asymptotic notation • Best case, worst case and average case analysis

  5. BasicConcepts • Data : • Information in raw or unorganized form is called as data.(alphabets , numbers, Symbols). • Types of data • Atomic: consist of single piece of information. • It can't be divided further into other meaningful pieces. e.g. Word “ Array” if we divide this word into separate characters original meaning will get lost.

  6. BasicConcepts Composite Data: It can be divided into different meaningful pieces/components. Example: “Address SKNCOE,Vadgaon,Pune-41” Even if we divide it into words every word has some meaning associated with it.

  7. BasicConcepts • Data Type : It specifies which type of value a variable can hold. • It has: • Set of data • Operations that can be performed on data • e.g. Integer is a data type .It consists of • Whole numbers in some defined range. • Operations like add, subtract, multiply, divide etc. are allowed on integers.

  8. Data Structure: It is combination of elements in which each element is either a data type or another data structure with defined rules. In simple words data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly used data structures - lists, arrays, stacks, queues, heaps, trees, and graphs.

  9. BasicConcepts Abstract Data Type(ADT): Abstracting means extracting some essential Information which we are interested in and ignoring other part. So while implementing any Abstract Data Type we hide implementation details from user so user is only extracting the information like what the data type can do and he is ignoring how it is done(implementation).

  10. BasicConcepts Understanding use of ADT: Consider an application where we want to simulate waiting line at a bank To determine how many tellers are needed to serve Customers efficiently. For this application we need to simulate “Queue”. As no such data type is available in C, we have to write code for Queue ourselves. Instead of writing a code for specific application , We can implement queue as an ADT.

  11. BasicConcepts Understanding use of ADT (contd.): i.e. Implement queue using any data structure like array or linked list. Define operations like insertion deletion etc. These implementation details are kept hidden from the user and It is made available to all users which are implementing similar applications.

  12. ClassificationOfDataStructures • 1.Linear and Non-Linear data structure: • In Linear data structures elements form a single sequence. • Every element can have at the max one successor • and one predecessor. • e.g. • Linked List Array

  13. ClassificationofDataStructure • In Non- Linear data structures this each element • can have more than one successor. • e.g. • Tree Graph

  14. ClassificationofDataStructure • 2.Static and Dynamic Data Structure: • In Static data structure memory allocation is done for the elements at complile time. • e.g. Array • int A[10]; // Fix 20 bytes are alloted for storing // 20 elements at compile time • In Dynamic Data Structures memory allocation is • done at run time(dynamically) • e.g. Linked List

  15. Classification Of Data Structure • 3.Persistent and Ephemeral Data Structure • A persistent data structure is one that when modifies preserve previous version of itself. • Such data structures are immutable(unchangeable) • as their operations do-not update structure in place. • e.g. In purely functional languages data structures are persistent • In Ephemeral data structure only one version is available at a time. After an update operation the structure which existed before the update is lost. • e.g. In Imperative languages most data structures are ephemeral.

  16. Analysis of Algorithm An algorithm is a set of instruction to be followed to solve a problem. There can be more than one solution (algorithm )to solve a problem. Before choosing a specific algorithm we have to analyse efficiency of all algorithms by focusing on two issues. 1.Space Complexity 2.Time Complexity

  17. Algorithm Analysis • Space Complexity: • The space complexityof a program is the amount of memory that it needs to run to completion. • It Depends upon: • Fixed space: C • Includes the instructions, variables, and constants • Independent of the size of problem • 2. Variable space: V • Includes dynamic allocation, functions' recursion • Total space of any program • S(P)= C+ V

  18. Algorithm Analysis e.g. Algorithm SUM() // To Sum the values in an array A Sum=0 Enter value for N Repeat for i=1 to N Sum = sum + A[i] Stop since A must be large enough to hold the N elements to be summed, size of A i.e. N varies. space needed by sum, I, and N is independent of problem size. We can write, S(P) = 3 + N. 3 for N,I and sum and N can vary for every run.

  19. Algorithm Analysis • Time Complexity: • Now a days since space available is larger and • Larger time complexity is more important issue than • Space complexity. • It is total time required by an algorithm to run a program. • Each operation in an algorithm has a cost. • e.g. count=count+1 takes some constant time.

  20. Analysis of Algorithm Frequency count: It means how many times certain instruction executed in a piece of code. Following example clears the concept:

  21. Analysis of Algorithm • Time taken by algorithm to execute on different • Machines are not same due to parameters like speed • So for defining time complexity of algorithm instead • Of writing exact frequency count we express it in a order of input size. • e.g. All algorithms having complexity functions like • 2n+3 , 4n+1, n are in same class . • Means their time complexity is in proportion of n. • Same for the functions like n3+4n2 + 20 , • 5n3+6n2 + 2, 2n3 +3 (They all are in same class)

  22. Asymptotic notations: A formal way of representing functions in different Classes. 3 Asymptotic notations: 1.Θ-notation 2.Ω notation 3.O-natation

  23. Algorithm analysis Θ-notation : Definition: Considering two non negative functions f and g, Θ(g) : {f | where f is non negative function such that there exist constants c1,c2,n1 such that c1g(n) <= f(n) <= c2 g(n) for all n>=n1 } e.g. To prove 5n3+6n2 + 2 belongs to Θ We can write 5n3 <=5n3+6n2 + 2<=5n3+6n3 + 2n3 i.e. 5n3 <=5n3+6n2 + 2< =13n3 Considering this in a form c1g(n) <= f(n) <= c2 g(n) we can say that Here c1=5 , c2=13 and n>=1=n1.

  24. Algorithm Analysis O-notation : Definition: Considering two non negative functions f and g, O(g):{f | where f is non negative function such that there exist constants c2,n1 such that f(n)>=c2g(n) for all n>=n1 }

  25. Algorithm Analysis O-notation : Definition: Considering two non negative functions f and g, O(g):{f | where f is non negative function such that there exist constants c2,n1 such that f(n)>=c2g(n) for all n>=n1 }

  26. Algorithm Analysis Special classes of algorithm: 1.Logarithmic : O(logn) 2.Linear : O(n) 3.Quadratic : O(n2) 4.Polynomal : O(nk) ,k>=1 5.Exponential : O(an) , n>1 Order :

  27. Algorithm Analysis O notation :denotes upper bound on complexity. Ω-notation :denotes lower bound on complexity. Θ-notation :denotes exact bound on complexity. e.g. 1.we can write Time complexity of linear search is O(n) where n is total no of elements in the list. Because to check for numbers in worst case we have to search whole list. 2.We can write Time complexity of an algorithm for finding maximum no from array of n elements is Ω(n) because minimum n-1 comparisons should be done. 3.We can represent time complexity of finding maximum number from an array as Θ(n) as well because we know upper bound for that algorithm too. It is O(n)

  28. Algorithm Analysis • The worst-case complexity of the algorithm: is the function defined by the maximum number of steps taken on any instance of size n. • The best-case complexity of the algorithm :is the function defined by the minimum number of steps taken on any instance of size n. • Finally, the average-case complexity of the algorithm is the function defined by the average number of steps taken on any instance of size n.

  29. UNIT-III • Thank You