Professional Documents
Culture Documents
4 X
LOOK : X
1 + +
RESULT:
Proposed
two solution: closed circuit and open circuit close circuit-the path lead to square to the starting square on the 64th move open circuit-the paths ends on any square but not ends near the starting square. Implementation discovered as inefficient but one solution becomes four
Definition :
Nature:
Example :
89 17 17 17 17 17 17
45 45 29 29 29 29
68 68 68 34 34 34 29
90 90 90 90 45 45 34
29 29 45 45 90 68 45
34 34 34 68 68 90 68
17 89 89 89 89 89 89
initial swap 89, 17 swap 45, 29 swap 68, 34 swap 90, 45 swap 90, 68 90 done
Sample Algorithm
for(int i = 1 ; i < n - 1 ; i++) { int k = i; for(int j = i + 1 ; i < n ; i++) { if(A[j] < A[k]) k = j; } if(k!=i) { int temp = A[i]; A[i] = A[k]; A[k] = temp; } }
Computation: BIG OH
Computation: Omega
Computation: Theta
Formula : O <= c.g(n)<=fn) <=c.g(n) Solution: O <= c.g(n)<=fn)<= c.g(n) O<= n2 <= 3n2+7n+1 <= n2 O<= n2 <=(3n2+7n+1 )/ n2 <= n2 O<= n2 /4 <=(3+7/n + 1/ n2 )<= n2
Substitute:
Computation: Theta
n= 5 O<= c <= 3+7/5+ 1/ 52 <= c O<= c<= ( 15 +7 +25)/25 <= c O<= c <=47/25 <= c C<= 1.88 n = 10 O <= c <= 3+7/10+ 1/ 100<= c O<= c <= ( 300 +70 +4)/100<= c O<= c <= 374/100<= c C<= 3.74
BUBBLE SORTING
Bubble sort is a simplesorting algorithmthat works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items andswappingthem if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list
1956 a reference to analysis of the algorithm regarding sorting called Sorting by Exchange was but does not directly called Bubble Sort. extensive bibliography and sequence of articles from the 1962 ACM Conference on Sorting do not use the term bubble sort, although the Sorting by Exchange algorithm
An
programming devotes a chapter of sorting, but uses the term Exchange Sort rather than bubble sort.
1962, Iverson uses the name Bubble Sort. This appears to be the first use of the term in print. Thus reinforces claims that Iverson is the first to use the term, though not conclusive. earlier publications the algorithm officially enters the ACM algorithm repository as Algorithm 175 in 1963 where it is named Shuttle Sort.
Despite
ALGORITHM SIMULATION
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
old [5 new [5 1 1 array 4 4 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[5 [5 1 1 array 4 4 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[5 [5 1 1 array 4 4 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[5 [5 1 1 array 4 4 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[(5 [(1 1) 5) array 4 4 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 5 5 array 4 4 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 5 5 array 4 4 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 (5 (4 array 4) 5) 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 5 5 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 5 5 2 2 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array (5 (2 2) 5) 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 2 2 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 2 2 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 2 2 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 2 2 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 2 2 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 2 2 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 4 4 array 2 2 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 (4 (2 array 2) 4) 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
ALGORITHM SIMULATION
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } }
[1 [1 2 2 array 4 4 5 5 8] 8]
TIME COMPLEXITY
for(x=n-1;x>0;x--){ for(y=0;y<x;y++){ if(array[y]>array[y+1]){ temp = array[y]; array[y] = array[y+1]; array[y+1] = temp; } } N+1 N+1(N) 1(N2) 1(N2) 1(N2) 1(N2) Total: 5N2+2n+1
While the point-in-polygon algorithm is useful for determining whether a few points are inside a polygon, it is woefully inefficient for filling a polygon, because it requires checking every side of the polygon for every pixel in the image. To speed things up tremendously, we will check each side of the polygon only once per pixel row. It works like this:
Figure 1 shows a polygon. We are about to render one row of pixels. All the pixels on that row have the same Y coordinate, which is represented by the red line in the figure. Loop through the polygon and build a list of threshold-crossing nodes, just as in the pointin-polygon algorithm but instead of comparing them with an X coordinate, store them all in a list. Figure 1 shows the indices (0 through 5) of the nodes. In this example, the polygon starts at the blue corner, and is traced counter-clockwise, which generates a fairly random horizontal order for the nodes.
Next, sort the node list so that it proceeds from left-to-right, as shown in Figure 2. This takes a little time, but we have to do it onlyonceper pixel row.
Now, as shown in Figure 3, it is a simple matter to fill all the pixels between each pair of nodes from node 0 to 1, node 2 to 3, and node 4 to 5.
Unfortunately because the Bubble Sorting Algorithm is so inefficient that most programmers and designers questions the usefulness automatically disregards it to a more faster and efficient algorithm such as quick sort, shell sort, etc. However, due to its simplicity, most books and sources that teaches data structures and algorithm still includes Bubble Sort as one of the best example of a sorting algorithm for it is easy to explain and understand for beginners.