Datastructuren Flashcards

INFODS van universiteit Utrecht

1
Q

Satellite data

A

The data associated with the keys in an input array for the sorting problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Record

A

A key and satellite date together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does insertion sort work with a stack of cards?

A

Start with an empty left hand and a pile of cards on the table.
Pick up the first card and put it in your left hand.
At every time step, remove one card from the pile on the table and compare it to the right-most card in your left hand. Go from right to left until you find a card that is lower or equal than the card you picked. Insert the card you picked on the right of this card.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the insertion sort algorithm take as input?

A

An array A containing the data and an integer n representing the number of keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

INSERTION-SORT(A, n)

A

for i=2 to i=n
…key = A[i]
…j = i-1
…while j>0 and A[j] > key
… … A[j+1] = A[j]
… … j = j-1
…A[j+1] = key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the input array A look like at each iteration of the for-loop in insertion sort?

A

The subarray A[1:i-1] is the sorted ‘left hand’ and the subarray A[i+1:n] is the unsorted ‘pile on the table’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What three things do you need to prove when using a loop invariant?

A
  1. Initialization
  2. Maintenance
  3. Termination
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you prove initialization for a loop invariant?

A

Prove that the loop invariant is true prior to the first loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you prove maintenance for a loop invariant?

A

Prove that, if the loop invariant is true before an iteration, then it will be true before the next iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you prove termination for a loop invariant?

A

Prove that the loop terminates, and that the loop invariant gives a useful property when the loop terminates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In a loop of ‘for i=2 to i=n’, what is the value of ‘i’ when the loop terminates?

A

i = n+1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Wat is het verschil tussen databases en datastructuren?

A

Bij databases bemoei je je niet met details van opslag, maar stop je vragn ‘aan de data’ in de SQL-query. Bij datastructuren probeer je beste organisatie van je data te vinden terwijl je rekening houdt met vragen die je gaat stellen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Wat zijn de kosten van operaties in een ongesorteerde rij?

A

