Lecture 1 Data Structures - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Lecture 1 Data Structures

Description:

Direct access to each element in the array so that values can be ... delete(S, i) = delete element at position I = sub(S, 0, i) sub(S, i 1, len(S)-(i 1) ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 16
Provided by: ITS7182
Category:

less

Transcript and Presenter's Notes

Title: Lecture 1 Data Structures


1
Lecture 1Data Structures
  • Shafay Shamail
  • September 05, 2006

2
Introduction
  • Course outline
  • Rules and regulations
  • Course contents
  • Grading

3
  • Rules
  • Conventions
  • Good Programming Practices

4
Data Types
  • Simple (basic)
  • char, int, float, double
  • Modifiers
  • signed, unsigned
  • Qualifiers
  • static, const, volatile, void
  • Structured (derived)
  • Arrays, structures, unions, classes
  • Advanced (composite)
  • List, queues, stacks, trees, graphs

5
Abstract Data Type (ADT)
  • Abstraction
  • Separating data from implementation
  • Generalization
  • ADT
  • A collection of related data items together with
    basic operations between them and operations to
    be performed on them

6
Arrays
  • Definition
  • Collection of items of same type in contiguous
    memory
  • ADT
  • Collection of data items/elements
  • A fixed size sequence (ordered set) of elements,
    all of the same type
  • Basic operations
  • Direct access to each element in the array so
    that values can be retrived from or stored in
    this element

7
Structures
  • Definition
  • Collection of items of same or different types in
    contiguous memory
  • ADT
  • Collection of data elements
  • A fixed-size sequence (ordered set) of elements,
    not necessarily of the same type. The elements
    are called members or fields.
  • Basic operations
  • Direct access to each member of the structure so
    that values can be retrieved or stored in this
    member

8
Strings
  • Definition
  • Collection of characters in contiguous memory
  • A special form of array
  • ADT
  • Collection of data elements
  • A finite sequence of characters drawn from some
    given character set
  • Basic operations
  • Input, output, compare, copy, insert, replace,
    length, concatenate, find, delete

9
Sequences
  • S lts0, s1, s2, , sn-1gt
  • S is of length n
  • len(S) n
  • first(S) s0
  • last(S) Sn-1
  • len(nilseq) 0
  • first(nilseq) not defined
  • last(nilseq) not defined

10
Sequences
  • abstract typedef ltlttpgtgt stp1
  • An ADT of a sequence spt1 of arbitrary length
    consisting of elements of same type tp
  • abstract typedef lttp0, tp1, , tpn-1gt stp2
  • ADT stp2, whose values are sequences of fixed
    length, and of elements of specific type
  • abstract typedef ltlttp, ngtgt stp3
  • ADT stp3, a sequence of fixed length n, all of
    same type tp elements

11
Sequences
  • abstract typedef ltltintgtgt seq1
  • Sequence of integers of any length
  • abstract typedef ltint, char, floatgt seq2
  • Sequence of length 3, consisting of int, char,
    float
  • abstract typedef ltltint, 10gtgt seq3
  • Sequence of 10 integers
  • abstract typedef ltlt , 2gtgt seq4
  • Arbitrary sequence of length 2 (pair)

12
Sequences
  • Two sequences are equal if each element of the
    first is equal to the corresponding element of
    the second
  • A subsequence is a contiguous portion of a
    sequence
  • If S is a sequence then sub(S, i, j) consists of
    j elements starting at location i within S
  • Concatenation U ST
  • All elements of S followed by all elements of T
  • Place (S, i, x)
  • Insert x after position i, or at first position
    if i-1, and shift all remaining elements to
    right by one position
  • place (S, i, x) sub(S, 0, i-1) ltxgt sub(S,
    i1, len(S)-(i1))
  • Delete
  • S-ltxgt Sequence S without all occurrences of S
  • delete(S, i) delete element at position I
  • sub(S, 0, i) sub(S, i1, len(S)-(i1))

13
ADT RATIONAL
  • / value definition /
  • abstract typedef ltinteger, integergt RATIONAL
  • condition RATIONAL1 ! 0
  • / operator definition /
  • abstract RATIONAL makerational(a,b)
  • Int a,b
  • precondition b ! 0
  • postcondition makerational0 a
  • makerational1 b
  • abstract RATIONAL add(a, b)
  • RATIONAL a, b
  • postcondition add1 a1b1
  • add0 a0b1 b0a1
  • abstract RATIONAL mult(a, b)
  • RATIONAL a, b
  • postcondition mult0 a0b0

14
ADT STRING
  • / value definition /
  • abstract typedef ltltchargtgt STRING
  • / operator definition /
  • abstract length (s)
  • STRING s
  • postcondition length len(s)
  • abstract STRING concat(s1, s2)
  • STRING s1, s2
  • postcondition concat s1s2
  • abstract STRING substr(s, i, j)
  • STRING s
  • int i, j
  • precondition 0 lt i lt len(s)
  • 0 lt j lt len(s) - i
  • postcondition substr sub(s, i, j)

15
ADT ARRAY
  • / value definition /
  • abstract typedef ltlteltype, ubgtgt ARRTYPE(ub,
    eltype)
  • / operator definition /
  • abstract eltype extract(a, i)
  • ARRTYPE(ub, eltype) a
  • int i
  • precondition 0 lt i lt ub
  • postcondition extract ai
  • abstract store(a, i, elt)
  • ARRTYPE(ub, eltype) a
  • int i
  • eltype elt
  • precondition 0 lt i lt ub
  • postcondition ai elti
Write a Comment
User Comments (0)
About PowerShow.com