Algorithm Day1

来源:互联网 发布:编程是什么 编辑:程序博客网 时间:2024/06/07 03:27

Algorithm Day 1

  • To get understand the impact of algorithm.
  • Know about the problem of “Dynamic connectivity”
  • Learned there are three ways to solve this problem:

    1. Quick find, Quick Union,
    2. Weighted Quick union,
    3. Weighted Quick union with path compression

    Weighted Quick unio with path compression

    Algorithm  performance comparison

Steps to developing a usable algorithm

  1. Model the problem.
  2. Find an algorithm to solve it.
  3. Fast enough? Fits in memory?
  4. If not, figure out why.
  5. Find a way to address the problem.
  6. Iterate until satisfied.

The scientific method.

Mathematical analysis.

Q1: So, How to solve the Kruskal’s minimum spanning tree with union-find ?

Q2: 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 m*log n or better and use extra space proportional to n.

Q3: Search in a bitonic array. An array is bitonic if it is comprised of an increasing sequence of integers followed immediately by a decreasing sequence of integers. Write a program that, given a bitonic array of n distinct integer values, determines whether a given integer is in the array.

  • Standard version: Use ∼3lgn compares in the worst case.
  • Signing bonus: Use ∼2lgn compares in the worst case (and prove that no algorithm can guarantee to perform fewer than ∼2lgn compares in the worst case).
原创粉丝点击