4. Linear
Search
Is a sequential searching algorithm
where we start from one end and
check every element of the list
until the desired element is found.
Time complexity: O(n)
5. Binary
Search
A searching algorithm used in a sorted array
by repeatedly dividing the search interval in
half. The idea is to use the information that the
array is sorted and reduce the time
complexity to O(log N).
Data size: length of the sequence - len
Dominationg operation: comparison -
S[m] == key
6. Quick Sort
Based on divide-and-conquer algorithm.
The idea is as follows (recursive version):
● For the sequence of length 1
nothing has to be done (stop the recursion)
● Longer sequence is reorganised so that
some element,
called pivot of the sequence is put on nal position
so that there is no larger element to the left of
pivot and no smaller element to the right of pivot.
● Subsequently steps 1 and 2 are applied to the
left and right
subsequences (recursively)
Time complexity: O (n*logn)
7. Decision Tree
Algorithm
Is a machine learning algorithm that
uses a decision tree to make
predictions. It follows a tree-like
model of decisions and their
possible consequences. The
algorithm works by recursively
splitting the data into subsets
based on the most significant
feature at each node of the tree.
8. Knapsack
Algorithm
Used in dynamic programming and greedy
algorithms.Given a set of items, each with
a weight and a value, determine the
maximum value that can be obtained by
selecting a subset of the items such that
the sum of their weights does not exceed a
given capacity.
Time complexity: O (N*W)
where 'N' is the number of weight elements
and 'W' is the capacity of the knapsack
9. Santa's Route Optimizer
Given a list of houses Santa needs to visit, which algorithm
can help determine the shortest possible route to visit all of
them exactly once and return to the North Pole?
● A. Depth-First Search
✅
Answer: Depth-First search does not calculate paths, it only explores the nodes. Binary
Search is applicable in algorithms on sorted arrays not graphs. Dijkstra’s algorithm calculates
shortest path but only from start node to any other given node, so it is not sufficient. TSP
problem is the exact (NP) problem that describes it and algorithms for solving it would apply.
● D. Binary Search
● B. Dijkstra's Algorithm
● C. The Traveling Salesman Problem (TSP) Solver
10. Elf Scheduling System
To efficiently manage the workload in Santa's workshop,
what kind of algorithm would be best for scheduling elf
tasks?
● A. Round Robin Scheduling
✅
Answer: Working under pressure requires prioritizing some tasks. Unfortunately, it is
impossible to do everything simultaneously. Therefore Priority Scheduling, with for example
Priority Queue would be perfect. It is based most likely on Heap, which makes it very
performant to determine which task to do next.
● D. Priority Scheduling
● B. First-Come, First-Served
● C. Shortest Job Next
11. Reindeer Lineup Logic
If Santa’s sleigh has 9 reindeers, but Blitzen cannot be next
to Vixen, in how many ways can Santa arrange the
reindeers?
Answer: 9! − ( 8! x 2 )
Good Job!
17. Level 2
Description: This year, Bajtek was responsible for buying presents for his entire
family. Unfortunately, he didn’t have much time to plan what gifts to buy, so he
hoped that buying a variety of random presents would suffice. On the bright side,
being wealthy, Bajtek could afford this approach. He knows that the older family
members expect gifts that are more expensive than those given to the younger
ones. This means that at least one gift for each of the i-th oldest family members
must be more expensive than any gift given to the i+1-th to n-th oldest members,
where the n-th oldest member is the youngest person. Fortunately, they are not
concerned about the quantity of gifts and their total price. You want to make
everyone as happy as possible, so you must give as many presents as you can
within given constraints.
30 min
18. Level 2
Input: First line contains two numbers n and k, representing the amount of gifts
Bajtek bought and number of family members, excluding Bajtek (1 ≤ n ≤ 10^4, 1 ≤ k ≤
10^4). Second line contains a number x, indicating the total worth of gifts one
family member can get (1 ≤ x ≤ 10^4)
Third line contains n numbers separated by spaces, where the i-th number denotes
the price of the i-th gift bought by Bajtek
Fourth line contains k numbers separated by spaces, where the i-th number
denotes the age of the i-th family member
Output: If it is impossible for Bajtek to satisfy everyone, output “IMPOSSIBLE”
Otherwise, output k lines, where each line describes the prices of gifts received by
the i-th family member.
19. Level 2
Note: You can leave some gifts and not give them to anyone. Hopefully these will
be of use some next year. There can be multiple correct answers.
It is assumed that the ages of family members are given in descending order, from
the oldest to the youngest. Additional follow-up does not guarantee this order.
Follow up:
1. The descending order of family members is no longer guaranteed
2. Suppose there is no X given, now output also the maximum value for X that
would satisfy all family members
3. You want to satisfy everyone and also make it fair, so the total worth of gifts
for every family member, should be as close to X as possible, but it can not
exceed it. In other words you want to minimize X - S_i, where S_i denotes total
price of i-th person’s gifts
21. Explanation:
Test case 1
Every family member has at least one gift that is more expensive that any younger
member of family have, so the first condition is satisfied. Total value of members gifts
are (5, 5, 4 ,4) so it is as fair as it can be. Note that e.g. (5, 4, 4, 5) and (5, 4, 5, 4) are also
correct answers.
Test case 2
Some family members wouldn’t get any gift, therefore it is impossible.
23. Solution:
Algorithm:
● Save input to arrays
● Sort gifts by prices
● Create an array to store current gifts sum for every member
● Try to give everyone at least one gift
● If there wasn't enough gifts, print impossible
● Give remaining gifts iterating from youngest members and most expensive gifts for
Follow up:
● To find maximum value of x, a binary search can be used
● To make it work without members sorted by age in input, save original indices and
then sort it.