Learn Algorithm

Algorithms                       Tushar Gahora             

What you will get:
・Intermediate-level survey course.
・Programming and problem solving, with applications.
Algorithm: method for solving a problem.
Data structure: method to store information. 

topic


Why study algorithms?

Their impact is broad and far-reaching. 

Internet. Web search, packet routing, distributed file sharing, ... Biology. Human genome project, protein folding, ... 

Computers. Circuit layout, file system, compilers, ... 

Computer graphics. Movies, video games, virtual reality, ... Security. Cell phones, e-commerce, voting machines, ... 

Multimedia. MP3, JPG, DivX, HDTV, face recognition,  ...

Social networks. Recommendations, news feeds, advertisements, ... Physics. N-body simulation, particle collision simulation, ...

・Study of algorithms dates at least to Euclid. 
・Formalized by Church and Turing in 1930s. 
・Some important algorithms were discovered by undergraduates in a course like this!

                                     “ Algorithms + Data Structures = Programs.” 

 

  • To solve problems that could not otherwise be addressed.
  • For intellectual stimulation.
  • To become a proficient programmer.
  • They may unlock the secrets of life and of the universe. Computational models are replacing math models in scientific inquir.

Algorithm with tushar



  • Their impact is broad and far-reaching. 
  • Old roots, new opportunities. 
  • To solve problems that could not otherwise be addressed. 
  • For intellectual stimulation. 
  • To become a proficient programmer. 
  • They may unlock the secrets of life and of the universe. 
  • For fun and profit.

Prerequisites

  • Programming: loops, arrays, functions, objects, recursion.
  • Java: we use as expository language.
  • Mathematics: high-school algebra.

Programming environment

  • Use your own, e.g., Eclipse.

Introduction




uestions.Algorithmic interview questions based on the lecture material.

1.1 UNION-FIND

Steps to developing a usable algorithm. 

Model the problem. 

Find an algorithm to solve it. 

Fast enough? Fits in memory?

 If not, figure out why.

 Find a way to address the problem. 

Iterate until satisfied.

‣ dynamic connectivity
 ‣ quick find
 ‣ quick union
 ‣ improvements
‣ applications

Dynamic connectivity

Given a set of N objects.


  • Union command: connect two objects

  • Find/connected query: is there a path connecting the two objects?

  • union(4, 3) union(3, 8) union(6, 5) union(9, 4) union(2, 1)
algorithm img-2

connected(0, 7)     x
 connected(8, 9)    ✔
 union(5, 0) 
union(7, 2)
 connected(0, 7)
 union(1, 0)
 union(6, 1)   ✔ 

algorithm-connectivity example



Modeling the objects

Applications involve manipulating objects of all types. 

・Pixels in a digital photo.
 ・Computers in a network
. ・Friends in a social network.
 ・Transistors in a computer chip
. ・Elements in a mathematical set.
 ・Variable names in Fortran program.

 ・Metallic sites in a composite system.

When programming, convenient to name objects 0 to N –1.

 ・Use integers as array index. 
・Suppress details not relevant to union-find.

                                        Modeling the connections

We assume "is connected to" is an equivalence relation: 

Reflexive: p is connected to p. 
・Symmetric: if p is connected to q, then q is connected to p. 
・Transitive: if p is connected to q and q is connected to r, then p is connected to r. Connected components. Maximal set of objects that are mutually connected.

algorithm-part-1-modelling the connection

Implementing the operations

Find query. Check if two objects are in the same component. 
Union command. Replace components containing two objects with their union.


No comments:

Powered by Blogger.