Toevoegen is makkelijk, O(1).
Zoeken is makkelijk maar tijdrovend, want je moet het query-element vergelijken met elk element, O(n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Enumeratie

A

Een bepaalde handeling met elk element doen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Wat zijn de kosten van toevoegen en zoeken in een gesorteerde rij?

A

Toevoegen is duur, want alles wat groter is dan x moet 1 plek opschuiven en dan moet je x daaronder invoegen, O(n). Zoeken kan snel, je kunt stoppen als je een el >x ziet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Wat zijn de 4 componenten van een loop?

A
  1. Initialisatie
  2. Conditie
  3. Body
  4. Terminatie
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Wat is de rekentijd van Binair zoeken?

A

O(lg n), logaritmisch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Hoe bewijs je een statement ‘A=B’ met inductie?

A

Herschrijf één kant stapsgewijs. Zet per stap de motivatie tussen {accolades}.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Hoe bewijs je een eigenschap ‘voor alle natuurlijke getallen’ met inductie?

A
  1. Neem n=0 en bewijs dat LHS en RHS tot hetzelfde herleid worden.
  2. Neem aan dat P(n) is waar en bewijs dat als P(n), dan P(n+1).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Wat zijn de onderdelen van de inductiestap ‘Als P(n), dan P(n+1) bewijzen?

A
  1. Isoleer de LHS van de inductiehypothese in de LHS van het ‘te bewijzen’.
  2. Vervang binnen de expressie de LHS door de RHS van de inductiehypothese.
  3. Werk naar de RHS van het ‘te bewijzen’ toe.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the worst-case running time of Quicksort?

A

THETA(n^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the expected running time of Quicksort if all elements are distinct?

A

O(n lg n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the three steps in the divide-and-conquer method?

A
  1. Divide an array A[p:r] in A[p : q-1] and A[q+1 : r]. The pivot is q.
  2. Call the algorithm recursively to each subarray.
  3. Combine the subarrays into A.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

QUICKSORT(A, p, r)

A

if (p<r)
{ q = PARTITION(A,p,r);
QUICKSORT(A,p,q-1);
QUICKSORT(A, q+1, r);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

PARTITION(A,p,r)

A

x = A[r];
i = p-1;
for(j=p to r-1)
{ if(A[j]<=x)
{ i++;
exchange A[i] with A[j]
}
exchange A[i+1] with A[r]
return i+1;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Stabiel (algoritme)

A

Een sorteeralgoritme waarbij records met gelijke keys in dezelfde volgorde blijven staan.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Comparison sort algoritme

A

Een sorteeralgoritme dat elementen verplaatst op basis van onderling vergelijken.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Is insertion sort stabiel?

A

Ja, als je stopt bij een key die gelijk is aan x en niet <x.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Wat is de complexiteit van insertion sort?

A

O(n^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Wanneer kun je insertion sort wél gebruiken?

A

Bij een array met ong. max. 20 keys, of als de keys al ongeveer op volgorde staan.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Wat is de invariant van selection sort?

A

Na i ronden bevat A[0 : i-1] de kleinste keys in oplopende volgorde.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Wat is de variant in Quicksort?

A

(s-r), de omvang van het onbekende stuk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

In welke drie groepen worden termen verdeeld bij de analyse van algoritmen?

A
  1. Exponentieel
  2. Polynomiaal
  3. Logaritmisch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Exponentieel

A

Met n in de exponent. De term met het hogere grondtal is leidend.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Polynomiaal

A

Een macht van n, de term met de hogere exponent is leidend.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Logaritmisch

A

Een macht van lg n. Grondtal maakt niet uit, een macht van n binnen de lg ook niet. Een macht van de log maakt wel uit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Asymptotic efficiency

A

How the running time of an algorithm increases with the size of the input in the limit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

O-notation (informal)

A

Characterizes an upper bound on the asymptotic behavior of a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Ω-notation

A

Characterizes a lower bound on the asymptotic behavior of a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Ω-notation (formal)

A

Ω(g(n)) = { f(n): there exist positive constants c and n0 such that 0<=cg(n)<=f(n) for all n>=n0}.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Θ-notation (informal)

A

Characterizes a tight bound on the asymptotic behavior of a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Θ-notation (formal)

A

Θ(g(n)) = { f(n): there exist positive constants c1, c2 and n0 such that 0<=c1g(n)<=f(n)<=c2g(n) for all n>=n0}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

O-notation (formal)

A

O(g(n)) = { f(n): there exist positive constants c and n0 such that 0<=f(n)<=cg(n) for all n>=n0}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

[theorem] For any two functions f(n) and g(n), we have f(n) = Θ(g(n)) if and only if…

A

f(n) = O(g(n)) and f(n) = Ω(g(n))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What does it mean if the asymptotic notation appears on the left-hand side of an equation?

A

No matter how the anonymous functions are chosen on the left of the euqual sign, there is a way to choose the anonymous functions on the right side of the equal sign to make the equation valid.

46
Q

What is o-notation used for?

A

To characterize an upper bound that is not asymptotically tight.

47
Q

o-notation (formal)

A

o(g(n)) = { f(n): for any positive constant c>0, there exists a constant n0>0 such that 0<=f(n)<cg(n) for all n>=n0}.

48
Q

ω-notation (formal)

A

ω(g(n)) = { f(n): for any positive c>0, there exists a constant n0>0 such that 0<=cg(n)< f(n) for all n>=n0}/

49
Q

Transitivity in asymptotic comparisons

A

f(n) = ASYMPTOTIC THING(g(n)) and g(n) = SAME ASYMPTOTIC SIGN(h(n)) imply f(n) = SAME AS. THING(h(n))

50
Q

Binary logarithm

A

lg n = log2n

51
Q

Natural logarithm

A

ln n = loge(n)

52
Q

lg^k (n) =

A

(lg n)^k

53
Q

What is the running time of any comparison sort for a regular case?

A

THETA (n lg n)

54
Q

Full binary tree

A

A tree in which each node is either a leaf or has both children

55
Q

Decision tree

A

A full binary tree in which each internal node indicates a comparison. The length of the longest simple path from the root to any leaf is the worst-case number of comparisons.

56
Q

A binary tree of height h has no more than … leaves.

A

2^h

57
Q

What does counting sort do?

A

It determines for each input element the number of elements less than or equal to hat element and places the element in the correct position in the output array.

58
Q

COUTNING-SORT(array A, int n, int k)

A

Make new arrays B[1:n] and C[0:k];
for i=0 to k {C[i] =0}
for j=1 to n {C[A[j]] ++;}
for i = 1 to k {C[i] = C[i] + C[i-1]}
for j=n downto 1 {B[ C[A[j]]] = A[j]; C[A[j]]–;}
return B

59
Q

Is counting sort stable?

A

yes

60
Q

RADIX-SORT(array A, int n, int d)

A

for i = 1 to d {sort array A[1:n] on digit i with a stable sorting algorithm, usually CS}

61
Q

What does bucket sort do?

A

It assumes that the input is drawn from a uniform distribution. Interval [0,1] is divided into n equal-sized subintervals and n input numbers distributed in the buckets. Sorts each bucket and then adds together.

62
Q

What is the average running time of bucket sort?

A

O(n)

63
Q

BUCKET-SORT(array A, int n)

A

Make new array B[0:n-1]
for i=0 to n-1 {make B[i] empty list;}
for i =1 to n {insert A[i] into list B[FLOOR(n*A[i]-1];}
for i =0 to n-1 {sort list B[i] with insertion sort;}
concatenate lists
return concatenated list

64
Q

Wat voor aanpassing doe je als je counting sort voor letters ipv ints gebruikt?

A

C[A[i] - ‘letter’] ++; ipv C[A[i]]++;

65
Q

Welke sorteeralgoritmes sorteren in-situ?

A
  1. Quicksort
  2. Insertion sort
  3. Heapsort
66
Q

welke sorteeralgoritmes sorteren niet in-situ?

A
  1. Counting sort
  2. Bucket sort
  3. Merge sort
67
Q

Wat betekent x&raquo_space; 16?

A

Een bitshift van 16. Geeft 16 nullen + de meest significante (1e) bits van getal x.

68
Q

Welke twee dingen moet je aantonen bij het bewijzen van ‘elke vorm van comparison sort gebruikt OMEGA(n lg n) vergelijkngen’?

A
  1. Een comparison heeft 2 mogelijke uitkomsten
  2. Het algoritme moet minimaal n! verschillende dingen kunnen doen, want n! verschillende inputvolgorden moeten op een andere manier herschikt worden.
69
Q

Hoeveel knopen zitten er maximaal op laag V van een tree?

A

2^V, want elke knoop heeft max 2 knopen onder zich

70
Q

Recursie

A

Een ontwerptechniek waarbij je je eigen product vast gebruikt door te doen alsof je kleinere problemen al opgelost hebt.

71
Q

Hoeveel tijd kost het vermenigvuldigen van n-digit getallen?

A

Theta(n^2), maar kan ook sneller.

72
Q

Rekenregel ‘Domeinsplitsing’

A

Als p<=r<=q, dan geldt SUM(i=p;i=r-1) A[i]
= SUM(i=p;i=r-1) A[i] + SUM(i=r;i=q-1) A[i].

73
Q

Recurrente betrekking

A

Definieert de waarde van een functie in termen van de waarde(n) voor kleinere parameter(s). Ook wel de Z-formule.

74
Q

Hoeveel kost het ritsen van n keys?

A

Theta (n)

75
Q

Uit welke twee onderdelen bestaat een recurrente betrekking?

A
  1. Randvoorwaarde
  2. Voortgangsvergelijking
76
Q

Welke drie dingen zijn onbelangrijk bij het asymptotisch oplossen van een recurrente betrekking?

A
  1. De randvoorwaarde
  2. Afronden bij delen
  3. Exacte voorwaarden van extra termen
77
Q

Wat is wél belangrijk bij het asymptotisch oplossen van een recurrente betrekking?

A

Hoe vaak je in recursie gaat.

78
Q

Given a sequence a_1 to a_n of numbers, where n is a nonnegative integer, the
finite sum of a_1 to a_n can be expressed as:

A

SUM (k=1; k=n) a_k

79
Q

What is the value of a summation for n < start value?

A

0

80
Q

What happens if the limit of a summation does not exist?

A

The series diverges.

81
Q

What happens if the limit of a summation does exist?

A

The series converges.

82
Q

How do you express the arithmetic series 1+2+3+…+n with a formula?

A

SUM(k=1; k=n) k
= n(n+1) / 2

83
Q

What is the formula for the sum of squares?

A
     6
84
Q

What is the formula for the sum of cubes?

A
       4
85
Q

What is the formula for this series: 1 + x + x^2 + x^3 + … + x^n?

A
       x-1
86
Q

What is the harmonic series?

A

1 + 1/2 + 1/3 + … + 1/n

87
Q

What does it mean when a sum telescopes?

A

Each of the terms is added in and subtracted out exactly once.

88
Q

How do you convert a formula with a product to a formula with a summation?

A

lg (PRODUCT a_k) = SUM( lg a_k)

89
Q

Sommatievariabele

A

De variabele die elke iteratie verandert, is gebonden en heeft buiten de sommatie geen betekenis.

90
Q

Term-formule

A

De formule binnen een sommatie die de termwaarde beschrijft afhankelijk van de sommatievariabele.

91
Q

Rekenkundige rij

A

Een rij getallen waarbij het verschil van opeenvolgende termen constant is.

92
Q

Rekenkundige reeks

A

De sommatie van een rekenkundige rij.

93
Q

Constant

A

Niet afhankelijk van de index-variabele.

94
Q

Meetkundige reeks

A

Een reeks getallen waarin het quotient van opeenvolgende termen constant is.

95
Q

Als de eerste term van een meetkundige reeks waarde A heeft en de groeifactor is r, dan is de sommatie:

A

SOM(i=0, n-1) A * (r^i)

96
Q

Vuistregel meetkundige reeks

A

(volgende-eerste) / (groeifactor-1)

97
Q

SOM(i=0, oneindig) i* (x^i) = … als |x|<1

A

x / (x-1)^2

98
Q

Constante factor regel

A

SOM(i=p, q) C * A_i =
C * SOM(i=p,q) A_i

99
Q

Constante term regel

A

SOM(i=p, q) C =
(q-p+1) * C

100
Q

Leeg domein regel

A

SOM(i=p, p-1) A_i=
0

101
Q

Eenpuntsregel

A

SOM(i=p, p) A_i=
A_p

102
Q

Termsplitsing regel

A

SOM(i=p, q) (A_i + B_i) =
SOM(i=p, q) A_i + SOM(i=p, q) B_i

103
Q

Domeinsplitsing regel

A

SOM(i=p, q) A_i =
SOM(i=p, r) A_i + SOM(i=r+1, q) A_i

104
Q

Afsplitsen regel

A

SOM(i=p, q) A_i =
SOM(i=p, q-1) A_i + A_q

105
Q

Hernoemen regel

A

SOM(i=p, q) A_i =
SOM(j=p, 1) A_j

106
Q

Dummy-transformatie regel

A

SOM(i=p, q) A_i =
SOM (i=pi(p), pi(q)) A_((pi^-1)*i)

107
Q

Wat doe je bij dummy-transformatie?

A

De term die eerst nummer i heeft, geef je nummer pi(i) De eerste en laatste term waren eerst nummer p en q, maar worden pi(p) en pi(q). In de termformule reken je het nieuwe nummer pi(i) eerst terug naar i met pi^-1.

108
Q

Wat is er bijzonder wanneer de sommatievariabele in de noemer van een breuk staat?

A

Het is onoplosbaar. Er bestaat geen simpelere uitdrukking voor, dus meot je het harmonisch getal gebruiken.

109
Q

Harmonisch getal

A

Hn, is SOM(i=1, n) 1/i

110
Q

Incremental method

A

For each element A[i], insert it into its proper place in the subarray A[1:i], having already sorted the subarray A[1:i-1].

111
Q

When is a recurrence well-defined?

A

If there is at least one function that satisfies the statement of the recurrence.

112
Q
A