Assign 3
Assign 3
Assign 3
Q1. (Euler Tour) You are given a tree containing n nodes and the value associated with each node. You
decided to go on a Euler tour on that tree and collect all the points from a node every time you visit
it. Print the value of total points collected during the tour.
SAMPLE INPUT 1:
5
2 4 8 6 10
12
13
24
35
SAMPLE OUTPUT 1:
46
Q2. (Priority Queue) You are given n lines of different lengths. You are required to convert it into a
single line in minimum time. The time it takes to join 2 lines is the sum of lengths of those 2 lines.
SAMPLE INPUT 1:
2
5
14295
7
5362491
SAMPLE OUTPUT 1:
43
78
Explanation- In 1st case, join 1st and 3rd line (which took 1+2=3 minutes), and make the array
[4,3,9,5]. Now, join 1st and 2nd line (which took 3+4=7 minutes), and makes the arrays as [7,9,5]. Now,
join 1st and 3rd line (which took 7+5=12 minutes), and makes the array as [9,12]. Now, join them
which will take 21 minutes.
So, the total time is 43 minutes.
Q3. (Hashing) You are given an array of n integers. You are required to find the number of indices
(i,j) such that i<j and aj +2*i=ai+2*j. Mind that indexing is 1 based.
SAMPLE INPUT 1:
2
6
351466
3
123
SAMPLE OUTPUT 1:
2
0
Explanation-
For first test case:
Pairs are (1,2) and (4,5).
Q4. (Hashing) A group of friends decided to play a game. Winning a round of it, rewards some positive
points and loosing, some negative points. The winner is the one with the maximum number of points.
In case, there are more than 1 player who has the maximum number of points, winner is the one who
gained it first.
SAMPLE INPUT 3:
4
Jeet 12
Jeet -5
Suyash 10
Jeet 3
SAMPLE OUTPUT 3:
Jeet
Submission Instructions:
You should retain the same grouping, if any. This grouping is allowed only for allowing peer
learning. However, you need to solve yourself all the questions. There will be a demo or viva
for these assignments at a later date. You should submit your exe file, and source files putting
all of those into a tar file/ zip file, and upload it into google class before the submission
deadline i.e. midnight of 16/11/2022. Your code should also run on Ubuntu systems (like in
the lab) for evaluation purposes. You should also keep a copy of your code. Any doubts or
queries regarding the questions can be emailed to f20200065@hyderabad.bits-pilani.ac.in.
I/C
(C R Hota)
-----------------------------