算法导论 第三版 第六章 答案 英
算法导论课程作业答案

算法导论课程作业答案Introduction to AlgorithmsMassachusetts Institute of Technology 6.046J/18.410J Singapore-MIT Alliance SMA5503 Professors Erik Demaine,Lee Wee Sun,and Charles E.Leiserson Handout10Diagnostic Test SolutionsProblem1Consider the following pseudocode:R OUTINE(n)1if n=12then return13else return n+R OUTINE(n?1)(a)Give a one-sentence description of what R OUTINE(n)does.(Remember,don’t guess.) Solution:The routine gives the sum from1to n.(b)Give a precondition for the routine to work correctly.Solution:The value n must be greater than0;otherwise,the routine loops forever.(c)Give a one-sentence description of a faster implementation of the same routine. Solution:Return the value n(n+1)/2.Problem2Give a short(1–2-sentence)description of each of the following data structures:(a)FIFO queueSolution:A dynamic set where the element removed is always the one that has been in the set for the longest time.(b)Priority queueSolution:A dynamic set where each element has anassociated priority value.The element removed is the element with the highest(or lowest)priority.(c)Hash tableSolution:A dynamic set where the location of an element is computed using a function of the ele ment’s key.Problem3UsingΘ-notation,describe the worst-case running time of the best algorithm that you know for each of the following:(a)Finding an element in a sorted array.Solution:Θ(log n)(b)Finding an element in a sorted linked-list.Solution:Θ(n)(c)Inserting an element in a sorted array,once the position is found.Solution:Θ(n)(d)Inserting an element in a sorted linked-list,once the position is found.Solution:Θ(1)Problem4Describe an algorithm that locates the?rst occurrence of the largest element in a?nite list of integers,where the integers are not necessarily distinct.What is the worst-case running time of your algorithm?Solution:Idea is as follows:go through list,keeping track of the largest element found so far and its index.Update whenever necessary.Running time isΘ(n).Problem5How does the height h of a balanced binary search tree relate to the number of nodes n in the tree? Solution:h=O(lg n) Problem 6Does an undirected graph with 5vertices,each of degree 3,exist?If so,draw such a graph.If not,explain why no such graph exists.Solution:No such graph exists by the Handshaking Lemma.Every edge adds 2to the sum of the degrees.Consequently,the sum of the degrees must be even.Problem 7It is known that if a solution to Problem A exists,then a solution to Problem B exists also.(a)Professor Goldbach has just produced a 1,000-page proof that Problem A is unsolvable.If his proof turns out to be valid,can we conclude that Problem B is also unsolvable?Answer yes or no (or don’t know).Solution:No(b)Professor Wiles has just produced a 10,000-page proof that Problem B is unsolvable.If the proof turns out to be valid,can we conclude that problem A is unsolvable as well?Answer yes or no (or don’t know).Solution:YesProblem 8Consider the following statement:If 5points are placed anywhere on or inside a unit square,then there must exist two that are no more than √2/2units apart.Here are two attempts to prove this statement.Proof (a):Place 4of the points on the vertices of the square;that way they are maximally sepa-rated from one another.The 5th point must then lie within √2/2units of one of the other points,since the furthest from the corners it can be is the center,which is exactly √2/2units fromeach of the four corners.Proof (b):Partition the square into 4squares,each with a side of 1/2unit.If any two points areon or inside one of these smaller squares,the distance between these two points will be at most √2/2units.Since there are 5points and only 4squares,at least two points must fall on or inside one of the smaller squares,giving a set of points that are no more than √2/2apart.Which of the proofs are correct:(a),(b),both,or neither (or don’t know)?Solution:(b)onlyProblem9Give an inductive proof of the following statement:For every natural number n>3,we have n!>2n.Solution:Base case:True for n=4.Inductive step:Assume n!>2n.Then,multiplying both sides by(n+1),we get(n+1)n!> (n+1)2n>2?2n=2n+1.Problem10We want to line up6out of10children.Which of the following expresses the number of possible line-ups?(Circle the right answer.)(a)10!/6!(b)10!/4!(c) 106(d) 104 ·6!(e)None of the above(f)Don’t knowSolution:(b),(d)are both correctProblem11A deck of52cards is shuf?ed thoroughly.What is the probability that the4aces are all next to each other?(Circle theright answer.)(a)4!49!/52!(b)1/52!(c)4!/52!(d)4!48!/52!(e)None of the above(f)Don’t knowSolution:(a)Problem12The weather forecaster says that the probability of rain on Saturday is25%and that the probability of rain on Sunday is25%.Consider the following statement:The probability of rain during the weekend is50%.Which of the following best describes the validity of this statement?(a)If the two events(rain on Sat/rain on Sun)are independent,then we can add up the twoprobabilities,and the statement is true.Without independence,we can’t tell.(b)True,whether the two events are independent or not.(c)If the events are independent,the statement is false,because the the probability of no rainduring the weekend is9/16.If they are not independent,we can’t tell.(d)False,no matter what.(e)None of the above.(f)Don’t know.Solution:(c)Problem13A player throws darts at a target.On each trial,independentlyof the other trials,he hits the bull’s-eye with probability1/4.How many times should he throw so that his probability is75%of hitting the bull’s-eye at least once?(a)3(b)4(c)5(d)75%can’t be achieved.(e)Don’t know.Solution:(c),assuming that we want the probability to be≥0.75,not necessarily exactly0.75.Problem14Let X be an indicator random variable.Which of the following statements are true?(Circle all that apply.)(a)Pr{X=0}=Pr{X=1}=1/2(b)Pr{X=1}=E[X](c)E[X]=E[X2](d)E[X]=(E[X])2Solution:(b)and(c)only。
新视野大学英语第三版读写教程 B3U6Section A 课后练习答案

Scripts • Life during the 1800s in America was alread difficult for many people. Of course there were rich factory owners in the North and plantation owners in the South, but the average farmer and his famiIy worked extremely hard just to survive Many poor men thought that fighting in the army was an opportunity for adventure and excitement.
owned more than 20 slaves didn't have figh to fight.
• 2 Because the Union had blocked off many of the ports
of the South, causing shortages of food and other items that people needed. Also, most of the war took place in the South
• This seemed much better than the hard work of everyday life. But they soon found out that war was both boring and terrifying.
• Both sides of the war eventually instituted a draft. This was when men were randomly chosen to enter the army whether they wanted to or not. However, the rich were able to legally avoid the draft. In the North they could pay a fee of $300 or pay someone else to take their place. In the South, men who owned more than 20 slaves didn't have to fight. • With so many men gone to war, women had to take up new jobs. They worked the fields on farms and at factories producing goods for the army. Some women served as nurses in the army, helping wounded soldiers recover. Women had to work very hard to provide for their families. Often not only their husbands were at war, but also their older sons and fathers.
算法导论 第三版 第七章 答案 英

