Exemple : Création d un AVL avec les entrées suivantes : 9, 4, 1, 3, 2, 8, 10, 6, 5, 11, 7 9

Documents pareils
Projet de programmation (IK3) : TP n 1 Correction

Programmation Par Objets

Prénom : Matricule : Sigle et titre du cours Groupe Trimestre INF1101 Algorithmes et structures de données Tous H2004. Loc Jeudi 29/4/2004

Corrigé des exercices sur les références

Licence Bio Informatique Année Premiers pas. Exercice 1 Hello World parce qu il faut bien commencer par quelque chose...

Programmer en JAVA. par Tama

Package Java.util Classe générique

Programmation avec des objets : Cours 7. Menu du jour

OpenPaaS Le réseau social d'entreprise

Un ordonnanceur stupide

TD3: tableaux avancées, première classe et chaînes

Les arbres binaires de recherche

INTRODUCTION A JAVA. Fichier en langage machine Exécutable

Java Licence Professionnelle Cours 7 : Classes et méthodes abstraites

Java Licence Professionnelle CISII,

Exceptions. 1 Entrées/sorties. Objectif. Manipuler les exceptions ;

F. Barthélemy. 17 mai 2005

Chapitre 10. Les interfaces Comparable et Comparator 1

Les structures de données. Rajae El Ouazzani

LMI 2. Programmation Orientée Objet POO - Cours 9. Said Jabbour. jabbour@cril.univ-artois.fr

Arbres binaires de recherche

Synchro et Threads Java TM

Maîtriser le menu contextuel dans un OfficeBean

Restaurant Application Quick Reference Guide

Exercices sur SQL server 2000

Master d Informatique Corrigé du partiel novembre 2010

TD2 Programmation concurrentielle

Objets et Programmation. origine des langages orientés-objet

Une introduction à Java

Serveur d'archivage 2007 Installation et utilisation de la BD exist

Programmation Réseau. Sécurité Java. UFR Informatique jeudi 4 avril 13

Premiers Pas en Programmation Objet : les Classes et les Objets

Machines virtuelles fonctionnelles (suite) Compilation ML Java

Présentation Windows Azure Hadoop Big Data - BI

JADE : Java Agent DEvelopment framework. Laboratoire IBISC & Départ. GEII Université & IUT d Evry nadia.abchiche@ibisc.univ-evry.

Lambda! Rémi Forax Univ Paris-Est Marne-la-Vallée

La persistance des données dans les applications : DAO, JPA, Hibernate... COMPIL 2010 francois.jannin@inp-toulouse.fr 1

Auto-évaluation Programmation en Java

Introduction à JDBC. Accès aux bases de données en Java

Création d objet imbriqué sous PowerShell.

Page 1 sur 5 TP3. Thèmes du TP : l la classe Object. l Vector<T> l tutorial Interfaces. l Stack<T>

RAPPELS SUR LES METHODES HERITEES DE LA CLASSE RACINE Object ET LEUR SPECIALISATION (i.e. REDEFINITION)

TP n 2 Concepts de la programmation Objets Master 1 mention IL, semestre 2 Le type Abstrait Pile

Langage et Concepts de ProgrammationOrientée-Objet 1 / 40

Sécurité des applications web. Daniel Boteanu

Quelques patterns pour la persistance des objets avec DAO DAO. Principe de base. Utilité des DTOs. Le modèle de conception DTO (Data Transfer Object)

PHP et mysql. Code: php_mysql. Olivier Clavel - Daniel K. Schneider - Patrick Jermann - Vivian Synteta Version: 0.9 (modifié le 13/3/01 par VS)

Généralités. javadoc. Format des commentaires. Format des commentaires. Caractères spéciaux. Insérer du code

Solutions du chapitre 4

Flux de données Lecture/Ecriture Fichiers

Extension SSO Java. Cette note technique décrit la configuration et la mise en œuvre du filtre de custom SSO Java.

2. Comprendre les définitions de classes

Pour signifier qu'une classe fille hérite d'une classe mère, on utilise le mot clé extends class fille extends mère

Développement Logiciel

Java 1.5 : principales nouveautés

IFIPS 5 / Nouvelles Architectures Logicielles Projet : Bus de web services avec «moteur» BPEL

Threads. Threads. USTL routier 1

7 Développement d une application de MapReduce

Introduction à Java. Matthieu Herrb CNRS-LAAS. Mars

Utilisation d objets : String et ArrayList

ACTIVITÉ DE PROGRAMMATION

Utilitaires méconnus de StrataFrame

