1 / 26

Heaps Binomiais

Heaps Binomiais. Rômulo de Almeida Bruno Mestrando em Ciência da Computação Professora Liliane Salgado Disciplina - Algoritmos. Histórico Visão Geral Árvores Binomiais Heap Binomial Operações em Heaps Binomiais Aplicações Referências. Agenda.

dasan
Télécharger la présentation

Heaps Binomiais

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Heaps Binomiais Rômulo de Almeida Bruno Mestrando em Ciência da Computação Professora Liliane Salgado Disciplina - Algoritmos

  2. Histórico • Visão Geral • Árvores Binomiais • Heap Binomial • Operações em Heaps Binomiais • Aplicações • Referências Agenda

  3. “A Data Structure for ManipulatingPriorityQueues”, Jean Vuillemin, 1978 – Université de Paris-sud, Orsay, France. • ABSTRACT: A data structure is described which can be used for representing a collection of priority queues. The primitive operations are insertion, deletion, union, update, and search for an item of earliest priority. • “Implementation and analysis of binomial queue algorithms” , Brown, M.R. Histórico

  4. Estrutura de dados que faz parte das mergeableheaps (Fibonacci heaps e Soft heaps) e suporta as seguintes operações: • MAKE-HEAP() • INSERT(H,x) • MINIMUM(H) • EXTRACT-MIN(H) • UNION(H1,H2) • DECREASE-KEY(H,x,k) • DELETE(H,x) Visão Geral

  5. Estrutura de Prioridades => Ruim para Busca Visão Geral (Análise Assintótica)

  6. Uma Árvore Binomial Bké uma árvore ordenada definida recursivamente: • k = 0, um único nó • Senão, duas árvores Bk-1 ligadas: a raiz de uma é a filha mais a esquerda da outra. Árvores Binomiais

  7. Propriedades de Bk: • possui 2k nós, • a altura da árvore é k, • há exatamente nós na profundidade i, ondei = 0,...,k • a raiz tem grau k (maior grau); se os nós filhos da raiz fossem numerados da esquerda para a direita por k-1, k-2, ..., 0, um dado nó i é a raiz de uma sub-árvore Bi. • Corolário: O grau máximo de qualquer nó de uma árvore binomial de n nós é lg n. Árvores Binomiais

  8. Um Heap Binomial H é um conjunto de árvores binomiais com as seguintes propriedades: • cada árvore é ordenada como um heap mínino (ou máximo) • Há no máximo uma árvore binomial em H com uma raíz de um determinado grau. • Se H tem n nós, então ela contém no máximo lgn + 1 árvores binomiais. Prova: observe que, em binário, n tem lgn + 1 bits. Como cada árvore binomial de ordem k tem 2knós, teríamos uma árvore para cada bit de n que fosse igual a 1. Heap Binomial

  9. Heaps são representadas como listas ordenadas (por grau/altura) de árvores binomiais • Exemplo: Uma heap binomial com 13 (=1011B) nós Heap Binomial

  10. Criar novo Heap Binomial • Encontrar chave mínima • Unir dois Heaps Binomiais • Inserir nó • Extrair nó com chave mínima • Decrementar chave • Apagar chave Operações em Heaps Binomiais

  11. MAKE-BINOMIAL-HEAP() - O(1) • Cria um heap binomial vazio onde o nó inicial é igual a null • BINOMIAL-HEAP-MINIMUM(H)- O(lgn) • Retorna o menor valor H.inicio = NIL return H y := NIL x := H.inicio min := infinity while x <> NIL do ifx.chave < min thenmin := x.chave y := x x := x.irmao return y Operações em Heaps Binomiais

  12. BINOMIAL-HEAP-UNION(H1,H2) - O(lgn) • 2 partes: • Criar um heap resultante com o merge (H1, H2). • Executar um laço até que esse novo heap tenha todas as sub árvores em ordem crescente por grau e que nenhuma sub árvore tenha mesmo grau que outra. Operações em Heaps Binomiais

  13. BINOMIAL-HEAP-UNION(H1,H2) • 4 casos (x = nó inicial do heap): • 1 (x.degree != next-x.degree): os ponteiros se deslocam uma posiçao mais baixo na lista de raízes. Ou seja, x passa a apontar para seu irmao. • 2 (x.degree = next-x.degree = next-x.irmao.degree): os ponteiros se movem uma posição mais abaixo na lista, e a próxima iteração executa o caso 3 ou o caso 4. • 3 (x.degree = next-x.degree != next-x.irmao.degree & x.key <= next-x.key): remove-se next-x da lista de raízes e a liga-se a x, criando uma árvore B k + 1 • 4 (x.degree = next-x.degree != next-x.irmao.degree & x.key > next-x.key): remove-se x da lista de raízes e a liga-se a next-x, criando uma árvore B k + 1 Operações em Heaps Binomiais

  14. BINOMIAL-HEAP-UNION(H1,H2) H:=make-binomial-Heap() H.inicio := Binomial-Heap-Merge(H1,H2) ifH.inicio = NIL thenreturn H x.ant := NIL x.prox := x.irmao whilex.prox <> NIL do if (x.grau <> x.prox.grau) or (x.prox.irmao <> NIL andx.prox.irmao.grau = x.grau) thenx.ant := x x := x.prox elseifx.chave <= x.prox.chave thenx.irmao := x.prox.irmao Binomial-Link(x.prox,x) elseifx.ant = NIL thenH.inicio = x.prox elsex.ant.irmao := x.prox Binomial-Link(x,x.prox) x := x.prox x.prox := x.irmao return H Operações em Heaps Binomiais

  15. BINOMIAL-HEAP-MERGE(H1,H2) BINOMIAL-LINK(Y,Z) a = H1.inicio b = H2.inicio H1.inicio = minimoGrau(a, b) if H1.inicio = NIL return if H1.inicio = b then b = a a = H1.inicio while b <> NIL do ifa.irmao = NIL thena.irmao = b return elseifa.irmao.grau < b.grau then a = a.irmao else c = b.irmao b.irmao = a.irmao a.irmao = b a = a.irmao b = c y.pai := z y.irmao := z.filho z.filho := y z.grau := z.grau + 1 Operações em Heaps Binomiais

  16. BINOMIAL-HEAP-UNION(H1,H2) APPLET IMG 1 IMG 2 Operações em Heaps Binomiais

  17. BINOMIAL-HEAP-INSERT(H,x) - O(lgn) • BINOMIAL-HEAP-EXTRACT-MIN(H) - O(lgn) H' := makeHeap() x.pai := NIL x.filho := NIL x.irmao := NIL x.grau := 0 H'.inicio := x H := uniao(H,H‘) EXEMPLO EXEMPLO //encontrar a raiz x com a chave mínima em H e remover x da lista H':= makeHeap() //inverter a ordem da lista ligada de filhos de x, e definir H' apontando //para o inicio da lista resultante H:= Uniao(H,H') return x Operações em Heaps Binomiais

  18. BINOMIAL-HEAP-DECREASE-KEY(H,x,k) - O(lgn) • BINOMIAL-HEAP-DELETE(H,x) - O(lgn) EXEMPLO if k > x.chave thenerror “newkey is greater thancurrentkey" x.chave := k y := x z := y.pai while z <> NIL andy.chave < z.chave do troca y.chave e z.chave if y and z havesatellitefields, exchangethem, too. y := z z := y.pai BINOMIAL-HEAP-DECREASE-KEY(H,x,-∞) BINOMIAL-HEAP-EXTRACT-MIN(H) Operações em Heaps Binomiais

  19. Artigo de Vuillemin: • Job scheduling • Discrete simulation languages, where labels represent the time at which events are to occur, • Various sorting problems • Optimal code constructions • Chartre's prime number generator • Brown's power series multiplication • Numerical analysis algorithms and in graph algorithms for such problems as finding shortest paths and minimum cost spanning tree. Aplicações

  20. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, SecondEdition. MIT Pressand McGraw-Hill, 2001. ISBN 0-262-03293-7. Chapter 19: Binomial Heaps, pp.455–475. • Vuillemin, J. (1978). A data structure for manipulating priority queues. Communications of the ACM21, 309-314. Disponível: http://portal.acm.org/citation.cfm?id=359478 • http://www.cse.yorku.ca/~aaw/Sotirios/BinomialHeap.html Referências

  21. ? Dúvidas

  22. VOLTAR

  23. VOLTAR

  24. VOLTAR

  25. VOLTAR

  26. VOLTAR

More Related