## Pages

### Data Structure Heap Algorithms MCA Sem 2

Data Structure Algorithm for  Heap Operations  pseudo-code.
After knowing and completely understanding this algorithm for  Heap Operations . You will be able to write a Data Structure Programs for  Heap Operations  in any language. The basic ideology and idea behind all the programs will be same. Yes the programs will differ according to the syntax and semantics of the language. This is a part of Mumbai University MCA Colleges Data Structure MCA Sem 2

ReheapUp:-

Algorithm ReheapUp(heap, newNode)
1 if(newNode <> 0) (* if not root of heap *)
1 parent := (newNode-1)/2
2 if (heap[newNode]>heap[parent]) (* child greater than parent *)
1 hold = heap[parent]
2 heap[parent] = heap[newNode] (* exchange *)
3 heap[newNode] = hold
4 ReheapUp (heap, parent) (*continue reheapUP *)
3 end if
2 end if
End ReheapUp

Heap Insertion:-

Algorithm InsertHeap(heap, last, data) : BOOLEAN
1 if (last = HeapSize -1)
1 return FALSE (* over the heap size limitation *)
2 increment last (* increase the size of the heap *)
3 heap[last] = data (* put the data at the last position *)
4 ReheapUp(heap, last) (* restore the heap *)
5 return TRUE
End InsertHeap

ReheapDown:-

Algorithm ReheapDown (heap, root, last)
1 if ((root*2 +1) <= last) (* There is at least left child *)
2 leftKey := heap[root*2 +1] (* left child value *)
3 rightChild := FALSE (* assume no right child)
1 if ((root*2 + 2) <= last) (* There is also right child *)
1 rightKey := heap[root*2 +2] (* right child value *)
2 rightChild := TRUE
2 end if
3 largeChildKey := leftKey;
4 largeChildIndex := root*2 + 1; (* assume left child larger *)
5 if (rightChild AND leftKey < rightKey)
1 largeChildKey := rightKey; (* right child exists and is larger *)
2 largeChildIndex := root*2 +2;
6 end if
7 if (heap[root] < largeChildKey) (* exchange larger child with root *)
1 hold := heap[root];
2 heap[root] := heap[largeChildIndex];
3 heap[largeChildIndex] := hold;
4 reheapDown (heap, largeChildIndex, last);
8 end if
2 end if
end ReheapDown
Heap Deletetion

Algorithm DeleteHeap(heap, last, dataOut)
1 if (last < 0) (* empty heap *)
1 return FALSE
2 dataOut := heap[0] (* remove the largest data at root *)
3 heap[0] := heap[last] (* restore the shape *)
4 decrement last
5 reheapDown (heap, 0, last) (* restore the order property *)
6 return TRUE
End DeleteHeap

Algorithm for converting to max heap:-

Algorithm CreateHeap(list)
1 set index to 1
2 loop (index <= listLength)
1 reheapUp(list, index)
2 increment index
3 end loop
End CreateHeap

Heap Sort Algorithm:-

Algorithm HeapSort(list, last)
(* Create a heap *)
1 CreateHeap(list)
2 sorted := last;
3 loop (sorted > 0)
1 holdData := list[0] (* exchange 0 and sorted *)
2 list[0] := list[sorted]
3 list[sorted] = holdData
4 decrement sorted
5 reheapDown (list, 0, sorted);
4 end loop
End HeapSort

Hope this Algorithm is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

### Data Structure Binary Search Algorithm

Data Structure Algorithm for  Binary Search pseudo-code.
After knowing and completely understanding this algorithm for  Binary Search . You will be able to write a Data Structure Program for  Binary Search  in any language. The basic ideology and idea behind all the programs will be same. Yes the programs will differ according to the syntax and semantics of the language. This is a part of Mumbai University MCA Colleges Data Structure MCA Sem 2

Algorithm Binary(list, from, to, target, location)
1 if from = to (* terminating condition *)
1 set location to from
2 return list[from] = target
2 end if
3 middle := (to – from) DIV 2;
4 if list[middle] = target (* found target *)
1 set location to middle
1 return TRUE
5 else
1 if list[middle] < target (* select second half *)
1 set found to Binary(list, middle+1, to, target, location)
2 else (* select first half *)
1 set found to Binary(list, from, middle-1, target, location)
3 end if
6 end if
7 return found
end Binary