Exercise 7.2-4
Let’s say that by “almost sorted” we mean that A[i] is at most c positions from its correct place in the sorted array, for some constant c. For INSERTIONSORT, we run the inner-while loop at most c times before we find where to insert A[j] for any particular iteration of the outer for loop. Thus the running time time is O(cn) = O(n), since c is fixed in advance. Now suppose we run QUICKSORT. The split of PARTITION will be at best n − c to c, which leads to O(n2) running time.
Chapter 7
Michelle Bodnar, Andrew Lohr
April 12, 2016
Exercise 7.1-1
13 19 9 5 12 8 7 4 21 2 6 11 13 19 9 5 12 8 7 4 21 2 6 11 13 19 9 5 12 8 7 4 21 2 6 11 9 19 13 5 12 8 7 4 21 2 6 11 9 5 13 19 12 8 7 4 21 2 6 11 9 5 13 19 12 8 7 4 21 2 6 11 9 5 8 19 12 13 7 4 21 2 6 11 9 5 8 7 12 13 19 4 21 2 6 11 9 5 8 7 4 13 19 12 21 2 6 11 9 5 8 7 4 13 19 12 21 2 6 11 9 5 8 7 4 2 19 12 21 13 6 11 9 5 8 7 4 2 6 12 21 13 19 11 9 5 8 7 4 2 6 11 21 13 19 12 Exercise 7.1-2
新视野大学英语第三版答案和译文第一册U6

