Presentation is loading. Please wait.

Presentation is loading. Please wait.

INSERTION INTO A LINEAR ARRAY Set J = N Repeat step 3 and 4 while J>= K Set LA[ J+1] = LA [ J ] Set J = J-1 Set LA [K] = ITEM Set N = N+1 Exit.

Similar presentations


Presentation on theme: "INSERTION INTO A LINEAR ARRAY Set J = N Repeat step 3 and 4 while J>= K Set LA[ J+1] = LA [ J ] Set J = J-1 Set LA [K] = ITEM Set N = N+1 Exit."— Presentation transcript:

1

2 INSERTION INTO A LINEAR ARRAY Set J = N Repeat step 3 and 4 while J>= K Set LA[ J+1] = LA [ J ] Set J = J-1 Set LA [K] = ITEM Set N = N+1 Exit

3 DELETING FROM A LINEAR ARRAY Set ITEM = LA[K] Repeat for J = K to N-1 Set LA[ J ] = LA [ J+1] Set N = N-1 Exit

4 LINEAR SEARCH Set DATA [N+1] = ITEM Set LOC = 1 Repeat while DATA[LOC] not equals to ITEM Set LOC = LOC+1 If LOC = N+1, then: Set LOC = 0 Exit

5 BINARY SEARCH Set BEG = LB, END = UB and MID = INT((BEG+END)/2) Repeat Steps 3 and 4 while BEG <= END and DATA[MID] not equals to ITEM If ITEM < DATA[MID], then: Set END = MID-1 Else: Set BEG = MID+1

6 Set MID = INT((BEG+END)/2) If DATA[MID] = ITEM, then: Set LOC = MID Else: Set LOC = NULL Exit

7 Traversing in linked list Set PTR=START Repeat while PTR !=NULL Apply PROCESS to INFO[PTR] Set PTR := LINK[PTR] Exit

8 Searching in linked list(unsorted) Set PTR=START Repeat step 3 and 4 while PTR != NULL If ITEM=INFO[PTR], and Exit set LOC=PTR Else: set PTR=LINK[PTR] Set LOC=NULL Exit

9 Searching in Sorted list Set PTR=START Repeat step 3 and 4 while PTR!= NULL If ITEM < INFO[PTR], then: set PTR=LINK[PTR] Else if ITEM=INFO[PTR], then: set LOC=PTR, and Exit Else: set LOC=NULL, and Exit Set LOC=NULL Exit

10 Insertion in linked list(beginning) If AVAIL=NULL, then: Write: OVERFLOW, and Exit Set NEW=AVAIL and AVAIL=LINK[AVAIL] Set INFO[NEW]=ITEM Set LINK[NEW]=START Set START=NEW Exit

11 Insertion at given node If AVAIL=NULL, then write: OVERFLOW, and Exit Set NEW=AVAIL and AVAIL=LINK[AVAIL] Set INFO[NEW]=ITEM If LOC=NULL, then set LINK[NEW]=START and START=NEW Else: set LINK[NEW]=LINK[LOC] and LINK[LOC]=NEW Exit

12 Searching in sorted linked list If START=NULL, then set LOC=NULL, and return If ITEM<INFO[START], then set LOC=NULL, and return Set SAVE=START and PTR=LINK[START] Repeat step 5 and 6 while PTR != NULL If ITEM<INFO[PTR], then set LOC=SAVE, and return Set SAVE=PTR, and PTR=LINK[PTR] Set LOC=SAVE Return

13 Deletion at given node If LOCP=NULL, then: set START=LINK[START] Else: set LINK[LOCP]=LINK[LOC] Set LINK[LOC]=AVAIL and AVAIL=LOC Exit

14 Insertion in Two way linklist 1.if AVAIL=NULL, then: Write: OVERFLOW, and Exit. 2. Set NEW:=AVAIL, AVAIL:= FORW[AVAIL], INFO[NEW]:=ITEM. 3. Set FORW[LOCA]: =NEW, FORW[NEW]: =LOCB, BACK[LOCB]: =NEW, BACK[NEW]: =LOCA. 4. Exit.

15 Deletion from a Two way linklist 1. Set FORW[BACK[LOC]] : =FORW[LOC] and BACK [FORW[LOC]] : =BACK[LOC]. 2. Set FORW[LOC]:= AVAIL and AVAIL : =LOC. 3.Exit.

