Upcoming SlideShare
×

# MELJUN CORTES - List (Mathematics of Computing)

90
-1

Published on

MELJUN CORTES - List (Mathematics of Computing)

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
90
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
0
0
Likes
0
Embeds 0
No embeds

No notes for slide

### MELJUN CORTES - List (Mathematics of Computing)

1. 1. Year 1 LESSON 7 LISTS♦ A record consists of different data items stored in an array♦ Below is a list consisting of four data items that are not linkedInv. No Cust. No. Date Inv. NoRec. 1 Rec. 1 Rec. 1 Rec. 1 Four lists which must stay ‘linked’♦ An example is given below CS113/0401/v1 Lesson 7 - 1
2. 2. Year 1 EXERCISETry the following quiz by matching thedevice to the explanation.This will provide a better understandingof linked records1.Modem A. A device used to receive from one circuit and automatically repeat and amplify and reshape the signals to another t circuit2.Font - End B. A system which removes some Processor of the processing load from a central computer, typically handling communication coordination functions before the data is sent to the central system for processing3.Repeater C. Devices needed at the ends of an analogue transmission line to translate between the digital code of computers and the analogue wave form; an abbreviation for modulation - demodulation CS113/0401/v1 Lesson 7 - 2
3. 3. Year 1 LINKED LISTS ♦ A linked list, or one-way list, is a linear collection of data elements, called nodes, where the linear order is given by means of pointers, That is, each node is divided into two parts: the first part contains the information of the element, and the second part, called the li9nk field or nextpointer field, contains the address of the next node in the list. ♦ Example : Linked list with 3 nodesName orStart Nextpointer field Information part CS113/0401/v1 Lesson 7 - 3
4. 4. Year 1 LINKED LIST♦ A more useful application of a list is a linked list The Invoice Number, Customer Number, Date and Amount are linked by a two way pointerInv. No Cust. No. Date Inv. NoRec. 1 Rec. 1 Rec. 1 Rec. 1 Two way pointer The lists after ordering CS113/0401/v1 Lesson 7 - 4
5. 5. Year 1 EXERCISE Example (Part c; Question 4/91) A LINKED TABLE holding KEY numerical values in ASCENDING order of which the POINTER ‘LISTSTART’ holds the value 2, containsLISTSTART 2 Index Key Link to Next Record 1 96 3 2 84 1 3 106 -1 i. Re-write the table as it would appear if we added, at INDEX 4 THE KEY 95 and KEY 110 at INDEX 5. [4] ii. Show the original table as it would appear if KEY 96 were DELETED. [2] CS113/0401/v1 Lesson 7 - 5
6. 6. Year 1 EXERCISE♦ Solution for part c(i);2 Index Key Link to Next Record 1 96 3 2 84 5 3 106 5 4 95 1 5 110 -1♦ Solution for part c(ii) (to be solve in class) CS113/0401/v1 Lesson 7 - 6
7. 7. Year 1 SYSTEM LISTS♦ Program location in main memory and its control during execution by linked list for example calling of subroutines by main programs♦ By managing pointers locations, the economy of storage and speed of execution are achieved PROCESS PROGRAM S/ROUTINE Spool Line 1 Line 1 : : : S/R call Line ‘n’ : Line ‘n; Program Lists with pointers CS113/0401/v1 Lesson 7 - 7
8. 8. Year 1 QUEUES♦ It is a FIFO (First-In-First-Out) structures which means that the first item to enter the queue is the first to leave and new items always get added to the end of the queue.♦ As with the stack we can represent a queue by a one- dimensional array with the need for two pointers. The first to indicate the front of the queue and the other indicate the next apace capable of holding an element joining the queue, these being the head and tail pointers respectively. CS113/0401/v1 Lesson 7 - 8
9. 9. Year 1 QUEUE♦ A method of inserting and retrieving data similar to a stack but on‘FIRST-IN- FIRST-OUT’ 1 Head 1 Pointer 2 3 1. ‘POP’ 4 2 2. ‘LIST’ 5 6 3. ‘PUSH’ 7 3 8 Tail Pointer♦ The queue operation is awkward because the elements are pushed to the front and new elements are added from the bottom, sometimes referred to as a PUSHUP STAQCK or LIST♦ Other types of queues can be the DEQUE (or DOUBLE-ended-Queue) and the WRAP-AROUND-STACK CS113/0401/v1 Lesson 7 - 9
10. 10. Year 1 DEQUE♦ Data are push and pop (add and delete) from both ends WRAP-AROUND-STACK♦ In this type the tail pointer cannot be push out but moves in a circular manner ahead of the head pointer CS113/0401/v1 Lesson 7 - 10
11. 11. Year 1 STACKS♦ The main characteristics of a stack is that it is a LIFO (Last-In-First-Out) structure. It can be liken to a pile of plates in which it is easy (if someone a little unstable ) to add extra plates to the top. Plates can also be easily removed from the top of the pile, but not by extrication from the bottom of the pile.♦ We can represent a stock as a one- dimensional array with two pointers, one pointer to the base of the stack ( to identify the first elements ) and the other pointing position of the first available element, this being called the stack pointer. CS113/0401/v1 Lesson 7 - 11
12. 12. Year 1 STACKS ♦ Stack works on ‘LAST-IN-FIRST- OUT’ The elements are added from the top termed as ‘PUSH’ and removed from the top termed ’POP’. The HEAD and TAIL pointers are used to control.Head pointer 8 7 7 6 6 5 Push 5 4 4 Pop 3 3 2 Head pointer 2Base pointer 1 8 Base pointer 1 3 Push and Pop operation CS113/0401/v1 Lesson 7 - 12
13. 13. Year 1 STACKSAn example of stack operation10 DIM S(50)80 REM **PUSHINGSEQUENCE**90 IF P <= 50 THEN 120100 PRINT “STACK FULL”110 STOP120 LET S(P) = E130 LET P = P + 1140 GOTO 90150 :Question:Can you write a Pseudo-code forthe ‘POP’ Operation? CS113/0401/v1 Lesson 7 - 13
14. 14. Year 1 ExerciseNCC JUNE 92 Q6.A. A circular QUEUE of characters is stored in RAM locations 500 t6o 509 inclusive. At the start the queue is empty and both Front and Back pointers set to 500. The BACK pointer is incremented as items are added. i. Show the queue and pointers after performing each of the following steps: ADD the characters A, B, C, D in order: Remove THREE characters: ADD the characters E, F, G, H, I: Remove ALL characters CS113/0401/v1 Lesson 7 - 14
15. 15. Year 1 EXERCISENCC JUNE 92 Q6.ii. How many characters can be stored in the queue? [1]iii. Describe briefly how we know the queue is full [3]iv. Why is the stack CIRCULAR? [1]v. State two uses of queues [2] CS113/0401/v1 Lesson 7 - 15