do quite a few in-depth research projects.• She resisted the temptation to laugh.noun + verb• An opportunity arose for me to work in China, so I went and spent a year there.•People feel educational standards slipped when the government cut finances.noun + noun•James has been a team leader / member / player, and he is now able to enjoy the fruits of his hard work.•Their demanding work schedule means they have less time to devote to school assignments. adjective + noun•And they reported lower levels of commitment to school and more modest educational aspirations.•This is not an empty threat; I will call the police if this happens again!verb + adverb• She smiled proudly as she looked at the photos of her new grandson.•I don’t like to travel with my brother because he drives carelessly.adverb + verb• I fully understand that there will be serious problems when doing this project.•You may respectfully listen to their advice, but don’t take it too seriously.In this unit about working part-time while studying, we have come across quite a few useful grammatical collocations, mainly in the patterns of “adjective + noun” and “noun + noun”.Please take a look at the following list of collocations in this unit:Text Astudent achievement, school performance, school engagement, heavy commitment, academicyear, school achievement, school commitment, educational aspirations, school careers, working students, school assignments, non-working students Text Bhigher education, undergraduate student, wealthy students, educational performance, formal education, educational funding, educational benefits PART IIKEY TO EXERCISESSECTION A111) A teaching assistant in kindergarten or a tutor2) A cashier in a store3) A waiter in a restaurant4) A car cleaner2 • I would like to work as a teaching assistantin kindergarten. I really enjoy spending timewith small children and I am thinking ofworking as a teacher in kindergarten in thefuture. So working as a teaching assistantwould definitely be a great experience for me.• I would like to work in a company, whetherbig or small, because in the future I plan toestablish my own business. Working part-time in a company would give me some ideaof what it is like to work in a company, howa company is run, and what job a boss shoulddo.210 Third Edition2In my opinion, the most important advantages of doing part-time jobs are: gaining work experience, acquiring communicative skills, and building connections for future career. In doing part-time jobs, especially those jobs which are related to my field of study, I can build up my work experience and enrich my resume. Besides, in working, I may have to communicate with different kinds of people, soit can help develop my communicative skills, which are essential to success. And in getting to know some important people in the workplace, I can build some contacts for my future career.Understanding the text11To measure the impact of employment on student achievement.2According to the research, a heavy commitment to part-time work undermines and significantly interferes with school achievement andcommitment.3About 10 hours per week or less.4Students become interested in study again.5Students may take easier classes, copyothers’ assignments, cut class, or refuse todo assignments, and over time, students’commitment to school is eroded bit by bit.6Students may find school less rewarding and interesting, and it is highly possible that thosewho have been working long hours will dropout of school before graduation.7Because teenagers working long hours frequently have more money to spend than their peers,and they often become used to spending theirearnings on drugs and alcohol.8Doing part-time jobs while studying isacceptable, but students should work nomore than 10 hours a week if they want to besuccessful in school. Critical thinking21 • Yes, I think early employment can definitelybuild character because besides study,you have to fit yourself into the workingenvironment. You can learn interpersonalskills, social responsibility and professionalethics in a working setting. Moreover, youhave to try hard to strike a balance betweenwork, study, and play. In this way, you willdevelop a strong sense of responsibility andboost your self-confidence.• No, not necessarily. Though early employmentmay help students to gain some workexperience, it is not necessarily helpful inbuilding their character. Because they have tospend quite a lot of time working and maybecome less responsible or less committedto their study. Too much work may also leadto alcohol and drug abuse. So, in some cases,early employment undermines character-building rather than help it.2 • Yes, I agree. Students have so many academictasks to complete in college that they hardlyhave any extra time for work. If they work,they will certainly have to spend less time andenergy on study, which is likely to depresstheir school performance. I see many workingstudents around me sleep in class, skip class,or copy others’ assignments. If they cannotbe responsible students when they should be,how could they become responsible peopleafter graduation? So, I think students shouldtake study as their main task instead of doingpart-time jobs.• No, I don’t agree. College students shouldprepare themselves for future careers, so theyneed not only to perform well academicallybut also develop other skills becausesurviving in society requires more than bookknowledge. Working part-time can exposestudents to the real world and help themacquire basic interpersonal skills. Besides, byearning money to pay for their study, collegestudents can learn how to manage their211UNIT 6 Earn as you learn?money and become less dependent on theirparents.3 • Yes, I agree with the author that workingwhile studying has many negative impactson students, such as not getting enough rest,decreased school performance, abuse of drugsand alcohol. As one’s time and energy arelimited, working, even part-time, will affectone’s study. Therefore, students should takestudy seriously and it is critical not to worklong hours while studying at college.• No, I don’t think there are so many negativeimpacts of working while studying asmentioned by the author. I have manyclassmates who are working part-timeto cover their tuition. Most of them areresponsible students as they want to sharethe financial burden with their parents. Theyalso study very hard for scholarships. At thesame time, they try to make full use of theirworking time. Some of them work with theirprofessors in the lab, so their work does notinterfere with their study. In fact, workingmay benefit their study because they canapply what is learned in class in practice.4 • Yes, I think part-time jobs may help builda sense of responsibility, which in turn mayenhance students’ school performance.Because if you take part-time jobs whilestudying, you have to follow the work ethics,observe the working schedule, work up toexpectations, contribute to teamwork, andbalance work and study. All these will helpyou to multitask, to be more efficient, tocultivate a sense of responsibility, and toenhance your school performance.• No, I don’t think part-time jobs help to builda sense of responsibility, not to mentionenhancing students’ school performancebecause students who take part-time work,especially those who work long hours, haveto strike a balance between work and study.To meet the demanding working schedule,more often than not, they have to cut corners,for example, by devoting less time to studyor ignoring homework. Moreover, they mayspend more on entertainment and luxurygoods as they have more spending money.Students who work long hours usually fail tomeet the academic requirements and have noclear plan for career development.5Part-time employment provides a good opportunity for students to learn many otherthings other than book knowledge. It has many positive influences:• building a sense of responsibility as you haveto accomplish your tasks;• building self-discipline as you have to manageyour time well and rely on yourself;• gaining social skills and work experienceas you interact with people outside theclassroom;• broadening your vision as you learn about theworkplace and society;• having more employment opportunities asyou gain work experience in preparation foryour future career.Words in use31indicate 2conventional3assess 4decrease5alter 6has undermined7 compromise 8controversial9resolved 10 abandonWord building4form formationoccupation occupysolve solution(To be continued)212 Third Editionpersuade persuasion transmit transmission original originality flexibility flexible secure security simple simplicity prosperousprosperity51 solution2 transmission3 prosperity4 formation5 flexible6 occupied7 originality8 productivity9 simplicity10 persuasion 11 representation 12 securityBanked cloze61 J2 C3 H4 D5 M6 G7 I8 A9 E 10 NExpressions in use71 cutting back on2 interfere with3 take a toll on4 at risk of5 dropped out6 in turn7 contribute to 8 are accustomed to 9 held on to 10in other wordsStructure analysis8(Continued )213UNIT 6 Earn as you learn?Structured writing9There are several reasons why people get fired from their jobs. First, people may lose their jobs if they have some dishonest behaviors, such as cheating in their job applications or telling lies in work. Second, employees may be fired due to poor attendance. No boss likes an employee who is often late for or absent from work. Third, people having difficulty getting along with their co-workers are also likely to be fired because they may cause conflicts in the workplace. Therefore, to be a good employee, it isimportant to be honest, punctual, and cooperative.10间隔年指的是学生休假不去上学而去旅游或工作等的一段时间,但不一定是一年。
算法导论(第三版)-复习-第六部分图论22-26[转]
![算法导论(第三版)-复习-第六部分图论22-26[转]](https://img.taocdn.com/s3/m/056830c148649b6648d7c1c708a1284ac85005ae.png)
算法导论(第三版)-复习-第六部分图论22-26[转]22习题22.1-5 有向图G(V, E)的平⽅图。
链表表⽰时,对每结点u的Adj[u]中所有v加⼊队列,后边出队边将Adj[v]加⼊Adj[u]中。
矩阵表⽰时,若w[i, j]、w[j, k]同时为1则将w[i, k]置1.习题22.1-6 O(V)的时间寻找通⽤汇点。
汇点的特征是邻接矩阵的第j列除[j, j]外所有元素为1. 可将每⾏调整[j ,j]后作为⼀个整数,所有整数与运算,为1的位是汇点。
习题22.1-7 有向⽆环图的关联矩阵B,BB’每个元素C[i, j]=∑B[i, k]*B’[k, j]=∑B[i, k]*B[j, k],即同时进i, j两结点与同时出i, j的结点总数-⼀进⼀出i, j两结点的结点总数。
习题22.2-7 类似BFS,d mod2为0则标为B(娃娃脸),d mod2为1则标为H(⾼跟鞋)。
但若有边连接相同类的结点,则⽆法划分。
wrestler(G){for each u in G{(u,v)=Adj[u];if(v.mark==u.mark){throw error;}if(v.d==NIL) {v.d=u.d+1; v.mark=v.d mod 2;}}}习题22.2-8 任意点之间的最短路径。
重复的Dijktra算法或Floyd-Warshall算法习题22.2-9 ⽆向图扩展为有向图。
问题变成要遍历所有边⼀次。
访问结点u时,将u的⼦结点v的其他边都可视为⼦集v,问题等价于u到v,访问v的集合,v到u。
u标为visiting⼊列,然后访问v,v标为visiting⼊列,然后访问v的后继结点,访问过的边标为visited,返回到visiting的点时,如果该点所有连接的边都标为visited只剩⼀条返回上级的边,则返回上级结点并将点标为visited,v出列,访问u的其他⼦结点,最终u出列。
全部结点出列后达到遍历所有边⼀次。
新视野大学英语第三版答案和译文第一册U6

do quite a few in-depth research projects.• She resisted the temptation to laugh.noun + verb• An opportunity arose for me to work in China, so I went and spent a year there.•People feel educational standards slipped when the government cut finances.noun + noun•James has been a team leader / member / player, and he is now able to enjoy the fruits of his hard work.•Their demanding work schedule means they have less time to devote to school assignments. adjective + noun•And they reported lower levels of commitment to school and more modest educational aspirations.•This is not an empty threat; I will call the police if this happens again!verb + adverb• She smiled proudly as she looked at the photos of her new grandson.•I don’t like to travel with my brother because he drives carelessly.adverb + verb• I fully understand that there will be serious problems when doing this project.•You may respectfully listen to their advice, but don’t take it too seriously.In this unit about working part-time while studying, we have come across quite a few useful grammatical collocations, mainly in the patterns of “adjective + noun” and “noun + noun”.Please take a look at the following list of collocations in this unit:Text Astudent achievement, school performance, school engagement, heavy commitment, academicyear, school achievement, school commitment, educational aspirations, school careers, working students, school assignments, non-working students Text Bhigher education, undergraduate student, wealthy students, educational performance, formal education, educational funding, educational benefits PART IIKEY TO EXERCISESSECTION A111) A teaching assistant in kindergarten or a tutor2) A cashier in a store3) A waiter in a restaurant4) A car cleaner2 • I would like to work as a teaching assistantin kindergarten. I really enjoy spending timewith small children and I am thinking ofworking as a teacher in kindergarten in thefuture. So working as a teaching assistantwould definitely be a great experience for me.• I would like to work in a company, whetherbig or small, because in the future I plan toestablish my own business. Working part-time in a company would give me some ideaof what it is like to work in a company, howa company is run, and what job a boss shoulddo.210 Third Edition2In my opinion, the most important advantages of doing part-time jobs are: gaining work experience, acquiring communicative skills, and building connections for future career. In doing part-time jobs, especially those jobs which are related to my field of study, I can build up my work experience and enrich my resume. Besides, in working, I may have to communicate with different kinds of people, soit can help develop my communicative skills, which are essential to success. And in getting to know some important people in the workplace, I can build some contacts for my future career.Understanding the text11To measure the impact of employment on student achievement.2According to the research, a heavy commitment to part-time work undermines and significantly interferes with school achievement andcommitment.3About 10 hours per week or less.4Students become interested in study again.5Students may take easier classes, copyothers’ assignments, cut class, or refuse todo assignments, and over time, students’commitment to school is eroded bit by bit.6Students may find school less rewarding and interesting, and it is highly possible that thosewho have been working long hours will dropout of school before graduation.7Because teenagers working long hours frequently have more money to spend than their peers,and they often become used to spending theirearnings on drugs and alcohol.8Doing part-time jobs while studying isacceptable, but students should work nomore than 10 hours a week if they want to besuccessful in school. Critical thinking21 • Yes, I think early employment can definitelybuild character because besides study,you have to fit yourself into the workingenvironment. You can learn interpersonalskills, social responsibility and professionalethics in a working setting. Moreover, youhave to try hard to strike a balance betweenwork, study, and play. In this way, you willdevelop a strong sense of responsibility andboost your self-confidence.• No, not necessarily. Though early employmentmay help students to gain some workexperience, it is not necessarily helpful inbuilding their character. Because they have tospend quite a lot of time working and maybecome less responsible or less committedto their study. Too much work may also leadto alcohol and drug abuse. So, in some cases,early employment undermines character-building rather than help it.2 • Yes, I agree. Students have so many academictasks to complete in college that they hardlyhave any extra time for work. If they work,they will certainly have to spend less time andenergy on study, which is likely to depresstheir school performance. I see many workingstudents around me sleep in class, skip class,or copy others’ assignments. If they cannotbe responsible students when they should be,how could they become responsible peopleafter graduation? So, I think students shouldtake study as their main task instead of doingpart-time jobs.• No, I don’t agree. College students shouldprepare themselves for future careers, so theyneed not only to perform well academicallybut also develop other skills becausesurviving in society requires more than bookknowledge. Working part-time can exposestudents to the real world and help themacquire basic interpersonal skills. Besides, byearning money to pay for their study, collegestudents can learn how to manage their211UNIT 6 Earn as you learn?money and become less dependent on theirparents.3 • Yes, I agree with the author that workingwhile studying has many negative impactson students, such as not getting enough rest,decreased school performance, abuse of drugsand alcohol. As one’s time and energy arelimited, working, even part-time, will affectone’s study. Therefore, students should takestudy seriously and it is critical not to worklong hours while studying at college.• No, I don’t think there are so many negativeimpacts of working while studying asmentioned by the author. I have manyclassmates who are working part-timeto cover their tuition. Most of them areresponsible students as they want to sharethe financial burden with their parents. Theyalso study very hard for scholarships. At thesame time, they try to make full use of theirworking time. Some of them work with theirprofessors in the lab, so their work does notinterfere with their study. In fact, workingmay benefit their study because they canapply what is learned in class in practice.4 • Yes, I think part-time jobs may help builda sense of responsibility, which in turn mayenhance students’ school performance.Because if you take part-time jobs whilestudying, you have to follow the work ethics,observe the working schedule, work up toexpectations, contribute to teamwork, andbalance work and study. All these will helpyou to multitask, to be more efficient, tocultivate a sense of responsibility, and toenhance your school performance.• No, I don’t think part-time jobs help to builda sense of responsibility, not to mentionenhancing students’ school performancebecause students who take part-time work,especially those who work long hours, haveto strike a balance between work and study.To meet the demanding working schedule,more often than not, they have to cut corners,for example, by devoting less time to studyor ignoring homework. Moreover, they mayspend more on entertainment and luxurygoods as they have more spending money.Students who work long hours usually fail tomeet the academic requirements and have noclear plan for career development.5Part-time employment provides a good opportunity for students to learn many otherthings other than book knowledge. It has many positive influences:• building a sense of responsibility as you haveto accomplish your tasks;• building self-discipline as you have to manageyour time well and rely on yourself;• gaining social skills and work experienceas you interact with people outside theclassroom;• broadening your vision as you learn about theworkplace and society;• having more employment opportunities asyou gain work experience in preparation foryour future career.Words in use31indicate 2conventional3assess 4decrease5alter 6has undermined7 compromise 8controversial9resolved 10 abandonWord building4form formationoccupation occupysolve solution(To be continued)212 Third Editionpersuade persuasion transmit transmission original originality flexibility flexible secure security simple simplicity prosperousprosperity51 solution2 transmission3 prosperity4 formation5 flexible6 occupied7 originality8 productivity9 simplicity10 persuasion 11 representation 12 securityBanked cloze61 J2 C3 H4 D5 M6 G7 I8 A9 E 10 NExpressions in use71 cutting back on2 interfere with3 take a toll on4 at risk of5 dropped out6 in turn7 contribute to 8 are accustomed to 9 held on to 10in other wordsStructure analysis8(Continued )213UNIT 6 Earn as you learn?Structured writing9There are several reasons why people get fired from their jobs. First, people may lose their jobs if they have some dishonest behaviors, such as cheating in their job applications or telling lies in work. Second, employees may be fired due to poor attendance. No boss likes an employee who is often late for or absent from work. Third, people having difficulty getting along with their co-workers are also likely to be fired because they may cause conflicts in the workplace. Therefore, to be a good employee, it isimportant to be honest, punctual, and cooperative.10间隔年指的是学生休假不去上学而去旅游或工作等的一段时间,但不一定是一年。
算法导论 第三版 第九章 答案 英

