coursera算法公开课练习题Interview(1)

这篇博客探讨了如何解决社交网络连接问题,通过优化的并查集数据结构实现动态连接,确保在mlogn的时间复杂度内完成所有成员的连通性判断。同时,讨论了具有特定规范元素的并查集,以及支持删除和查找后继元素的数据结构设计,所有操作要求在对数时间内完成。
摘要由CSDN通过智能技术生成
  1. Question: Social network connectivity. Given a social network containing n members and a log file containing m timestamps at which times pairs of members formed friendships, design an algorithm to determine the earliest time at which all members are connected (i.e., every member is a friend of a friend of a friend … of a friend). Assume that the log file is sorted by timestamp and that friendship is an equivalence relation. The running time of your algorithm should be mlogn or better and use extra space proportional to n.

    问题描述:上面的问题说的是一个社交网络的动态连接问题,问题描述中是说一共有n名成员和一个包括m个时间戳的log文件(在每个时间戳内两名成员成为了朋友),现在想要知道在什么时间戳结束后所有的成员都成为了好朋友,即所有的节点连通了。要求运行时间是mlogn以下,空间是和n成比例的。

    解决方案:数据结构采用压缩路径且带权值的quick-union,将log文件抽象成有序数组,数组中的对象是将要连通的两个分量以及一个时间戳,在union操作里面参数是数组中的对象,并加入对于count即组件数的判定,当count等于1的时候,打印出此时输入对象的时间戳分量。

  2. Question

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值