Paginer les données côté serveur, mettre en cache côté client

TP3. Mail. Attention aux fausses manoeuvres lors de ce TP vous pouvez endommager votre mail sur ouindose.

Communication inter-processus (IPC) : tubes & sockets. exemples en C et en Java. F. Butelle

Programme Compte bancaire (code)

Programmation Orientée Objet - Licence TIS CM8/9. Rappel sur la séance précédente. Lancelot Pecquet Lancelot.Pecquet@math.univ-poitiers.

4. Outils pour la synchronisation F. Boyer, Laboratoire Lig

Programmation Objet Java Correction

1. Structure d un programme C. 2. Commentaire: /*..texte */ On utilise aussi le commentaire du C++ qui est valable pour C: 3.

Design patterns. Design patterns - définition. Design patterns - avantages

API04 Contribution. Apache Hadoop: Présentation et application dans le domaine des Data Warehouses. Introduction. Architecture

Corrigés des premiers exercices sur les classes

Plan du cours. Historique du langage Nouveautés de Java 7

Info0101 Intro. à l'algorithmique et à la programmation. Cours 3. Le langage Java

Programmation par les Objets en Java

Comment Accéder à des Bases de Données MySQL avec Windows lorqu'elles sont sur un Serveur Linux

TD/TP PAC - Programmation n 3

Insérer des images dans Base

Introduction au langage Java

Généricité. en Java. (polymorphisme paramétrique) Philippe GENOUD UJF Janvier

Cette application développée en C# va récupérer un certain nombre d informations en ligne fournies par la ville de Paris :

ARBRES BINAIRES DE RECHERCHE

TD Objets distribués n 3 : Windows XP et Visual Studio.NET. Introduction à.net Remoting

PROJET 1 : BASE DE DONNÉES REPARTIES

Bases de données et fournisseurs de contenu

Modélisation PHP Orientée Objet pour les Projets Modèle MVC (Modèle Vue Contrôleur) Mini Framework

Durée estimée :1 journée Date de la réalisation : Description Fournisseur Référence Nombre PU HT LM35CZ, LM35AZ LM35DZ

4. Groupement d objets

TD/TP PAC - Programmation n 3

Rapport de Mini-Projet en ArcGIS Engine

Chapitre V. Les classes : Object, Vector, etc.

Olivier Mondet

Programmation Orientée Objet

ETUDE DE CAS en UML : GESTION DES COMMANDES DE PIECES FABRIQUEES PAR LA SOCIETE C

Cours 1: Java et les objets

Travaux Pratiques : Lucène - Gestion d un index plein texte

Interfaces graphiques avec l API Swing

Serveur d'application Client HTML/JS. Apache Thrift Bootcamp

Transcription:

Principe d une liste simplement chainée Algorithmes, structures, données Tail onqueue 8 7 dequeue head Arbre - Height (hauteur) : Taille du chemin le plus long vers une feuille - Size (taille) : Nombre de nœuds de l arbre - Lowness (bassesse) : Taille du chemin le plus court vers une feuille - Leaves (sorties) : Nombre de feuilles - Isomorphic: Deux arbres sont isomorphiques s ils ont la même structure (même nombre de nœuds et placés au même endroit) - Balanced : Un arbre est dit équilibré si le poids du sous arbre gauche a ou moins de différence avec le poids du sous arbre droit Arbre de recherche Lors de l insertion d une valeur on va choisir où l insérer pour avoir une recherche plus efficace, si la valeur ajoutée est inférieure à son père on va l ajouter à gauche sinon on va l ajouter à droite. AVL (un AVL est équilibré) de minimale : Hauteur de l AVL Nombre de sommets + + = + + = 7 7+ + = 5 6 7 5 Exemple : Création d un AVL avec les entrées suivantes : 9,,,,, 8,, 6, 5,, 7 9 9 9 On effectue donc une rotation : Problème car l arbre devient déséquilibré 9 9 9 On effectue alors une première rotation pour remonter, puis une seconde pour rééquilibrer l arbre : 9 9

