Sunteți pe pagina 1din 31

Structuri de Date

alexandru.olteanu@cs.pub.ro
Universitatea
Politehnica
Bucureti
M.C.Escher Magic Mirror
Sistemele de calcul au nevoie de structur
STRUCTURI DE DATE CURSUL 1 Introducere
Februarie 2014
2
Ca n Matrix
STRUCTURI DE DATE CURSUL 1 Introducere
3
Februarie 2014
The Matrix
Coada (Queue)
STRUCTURI DE DATE CURSUL 1 Introducere
4
Februarie 2014
enqueue
dequeue
front
isEmpty
variaiuni: Priority Queue
Stiva (Stack)
STRUCTURI DE DATE CURSUL 1 Introducere
5
Februarie 2014
push
pop
top (peek)
isEmpty
Lista (List)
STRUCTURI DE DATE CURSUL 1 Introducere
6
Februarie 2014
add / remove
get
update
length
Dicionar (HashTable)
STRUCTURI DE DATE CURSUL 1 Introducere
7
Februarie 2014
put
get
hasKey
Grafuri (Graphs)
STRUCTURI DE DATE CURSUL 1 Introducere
8
Februarie 2014
Breadth-First Search
Depth-First Search
Arbori (Trees)
STRUCTURI DE DATE CURSUL 1 Introducere
9
Februarie 2014
Arbori Binari de Cutare (Binary Search Tree)
STRUCTURI DE DATE CURSUL 1 Introducere
10
Februarie 2014
search
add / remove
balance
use gdb
Heap
STRUCTURI DE DATE CURSUL 1 Introducere
11
Februarie 2014
300
search
add / remove
balance
Treap (Tree + Heap)
STRUCTURI DE DATE CURSUL 1 Introducere
12
Februarie 2014
proprietatea de Binary Search Tree pe cheie
proprietatea de Heap pe prioritate
search
add / remove
balance
Mulimi disjuncte
STRUCTURI DE DATE CURSUL 1 Introducere
13
Februarie 2014
Union
Find
Social Graph on Facebook
Tematica cursului i laboratorului
STRUCTURI DE DATE CURSUL 1 Introducere
14
1 - Introducere in C++
2 - Noiuni de C++ i Sortare
3 - Stive
4 - Cozi
5 - Liste generice
6 - HashTable
7 - Grafuri
8 - Arbori Binari
9 - Arbori Binari de Cutare
10 - Heap-uri
11 - Treap-uri
12 - Mulimi Disjuncte
Analiza Algoritmilor
Programare Orientata pe Obiecte
etc.
Februarie 2014
Resurse
STRUCTURI DE DATE CURSUL 1 Introducere
15
http://cs.curs.pub.ro self enrolment; curs + teme
http://ocw.cs.pub.ro/courses/sd-ca - laburi: teorie + cerinte
materiale de studiu, citit
Februarie 2014
Punctaje
STRUCTURI DE DATE CURSUL 1 Introducere
16
40p examen
12p lucrare la curs, la jumtatea semestrului
(nu este partial! nu degreveaza materia, nu se poate reface la final)
30p teme + 6p bonus
(temele pot merge pana la punctaj 120%)
20p activitate laborator + 2p bonus
(laboratoarele pot merge pana la punctaj 110%)
--------------------------------------------------------------------------
Total posibil = 110p


absolvire: minim 30p din parcurs + minim 20p din examen

Februarie 2014
Reguli
STRUCTURI DE DATE CURSUL 1 Introducere
17
mutri ntre semigrupe:
doar n primele 2 sptmni
doar cu acordul ambilor asisteni
doar n limita locurilor disponibile

punctajul laboratorului
la nceput test gril: 5 ntrebri n 5 minute
minim 3 rsp corecte pentru 30% din punctajul labului
restul de 70% din cerine publice i la prima vedere

4 teme
egale ca punctaj, intervale egale de timp
maxim 3 zile ntrziere
reguli aspre mpotriva copierii temelor
http://ocw.cs.pub.ro/courses/sd-ca/regulament
Februarie 2014
Excepii
STRUCTURI DE DATE CURSUL 1 Introducere
18
punctaje din oficiu pentru performane bune la concursuri
http://ocw.cs.pub.ro/courses/sd-ca/concursuri