16 Push in Stack If TOP=MAXSTK, then: print: OVERFLOW,and RETURN 2.Set TOP:=TOP+1 3.Set STACK[TOP]:=ITEM. 4.Return

17 POP in stack 1. If TOP=0, then: print: UNDERFLOW, and return. 2.Set ITEM:=STACK[TOP]. 3.Set TOP:=TOP-1 4.Return

18 POLISH(Q,P) Infix to Postfix Push “(“ onto Stack, and add “)” to the end of Q. Scan Q form left to right and repeat Steps 3 to 6 for each element of Q until the stack is empty: If an operand in encountered, add it to P. If a left parenthesis is encountered,push it into Stack.

19 If an operator is encountered, then : (a) Repeatedly pop from stack and add to P each operator (on the top of Stack) which has the same priority as or higher precedence than. (b) Add to stack. If a parentheses is encountered, then : (a) Repeatedly pop from stack and add to P each operator (on the top of Stack) until a left parenthesis. (b) Remove the left parenthesis.[Do not add the left parenthesis to P. ] Exit.

20 PUSH_LINKSTACK(INFO,LINK,TOP,A VAIL,ITEM) 1. if AVAIL=NULL then write OVERFLOW and exit 2. set NEW=AVAIL and AVAIL=LINK[AVAIL] 3. set INFO[NEW]=ITEM 4. set LINK[NEW]=TOP 5. Set TOP=NEW 6.EXIT

21 POP_LINKSTACK(INFO,LINK,TOP,AV AIL,ITEM) 1. if TOP=NULL then write UNDERFLOW and exit 2. set ITEM=INFO[TOP] 3. set TEMP=TOP and TOP=LINK[TOP] 4. set LINK[TEMP]=AVAIL and AVAIL= TEMP 5.EXIT

22 Evaluation of Postfix Expression This algorithm finds the value of an arithmetic expression P written in postfix notation. 1. Add a right parenthesis “)” at the end of P. {This act as sentinel} 2. Scan P form left to right and repeat Steps 3 and 4 for each element of P until the sentinel “)” is encountered. 3. If an operand is encountered,put it on Stack.

23 4. If an operator is encountered, then: (a) Remove the two top elements of Stack, where A is the top element and B is the next to top element. (b) Evaluate B A. (c) Place the result of (b) back on Stack. 5. Set VALUE equal to the top element on Stack. 6. Exit.

24 Insertion In Queue QINSERT(QUEUE,N,FRONT,REAR,ITEM) This procedure inserts an element ITEM into queue 1. If FRONT=1 and REAR =N, or if FRONT =REAR+1,then write OVERFLOW and return. 2. FRONT = NULL then set FRONT=1 and REAR=1. Else if REAR =N then set REAR=1. Else Set REAR=REAR +1 3. Set QUEUE[REAR]=ITEM 4. RETURN

25 QDELETE(QUEUE,N,FRONT,REAR,ITEM) 1. if FRONT=NULL then write UNDERFLOW and return 2. Set ITEM=QUEUE[FRONT] 3. If FRONT=REAR then Set FRONT=NULL and REAR=NULL Else if FRONT=N,then Set FRONT=1 Else Set FRONT=FRONT+1 4.Exit

26 LINKQ_INSERT(INFO,LINK,FRONT,REAR, AVAIL,ITEM) 1. If AVAIL=NULL then write OVERFLOW and exit 2. set NEW=AVAIL and AVAIL=LINK[AVAIL] 3. Set INFO[NEW]=ITEM and LINK[NEW]=NULL 4. if(FRONT=NULL) then FRONT=REAR=NEW else set LINK[REAR]=NEW and REAR=NEW exit

27 LINKQ_DELETE(INFO,LINK,FRONT,R EAR,AVAIL,ITEM) 1. If (FRONT=NULL) then write UNDERFLOW and exit 2. Set TEMP=FRONT 3. ITEM=INFO[TEMP] 4. FRONT=LINK[TEMP] 5. LINK[TEMP]=AVAIL and AVAIL=TEMP 6. exit


Download ppt "INSERTION INTO A LINEAR ARRAY Set J = N Repeat step 3 and 4 while J>= K Set LA[ J+1] = LA [ J ] Set J = J-1 Set LA [K] = ITEM Set N = N+1 Exit."

Similar presentations


Ads by Google