Hope this Algorithm is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

### Data Structure Quick Sort Algorithm

Data Structure Algorithm for  Quick sort  pseudo-code.

After knowing and completely understanding this algorithm for  Quick sort . You will be able to write a Data Structure Program for  Quick sort  in any language. The basic ideology and idea behind all the programs will be same. Yes the programs will differ according to the syntax and semantics of the language. This is a part of  Mumbai University MCA Colleges Data Structure MCA Sem 2

Algorithm QuickSort(list, left, right) (* Assume the list is not empty. *)
1 set pivot to Median(left, right, middle)
2 set sortLeft to left+1
3 set sortRight to right
4 loop sortLeft <= sortRight
1 loop [sortLeft] < [pivot]
1 increment sortLeft
2 end loop
3 loop [sortRight] >= [pivot]
1 decrement sortRight
4 end loop
5 if sortLeft < sortRight
1 exchange( sortLeft, sortRight)
2 increment sortLeft
3 decrement sortRight
6 end if
5 end loop
6 exchange(pivot, sortLeft-1) (* return the pivot into correct location *)
(* start left partition sort *)
7 if left < pivot
1 quickSort(list, left, pivot-1)
8 end if
(* start right partition sort *)
9 if right > pivot
1 quickSort(list, pivot+1, right)
10 end if
End QuickSort

Hope this Algorithm is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

### Data Structure Sequential Search Algorithm.

Data Structure Algorithm for  Sequential Search  pseudo-code.
After knowing and completely understanding this algorithm for  Sequential Search . You will be able to write a Data Structure Program for  Sequential Search  in any language. The basic ideology and idea behind all the programs will be same. Yes the programs will differ according to the syntax and semantics of the language. Mumbai University MCA College Algorithm

Algorithm SeqSearch(list, last,target,location)
1 set current to 0
2 set found to FALSE
3 loop (current < endList AND
list[current] <> target)
1 increment current
4 end loop
5 set location to current
6 if (list[current] = target)
1 set found to TRUE
7 end if
End SeqSearch

Hope this Algorithm is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

### Data Structure Shell Sort Algorithm MCA Sem 2

Data Structure Algorithm for Shell sort pseudo-code.

After knowing and completely understanding this algorithm for Shell sort. You will be able to write a Data Structure Program for Shell sort in any language. The basic ideology and idea behind all the programs will be same. Yes the programs will differ according to the syntax and semantics of the language. This is a part of Mumbai University MCA Colleges Data Structure MCA Sem 2

Algorithm ShellSort(list) (* Assume the list is not empty. *)
1 set increment to half the list length
2 loop (* for each value of increment *)
1 …
2 loop (* for each segment *)
1 …
2 loop (* for finding the correct position for each element *)
1 …
2 store the element in correct position
3 end loop
4 move to next segment
3 end loop
4 set increment to increment/2
3 end loop
End ShellSort

Hope this Algorithm is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

### Data Structure Insertion Sort Algorithm

Data Structure Algorithm for Straight Insertion sort pseudo-code.
After knowing and completely understanding this algorithm for Insertion sort. You will be able to write a Data Structure Program for Insertion sort in any language. The basic ideology and idea behind all the programs will be same. Yes the programs will differ according to the syntax and semantics of the language.
This algorithm is a part of Mumbai University MCA Colleges Data Structure MCA Sem 2.

Algorithm InsertionSort(list) (* Assume the list is not empty. *)
1 set listWall to startList (* listWall points to start of unsorted list *)
2 loop while listWall <= endList
1 set hold to listWall
2 set current to listWall prev
(* scan the sorted list moving larger elements to right *)
3 loop while (current > startList) AND hold key < current key
1 move current to current next
3 set current to current prev
4 end loop (* found the insertion point *)
5 move hold to current next
7 set listWall to listWall next
3 end loop
End InsertionSort

Hope this Algorithm is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.