Download presentation
Presentation is loading. Please wait.
Published byApril Andrews Modified over 9 years ago
1
lecture 81 Table Search (1) 02ART HISTORY 04BIOLOGY 19CHEMISTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 54STATISTICS 05 COURSES OCCURS 10 TIMES INDEXED BY ARR-SUB. 10 CALL-NUM PIC 99 10 SUBJECT PIC X(15)
2
lecture 82 Table Search (2) What subject has value 39? Find a record in the table that matches a query –The search key is the entry value we search on What algorithm will find this record?
3
lecture 83 Seqential Search 02ART HISTORY 04BIOLOGY 19CHEMISTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 53STATISTICS 39 1st try 2nd try 3rd try 4th try 5th try 6th try 7th try FINANCE Match
4
lecture 84 Search Key : CALL-NUM MOVE “N” ITEM-FOUND. PERFORM VARYING ARR-SUB FROM 1 BY 1 UNTIL ITEM-FOUND = “Y” OR ARR-SUB = 10 IF CALL-NUM (ARR-SUB) = 39 MOVE “Y” TO ITEM-FOUND END-PERFORM
5
lecture 85 SEARCH Statement (1) SET ARR-SUB TO 1. SEARCH COURSES AT END MOVE “N” TO ITEM-FOUND WHEN CALL-NUM (ARR-SUB) = 39 MOVE “Y” TO ITEM-FOUND.
6
lecture 86 SEARCH Statement (2) SEARCH ident-1 VARYING {ident-2 | index-name} { AT END statement-1} { WHEN cond-1 statement-2} END-SEARCH. Sequential search starts at the entry denoted by the current index value AT END is executed when the end of the table is reached One or more WHEN clauses allowed –When any of one them are satisfied the search ends VARYING clause names the index –May associate more than one index with the table –Uses the first index named in the INDEX BY clause if omitted
7
lecture 87 Binary Search 02ART HISTORY 04BIOLOGY 19CHEMISTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 53STATISTICS 39 1st try FINANCE Match 2nd try 3rd try
8
lecture 88 SEARCH Statement (3) 05 COURSES OCCURS 10 TIMES ASCENDING KEY IS CALL-NUM INDEXED BY ARR-SUB. 10 CALL-NUM PIC 99 10 SUBJECT PIC X(15) SEARCH ALL COURSES AT END MOVE “N” TO ITEM-FOUND WHEN CALL-NUM (ARR-SUB) = 39 MOVE “Y” TO ITEM-FOUND.
9
lecture 89 SEARCH Statement (4) L# table-name OCCURS integer TIMES {ASCENDING/DESCENDING} KEY IS ident-1 INDEXED BY {index-1 …} SEARCH ALL table-name { AT END statement-1} { WHEN statement-2} END-SEARCH.
10
lecture 810 SEARCH Statement (5) For Binary Search use SEARCH ALL The entries in the table should be sorted in ascending/descending order on the key field AT END is executed if no entry satisfies the condition The search ends if the WHEN clause is satisfied
11
lecture 811 Binary Search : Worst Case NUMBER OF ELEMENTSMAXIMUM NUMBER OF COMPARISONS 8 - 15 16 - 31 32 - 63 64 - 127 128 - 255 256 - 511 512 - 1023 1024 - 2047 2048 - 4095 (less than 2 4 ) (less than 2 5 ) (less than 2 6 ) (less than 2 7 ) (less than 2 8 ) (less than 2 9 ) (less than 2 10 ) (less than 2 11 ) (less than 2 12 ) 4 5 6 7 8 9 10 11 12
12
lecture 812 Sort (1) NAME YEARMAJOR Smith1Liberal arts Jones4Engineering Adams3Business Howe2Liberal arts Frank1 Engineering Zev4Business Benjamin 4Business Grauer3Liberal arts Crawford 2Engineering Deutsch4Business Makoske 1Business Unsorted Data
13
lecture 813 Sort (2) Primary Key: Name (Ascending) NAME YEARMAJOR Adams3Business Benjamin 4Business Crawford 2Engineering Deutsch4Business Frank1 Engineering Grauer3Liberal arts Howe2Liberal arts Jones4Engineering Makoske 1Business Smith1Liberal arts Zev4Business Sorted Data, One Key
14
lecture 814 Sort (3) Sorted Data, Two Keys Primary key: Year (descending) Secondary key: Name (ascending) NAME YEARMAJOR Benjamin 4Business Deutsch4Business Jones4Engineering Zev4Business Adams3Business Grauer3Liberal arts Crawford 2Engineering Howe2Liberal arts Frank1 Engineering Makoske 1Business Smith1Liberal arts
15
lecture 815 Sort (4) Primary Key: major (Ascending) Secondary Key: year (Descending) Tertiary Key: name (Ascending) NAMEYEARMAJOR Benjamin 4Business Deutsch4Business Zev4Business Adams3Business Makoske 1Business Jones4Engineering Crawford 2Engineering Frank1 Engineering Grauer3Liberal arts Howe2Liberal arts Smith1Liberal arts Sorted Data, Three Keys
16
lecture 816 ASCII Table (space) “(quotation mark) $(currency symbol) ‘(apostrophe) ((left parenthesis) )(right parenthesis) *(asterisk) +(plus symbol),(comma) -(hyphen, minus symbol).(period, decimal point) /(slash) 0 through 9 ;(semicolon) (greater than) A through Z (upper case) a through z (lower case)
17
lecture 817 SORT : A Table SORT table-name { ON ASCENDING/DESCENDING KEY ident-1… } { WITH DUPLICATES IN ORDER}. ASCENDING/DESCENDING may be defined at the table declaration –Key fields at the SORT statement override DUPLICATES clause order by table order
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.