You are on page 1of 10

1.) Consider a gate with two input bits and a output bit.

The output is only 1 if both input bits are

equal to 1, otherwise 0.

What is the name of the gate?

AND Gate

2.) A good algorithm should be effective.

What does that in general mean (state two points)?

3.) Would you use linear search in a sorted array? Why?

No, I would use binary search. Because it is faster method, especially when the array was already sorted
(it doesn’t pay to pre-process the list to be able to use this method).

4) What does the Big O show?

Big O Notation shows the time complexity of algorithms. It calculates the time taken to run an algorithm
as the input grows.

5) What is pseudo-linear time?

Pseudo-polynomial time complexity means polynomial in the value of input but exponential in the size
of input.

6) Assume an logarithmic algorithm, e.g. O(log_2 (n)) needs 10 second to run for 1000 data points.

What is your guess how long it runs for 2000 data points?
7) What is the traveling salesperson problem? Is it difficult or easy to solve?
The algorithm is impossible to run (in this century) for a large number of cities. So far, there is no fast
algorithm and it is believed that it is even impossible to have a smart algorithm for this problem. The
best are approximate solutions.

8) What is the common Big-O-Notation for an Algorithm running through a phone book reading just the
persons name starting with the letter “A”:

O(n) - Linear

9.) A common method of simplification is to divide a problem into subproblems of the same type is

called:

Divide and conquer

10.) Present some pseudo-code to calculate the Fibonacci numbers with a recursive approach.

11.) The Fibonacci numbers can be calculated using the “Divide and Conquer” or the “Dynamic
approach”. What is the advantage / disadvantage of the two approaches?
12.) Name the rule for a Stack (what happens with the first element which is inserted):

The rule for a stack is called Last in First Out (LiFo). The first element is like “the last person in the
waiting line and last to enter the bus” because new added elements are added on top of it.
13.) For a Max-Heap Data Structure the root of the array [7,2,1,25,3,19,80] would be

80

14.) Compare a linked list to an array:

15.) Time complexity for an operation in a linked-list needs

16.) Assume you have trading platform where new data has to be appended fast.

What data-structure would you use:

Linked list

17.) What is a collision in a hash table?


A collision is when the same index is produced by hash function for multiple keys.

18.) A solution for a collision using a hash function is?

Chaining: If a hash function produces the same index for multiple elements, the elements are stored in
the same index by a linked list.

19.) Name two sorting algorithms which are Divide and Conquer Algorithms:

Merge sort · Quicksort

20.)

for all elements of list


if list[i] > list[i+1]
swap(list[i], list[i+1])

What is the name of this algorithm?

Bubble Sort

21.)

i←1
while i < length(A)
x ← A[i]
j←i-1
while j >= 0 and A[j] > x
A[j+1] ← A[j]
j←j-1
end while
A[j+1] ← x
i←i+1
end while

What is the name of this algorithm?

Insertion sort
22.)

algorithm mysort(A, lo, hi) is


if lo < hi then
p := partition(A, lo, hi)
mysort(A, lo, p - 1)
mysort(A, p + 1, hi)
algorithm partition(A, lo, hi) is
pivot := A[hi]
i := lo
for j := lo to hi do
if A[j] < pivot then
swap A[i] with A[j]
i := i + 1
swap A[i] with A[hi]
return i

What is the name of this algorithm?

Quicksort

23.) The problem of counting sort is that it

- Space Complexity is given by 𝑂(𝑚𝑎𝑥). Hence space needed can be high, if maximum value is large.

- Cannot handle decimal value.

24.) What is the height of a node?

The height of a node is the number of edges to the deepest leaf (longest path from the node to a leaf
node).

25.) The following type of traversal is called?

1.) visit all nodes in left subtree


2.) visit root node
3.) visit all nodes in right subtree
Inorder Traversal

26.) A tree in which every node has either two or no children is called:

Full binary tree

27.) Multiple Choice (several answers can be correct):

The following tree

/\

23

is

o a full binary tree

o a complete binary tree

o a binary tree

o a balanced tree

28.) What is a graph?

A graph data structure is a collection of nodes that have data and are connected to other nodes.

29.) Name 3 graph operations:

 Check if element is included in graph


 Graph traversal
 Add vertices and/or edges to graph

Find path from one vertex to another


30.) How would you store best a graph of a large social network.

31.)

State the adjacency matrix of the following graph

0–1

2–3

0 1 2 3
0 0 1 1 0
1 1 0 0 0
2 1 0 0 1
3 0 0 1 0

32.) State the steps of depth first search through the following graph/tree:

A -> B -> D -> E -> C

33.) What is the aim of the union-find algorithm?

34.) For what algorithm is the union-find algorithm needed? Why?

Kruskal's algorithm only works, when it can be determined if a cycle is found.

That is the task of the union-find algorithm.


A union-find algorithm is an algorithm that performs two operations:

Find: Determine which subset a particular element is in. This can be used for determining if two
elements are in the same subset.

Union: Join two subsets into a single subset.

35.) The following algorithm


1. Start with random vertex

2. Find all edges connect tree to new vertices

3. Take minimum and add it to the tree

4. Repeat steps 2 and 3 until minimum spanning tree is reached

is called?

Prim's Algorithm

36.) Name two algorithms to find a minimum spanning tree:

Kruskal's algorithm

Prim's Algorithm

37.) Consider the following graph:

The minimum spanning tree is given by connecting?


2–1–3–6–5-4

38.) What does the minimum spanning tree minimize?

The sum of weight of the edges

39.) Dijkstra’s algorithm would find which path from A to C

A -> D -> E -> C

You might also like