This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package recursive; | |
| import java.util.Scanner; | |
| public class Recursive { | |
| public int recur(int n) | |
| { | |
| if(n==1) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package stringreduction; | |
| import java.util.Scanner; | |
| public class StringReduction { | |
| public void reductioin(StringBuffer str) | |
| { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package stack; | |
| import java.util.Stack; | |
| public class STACK { | |
| public void POP(Stack STACK, int TOP) | |
| { | |
| if(TOP==0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ALgorithm: | |
| BINARY(DATA,LB,UB,ITEM,LOC) | |
| Here DATA is a sorted array with lower bound LB and upper bound UB, and ITEM is a given item of information. The variable BEG , END and MID | |
| denote, respectively, the beginning, end and middle locations of a segment of elements of DATA. This algorithm finds the location LOC of ITEM in | |
| DATA or sets LOC = NULL. | |
| 1. [Initialize segment variables.] | |
| Set BEG:=LB, END:=UB and MID =INT((BEG+END)/2). | |
| 2. Repeat Steps 3 and 4 while BEG <= END and DATA[MID] !=ITEM. | |
| 3. If ITEM<DATA[MID],then: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Algorithm: | |
| (DATA, N,ITEM,LOC) Here DATA is a linear array with N elements, and ITEM is a given item of information. This algorithm finds the location LOC | |
| of ITEM in DATA, or sets LOC:=0 if the search is unsuccessful. | |
| 1. [Insert.ITEM at the end of DATA.] Set DATA[N+1]:= ITEM. | |
| 2. [Initialize counter.]Set LOC:=1. | |
| 3. [Search for ITEM.] | |
| Repeat while DATA[LOC]!=ITEM: | |
| Set LOC:= LOC+1. | |
| [End of loop.] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Here DATA is an array with N elements. This elements.This algorithm sorts the elements in DATA. | |
| 1. Repeat Steps 2 and 3 for K=1 to N-1. | |
| 2. Set PTR:=1.[Initializes pass pointer PTR.] | |
| 3. Repeat while PTR<=N-K:[Executes pass.] | |
| (a) If DATA[PTR]>DATA[PTR] and DATA[PTR +1]. | |
| Interchange DATA[PTR] and DATA[PTR+1]. | |
| [End of IF structure.] | |
| (b) Set PTR:=PTR+1. | |
| [End of inner loop.] | |
| [End of Step 1 outer loop.] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Algorithm 4.3:: | |
| (Deleting from a Linear Array) DELETE(LA,N,ITEM) | |
| Here LA is a linear array with N elements and K is positive interger such that K<=N.This algorithm deletes the Kth element from LA. | |
| 1. Set ITEM:=LA[K]. | |
| 2. Repeat for J=K to N-1: | |
| [Move J+1st element upward.] Set LA[J]:= LA[J=1]. | |
| [End of loop.] | |
| 3. [Reset the number N of elements in LA.] Set N:=N-1; | |
| 4. Exit. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Algorithm::: | |
| Here LA is a Linear Array with N elements and K is a positive integer such that K<+N. This algorithm inserts an element ITEM into the Kth | |
| position in LA. | |
| 1. [Initialize counter.] Set J:=N. | |
| 2. Repeat Steps 3 and 4 while J>=K. | |
| 3. [Move Jth element downward.] Set LA[J+1]:= LA[j]. | |
| 4. [Decrease counter.]Set J:= J-1. | |
| [End of Step 2 loop.] | |
| 5. [Insert element.] Set LA[K]:=ITEM. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Algorithm:: | |
| 1. [Initialize counter.] Set K:= LB. | |
| 2. Repeat Steps 3 and 4 while K<=UB. | |
| 3. [Visit element.] Apply PROCESS to LA[K]. | |
| 4. [Increase counter.] Set K:=K+1. | |
| [End of step 2 loop.] | |
| 5. Exit. | |
| ****CODE****** | |
| package algorithmicnotation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Algorithm:: | |
| 1. [Initialize] Set K:=1 and MAX:=S-R+1. | |
| 2. Repeat Steps 3 to 5 while K<=MAX: | |
| 3. Repeat for L=1 to R: [Tests each character of P.] | |
| If P[L]!=T[K+L-1]. then: Go to Step 5. | |
| [End of inner loop.] | |
| 4. [Success.] Set INDEX =K, and Exit. | |
| 5. Set K:= K+1. | |
| [End of Step 2 outer loop.] | |
| 6. [Failure.] Set INDEX=0. |
NewerOlder