On ne rencontre pas de problème jusqu à 5 : Qu on résout par une rotation : 9 9 8 6 6 5 8 5 Et de la même manière jusqu à la dernière insertion : 6 9 5 8 7 Si on veut retirer tous les nœuds de l arbre précédent sans avoir à le rééquilibrer on devra suivre l ordre de suppression suivant :,, 7,,, 5, 8,,, 9, 6 Implémentation java public class BinarySearchTree<AnyType extends Comparable<? super AnyType>> implements Iterable<AnyType> { // The tree root private BinaryNode<AnyType> root; * Construct the tree. public BinarySearchTree( ) { root = null; /////////////// isempty * Test if the tree is logically empty. * @return true if empty, false otherwise. public boolean isempty( ) { return root==null; /////////////// makeempty * Make the tree logically empty. public void makeempty( ) {

root=null; /////////////// contains * Find an item in the tree. * @param x the item to search for. * @return true if not found. public boolean contains( AnyType x ) { return contains(x, root); * Internal method to find an item in a subtree. * @param x is item to search for. * @return node containing the matched item. private boolean contains( AnyType x, BinaryNode<AnyType> t ) { if(t == null) return false; if(t.element.equals(x)) return true; return contains(x, x.compareto(t.element)<? t.left : t.right); /////////////// insert * Insert into the tree; duplicates are ignored. * @param x the item to insert. public void insert( AnyType x ) { root = insert(x, root); * Internal method to insert into a subtree. * @param x the item to insert. * @return the new root of the subtree. private BinaryNode<AnyType> insert( AnyType x, BinaryNode<AnyType> t ) { if(t == null) t = new BinaryNode<AnyType>(x); else{ if(t.element.compareto(x)<) t.right = insert(x, t.right); else if (t.element.compareto(x)>) t.left = insert(x, t.left); /////////////// findmin

* Find the smallest item in the tree. * @return smallest item or null if empty. public AnyType findmin( ) throws EmptyTreeException { if(isempty()) throw new EmptyTreeException(); return findmin(root).element; * Internal method to find the smallest item in a subtree. * @return node containing the smallest item. private BinaryNode<AnyType> findmin( BinaryNode<AnyType> t ) { if(t.left==null) return findmin(t.left); /////////////// findmax * Find the largest item in the tree. * @return the largest item of null if empty. public AnyType findmax( ) throws EmptyTreeException { if(isempty()) throw new EmptyTreeException(); return findmax(root).element; * Internal method to find the largest item in a subtree. * @return node containing the largest item. private BinaryNode<AnyType> findmax( BinaryNode<AnyType> t ) { if(t.right==null) return findmax(t.right); /////////////// remove * Remove from the tree. Nothing is done if x is not found. * @param x the item to remove. public void remove( AnyType x ) { if(contains(x, root)) root = remove(x, root);

* Internal method to remove from a subtree. * @param x the item to remove. * @return the new root of the subtree. private BinaryNode<AnyType> remove( AnyType x, BinaryNode<AnyType> t ) { if(t==null) return null; int c = x.compareto(t.element); if(c>) t.right=remove(x,t.right); else if(c<) t.left=remove(x, t.left); else if(t.left==null) return t.right; else if(t.right==null) return t.left; else t.left = removemax(t.left, t); private BinaryNode removemax(binarynode t, BinaryNode n){ if(t.right==null){ n.element=t.element; return t.left; t.right=removemax(t.right, n); /////////////// removelessthan * Remove from the tree all the elements * less than min * @param min the minimum value left in the tree public void removelessthan(anytype min) { root = removelessthan(root, min); private BinaryNode<AnyType> removelessthan(binarynode<anytype> t, AnyType min) { if(t==null) return null; if(min.compareto(t.element)>) return removelessthan(t.right, min); t.left=removelessthan(t.left, min);

//////////////////////////////////////////////////// // Convenience method to print a tree //////////////////////////////////////////////////// public void display() { display(root,"",""); private void display(binarynode<anytype> t, String r, String p) { if ( t == null ) { System.out.println(r); else { String rs = t.element.tostring(); System.out.println(r + rs); if ( t.left!= null t.right!= null ) { String rr = p + ' ' + makestring('_',rs.length()) + ' '; display(t.right,rr, p + ' ' + makestring(' ',rs.length() + )); System.out.println(p + ' '); display(t.left,rr, p + makestring(' ',rs.length() + )); private String makestring(char c, int k) { String s = ""; for ( int i = ; i < k; i++ ) { s += c; return s; //////////////////////////////////////////////////// // Inner class BinaryNode<AnyType> //////////////////////////////////////////////////// // Basic node stored in unbalanced binary search trees private static class BinaryNode<AnyType> { // Constructors BinaryNode( AnyType theelement ) { this( theelement, null, null ); BinaryNode( AnyType theelement, BinaryNode<AnyType> lt, BinaryNode<AnyType> rt ) { element = theelement; left = lt; right = rt; AnyType element; // The data in the node BinaryNode<AnyType> left; // Left child BinaryNode<AnyType> right; // Right child