2Hale Waihona Puke is less than roughly 4n/14 of the elements. So, we are never calling it recursively on more than 10n/14 elements. So, T (n) ≤ T (n/7) + T (10n/14) + O(n). So, we can show by substitution this is linear. Suppose T (n) < cn for n < k , then, for m ≥ k , T (m) ≤ T (m/7) + T (10m/14) + O(m) ≤ cm(1/7 + 10/14) + O(m). So, as long as we have that the constant hidden in the big-Oh notation is less than c/7, we have the desired result. Suppose now that we use groups of size 3 instead. So, For similar reasons, we have that the recurrence we are able to get is T (n) = T ( n/3 ) + T (4n/6) + O(n) ≥ T (n/3) + T (2n/3) + O(n). So, we will show it is ≥ cn lg(n). T (m) ≥ c(m/3) lg(m/3) + c(2m/3) lg(2m/3) + O(m) ≥ cm lg(m) + O(m). So, we have that it grows more quickly than linear. Exercise 9.3-2 We know that the number of elements greater than or equal to x and the number of elements less than or equal to x is at least 3n/10 − 6. Then for n ≥ 140 we have 3n/10 − 6 = Exercise 9.3-3 We can modify quicksort to run in worst case n lg(n) time by choosing our pivot element to be the exact median by using quick select. Then, we are guaranteed that our pivot will be good, and the time taken to find the median is on the same order of the rest of the partitioning. Exercise 9.3-4 Create a graph with n vertices and draw a directed edge from vertex i to vertex j if the ith and j th elements of the array are compared in the algorithm and we discover that A[i] ≥ A[j ]. Observe that A[i] is one of the i − 1 smaller elements if there exists a path from x to i in the graph, and A[i] is one of the n − i larger elements if there exists a path from i to x in the graph. Every vertex i must either lie on a path to or from x because otherwise the algorithm can’t distinguish between i ≤ x and i ≥ x. Moreover, if a vertex i lies on both a path to x and a path from x then it must be such that x ≤ A[i] ≤ x, so x = A[i]. In this case, we can break ties arbitrarily. Exercise 9.3-5 To use it, just find the median, partition the array based on that median. If i is less than half the length of the original array, recurse on the first half, if i is half the length of the array, return the element coming from the median finding 3 n n + − 6 ≥ n/4 + 140/20 − 6 = n/4 + 1 ≥ n/4 . 4 20
新视野大学英语第三版读写教程第二册第六单元课后答案

