User:DAA5N6/sandbox

1)  Euclidean Algorithm 

The Euclidean Algorithm for finding GCD(A,B) is as follows:

If A = 0 then GCD(A,B)=B, since the GCD(0,B)=B, and we can stop. If B = 0 then GCD(A,B)=A, since the GCD(A,0)=A, and we can stop.

Write A in quotient remainder form (A = B⋅Q + R)

Find GCD(B,R) using the Euclidean Algorithm since GCD(A,B) = GCD(B,R)

2) Airline itinerary 

Step-I:- First open your desired airlines website (let us consider spicejet)

Step-II:- Then select the starting and destination locations, enter the required details and then click on find flights (Let us consider the starting point as Hyderabad and destination to be Ahmadabad)

Step-III:- Now it shows different routes for your destination location. There are 2 different ways u can reach your location 1.Direct 2.Hopping ( Hopping means there would be a change of flights (or) the same flight would stop at different locations before reaching the destination.               Direct means there would be no change of flight's between the course of your journey.)

Step-IV:-

Now u have just have to login into your account and make the payment required.

3) The PageRank Algorithm

The original PageRank algorithm was described by Lawrence Page and Sergey Brin in several publications. It is given by

PR(A) = (1-d) + d (PR(T1)/C(T1) + ... + PR(Tn)/C(Tn)) where

PR(A) is the PageRank of page A,

PR(Ti) is the PageRank of pages Ti which link to page A,

C(Ti) is the number of outbound links on page Ti and

d is a damping factor which can be set between 0 and 1.

So, first of all, we see that PageRank does not rank web sites as a whole, but is determined for each page individually. Further, the PageRank of page A is recursively defined by the PageRanks of those pages which link to page A.

The PageRank of pages Ti which link to page A does not influence the PageRank of page A uniformly. Within the PageRank algorithm, the PageRank of a page T is always weighted by the number of outbound links C(T) on page T. This means that the more outbound links a page T has, the less will page A benefit from a link to it on page T. The weighted PageRank of pages Ti is then added up. The outcome of this is that an additional inbound link for page A will always increase page A's PageRank. Finally, the sum of the weighted PageRanks of all pages Ti is multiplied with a damping factor d which can be set between 0 and 1. Thereby, the extend of PageRank benefit for a page by another page linking to it is reduced.

4) Design Strategies

i)Divide and Conquer- Merge Sort

Step 1 − if it is only one element in the list it is already sorted, return. Step 2 − divide the list recursively into two halves until it can no more be divided. Step 3 − merge the smaller lists into new list in sorted order.

ii)Decrease and Conquer

Algorithm bfs(v)

Step-I count++ step-II mark v with count Step-III add v to queue while queue is not empty do       Step-IV  for each vertex w adjacent to front of queue do         if w is marked 0 then // not visited count++ Step-V add w to queue remove front from queue

iii) Transform and Conquer 

Algorithm for heap

Step 1 − Create a new node at the end of heap. Step 2 − Assign new value to the node. Step 3 − Compare the value of this child node with its parent. Step 4 − If value of parent is less than child, then swap them. Step 5 − Repeat step 3 & 4 until Heap property holds.

iv) Greedy Approach

Algorithm for Kruskal's

1. Sort all the edges in non-decreasing order of their weight. 2. Pick the smallest edge. Check if it forms a cycle with the spanning tree formed so far. If cycle is not formed, include this edge. Else, discard it. 3. Repeat step#2 until there are (V-1) edges in the spanning tree.

v)  Dynamic Programming 

Algorithm for knapsack problem

Value(n,S) {                   if (n == 0) return 0; if (arr[n][S] != unknown) return arr[n][S]; // <- added this if (s_n > S) result = Value(n-1,S); else result = max{v_n + Value(n-1, S-s_n), Value(n-1, S)}; arr[n][S] = result; // <- and this return result; }

vi)  Backtracing/Branch and Bound 

Algorithm for DFS

Step 1 − Visit the adjacent unvisited vertex. Mark it as visited. Display it. Push it in a stack. Step 2 − If no adjacent vertex is found, pop up a vertex from the stack. (It will pop up all the vertices from the stack, which do not have adjacent vertices.) Step 3 − Repeat Rule 1 and Rule 2 until the stack is empty.

vii)  Space and Time Tradeoff 

Boyer-Moore Algorithm outline

1. Using the pattern and the text, construct the bad-symbol shift table as for Horspool's algorithm 2. Using the pattern, construct the good-suffix shift table 3. Align the pattern against the beginning of the text 4. Repeat until match occurs or the pattern reaches the end of the text. Starting with the last character of the pattern and check the matching. Track the number of matches, k.                     Calculate d1 = max(t1(c)-k, 1). If k > 0 also get d2 from the good suffix shift table, shift d = max(d1, d2).