AA TestSample Solutions
AA TestSample Solutions
equal to 1, otherwise 0.
AND Gate
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).
Big O Notation shows the time complexity of algorithms. It calculates the time taken to run an algorithm
as the input grows.
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:
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
16.) Assume you have trading platform where new data has to be appended fast.
Linked list
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:
20.)
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
Insertion sort
22.)
Quicksort
- Space Complexity is given by 𝑂(𝑚𝑎𝑥). Hence space needed can be high, if maximum value is large.
The height of a node is the number of edges to the deepest leaf (longest path from the node to a leaf
node).
26.) A tree in which every node has either two or no children is called:
/\
23
is
o a binary tree
o a balanced tree
A graph data structure is a collection of nodes that have data and are connected to other nodes.
31.)
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:
Find: Determine which subset a particular element is in. This can be used for determining if two
elements are in the same subset.
is called?
Prim's Algorithm
Kruskal's algorithm
Prim's Algorithm