SlideShare a Scribd company logo
1 of 24
Explanation
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)
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
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)
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.
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
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
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
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!
Coding
Challenge in
groups
Practice an algorithms
Write a Java program to find a
specified element in a given array of
elements using Binary Search.
15 min
Practice an algorithms
Write a Java program to find a specified
element in a given array of elements using
Linear Search.
15 min
Practical
Tasks
Level 1 Christmas Tree
15 min
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
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.
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
Example:
Test case 1
Input:
8 4 6 1 2 1 4 3 5 1 1 81 43 37 15
Output:
5 4 1 3 1
2 1 1
Test Case 2
Input:
7 12 31 1 2 3 4 5 6 7 8 9 10 11 12 44 43 39 38
22 21 20 15 12 10 2 1
Output:
IMPOSSIBLE
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.
Solution:
Corner cases:
● n < k ⇒ Impossible
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.
Thank you ❤️

More Related Content

Similar to Christmas Coding

Unit 6 Graph Theory - AssignmentTotal points for Assignment 35 .docx
Unit 6 Graph Theory - AssignmentTotal points for Assignment  35 .docxUnit 6 Graph Theory - AssignmentTotal points for Assignment  35 .docx
Unit 6 Graph Theory - AssignmentTotal points for Assignment 35 .docx
dickonsondorris
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitations
chidabdu
 
lecture 10
lecture 10lecture 10
lecture 10
sajinsc
 
Probabilistic group theory, combinatorics, and computing
Probabilistic group theory, combinatorics, and computingProbabilistic group theory, combinatorics, and computing
Probabilistic group theory, combinatorics, and computing
Springer
 

Similar to Christmas Coding (20)

Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
 
Computer Science Exam Help
Computer Science Exam Help Computer Science Exam Help
Computer Science Exam Help
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit 6 Graph Theory - AssignmentTotal points for Assignment 35 .docx
Unit 6 Graph Theory - AssignmentTotal points for Assignment  35 .docxUnit 6 Graph Theory - AssignmentTotal points for Assignment  35 .docx
Unit 6 Graph Theory - AssignmentTotal points for Assignment 35 .docx
 
DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitations
 
Unit 2
Unit 2Unit 2
Unit 2
 
Chapter 4 ds
Chapter 4 dsChapter 4 ds
Chapter 4 ds
 
DLL _WEK1_LC33-35.pdf
DLL _WEK1_LC33-35.pdfDLL _WEK1_LC33-35.pdf
DLL _WEK1_LC33-35.pdf
 
Chapter-3-Sample-Space-of-Experiment.pdf
Chapter-3-Sample-Space-of-Experiment.pdfChapter-3-Sample-Space-of-Experiment.pdf
Chapter-3-Sample-Space-of-Experiment.pdf
 
lecture 10
lecture 10lecture 10
lecture 10
 
Permutations and Combinations IIT JEE+Olympiad Lecture 4
Permutations and Combinations IIT JEE+Olympiad Lecture 4Permutations and Combinations IIT JEE+Olympiad Lecture 4
Permutations and Combinations IIT JEE+Olympiad Lecture 4
 
Perform brute force
Perform brute forcePerform brute force
Perform brute force
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxbcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
 
Lec34
Lec34Lec34
Lec34
 
Probabilistic group theory, combinatorics, and computing
Probabilistic group theory, combinatorics, and computingProbabilistic group theory, combinatorics, and computing
Probabilistic group theory, combinatorics, and computing
 
MLSD18. Unsupervised Learning
MLSD18. Unsupervised LearningMLSD18. Unsupervised Learning
MLSD18. Unsupervised Learning
 
Module 2_ Divide and Conquer Approach.pptx
Module 2_ Divide and Conquer Approach.pptxModule 2_ Divide and Conquer Approach.pptx
Module 2_ Divide and Conquer Approach.pptx
 

More from GDSC PJATK (8)

Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum Computing
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
SheDev 2024
SheDev 2024SheDev 2024
SheDev 2024
 
Bit N Build Poland
Bit N Build PolandBit N Build Poland
Bit N Build Poland
 
DevFest Warsaw
DevFest WarsawDevFest Warsaw
DevFest Warsaw
 
Info Session
Info SessionInfo Session
Info Session
 
Solution Challenge
Solution ChallengeSolution Challenge
Solution Challenge
 
Journey to Google
Journey to GoogleJourney to Google
Journey to Google
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Christmas Coding

  • 1.
  • 3.
  • 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!
  • 13. Practice an algorithms Write a Java program to find a specified element in a given array of elements using Binary Search. 15 min
  • 14. Practice an algorithms Write a Java program to find a specified element in a given array of elements using Linear Search. 15 min
  • 16. Level 1 Christmas Tree 15 min
  • 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
  • 20. Example: Test case 1 Input: 8 4 6 1 2 1 4 3 5 1 1 81 43 37 15 Output: 5 4 1 3 1 2 1 1 Test Case 2 Input: 7 12 31 1 2 3 4 5 6 7 8 9 10 11 12 44 43 39 38 22 21 20 15 12 10 2 1 Output: IMPOSSIBLE
  • 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.
  • 22. Solution: Corner cases: ● n < k ⇒ 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.