This document contains summaries of algorithms and data structures including counting sort, radix sort, binary search trees, priority queues, and Prim's algorithm. Counting sort counts the number of objects that have each distinct key value and uses arithmetic to determine the positions of each object in the output array. Radix sort extends counting sort to handle numbers in different bases. Binary search trees allow searching, insertion, and deletion in logarithmic time. Priority queues organize elements based on priority and the maximum heap tree is commonly used to implement them. Prim's algorithm finds the minimum spanning tree of a connected, undirected graph.
This document contains summaries of algorithms and data structures including counting sort, radix sort, binary search trees, priority queues, and Prim's algorithm. Counting sort counts the number of objects that have each distinct key value and uses arithmetic to determine the positions of each object in the output array. Radix sort extends counting sort to handle numbers in different bases. Binary search trees allow searching, insertion, and deletion in logarithmic time. Priority queues organize elements based on priority and the maximum heap tree is commonly used to implement them. Prim's algorithm finds the minimum spanning tree of a connected, undirected graph.
This document contains summaries of algorithms and data structures including counting sort, radix sort, binary search trees, priority queues, and Prim's algorithm. Counting sort counts the number of objects that have each distinct key value and uses arithmetic to determine the positions of each object in the output array. Radix sort extends counting sort to handle numbers in different bases. Binary search trees allow searching, insertion, and deletion in logarithmic time. Priority queues organize elements based on priority and the maximum heap tree is commonly used to implement them. Prim's algorithm finds the minimum spanning tree of a connected, undirected graph.
1 Read A[1--.N] 3.2 find all adjacent node from v i.e w and update c[w] 2 Max=0 3.3 if c[w]>c(v,W] 3 For I = 1 to n 3.3.1 c[w] = C[v,w] 3.1if A[i]>Max 3.3.2 N(w)=V 3.2 Max = A[i] 4 for I = 0 to max B tree searching 4.1 b[i] = 0 Bsearch(x,key) 5. For I = 1 to n 1. i=1 B[A[i]]]= B[A[i]] +1 2.while i<=n[x]and key>keyi[x] 6.For I = 1 to max 2.1 i=i+1 6.1 B[i]=B[i]+1 3. If i<=n[x] ans key=ki[x] 7. For I = N down to 1 3.1 return(x,i) 7.1 C[B[A[i]]]=A[i] 4. if leaf[x] 7.2 B[A[i]] = B[A[i]]-1 4.1 return nil Else Counting Sort(A,n,div) 5. disk-read(ci[x] 1. for I = 0 to 9 6. Bsearch(ci[x],k) 1.1 B[i] = 0 7. End 2. For I = 1 to n 2.1 B[A[i]/div%10]= B[A[i]/div%10] +1 Minimum and Maximum searching 3.For I = 1 to 9 1. Min = a[1] 3.1 B[i]=B[i]+B[i-1] 2.Max= a[1] 4. For I = N down to 1 3.For I = 2 to n 4.1 C[B[A[i]/div%10]]=A[i] 3.1 if A[i] <min 4.2 B[A[i]] = B[A[i]]-1 3.1.1 Min = a[i] 5. For I = 1 to.. N 3.2 If a[i] > max 5.1 A[i]=c[i] 3.2.1 max =A[i] • Algorithm of radix sort 4.Print max 1. Read A[1…N]] 5 Print min 2. find max Total comparison = 2n-2 2. For div=1 to max/div>0 step div*10 2.1 call counting sort(A,N,div) Master method of Complexity Analysis 3.print A[1..N] • Recurrence Relation T(n) = aT(n/b) +f(n) • Iterative Algorithm to make Maximum Heap Tree Let a>=1 and b>1 be constant ,let f(n ) be a function 1. For i= 2 to n • Three cases 1.1 item = a[i] • 1) if f(n) = O(n log b a -Ɛ) for some constant Ɛ>0 ,then 1.2 key=i T(n) =O(n log b a) 1.3 Par=i/2 2) If f(n) = O(n log b a) then 1.4 While (par>=1) && item >A[par] T(n) = O(n log b a lg n) log a +Ɛ a. A[key]= a[par] 3 .if f(n) = O(n b ) for some constant Ɛ>0 an if af(n/b) <= cf(n) for some b Key=par constant c<1 and all sufficiently large n then C. Par=par/2 T(n) = O(f(n) [End while] Priority Queue 1.5 A[key[=item • It is a queue, which works on priority basis as service is given [End for] to the highest priority element 2. Print a[1.n] • Each elements has a different priority 3 stop • Array is best data structure to create a priority queue Recursive approach • Maximum heap tree is used to create priority queue • Max-Heapify (A, i): • Array of structure is used as one information of structure is data and 1 left ← 2*i // ← means "assignment" another part is priority 2 right ← 2*i + 1 • Increase_priority(Q,x,new_pri) 3 largest ← i 1. i=index of x 4 if left ≤ heap_length[A] and A[left] > A[largest] then: 2. Q[i].p = new_pri 4.1 largest ← left 3. Par= i/2 5 if right ≤ heap_length[A] and A[right] > A[largest] then: 4. While(i>1 and Q[par]<Q[i]) 5.1 largest ← right 4.1 swap ( Q[i].p,Q[par].p) 6 if largest ≠ i then: 4.2 swap ( Q[i].d,Q[par].d) 6.1 swap (A[i] and A[largest]) 4.3 i= par 6.2 Max-Heapify(A, largest) 4.3 Par= par/2 7. Print A[1..n] 5. end 8.stop • Insert (Q,x,p)- 1. N= N+1 Prims algorithm 2. Q[N] = -1 1. X=1,Y={V-1} 3. Q[N]=X 2. For I = 2 to n 4. Increase_priority(Q,Q[N],p) 2.1 if C[1,i] <>0 Delete 2.2 c[i]=C[1,i] 1. A=Q[1].p 2.3 N[i]=1 2. B=Q[1]].d Else 3. Swap(q[1].p,Q[N].p) 2.3 c[i]= ∞ 4. Swap(Q[1].d,q[1].d) 3 for I = 2 to n 5. N=N-1 3.1 v = find minimum(c[j]) 6. Heapify(Q,1)