CSCI-1080 Intro To CS: World Wide WebInformation, computation, and algorithmsComputer science is “the study of the theoretical foundations of information and computation” Wikipedia, 2016. Examples of information include:
We will not attempt to define information. Instead, we simply note that sets and ordered lists, which we have already discussed, provide a basic foundation for the theory of information. Computation is a form of action. Examples include:
An algorithm is a step-by-step procedure for performing a computation. We introduced algorithms to illustrate network dynamics. Our repertoire of algorithms so far includes the random graph algorithm, the triadic closure algorithm, and the preferential attachment algorithm. Summation: an example of what computation isAdding a series of numbers, called summation, is a simple example of computation. Below is a basic algorithm for summation: Summation Algorithm:Input: Integer n, with n > 0 Output: Variable t =1+2+3+ … + n Steps:
The symbol Example: The simplest form of summation notation is ![]() Given an integer n>0, the above notation represents the sum 1+2+3+…+n. Example: We use sets to define a more general notion of summation. Let A = {1,2,3,…,n} with n>0. Then the previous example can also be written ![]() Notice how the more general notation for summation is similar to implicit notation for sets. In the above example, the dummy variable is i and the true/false statement is Example: Let A = {1,5,8,20}. Consider ![]() This is Example: Let A = {2,4,8}. Consider ![]() How much is HTML: an example of what computation is notHTML is arguably the fundamental computer language of the Web and the basis of Web programming; however, many computer scientists do not consider HTML to be a programming language. The distinction between the popular notion of “Web programming” and the computer science notion of “programming language” hinges on computation. A computer scientist uses a programming language to express algorithms that do computation. In contrast, Web programming does not require the author to write algorithms to do computation. For example, if you want to add the numbers HTML does not express algorithms, but it certainly does represent information. For example, if you wanted to write a story about adding the numbers
If you used HTML to write a story about adding the numbers For example, you could use the Web scripting language PHP to add Examples of Algorithms seen so farRandom Graph Algorithm1. Start with node set V with |V|>1 2. E = { } 3. Choose random pair of nodes x, y that are non-adjacent 4. Add element {x,y} to set E 5. If |E| = |V|*(|V|-1)/2 then we're done 6. Go to step 3 Random Graph Algorithm v2Alternatively, we can stop when we have tried to add an edge for each couple of nodes: 1. Start with node set V with |V|>1 2. E = { } 3. counter = 0 4. Choose random pair of nodes x, y that are non-adjacent 5. counter = counter + 1 6. Add element {x,y} to set E 7. If counter = |V|*(|V|-1)/2 then we're done 8. Go to step 4 Triadic Closure Algorithm1. Start with graph G=(V,E) with |V|>0 and |E|>0 2. Choose random pair of nodes x, y that are non-adjacent and share a common neighbor 3. If no such pair of nodes x, y exists, then we’re done 4. Add element {x,y} to set E 5. Go to step 2 Triadic Closure Bias Algorithm v11. Start with: a. T = bias toward triadic closure = number between 0 and 1 inclusive b. graph G=(V,E) with |V|>0 and |E|>0 2. "Flip a coin": r = random number between 0 and 1 inclusive 3. If (r ≤ T) Choose random pair of nodes x, y that are non-adjacent and share a common neighbor Else Choose random pair of nodes x, y that are non-adjacent 4. If no such pair of nodes x, y exists, then we’re done 5. Add element {x,y} to set E 6. Go to step 2 Triadic Closure Bias Algorithm v21. Start with: a. T = bias toward triadic closure = number between 0 and 1 inclusive b. graph G=(V,E) with |V|>0 and |E|>0 2. "Flip a coin": r = random number between 0 and 1 inclusive 3. If (r ≤ T) Choose random pair of nodes x, y that are non-adjacent and share a common neighbor. The probability of choosing pair {x,y} corresponds to the number of neighbors that x and y share. Else Choose random pair of nodes x, y that are non-adjacent 4. If no such pair of nodes x, y exists, then we're done 5. Add element {x,y} to set E 6. Go to step 2 Triadic Closure Bias Algorithm v31. Start with: a. T = bias toward triadic closure = number between 0 and 1 inclusive b. graph G=(V,E) with |V|>0 and |E|>0 2. "Flip a coin": r = random number between 0 and 1 inclusive 3. If (r ≤ T) Choose random pair of nodes x, y that are non-adjacent and share a common neighbor. The probability of choosing pair {x,y} corresponds to |N(x) ∩ N(y)| / |N(x) U N(y)|. Else Choose random pair of nodes x, y that are non-adjacent 4. If no such pair of nodes x, y exists, then we’re done 5. Add element {x,y} to set E 6. Go to step 2 Computing distance, part oneGiven an undirected graph Computing distance in a graph relates to several important topics in Web science:
Computing distance in a graph is also very closely related to computing shortest paths in a graph. Finding shortest paths is a fundamental problem in computer science that is traditionally solved with breadth-first search. Our distance algorithm is a slightly simplified version of breadth-first search. We motivate our distance algorithm with the following scenario:
Given the above scenario, who will receive meme m from whom, and how many steps will it take for m to reach each person in the network? Answering these questions drives the distance algorithm. Example:
Computing distance, part two: ExampleBelow is another example that illustrates how to compute distance in a graph. It explicitly counts iterations (of the algorithm we will soon write) and it introduces some more formal bookkeeping: Set For example:
Below we use Beginning:
Iteration 1:
Iteration 2:
Iteration 3:
Iteration 4:
Iteration 4:
At the end of iteration 5, we see that there are no nodes distance 6 from the source node. Therefore, there are no nodes distance 7 from the source node, no nodes distance 8, etc. Note that if a graph is not connected, then when the algorithm ends, only nodes in the same connected component as the source node will have been visited, and nodes in other components will not have been visited. Nodes that are still unvisited at the end of the algorithm are distance infinity from the source. Computing distance, part three: AlgorithmThe algorithm below states more formally the steps of the computation illustrated above. Distance Algorithm:Input: Undirected graph Output: Distance from s to t in G Steps:
The contect of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. |