0
1 Basic Concepts and     Notations   Data Structures – Basic Concepts and Notations   1
ObjectivesAt the end of the lesson, the student should be able to:●   Explain the process of problem solving●   Define dat...
Problem Solving Process●   Programming – a problem-solving process which could be    viewed in terms of the following doma...
Problem Solving Process         Problem Domain    Data Structures – Basic Concepts and Notations   4
Problem Solving Process         Machine Domain    Data Structures – Basic Concepts and Notations   5
Problem Solving Process         Solution Domain    Data Structures – Basic Concepts and Notations   6
Problem Solving Process●   Two related tasks at the solution domain     –   Structuring of higher level data representatio...
Data Type, Abstract Data      Type and Data Structure●   Data type - kind of data that variables can assume in a    progra...
Data Type, Abstract Data         Type and Data Structure     public interface Stack{       public int size();    /* return...
Algorithm●   Finite set of instructions which, if followed, will accomplish a    task     –   Finiteness - an algorithm mu...
Addressing Methods●   Computed Addressing Method - used to access the    elements of a structure in pre-allocated space   ...
Addressing Methods–   Memory pool or avail list - source of the nodes from which linked    structures are built           ...
Addressing Methods–   Two basic procedures that manipulate the avail list are getNode and    retNode, which requests for a...
Mathematical Functions●    Floor of x (  x  ) - greatest integer less than or equal to x, x    is any real number●    Ce...
Mathematical Functions●   Identities     –   x=x            if and only if x is an integer     –   x=x            ...
Complexity of Algorithms●   Algorithm Efficiency     –   Space utilization - amount of memory required to store the data  ...
Complexity of Algorithms●   The Big-Oh Notation (or simply O-Notation)     –   T(n) grows at a rate proportional to n and ...
Complexity of AlgorithmsRule for Sums    Suppose that T1(n) = O( f(n) ) and T2(n) = O( g(n) ).    Then, t(n) = T1(n) + T2(...
Complexity of Algorithms                                    ExamplesConsider the algorithm below :    for (i=1; i <= n, i+...
Complexity of Algorithms                                  ExamplesLINEAR SEARCH ALGORITHM1   found = false;               ...
Complexity of Algorithms●   The Big-Oh Notation              Big-Oh             Description       Algorithm           O(1)...
Complexity of AlgorithmsGeneral rules on determining the running time of an algorithm●   FOR loops     –   At most the run...
Summary●   Programming as a problem solving process could be viewed in    terms of 3 domains – problem, machine and soluti...
Upcoming SlideShare
Loading in...5
×

MELJUN CORTES Jedi slides data st-chapter01-basic concepts and notations

462

Published on

MELJUN CORTES Jedi slides data st-chapter01-basic concepts and notations

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
462
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "MELJUN CORTES Jedi slides data st-chapter01-basic concepts and notations"

  1. 1. 1 Basic Concepts and Notations Data Structures – Basic Concepts and Notations 1
  2. 2. ObjectivesAt the end of the lesson, the student should be able to:● Explain the process of problem solving● Define data type, abstract data type and data structure● Identify the properties of an algorithm● Differentiate the two addressing methods - computed addressing and link addressing● Use the basic mathematical functions to analyze algorithms● Measure complexity of algorithms by expressing the efficiency in terms of time complexity and big-O notation Data Structures – Basic Concepts and Notations 2
  3. 3. Problem Solving Process● Programming – a problem-solving process which could be viewed in terms of the following domains: – Problem domain ● input or the raw data to process ● output or the processed data – Machine domain ● storage medium - consists of serially arranged bits that are addressable as a unit ● processing unit - allow us to perform basic operations – Solution domain - links the problem and machine domains Data Structures – Basic Concepts and Notations 3
  4. 4. Problem Solving Process Problem Domain Data Structures – Basic Concepts and Notations 4
  5. 5. Problem Solving Process Machine Domain Data Structures – Basic Concepts and Notations 5
  6. 6. Problem Solving Process Solution Domain Data Structures – Basic Concepts and Notations 6
  7. 7. Problem Solving Process● Two related tasks at the solution domain – Structuring of higher level data representations – Synthesis of algorithms● Data structures and algorithms are the building blocks of computer programs Data Structures – Basic Concepts and Notations 7
  8. 8. Data Type, Abstract Data Type and Data Structure● Data type - kind of data that variables can assume in a programming language and for which operations are automatically provided● Abstract Data Type (ADT) - mathematical model with defined operations. In Java, an ADT can be expressed with an interface Data Structures – Basic Concepts and Notations 8
  9. 9. Data Type, Abstract Data Type and Data Structure public interface Stack{ public int size(); /* returns the size of the stack */ public boolean isEmpty(); /* checks if empty */ public Object top() throws StackException; public Object pop() throws StackException; public void push(Object item) throws StackException; }● Data structure – the implementation of ADT in terms of the data types or other data structures.In Java, a data structure can be expressed with a class Data Structures – Basic Concepts and Notations 9
  10. 10. Algorithm● Finite set of instructions which, if followed, will accomplish a task – Finiteness - an algorithm must terminate after a finite number of steps – Definiteness - ensured if every step of an algorithm is precisely defined – Input - domain of the algorithm which could be zero or more quantities – Output - set of one or more resulting quantities; also called the range of the algorithm – Effectiveness - ensured if all the operations in the algorithm are sufficiently basic that they can, in principle, be done exactly and in finite time by a person using paper and pen Data Structures – Basic Concepts and Notations 10
  11. 11. Addressing Methods● Computed Addressing Method - used to access the elements of a structure in pre-allocated space int x[10][20]; a = x[4][3];● Link Addressing Method – used to manipulate dynamic structures where the size and shape are not known beforehand or changes at runtime class Node{ Object info; Node link; Node() { } Node (Object o, Node l){ info = o; link = l; } } Data Structures – Basic Concepts and Notations 11
  12. 12. Addressing Methods– Memory pool or avail list - source of the nodes from which linked structures are built class AvailList { Node head; AvailList(){ head = null; } AvailList(Node n){ head = n; } } Data Structures – Basic Concepts and Notations 12
  13. 13. Addressing Methods– Two basic procedures that manipulate the avail list are getNode and retNode, which requests for a node and returns a node respectively. Node getNode(){ Node a; if ( head == null) { return null; /* avail list is empty */ } else { a = head.link; /* assign node to return to a */ head = head.link.link; return a; } } void retNode(Node n){ n.link = head.link; /* adds the new node at the start of the avail list */ head.link = n; } Data Structures – Basic Concepts and Notations 13
  14. 14. Mathematical Functions● Floor of x (  x  ) - greatest integer less than or equal to x, x is any real number● Ceiling of x (  x  ) - smallest integer greater than or equal to x, where x is any real number● Modulo - given any two real numbers x and y, – x mod y = x if y = 0 =x-y*x/y if y <> 0 Data Structures – Basic Concepts and Notations 14
  15. 15. Mathematical Functions● Identities – x=x if and only if x is an integer – x=x if and only if x is not an integer – - x  = −  x  –  x  +  y  <=  x + y  – x =  x  + x mod 1 – z ( x mod y ) = zx mod zy Data Structures – Basic Concepts and Notations 15
  16. 16. Complexity of Algorithms● Algorithm Efficiency – Space utilization - amount of memory required to store the data – Time efficiency - amount of time required to process the data ● Execution time - amount of time spent in executing instructions of a given algorithm. Notation: T(n). Several factors that affect the execution time include: – input size – Instruction type – machine speed – quality of source code of the algorithm implementation – quality of the machine code generated from the source code by the compiler Data Structures – Basic Concepts and Notations 16
  17. 17. Complexity of Algorithms● The Big-Oh Notation (or simply O-Notation) – T(n) grows at a rate proportional to n and thus T(n) is said to have “order of magnitude n” denoted by the O-notation: T(n) = O(n) – Formal definition: g(n) = O(f(n)) if there exists two constants c and n0 such that | g(n) | <= c * | f(n) | for all n >= n0. – Operations on the O-Notation: ● Rule for Sums Suppose that T1(n) = O( f(n) ) and T2(n) = O( g(n) ). Then, t(n) = T1(n) + T2(n) = O( max( f(n), g(n) ) ). ● Rule for Products Suppose that T1(n) = O( f(n) ) and T2(n) = O( g(n) ). Then, T(n) = T1(n) * T2(n) = O( f(n) * g(n) ). Data Structures – Basic Concepts and Notations 17
  18. 18. Complexity of AlgorithmsRule for Sums Suppose that T1(n) = O( f(n) ) and T2(n) = O( g(n) ). Then, t(n) = T1(n) + T2(n) = O( max( f(n), g(n) ) ). Proof: By definition of the O-notation, T1(n) <= c1 f(n) for n >= n1 and T2(n) <= c2 g(n) for n >= n2. Let n0 = max(n1, n2). Then T1(n) + T2(n) <= c1 f(n) + c2 g(n) n >= n0. <= (c1 + c2) max(f(n),g(n)) n >= n0. <= c max ( f(n), g(n) ) n >= n0. Thus, T(n) = T1(n) + T2(n) = O( max( f(n), g(n) ) ). e.g. a. T(n) = 3n3 + 5n2 = O( n3 ) b. T(n) = 2n + n4 + n log n = O( 2n ) Data Structures – Basic Concepts and Notations 18
  19. 19. Complexity of Algorithms ExamplesConsider the algorithm below : for (i=1; i <= n, i++) for (j=1; j <= n, j++) // steps which take O(1) timeSince the steps in the inner loop will take n + n-1 + n-2 + ... + 2 + 1 times, then the running time is n( n+1 ) / 2 = n2 / 2 + n / 2 = O( n2 ) Data Structures – Basic Concepts and Notations 19
  20. 20. Complexity of Algorithms ExamplesLINEAR SEARCH ALGORITHM1 found = false; T( n ) = 3n + 3 so that T( n ) = O( n )2 loc = 1;3 while ((loc <= n) && (!found)){ Since g( n ) <= c f( n ) for n >= n 0, then4 if (item == a[loc]found = true;5 else loc = loc + 1;6 } 3n + 3 <= c nSTATEMENT # of times executed 3n + 3 <= c = 3 + 3 / n <= c1 12 1 ---------3 n+1 n4 n5 n Thus c = 4 and n0 = 3. Data Structures – Basic Concepts and Notations 20
  21. 21. Complexity of Algorithms● The Big-Oh Notation Big-Oh Description Algorithm O(1) Constant O(log2n) Logarithmic Binary Searc h O(n) Linear Sequential Search O(n log2n) Heapsort O(n2) Quadratic Insertion Sort O(n3) Cubic Floyd’s Algorithm O( 2n ) Exponential F(n) Running Time log2n 19.93 microseconds n 1.00 seconds n log2n 19.93 seconds n2 11.57 days n3 317.10 centuries 2n Eternity Data Structures – Basic Concepts and Notations 21
  22. 22. Complexity of AlgorithmsGeneral rules on determining the running time of an algorithm● FOR loops – At most the running time of the statement inside the for loop times the number of iterations.● NESTED FOR loops – Analysis is done from the inner loop going outward. The total running time of a statement inside a group of for loops is the running time of the statement multiplied by the product of the sizes of all the for loops.● CONSECUTIVE STATEMENTS – The statement with the maximum running time.● IF/ELSE – Never more than the running time of the test plus the larger of the running times of the conditional block of statements. Data Structures – Basic Concepts and Notations 22
  23. 23. Summary● Programming as a problem solving process could be viewed in terms of 3 domains – problem, machine and solution.● Data structures provide a way for data representation. It is an implementation of ADT.● An algorithm is a finite set of instructions which, if followed, will accomplish a task. It has five important properties: finiteness, definiteness, input, output and effectiveness.● Addressing methods define how the data items are accessed. Two general types are computed and link addressing.● Algorithm efficiency is measured in two criteria: space utilization and time efficiency. The O-notation gives an approximate measure of the computing time of an algorithm for large number of input Data Structures – Basic Concepts and Notations 23
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×