100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
College aantekeningen Data Structures and Algorithms (X_400614) Final Term €10,49
In winkelwagen

College aantekeningen

College aantekeningen Data Structures and Algorithms (X_400614) Final Term

 10 keer bekeken  0 keer verkocht

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

Voorbeeld 3 van de 29  pagina's

  • 15 december 2022
  • 29
  • 2020/2021
  • College aantekeningen
  • Mehrabi
  • Alle colleges
Alle documenten voor dit vak (2)
avatar-seller
gideonrouwendaal
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”?

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

Verzekerd van kwaliteit door reviews

Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper gideonrouwendaal. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €10,49. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 53068 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€10,49
  • (0)
In winkelwagen
Toegevoegd