Garantie de satisfaction à 100% Disponible immédiatement après paiement En ligne et en PDF Tu n'es attaché à rien
logo-home
College aantekeningen Data Structures and Algorithms (X_400614) Final Term $11.80
Ajouter au panier

Notes de cours

College aantekeningen Data Structures and Algorithms (X_400614) Final Term

 0 fois vendu
  • Cours
  • Établissement

Alle College aantekeningen voor Data Structures and Algorithms (na de midterm)

Aperçu 3 sur 29  pages

  • 15 décembre 2022
  • 29
  • 2020/2021
  • Notes de cours
  • Mehrabi
  • Toutes les classes
avatar-seller
Trees and AVL tress
The height of a node:

- If the node has no children: -1
- If the node is a parent: 0
- Height of a random node is the max height (left subtree , right subtree) + 1
- Balance is (the height of the left subtree – height of the right subtree) is smaller or equal to 1

If the equation of the balance is positive: left-heavy. If it is negative: right-heavy.

If the tree is left-heavy:

- Right rotation
- Left-right rotation

If the tree is right-heavy:

- Left rotation
- Right-left rotation

Trees important points
- A node without children is a leaf (external node)
- Each node with children is an internal node
- The depth of a node is the length of the path from that node to the root
- The height of a node is the length of the longest path from that node to a leaf

A Binary tree: each node has AT MOST 2 children

A full Binary tree: all internal nodes have 2 children OR 0 children. The following holds if the tree is a
binary tree: the amount of leaves = the amount of internal nodes + 1

Running time of 3 traversal algorithms: Big Theta of n. Each node will be visited exactly 2 times ( in
preorder and inorder) and three times in postorder. Total number of inorder and preorder is 2n and
postorder 3n  Theta(n). Each visit is Theta(1)

AVL trees
Height-Balanced property: for every internal node v, the heights of its children differ at most 1

The height of an AVL tree storing n keys = O(log(n))

Running time of search operation assuming the size of the input tree is n? Big O of log(n)

Running time of insertion operation assuming the size of the input tree is n? Big O of log(n)

Running time of deletion operation assuming the size of the input tree is n? Big O of log(n)



Hash tables
In general: hash tables are able to perform every dictionary operation in O(1) time, in average
(expectation)

,Preventing collisions by chaining
Worst case search time could be Theta(n), because than it is just a linked list

Simple Uniform Hashing: the hash function maps a key to a uniform choice  each of the slots is
equally likely to be hashed to

For a set of n keys and slots we have: the expected (average) length of each chain is n/m (load
factor)

If Simple Uniform Hashing is applied: each dictionary operation will take O(1 + load factor)

Open addressing
In a has table with load factor alpha in which collisions are resolved by open-addressing, the
expected runtime of an unsuccessful search is theta (1/(1-alpha)), under the assumption of simple
uniform hashing.

In a hash table with load factor alpha in which collisions are resolved by open-addressing, the
expected runtime of a successful search is theta ((1-alpha) * log(1/1-alpha)), under the assumption
of simple uniform hashing.

If you want to delete an item in hashtable, write a special character once the deletion has been
performed. If you search for new items to delete, the algorithm to delete an item will assume “it is
full” and will continue searching for the to-delete item.

What is the space complexity of a hash table of size m storing n items, in which collisions are
resolved using chaining?

Theta(n+m)

What is the space complexity of a hash table of size m storing n items, in which collisions are
resolved using open-addressing?

Theta(m)

Suppose we wat to store a set S of n keys in a hash table T with size m, with m = n + 2, and a hash
function that behaves uniformly. Should we resolve collisions with chaining or with open-
addressing?

, Hash-table using open addressing from hashtable with m slots to 2m slots is expanding. (If the
amount of elements cannot suit the amount of slots). From 2m slots to m slots is shrinking.



Lecture 6: AVL trees and Hash Tables
AVL trees
Data structure that is an efficient data structure for implementing dictionary ADT. AVL trees are able
to perform every dictionary operation in O(log(n)) worst-case time.

Ideally we wish to have BSTs that have always a small height, no matter how the sequence of
insertion/deletion is. This would result in having fast dictionary data structures! AVL trees are BSTs
that have always a small height.

Height-Balanced Property: For every internal node v of T, the heights of children of v differ by at
most 1. Any binary search tree T that satisfies the height-balanced property is called an AVL tree.

The promise is that the heights of siblings don't differ by more than 11. In other words,
the promise is that for every node pp, the heights of the children of pp differ by at
most 11 from each other.

The height of an AVL tree storing n keys is O(logn)

If you perform an insertion, this might violate the height-balance property of T. If it violates, how to
“repair”?

Les avantages d'acheter des résumés chez Stuvia:

Qualité garantie par les avis des clients

Qualité garantie par les avis des clients

Les clients de Stuvia ont évalués plus de 700 000 résumés. C'est comme ça que vous savez que vous achetez les meilleurs documents.

L’achat facile et rapide

L’achat facile et rapide

Vous pouvez payer rapidement avec iDeal, carte de crédit ou Stuvia-crédit pour les résumés. Il n'y a pas d'adhésion nécessaire.

Focus sur l’essentiel

Focus sur l’essentiel

Vos camarades écrivent eux-mêmes les notes d’étude, c’est pourquoi les documents sont toujours fiables et à jour. Cela garantit que vous arrivez rapidement au coeur du matériel.

Foire aux questions

Qu'est-ce que j'obtiens en achetant ce document ?

Vous obtenez un PDF, disponible immédiatement après votre achat. Le document acheté est accessible à tout moment, n'importe où et indéfiniment via votre profil.

Garantie de remboursement : comment ça marche ?

Notre garantie de satisfaction garantit que vous trouverez toujours un document d'étude qui vous convient. Vous remplissez un formulaire et notre équipe du service client s'occupe du reste.

Auprès de qui est-ce que j'achète ce résumé ?

Stuvia est une place de marché. Alors, vous n'achetez donc pas ce document chez nous, mais auprès du vendeur gideonrouwendaal. Stuvia facilite les paiements au vendeur.

Est-ce que j'aurai un abonnement?

Non, vous n'achetez ce résumé que pour $11.80. Vous n'êtes lié à rien après votre achat.

Peut-on faire confiance à Stuvia ?

4.6 étoiles sur Google & Trustpilot (+1000 avis)

64670 résumés ont été vendus ces 30 derniers jours

Fondée en 2010, la référence pour acheter des résumés depuis déjà 15 ans

Commencez à vendre!

Récemment vu par vous


$11.80
  • (0)
Ajouter au panier
Ajouté