labul 1:
testul se puncteaz din oficiu pentru participani
testul se d la final
focus pe familiarizare cu C++ / mediul de dezvoltare
Februarie 2014
Introduction to C++ Programming
STRUCTURI DE DATE CURSUL 1 Introducere
19
Similar to C Programming
Inclusion of headers
Definition of types/classes
Declaration of global variables
Definition of functions
The main function
Februarie 2014
#include <iostream>
#include <string>

using namespace std;

string name = "Joe";

void sayHello(name) {
cout << "Hello "<< name << endl;
}

int main()
{
sayHello(name);
return 0;
}
Global variables should be avoided when unnecessary
http://c2.com/cgi/wiki?GlobalVariablesAreBad
Extra C++ Concepts
STRUCTURI DE DATE CURSUL 1 Introducere
20

C++ classes
May contain both variables (fields) and functions with
public/private/protected access specifications
Inheritance (only very basic aspects)
the rest is handled in the OOP course

Templates (generalized classes, functions, variables, etc.)
Usually used for specifying data types
Februarie 2014
In C++, class and struct differ only in default access specifications
http://www.geeksforgeeks.org/g-fact-76/
Data Types and Cast
STRUCTURI DE DATE CURSUL 1 Introducere
21
Basic types
int
char
float
double
void only for function return values
Structured data types
struct s { int x; char y[2], z; double w };
Classes and Templates
Pointer types
int*, int**, ...
char*, char**, ...
float*, float**, ...
double*, double**, ...
void*, void**, ...
Pointers to structs
Pointers to classes
Defining (multidimensional) arrays
int v[100] // a static array named v with 100 elements, indexed from 0 to 99
int u[100][150], v[10][20][30], w[10][20][30][40], ...
char u[100], v[10][20], w[10][20][30], ...
float u[100], v[10][20], w[10][20][30], ...
struct s u[100], v[10][20], w[10][20][30], ...

Februarie 2014
Type conversions: implicit, explicit
http://www.cplusplus.com/doc/tutorial/typecasting/
Class
STRUCTURI DE DATE CURSUL 1 Introducere
22
Februarie 2014
class class_name {
access_specifier_1:
members;
methods;
access_specifier_2:
members;
methods;
...
constructor // same name as the class
destructor // ~class_name
}

Access specifier = public / private / protected
A class may contain variables and methods
Complex number(2, 3);
Function Templates
STRUCTURI DE DATE CURSUL 1 Introducere
23
Februarie 2014
class Student {
public notaSD;
bool operator>(Student s1, Student s2) {
return s1.notaSD > s2.notaSD;
}
}

getMax<Student> (andreea, mihai);
operator
overload
Class Templates
STRUCTURI DE DATE CURSUL 1 Introducere
24
Februarie 2014
KeyStorage<Student> keyElement;
1 2 3 4
Variabile i Constante
STRUCTURI DE DATE CURSUL 1 Introducere
25
Februarie 2014
#define PI 3.14

int a = 5;

const int b = 6;
int const c = 6;

float A = 2*PI*a;

a poate fi modificat

b i c nu pot fi modificate

PI se nlocuiete la precompilare
const int * c1;
int const * c2;
int * const c3;
?
const la funcii? data viitoare
Const: why & how
http://duramecho.com/ComputerInformation/WhyHowCppConst.html
Memory allocation
STRUCTURI DE DATE CURSUL 1 Introducere
26
Februarie 2014
Memory allocation in C
STRUCTURI DE DATE CURSUL 1 Introducere
27
Februarie 2014
int *ptr = malloc(10 * sizeof (int));
int *ptr = calloc(10,sizeof (int));
Memory allocation in C++
STRUCTURI DE DATE CURSUL 1 Introducere
28
Februarie 2014
Student *semigrupa = new Student[15];
delete[] semigrupa;
Complex(2,3)

~Complex()
2) Constructorul si destructorul sunt
apelati explicit
1) Constructorul este apelat explicit si
destructorul implicit la dealocare
Debugging and Coding Style
STRUCTURI DE DATE CURSUL 1 Introducere
29
Februarie 2014
Debugging tools and guidelines
http://ocw.cs.pub.ro/courses/sd-ca/resurse/debugging
Every major open-source project has its own style guide
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
Takeaway
STRUCTURI DE DATE CURSUL 1 Introducere
30
tipuri i cast
clase, constructori / destructori
variabile i constante
alocarea memoriei, pointeri
function templates i class templates
debugging
coding style
Februarie 2014
Q&A
STRUCTURI DE DATE CURSUL 1 Introducere
31
Februarie 2014

S-ar putea să vă placă și