[Solved] Algorithm Homework5-Alberts Dream

$25

File Name: Algorithm_Homework5-Alberts_Dream.zip
File Size: 310.86 KB

SKU: [Solved] Algorithm Homework5-Albert’s Dream Category: Tag:
5/5 - (1 vote)

Albert has a dream: he wants to create his own dictionary (Merriam Webster is his idol and he hopes to have his own nameon a thick book one day). Albert realizes that he does not know enough words to create a complete dictionary. But he hasmany many books and if he could only get all of the unique words out of those, he would be happy.You are Alberts best friend and majoring in computer science, so you offer to help with processing all the texts andselecting only the unique words. You are going to write a program that processes text and produces a list of unique words inalphabetical order. Before you do that, Albert gives you his definition of a word. A word is a sequence of one or moreconsecutive alphabetic characters in upper or lower case. Albert also wants your program to be case insensitive, that iswords like APPLE, apple, appLE should be treated as the same.InputThe input is a text with up to 5,000 lines. Each line has at most 200 characters. The input if terminated by EOF. OutputA list of different/unique words that appear in the input text, one per line. You are guaranteed that the number of uniquewords in the text is no more than 5,000.Example 1Input:Albert has a dream: he wants to create his own dictionary (Merriam Webster ishis idol and he hopes to have his own name on a thick book one day).Output:aalbertandbookcreatedaydictionarydreamhashavehehishopesidolismerriamnameononeownthicktowantswebsterExample 2Input:121()* &* abc *[email protected]#Output:Page 2/2abcawrePage 1/1Bit-wise ORGiven 3 non-negative integers N, L, R. Find the maximum integer x such that1. L <= x <= R2. x OR N is maximized (OR stands for bit-wise OR operation here), i.e. for all integer y in the close interval [L,R], wehave: (y OR N) <= (x OR N)InputThere will be 3 integers N, L, R on a single line, where L <= R. You can assume that 0 <= N,L,R <= 4294967295.OutputPrint a line containing the value of x such that x OR N is maximized.Example 1Input:10 10 10Output:10Example 1Input:100 50 60Output:59Page 1/1Efficient AddingYou are tasked with writing a program that adds a sequence of numbers. But the added challenge is to do so efficiently!The cost of adding two numbers a and b is equal to their sum a+b . For example: to add 1, 2, and 3, you can do it asfollows:1 + 2 = 3, cost of 33 + 3 = 6, cost of 6Total cost = 9or2 + 3 = 5, cost of 51 + 5 = 6, cost of 6Total cost = 11or1 + 3 = 4, cost of 42 + 4 = 6, cost of 6Total cost = 10Your goal is to add the numbers so that the cost is as small as possible.InputThe first line of input contains a positive number N ( 2 <= N <= 5000 ) that tells you how many numbers there are toadd.The second line of input contains those N numbers 0 <= n_1, n_2, , n_N <= 100,000 .OutputThe minimum total cost of addition followed by a newline.Example 1Input:31 2 3Output:9Example 2Input:41 2 3 4Output:19Page 1/1Preparing ProblemsStudents needs problems to practice techniques they learned in class. Teachers also need problems to test students. Youare a problem-setter for an un-named course at NYU.To avoid plagiarism, problems can not be reused for this course. You will prepare new problems each month.At the beginning of this year, there are S problems that is ready.Strangely enough, you are able to foresee the number of problems you can create in each of the 12 months of this year aswell as the number of problems required in each month.If N problems are required in a month and there are not enough problems at that time, then the quizzes and homeworksfor that month are canceled. And the unused problems can be used in the following months.Write a program to determine if there are enough problems for each month. Please keep in mind that, if a problem iscreated in month X , it can only be used in month X+1 and the later months.InputThe first line contains an integer S ( 0 <= S <= 100 ). Number of problems that are ready at the beginning of the year.The 2-nd line has 12 space separated integers, denoting the number of problems that ca be created each of the 12 monthsof that year. The months are in the same order as they appear in the calendar. These integers will be between 0 and 20(inclusive).The 3-rd line has another 12 space separated integers, the number of problems needed in each of those 12 months (withthe same order as above). These integers will be between 0 and 20 (inclusive).OutputPrint 12 lines.If there are enough problems to meet the requirements in month i ( 1 <= i <= 12 ), print A lot of grading. in the i -thline, otherwise print No homework.Example 1Input:53 0 3 5 8 2 1 0 3 5 6 90 0 10 2 6 4 1 0 1 1 2 2Output:A lot of grading.A lot of grading.No homework.A lot of grading.A lot of grading.A lot of grading.A lot of grading.A lot of grading.A lot of grading.A lot of grading.A lot of grading.A lot of grading.Page 1/1Running MedianProfessor Stats has a new theory of how useful the median value could be in describing a real-life data set. She isespecially interested in analyzing the running medians. As her research assistant, you are tasked with writing a programthat calculates the running median as the data is received, i.e., for each subsequence starting at data point 1 up to datapoint K (where K ranges from 1 up to the largest index of any data point), you need to compute the median of thatsubsequence.If the current sequence has an odd number of elements, then the median is the middle element when the values are insorted order. For example, for the sequence {1, 3, 6, 2, 7}, the median is 3.If the current sequence has an even number of elements, then the median is the average of the two middle elements. Forexample, for the sequence {1, 3, 6, 2, 7, 8}, the median is (3+6)/2 = 4.5. Since Professor Stats lives in the Integer World,you need to report only the integer part of the median, so in this case the program should report 4 (not 4.5).InputThe input consists of series of integers X ( 0 <= X <= 2^31 ). The total number of integers N is less than 100,000.Each line of input contains only one integer, but the numbers may have leading or trailing spaces.OutputFor each input line (each new value), print the current value of the running median.Example 1Input:1346070502Output:1233427

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Algorithm Homework5-Alberts Dream
$25