Professional Documents
Culture Documents
cbonchis@info.uvt.ro
Organizational
Course objectives: present main data structures, improve programming. Final grade = sum of all: 1 p appreciation, 4 p homework, 2 p - laboratory test, 3 p - problem implementation, 2 p - final exam if you have >10 p the final grade is 10, if you have <5p fail
Attendance: recommended. Expect you: To be up to date with class material. To hand out programming assignments by the stated deadlines. Expect you: Work harder than for C programming language.
Important
Academic honesty: cheating leads to failing class and reporting. OK/encouraged: speak up in class. Two-way, rather than one-way communication. Request: be concise, to the point, respect time spent together in class. Disclaimer: I can make mistakes/be wrong. Let me know (in person, email) how I can improve things.
Introduction to Algorithms, Second Edition by: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein http://mitpress.mit.edu/algorithms/ Adam Drozdek Data structures and algorithms in C++, third edition, Thomson Course Technology, 2005. Michael T. Goodrich, Roberto Tamassia, David M. Mount Data Structures and Algorithms in C++.Second Edition Gabriel Istrate last year lectures: http://gabrielistrate.weebly.com/pentru-studenti.html other prefered Data Structures books
The plan
Linked Lists. Singly linked lists, Doubly linked lists. Stacks, queues, dequeues. Binary Search Trees AVL trees. Heaps. Red-black trees. Hash tables. Augmenting Data Structures.
Data structures: a way to define data types we want. Many tasks can be specified in terms of input and output. Input/output: data. Divided into types. Predefined (in C: int, Data types can involve packaging multiple elements of
Performance requirements. Operations abstracted from requirements. Frequent operations should be fast.
Examples
Problem 1 Read a stream of words from an input. Maintainset of words, with frequencies. Want: quickly test if we have seen a word. Quickly update frequency. Problem 2 Evaluating postfix arithmetic expressions Problem 3 Computation of shortest paths from a Weighted Graph.
TCP: basis for much of Internet traffic. Data requirement: We need to buffer a packet that is out-of order. We need to pop elements that become in-order. We need to test emptyness of buffer. We need to produce first missing element Operation performance O(1)?.
(Abstract) sets of data ... E.g. complex numbers: two floats. ... together with operations one can perform on the data ... E.g. integer + (addition), - (subtraction), (multiplication) ... and performance guarantees. How to precisely implement operations is not a part of data structure specification. Concepts, not code.
Data types
All DS that share a common structure and expose the same set of operations. Predefined data types: array, structures, files. Scalar data type: ordering relation exists among elements. More complicated, dynamic DS: Lists, circular lists, trees, hash tables, graphs. Standard template library (STL): library of container classes, algorithms, and iterators; provides many of the basic algorithms and data structures of computer science
Available on most hardware. Often subject to standardization. Integer data type: subset of integers. Operations: exact. In case of overflow computation stopped. Unsigned/signed integers, twos complement.
Value -128 -127 -1 0 127 128 255 Unsigned 00000000 01111111 10000000 11111111 Signed 11111111 10000001 00000000 01111111 Two's complement 10000000 10000001 11111111 00000000 01111111 -
floating point representation. simple (32 bits), double (64 bits), extended precision (80 bits ). representation: three parts. sign, exponent, significand(mantissa). mantissa: normalized (by adjusting exponent) so that most significant bit is 1. e.g. double: 64 bits, one for the sign, 52 bits for mantissa (normalized), 11 bits exponent (base 2). arithmetic operations: +,-,*, / also % and bitwise operations.
Ensures random access to its elements. Composed of objects of the same type. int myarray[10]; One dimensional arrays. Multidimensional arrays. type name[lim1]...[limn]; alternative in C++: vector.
some OOP
OOP: revolves around concept of object Objects: created using class definition Combining of data and related operations is called encapsulation. Allow us to conceal details of object operations from other objects (information-hiding).
Classes
class C{
public: ... (functions and data members) private: ... (functions and data members)
Classes: Constructors/Destructors
class C{
public: C(); // constructor C(const C &); // copy constructor ~C(); // destructor ...
Pointers
Variables that hold addresses of other variables. Dynamic memory allocation: Assignment: *p=20; Deallocation: delete p; <=> free(p); Delete reference: upon deallocation should assign p = 0;
r is a reference variable. Must be initialized in definition as reference to a particular variable. reference: different name for/constant pointer to variable.
cout << n << << *p<< << r<< endl; 555 n= 7; (*p = 7, r = 7) 777
void swapint(int *a, int *b){ int temp = *a; *a = *b; *b = temp; } swap two reals void swapfloat(float *a, float *b){ float temp = *a; *a = *b; *b = temp; }
Generic Functions
template<class genType> (genType &el1, genType &el2){ genType tmp = el1; el1 = el2; el2 = tmp; }
Generic Classes
template<class genType> class genClass{ genType storage[50]; ... } template<class genType,int size=50> class genClass2{ genType storage[size]; ... } genClass <int> intObject1; genClass2<int,100> intObject2; E.g. see map from C++
Conclusions
Any questions?