Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

10. Introduction to Datastructure

Data structure introduction

  • Login to see the comments

10. Introduction to Datastructure

  1. 1. Introduction to Algorithms By Nilesh Dalvi Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College. http://www.slideshare.net/nileshdalvi01 Java and DataJava and Data StructuresStructures
  2. 2. Algorithm The algorithm is defined as the a collection of unambiguous instructions occurring in some specific sequence and such an algorithm should produce output for given set of input in finite amount of time. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  3. 3. Algorithm • write an algorithm to count the sum of n numbers Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm sum (1, n) { //Problem Desc: Algorithm for finding sum of n numbers //Input: 1 to n numbers //Output: Sum of n numbers result := 0; for i:= 1 to n do i:= i + 1 result := result + i; }
  4. 4. Algorithm • write an algorithm to check whether the given no is even or odd. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm EvenOddTest(val) { //Problem Desc: Algorithm for checking whether the given no is even or odd. //Input: 1 to n number //Output: Even or odd number if(val % 2 == 0) write("No is even"); esle write ("No is odd"); }
  5. 5. Algorithm • write an algorithm for sorting the given elements Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm Sort (a, n) { //Problem Desc: Algorithm for sorting the elements. //Input: An array //Output: Sorted array for i:=1 to n do { for j:= i +1 to n-1 do { if(a[i]) > a[j]) then { temp := a[i]; a[i] := a[j]; a[j] := temp; } } write("List is sorted!"); } }
  6. 6. Algorithm • write an algorithm for calculating factorial of n numbers Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm factCalc (n) { //Problem Desc: For calculating factorial of given no //Input: Number //Output: Factorial of given number if n := 1 then return 1; else return n * factCalc(n - 1); }
  7. 7. Algorithm • write an algorithm for multiply two matrices Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm mulMatrix (A, B, n) { //Problem Desc: Multilpy two matrices //Input: Matrix A and Matrix B //Output: Matrix C for i := 1 to n do for j := 1 to n do C[i][j] := 0; for k := 1 to n do C[i][j] := C[i][j] + A[i][k] * B[k][j]; }
  8. 8. Fundamentals of analysis of algorithms • The efficiency of an algorithm can be decided by measuring the performance of an algorithm. • We can measure the performance of an algorithm by computing two factors – Amount of time required by an algorithm to execute (time complexity) – Amount of storage required by an algorithm (space complexity) Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  9. 9. Space Complexity • Space complexity can be defined as amount of memory required by an algorithm to run. • To compute space complexity we use two factors : constant space and variable space • Constant space includes instructions, variables and constants • Variable space includes dynamic allocations, function recursion. • Space requirement, s(p) = C + sp • sp is the space dependent upon instance characteristics. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  10. 10. Time Complexity • The time complexity of an algorithm is the amount of computer time required by an algorithm to run complete the task. • The time complexity, T(p), taken by a program p is the sum of the compile time and the run time. • Total Time, T(p) = compile time + run (execution) time Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  11. 11. Asymptotic Notations: • To choose the best algorithm, we need to check efficiency of each algorithm. • Efficiency can be measured by computing space and time complexity. • So, Asymptotic notation is a shorthand way to represent the time complexity. • Using asymptotic notations we can give time complexity as “fastest possible”, “slowest possible” or “average time”. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  12. 12. Big Oh Notation: • Denoted by ‘O’ • Method if representing upper time of representing the upper bound of algorithms running time. • Using big Oh notation we can give longest amount of time taken by the algorithm to complete. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  13. 13. Omega Notation: • Denoted by ‘Ω’ • It is used to represent the lower bound of algorithm running time. • Using omega (Ω) notation we can denote shortest amount of time taken by algorithm. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  14. 14. Theta Notation: • Denoted by ‘Θ’ • By this method the running time is between upper bound and lower bound. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  15. 15. Data Structure • Data may be organized in many different ways. • A data structure is a arrangement of data in a computer memory or on a disk. • The logical or mathematical model of a particular organization of data is called data structure. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  16. 16. Data Structure Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  17. 17. Data Structure Operation Data appearing in data structures are processed by means of operations. Operations are: •Traversing: Accessing each record exactly once so that certain items in the record may be processed. •Searching: Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  18. 18. Data Structure Operation • Inserting: Adding the new record to the structure. • Deleting: Removing a record from the structure. Special operations: • Sorting: Arranging the records in some logical order • Merging: Combining the records in two-different sorted files into a single-sorted file. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  19. 19. Linear 1. Array: 2. Stack 3. Queue 4. Linked List Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  20. 20. Array • An array is a collection of homogeneous type of data elements. • An array is consisting of a collection of elements . • Operation Performed On Array: 1. Traversing 2. Search 3. Insertion 4. Deletion 5. Sorting 6. Merging Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). 1 2 3 4 5 Representation of array
  21. 21. Stack • A Stack is a list of elements in which an element may be inserted or deleted at one end which is known as TOP of the stack. • Operation Performed On Array: 1. Push: add an element in stack 2. Pop: remove an element in stack 3. Peek :Current processed element Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). a b c TOP
  22. 22. Queue • A queue is a linear list of element in which insertion can be done at one end which is known as REAR and deletion can be done which is known as FRONT. • Operation: 1. Insertion : add a new element in queue 2. Deletion: Removing an element in queue Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  23. 23. Queue Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  24. 24. Linked List • A Linked list is a linear collection of data elements . • It has two part one is info and other is link part. • info part gives information and link part is address of next node • Operation: 1. Traversing 2. Searching 3. Insertion 4. Deletion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  25. 25. Non-Linear 1. Graph 2. Tree 3. Table 4. Set Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  26. 26. Graph • A graph is a collection of sets V and E where V is a finite non-empty set of vertices and E is finite non- empty set of edges. • Vertices – node in graph • Edges – Two adjacent nodes are joined by edges. • Graph G = {V, E} • Operation: 1. Insertion 2. Deletion 3. Searching Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  27. 27. Tree • Tree is a finite set of one or more nodes such that – There is a specially designed node called root. – The remaining nodes are partitioned into n>=0 disjoint sets T1, T2, T3, …., Tn are called the sub-trees of the Root. • Operation: 1. Insertion 2. Deletion 3. Searching Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  28. 28. Tables • This is kind of data structure plays an important role in information retrieval. • Types of tables: – Rectangular – Jagged – Inverted – Hash • Operation: 1. Insertion 2. Deletion 3. Searching Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Key Value 0 “Abc” 1 “Pqr”
  29. 29. Sets • Heap is a complete binary tree Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  30. 30. Q & A

×