note3_find the celebrity

题目描述:

A guest at a party is a celebrity if this person is known by every other guest, but knows none of them. There is at most one celebrity at a party, for if there were two, they would know each other. A particular party may have no celebrity. Your assignment is to find the celebrity, if one exists, at a party, by asking only one type of question—asking a guest whether they know a second guest. Everyone must answer your questions truthfully. That is, if Alice and Bob are two people at the party, you can ask Alice whether she knows Bob; she must answer correctly. Use mathematical induction to show that if there are n people at the party, then you can find the celebrity, if there is one, with 3(n − 1) questions. [Hint: First ask a question to eliminate one person as a celebrity. Then use the inductive hypothesis to identify a potential celebrity. Finally, ask two more questions to determine whether that person is actually a celebrity.]

 题解:

Basis step - With 2 people at the party, we would need to find out how many questions at most we would need to find a celebrity.

n = 2

2 ≤ 3(2-1)

2 ≤ 3(1)

2 ≤ 3 True. Only 2 questions are needed

 

Induction Hypothesis :

Assuming f(k) is true, so for every k people, you can find a celebrity with >less than 3(k-1) questions, assuming one exists.

Induction Step:

 

 

posted @   哎呦_不想学习哟~  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示