Unit 6–Section ALanguage Focus–Words in Use1.When employees participated in the problem-solving process, they were much more willingto (implement) solutions to the problems.2. A strong police force has been placed between the two (rival) groups in the village toprevent fighting and killing.3.Although personally we believe this to be of only secondary importance, its potential rolein (motivating) innovative acts cannot be ignored.4.Though many things have been changed culturally, there is a commitment and sense of responsibility that have not yet been (discarded) in today's society.5.Western nations have older and shrinking populations since they entered the 21st century and their (fluctuating) birth rates have also posed problems.6.She didn't want to marry him and was (prejudiced) against him because he had only a bachelor's degree and didn't meet her expectations for marriage.7.The president is in trouble and will have to work hard to (restore) his credibility afterpeople discovered that he was not telling the truth.8.To study a number of subjects in the humanities has been both enjoyable and (enlightening) , providing me with a new and different perspective on the world in which we live.9.People are concerned about the environment issue because air and water pollution not only affects everyone's health but also makes it difficult for businesses to (profit) .10.Instead of ignoring or envying successful students, I made it my mission to (investigate)the mysterious causes of their success and greatness.Word Building1.strategy2.sympathy3.confirm4.locate5.reflect6.provide7.install8.register9.quotation10.sympathy11.critic12.industrial1.strategic2.sympathetic3.confirmation4.location5.reflection6.provision7.installation8.registration9.quote10.sympathize11.criticize12.industrialize1.He's usually indifferent to the feelings of other people; he can neither understand nor (sympathize) with my eagerness and anxiety.2.There has been no official (confirmation) that the documents are original, although different sources from the media and the public suggest that they are.3.There's a consensus that the (strategic) defense of a country depends on a powerful airforce and marine force, in addition to advanced arms.4.Total construction time of the shop was about 30 days including the (installation) of the newly-imported machines and the assembly of the various parts.5.To illustrate my point of view, I would like to (quote) from a source that many of us findmore authoritative than the words of a businessman.6.People need to be kind. Therefore, I am not ashamed to be regarded as (sympathetic) to the anxieties of those who are treated harshly in life.7.In business, we often do things inappropriately. For example, we may (criticize) someone's work in front of their co-workers.8.The restaurant has recently moved here because its owners want to provide a convenient (location) for their customers in this area.9.Cultural awareness will help you when you learn the language. After all, language is a(n) (reflection) of the culture from which it developed.10.Students are no longer learning how to (industrialize) agricultural economy; instead, they are learning the digital economy.11.People living in this remote area for generations have harsh living conditions and poor (provision) of housing, food and medicines.12.If you do not get the detailed information required for the school's (registration) , you maylose the opportunity to take the classes you want.Banked ClozeSimplifying is not necessarily about less. It can be about more: more time, more enjoyment, more accomplishment, and more of what (1) (profits) you. If you do a lot of things that don't bring you joy or support your long-term plan, then doing less of that kind of things makes sense because you can't (2) (preserve) everything. The purpose of simplifying is to remove what's not important.To understand what should be (3) (discarded), try to think of activities and things as either assets or obligations. An asset is something that is valuable. Some (4) (corresponding) examples are stocks, bonds, buildings, land, gold, etc., but a little more broadly, an asset is anything that can strengthen and (5) (motivate) you, moving you closer to your goals. However, obligations are debts. An obligation is anything that (6) (weakens) you, moves you farther from your goals, provides negative stress, creates anxiety, and decreases your health. Then how can you (7) (implement) the idea of simplifying? Think about your daily activities and start with just one area. For example,you may begin with (8) (obligations) by making a long list of your daily activities. Your list may (9) (revolve) around such routines as paying bills and planning a birthday party for a friend, etc.Do the activities get you closer to your goals? If not, (10) (modify) the list. Remove what is unnecessary in order to concentrate more on something important in your life.Language Focus–Expressions in Use1.Though he was 80 years old, blind and hardly able to walk, his family (was attached to)him so much that they could hardly bear the thought of his death.2.The support our volunteers provide to the community as well as society cannot (be measured in) purely practical terms, and their continuing contribution is vital.3.Please don't forget the Tourist Guide, which should (come in handy) when you travel to different places in Asia and Europe for the next few weeks.4.These people living in this area are still (clinging to) their traditions which give their life meaning and help them in answering many questions.5.You will (pay a big price) for not learning English; you never know how much you willmiss without being able to speak English.6.If you (are exhausted from) travel and trying to adjust to a new time zone, you may not beready to face the new challenging environment yet.7.The general manager of the company intends to introduce new management courses, and tighter controls will be (imposed on) internal management to raise efficiency.8.Class discussions next week will (revolve around) the importance of love, communication anda close relationship between parents and their children.Translation英译汉Minimalism (极简主义) is about getting rid of excess stuff and keeping only what you need. Minimalist living, in simplest terms, is to live with as less as possible, mentally and physically until you achieve peace of mind. Results that ensue are less stress, more time, and increased happiness. Minimalists like to say that they're living more meaningfully, more deliberately, and that the minimalist lifestyle allows them to focus on what's more important in life: friends, hobbies, travel, experiences. Of course, minimalism doesn't meanthere's anything inherently wrong with owning material possessions. Today's problem seems to be that we tend to givetoo much meaning to our things, often forsaking ( 扔掉 ) our health, our relationships, our passions, our personal growth, and our desire to contribute beyond ourselves. In addition to its application in people's daily life, minimalism also finds application in many creative disciplines, including art, architecture, design, dance, film making, theater, music, fashion, photography and literature.极简主义是指去掉剩余的,仅保存需要的部分。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Chapter6Michelle Bodnar,Andrew LohrDecember31,2016Exercise6.1-1At least2h and at most2h+1−1.Can be seen because a complete binarytree of depth h−1hasΣh−1i=02i=2h−1elements,and the number of elementsin a heap of depth h is between the number for a complete binary tree of depth h−1exclusive and the number in a complete binary tree of depth h inclusive.Exercise6.1-2Write n=2m−1+k where m is as large as possible.Then the heap consists of a complete binary tree of height m−1,along with k additional leaves along the bottom.The height of the root is the length of the longest simple path to one of these k leaves,which must have length m.It is clear from the way we defined m that m= lg n .Exercise6.1-3If there largest element in the subtee were somewhere other than the root, it has a parent that is in the subtree.So,it is larger than it’s parent,so,the heap property is violated at the parent of the maximum element in the subtreeExercise6.1-4The smallest element must be a a leaf node.Suppose that node x contains the smallest element and x is not a leaf.Let y denote a child node of x.By the max-heap property,the value of x is greater than or equal to the value of y.Since the elements of the heap are distinct,the inequality is strict.This contradicts the assumption that x contains the smallest element in the heap. Exercise6.1-5Yes,it is.The index of a child is always greater than the index of the parent, so the heap property is satisfied at each vertex.1Exercise6.1-6No,the array is not a max-heap.7is contained in position9of the array,so its parent must be in position4,which contains6.This violates the max-heap property.Exercise6.1-7It suffices to show that the elements with no children are exactly indexed by{ n/2 +1,...,n}.Suppose that we had an i in this range.It’s childeren would be located at2i and2i+1but both of these are≥2 n/2 +2>n and so are not in the array.Now,suppose we had an element with no kids,this means that2i and2i+1are both>n,however,this means that i>n/2.This means that i∈{ n/2 +1,...,n}.Exercise6.2-1271731613101571248902717101613315712489027171016138157124830Exercise6.2-2Algorithm1MIN-HEAPIFY(A,i)1:l=LEF T(i)2:r=RIGHT(i)3:if l≤A.heap−size and A[l]<A[i]then4:smallest=l5:else smallest=i6:end if7:if r≤A.heap−size and A[r]<A[smallest]then8:smallest=r9:end if10:if smallest=i then11:exchange A[i]with A[smallest]12:MIN-HEAPIFY(A,smallest)13:end ifThe running time of MIN-HEAPIFY is the same as that of MAX-HEAPIFY. Exercise6.2-3The array remains unchanged since the if statement on line line8will be false.2Exercise6.2-4If i>A.heap−size/2then l and r will both exceed A.heap−size so the if statement conditions on lines3and6of the algorithm will never be satisfied. Therefore largest=i so the recursive call will never be made and nothing will happen.This makes sense because i necessarily corresponds to a leaf node,so MAX–HEAPIFY shouldn’t alter the heap.Exercise6.2-5Iterative Max Heapify(A,i)while i<A.heap-size dol=LEFT(i)r=LEFT(i)largest=iif l≤A.heap-size and A[l]>A[i]thenlargest=lend ifif l≤A.heap-size and A[r]>A[i]thenlargest=rend ifif largest=i thenexchange A[i]and A[largest]elsereturn Aend ifend whilereturn AExercise6.2-6Consider the heap resulting from A where A[1]=1and A[i]=2for 2≤i≤n.Since1is the smallest element of the heap,it must be swapped through each level of the heap until it is a leaf node.Since the heap has height lg n ,MAX-HEAPIFY has worst-case timeΩ(lg n).Exercise6.3-1531710841962295317228419610953192284176109584192231761098451922317610984221953176109842219103176593Exercise6.3-2If we had started at1,we wouldn’t be able to guarantee that the max-heap property is maintained.For example,if the array A is given by[2,1,1,3]then MAX-HEAPIFY won’t exchange2with either of it’s children,both1’s.How-ever,when MAX-HEAPIFY is called on the left child,1,it will swap1with3. This violates the max-heap property because now2is the parent of3.Exercise6.3-3All the nodes of height h partition the set of leaves into sets of size between 2h−1+1and2h,where all but one is size2h.Just by putting all the children of each in their own part of trhe partition.Recall from6.1-2that the heap has height lg(n) ,so,by looking at the one element of this height(the root),we get that there are at most2 lg(n) leaves.Since each of the vertices of height h partitions this into parts of size at least2h−1+1,and all but one corresponds to a part of size2h,we can let k denote the quantity we wish to bound,so,(k−1)2h+k(2h−1+1)≤2 lg(n) ≤n/2sok≤n+2h2h+1+2h+1≤n2h+1≤n2h+1Exercise6.4-14513225717208451320257172845252013717284255201371728425132057172842513208717254413208717252520134871725252013178742525513178742202517135874220252135874172025132587417202513852741720254852713172025845271317202587524131720254752813172025745281317202524578131720255427813172025245781317202542578131720252457813172025Exercise6.4-2We’ll prove the loop invariant of HEAPSORT by induction:Base case:At the start of thefirst iteration of the for loop of lines2-5we have i=A.length.The subarray A[1..n]is a max-heap since BUILD-MAX-HEAP(A)was just called.It contains the n smallest elements,and the empty subarray A[n+1..n]trivially contains the0largest elements of A in sorted order.Suppose that at the start of the i th iteration of of the for loop of lines2-5, the subarray A[1..i]is a max-heap containing the i smallest elements of A[1..n] and the subarray A[i+1..n]contains the n−i largest elements of A[1..n]in sorted order.Since A[1..i]is a max-heap,A[1]is the largest element in A[1..i]. Thus it is the(n−(i−1))th largest element from the original array since the n−i largest elements are assumed to be at the end of the array.Line3swaps A[1]with A[i],so A[i..n]contain the n−i+1largest elements of the array, and A[1..i−i]contains the i−1smallest elements.Finally,MAX-HEAPIFY is called on A,1.Since A[1..i]was a max-heap prior to the iteration and only the elements in positions1and i were swapped,the left and right subtrees of node1,up to node i−1,will be max-heaps.The call to MAX-HEAPIFY will place the element now located at node1into the correct position and restore the5max-heap property so that A[1..i−1]is a max-heap.This concludes the next iteration,and we have verified each part of the loop invariant.By induction, the loop invariant holds for all iterations.After thefinal iteration,the loop invariant says that the subarray A[2..n] contains the n−1largest elements of A[1..n],sorted.Since A[1]must be the n th largest element,the whole array must be sorted as desired.Exercise6.4-3If it’s already sorted in increasing order,doing the build max heap-max-heap call on line1will takeΘ(n lg(n))time.There will be n iterations of the for loop, each takingΘ(lg(n))time because the element that was at position i was the smallest and so will have lg(n) steps when doing max-heapify on line5.So, it will beΘ(n lg(n))time.If it’s already sorted in decreasing order,then the call on line one will only takeΘ(n)time,since it was already a heap to begin with,but it will still take n lg(n)peel offthe elements from the heap and re-heapify.Exercise6.4-4Consider calling HEAPSORT on an array which is sorted in decreasing order. Every time A[1]is swapped with A[i],MAX-HEAPIFY will be recursively called a number of times equal to the height h of the max-heap containing the elements of positions1through i−1,and has runtime O(h).Since there are2k nodes at height k,the runtime is bounded below bylg ni=12i log(2i)=lg ni=1i2i=2+( lg n −1)2 lg n =Ω(n lg n).Exercise6.4-5Since the call on line one could possibly take only linear time(if the input was already a max-heap for example),we will focus on showing that the for loop takes n log n time.This is the case because each time that the last element is placed at the beginning to replace the max element being removed,it has to go through every layer,because it was already very small since it was at the bottom level of the heap before.Exercise6.5-1The following sequence of pictures shows how the max is extracted from the heap.1.Original heap:615 13540126298172.we move the last element to the top of theheap 3.13>9>1so,we swap1and13.4.Since12>5>1,we swap1and12.75.Since6>2>1,we swap1and6.Exercise6.5-2The following sequence of pictures shows how10is inserted into the heap, then swapped with parent nodes until the max-heap property is restored.The node containing the new key is heavily shaded.1.Original heap:815 13540126298172.MAX-HEAP-INSERT(A,10)is called,so wefirst append a node assignedvalue−∞:3.The key value of the new node is updated:4.Since the parent key is smaller than10,the nodes are swapped:95.Since the parent node is smaller than10,the nodes are swapped:Exercise6.5-3Heap-Minimum(A)1:return A[1]Heap-Extract-Min(A)1:if A.heap-size<1then2:Error“heap underflow”3:end if4:min=A[1]5:A[1]=A[A.heap−size]6:A.heap−size−−7:Min-heapify(A,1)8:return minHeap-decrease-key(A,i,key)101:if key¿A[i]then2:Error“new key larger than old key”3:end if4:A[i]=key5:while i>1and A[P arent(i)]<A[i]do6:exchange A[i]with A[P arent(i)]7:i=P arent(i)8:end whileMin-Heap-Insert(A,key)1:A.heap−size++2:A[A.heap−size]=∞3:Heap-Decrease-Key(A,A.heap-size,key)Exercise6.5-4If we don’t make an assignment to A[A.heap−size]then it could contain any value.In particular,when we call HEAP-INCREASE-KEY,it might be the case that A[A.heap−size]initially contains a value larger than key,causing an error.By assigning−∞to A[A.heap−size]we guarantee that no error will occur.However,we could have assigned any value less than or equal to key to A[A.heap−size]and the algorithm would still work.Exercise6.5-5Initially,we have a heap and then only change the value at i to make it larger.This can’t invalidate the ordering between i and it’s children,the only other thing that needs to be related to i is that i is less than it’s parent,which may be false.Thus we have the invariant is true at initialization.Then,when we swap i with its parent if it is larger,since it is larger than it’s parent,it must also be larger than it’s sibling,also,since it’s parent was initially above its kids in the heap,we know that it’s parent is larger than it’s kids.The only relation in question is then the new i and it’s parent.At termination,i is the root,so it has no parent,so the heap property must be satisfied everywhere.Exercise6.5-6Replace A[i]by key in the while condition,and replace line5by“A[i]= A[P ARENT(i)].”After the end of the while loop,add the line A[i]=key. Since the key value doesn’t change,there’s no sense in assigning it until we know where it belongs in the heap.Instead,we only make the assignment of the parent to the child node.At the end of the while loop,i is equal to the position where key belongs since it is either the root,or the parent is at least11key,so we make the assignment.Exercise6.5-7Have afield in the structure that is just a count of the total number of elements ever added.When adding an element,use the current value of that counter as the key.Exercise6.5-8The algorithm works as follows:Replace the node to be deleted by the last node of the heap.Update the size of the heap,then call MAX-HEAPIFY to move that node into its proper position and maintain the max-heap property. This has running time O(lg n)since the number of times MAX-HEAPIFY is recursively called is as most the height of the heap,which is lg n .Algorithm2HEAP-DELETE(A,i)1:A[i]=A[A.heap−size]2:A.heap−size=A.heap−size+13:MAX-HEAPIFY(A,i)Exercise6.5-9Construct a min heap from the heads of each of the k lists.Then,tofind the next element in the sorted array,extract the minimum element(in O lg(k) time).Then,add to the heap the next element from the shorter list from which the extracted element originally came(also O(lg(k))time).Sincefinding the next element in the sorted list takes only at most O(lg(k))time,tofind the whole list,you need O(n lg(k))total steps.Problem6-1a.They do not.Consider the array A= 3,2,1,4,5 .If we run Build-Max-Heap,we get 5,4,1,3,2 .However,if we run Build-Max-Heap’,we will get 5,4,1,2,3 instead.b.Each insert step takes at most O(lg(n)),since we are doing it n times,weget a bound on the runtime of O(n lg(n)).Problem6-2a.It will suffice to show how to access parent and child nodes.In a d-ary array,PARENT(i)= i/d ,and CHILD(k,i)=di−d+1+k,where CHILD(k,i) gives the k th child of the node indexed by i.12b.The height of a d-ary heap of n elements is with1of log d n.c.The following is an implementation of HEAP-EXTRACT-MAX for a d-aryheap.An implementation of DMAX-HEAPIFY is also given,which is the analog of MAX-HEAPIFY for d-ary heap.HEAP-EXTRACT-MAX con-sists of constant time operations,followed by a call to DMAX-HEAPIFY.The number of times this recursively calls itself is bounded by the height of the d-ary heap,so the running time is O(d log d n).Note that the CHILD function is meant to be the one described in part(a).Algorithm3HEAP-EXTRACT-MAX(A)for a d-ary heap1:if A.heap−size<1then2:error“heap underflow”3:end if4:max=A[1]5:A[1]=A[A.heap−size]6:A.heap−size=A.heap−size−17:DMAX-HEAPIFY(A,1)Algorithm4DMAX-HEAPIFY(A,i)1:largest=i2:for k=1to d do3:if CHILD(k,i)≤A.heap−size and A[CHILD(k,i)]>A[i]then4:if A[CHILD(k,i)]>largest then5:largest=A[CHILD(k,i)]6:end if7:end if8:end for9:if largest=i then10:exchange A[i]with A[largest]11:DMAX-HEAPIFY(A,largest)12:end ifd.The runtime of this implementation of INSERT is O(log d n)since the whileloop runs at most as many times as the height of the d-ary array.Note that when we call PARENT,we mean it as defined in part(a).e.This is identical to the implementation of HEAP-INCREASE-KEY for2-aryheaps,but with the PARENT function interpreted as in part(a).The run-time is O(log d n)since the while loop runs at most as many times as the height of the d-ary array.13Algorithm5INSERT(A,key)1:A.heap−size=A.heap−size+12:A[A.heap−size]=key3:i=A.heap−size4:while i>1and A[P ARENT(i)<A[i]do5:exchange A[i]with A[P ARENT(i)]6:i=P ARENT(i)7:end whileAlgorithm6INCREASE-KEY(A,i,key)1:if key<A[i]then2:error“new key is smaller than current key”3:end if4:A[i]=key5:while i>1and A[P ARENT(i)<A[i]do6:exchange A[i]with A[P ARENT(i)]7:i=P ARENT(i)8:end whileProblem6-3a.2345 891214 16∞∞∞∞∞∞∞b.For every i,j,Y[1,1]≤Y[i,1]≤Y[i,j].So,if Y[1,1]=∞,we know thatY[i,j]=∞for every i,j.This means that no elements exist.If Y is full,it has no elements labeled∞,in particular,the element Y[m,n]is not labeled ∞.c.Extract-Min(Y,i,j),extracts the minimum value from the young tableau Yobtained by Y [i ,j ]=Y[i +i−1,j +j−1].Note that in running this algorithm,several accesses may be made out of bounds for Y,define these to return∞.No store operations will be made on out of bounds locations.Since the largest value of i+j that this can be called with is n+m,and this quantity must increase by one for each call,we have that the runtime is bounded by n+m.d.Insert(Y,key)Since i+j is decreasing at each step,starts as n+m and isbounded by2below,we know that this program has runtime O(n+m). e.Place the n2elements into a Young Tableau by calling the algorithm frompart d on each.Then,call the algorithm from part c n2to obtain the numbers in increasing order.Both of these operations take time at most2n∈O(n), and are done n2times,so,the total runtime is O(n3)141:min=Y[i,j]2:if Y[i,j+1]=Y[i+1,j]=∞then3:Y[i,j]=∞4:return min5:end if6:if Y[i,j+1]<Y[i+1,j]then7:Y[i,j]=Y[i,j+1]8:Y[i,j+1]=min9:return Extract-min(y,i,j+1)10:else11:Y[i,j]=Y[i+1,j]12:Y[i+1,j]=min13:return Extract-min(y,i+1,j)14:end if1:i=m,j=n2:Y[i,j]=key3:while Y[i−1,j]>Y[i,j]or Y[i,j−1]>Y[i,j]do 4:if Y[i−1,j]<Y[i,j−1]then5:Swap Y[i,j]and Y[i,j−1]6:j−−7:else8:Swap Y[i,j]and Y[i−1,j]9:i−−10:end if11:end while15f.Find(Y,key).Let Check(y,key,i,j)mean to return true if Y[i,j]=key,oth-erwise do nothingi=j=1while Y[i,j]<key and i<m doCheck(Y,key,i,j)i++end whilewhile i>1and j<n doCheck(i,j)if Y[i,j]<key thenj++elsei–end ifend whilereturn false16。