Searching Tables.. Creating Pre-filled Tables A B C D E F G H I J K L ABCDEFGHIJKLM NOPQRSTUVWXYZ 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13)

Slides:



Advertisements
Similar presentations
The Important Thing About By. The Important Thing About ******** The important thing about ***** is *****. It is true s/he can *****, *****, and *****.
Advertisements

Topic 14 Searching and Simple Sorts "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The.
Lesson 8 Searching and Sorting Arrays 1CS 1 Lesson 8 -- John Cole.
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Chapter 12 Array Processing and Table Handling. Defining Series of Input Fields Coding record with 24 independent hourly fields is cumbersome 01Temp-Rec.
Let's learn the alphabet ! ABCDEFGHIJKLM NOPQRSTUVWXYZ.
Advanced Tables.. 01 JeansTable. One Dimension Table.
THE STENOTYPE MACHINE AND KEYBOARD.
Copyright © 2012 Pearson Education, Inc. Chapter 8: Searching and Sorting Arrays.
1 MEASURES OF CENTRAL TENDENCY AND DISPERSION AROUND THE MEDIAN.
Search and Recursion CS221 – 2/23/09. List Search Algorithms Linear Search: Simple search through unsorted data. Time complexity = O(n) Binary Search:
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
 2003 Prentice Hall, Inc. All rights reserved Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
Searching Arrays Linear search Binary search small arrays
Searching Arrays. COMP104 Array Sorting & Searching / Slide 2 Unordered Linear Search * Search an unordered array of integers for a value and save its.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 9 Searching.
Dictionary A template for an electronic dictionary.
Chapter 8 ARRAYS Continued
12-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 8: Searching and Sorting Arrays.
Chapter 16: Searching, Sorting, and the vector Type.
Copyright © 2012 Pearson Education, Inc. Chapter 8: Searching and Sorting Arrays.
1 Searching. 2 Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods (1)
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 8: Searching and Sorting Arrays.
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
C# PROGRAMMING Searching & Sorting. Objective/Essential Standard Essential Standard 3.00 Apply Advanced Properties of Arrays Indicator 3.03 Apply procedures.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
SEARCHING.  This is a technique for searching a particular element in sequential manner until the desired element is found.  If an element is found.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
Chapter 12 (part 2) Table Handling and Search Techniques.
1 Chapter – 12 Table Lookups Table Codes –Expanded Values –Types of Codes Numeric Alphabetic Alphanumeric.
Lecture 81 Table Search (1) 02ART HISTORY 04BIOLOGY 19CHEMISTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 54STATISTICS.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
1 5. Abstract Data Structures & Algorithms 5.2 Static Data Structures.
Hashing Hashing is another method for sorting and searching data.
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
Question 1a) What is printed by the following Java program? int s; int r; int i; int [] x = {4, 8, 2, -9, 6}; s = 1; r = 0; i = x.length - 1; while (i.
Chapter 9 slide 1 Introduction to Search Algorithms Search: locate an item in a list (array, vector, table, etc.) of information Two algorithms (methods):
1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view.
1 Review for test 2 Chapters 7, 8, 9, 11, What is wrong with the following paragraphs? PARA-A. PARA-B. ADD A TO B MOVE 0 TO X PERFROM PARA-A PERFORM.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE.
Multi-Dimensional Arrays. Agenda Multiple-Level Arrays.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
12-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Unit 2 Day 11 FOCS – Human Computer Interaction. Tower Building Presentation Explain your solution.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 8A Binary Search (Concepts)
Chapter 16: Searching, Sorting, and the vector Type.
1 compares each element of the array with the search key. works well for small arrays or for unsorted arrays works for any table slow can put more commonly.
Searching Arrays Linear search Binary search small arrays
Searching and Sorting Arrays
Chapter 16: Searching, Sorting, and the vector Type
Tables and PERFORM..VARYING
2-Way Tables, Statistics, & Probability
F - Ratio Table Degrees of Freedom for the Factor
Chapter 18-3 Recursion Dale/Weems.
Searching and Sorting Arrays
Standard Version of Starting Out with C++, 4th Edition
Chapter 4.
Searching and Sorting Arrays
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Presentation transcript:

Searching Tables.

Creating Pre-filled Tables A B C D E F G H I J K L ABCDEFGHIJKLM NOPQRSTUVWXYZ 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ".

Creating Pre-filled Tables A B C D E F G H I J K L ABCDEFGHIJKLM NOPQRSTUVWXYZ 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ". 02 FILLER REDEFINES TableValues. 03 Letter PIC X OCCURS 26 TIMES. ABCDEFGHIJKLM NOPQRSTUVWXYZ 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ". 02 FILLER REDEFINES TableValues. 03 Letter PIC X OCCURS 26 TIMES.

Searching a Table 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ". 02 FILLER REDEFINES TableValues. 03 Letter PIC X OCCURS 26 TIMES. PERFORM VARYING Idx FROM 1 BY 1 UNTIL LetterIn EQUAL TO Letter(Idx) END-PERFORM. DISPLAY LetterIn, "is in position ", Idx. A B C D E F G H I J K L

Search Syntax

SET Syntax

Searching a Table 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ". 02 FILLER REDEFINES TableValues. 03 Letter PIC X OCCURS 26 TIMES INDEXED BY LetterIdx. SET LetterIdx TO 1. SEARCH Letter AT END DISPLAY "Letter not found!" WHEN Letter(LetterIdx) = LetterIn DISPLAY LetterIn, "is in position ", Idx END-SEARCH. 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ". 02 FILLER REDEFINES TableValues. 03 Letter PIC X OCCURS 26 TIMES INDEXED BY LetterIdx. SET LetterIdx TO 1. SEARCH Letter AT END DISPLAY "Letter not found!" WHEN Letter(LetterIdx) = LetterIn DISPLAY LetterIn, "is in position ", Idx END-SEARCH. A B C D E F G H I J K L

Searching a Two Dimension Table TimeTable. 02 Day OCCURS 5 TIMES INDEXED BY DayIdx. 03 Hours OCCURS 8 TIMES INDEXED BY HourIdx. 04 Item PIC X(10). 04 Location PIC X(10). SET DayIdx TO 0. PERFORM UNTIL MeetingFound OR DayIdx > 5 SET DayIdx UP BY 1 SET HourIdx TO 1 SEARCH Hours WHEN MeetingType = Item(DayIdx, HourIdx) SET MeetingFound TO TRUE DISPLAY MeetingType " on " DayIdx " at " HourIdx END-SEARCH END-PERFORM.

Search All Syntax.

Using the Search All 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ". 02 FILLER REDEFINES TableValues. 03 Letter PIC X OCCURS 26 TIMES ASCENDING KEY IS Letter INDEXED BY LetterIdx. SEARCH ALL Letter WHEN Letter(LetterIdx) = LetterIn DISPLAY LetterIn, "is in position ", Idx END-SEARCH. 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13) VALUE "ABCDEFGHIJKLM". 03 FILLER PIC X(13) VALUE "NOPQRSTUVWXYZ". 02 FILLER REDEFINES TableValues. 03 Letter PIC X OCCURS 26 TIMES ASCENDING KEY IS Letter INDEXED BY LetterIdx. SEARCH ALL Letter WHEN Letter(LetterIdx) = LetterIn DISPLAY LetterIn, "is in position ", Idx END-SEARCH. A B C D E F G H I J K L

How the Search All works. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 1 Lower 26 Upper 13M Middle = Letter(Middle)

How the Search All works. N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 14 Lower 26 Upper 13M Middle = Letter(Middle)

How the Search All works. N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 14 Lower 26 Upper 20T Middle = Letter(Middle)

How the Search All works. N O P Q R S A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 14 Lower 19 Upper 20T Middle = Letter(Middle)

How the Search All works. N O P Q R S A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 14 Lower 19 Upper 16P Middle = Letter(Middle)

How the Search All works. Q R S A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 17 Lower 19 Upper 16P Middle = Letter(Middle)

How the Search All works. Q R S A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 17 Lower 19 Upper 18R Middle = Letter(Middle)

How the Search All works. Q R S A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 17 Lower 17 Upper 18R Middle = Letter(Middle)

How the Search All works. Q A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 17 Lower 17 Upper 18Q Middle = Letter(Middle)

How the Search All works. Q A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ALGORITHM. Middle = (Lower + Upper) / 2 CASE TRUE WHEN Letter(Middle) < "Q" THEN Lower = Middle + 1 WHEN Letter(Middle) > "Q" THEN Upper = Middle -1 WHEN Letter(Middle) = "Q" THEN SET ItemFound TO TRUE WHEN Lower > Upper THEN ItemNotInTable TO TRUE 17 Lower 17 Upper 18Q Middle = Letter(Middle)

Search All Example. Post Codes and Names 01 StateTable. 02 StateValues. 03 FILLER PIC X(20) VALUE ?????????????? Post Codes and Names 03 FILLER PIC X(20) VALUE ?????????????? 02 FILLER REDEFINES StateValues. 03 States OCCURS 50 TIMES ASCENDING KEY IS StateName INDEXED BY StateIdx. 04 PostCode PIC X(6). 04 StateName PIC X(14). SEARCH ALL States AT END DISPLAY "State not found" WHEN StateName(StateIdx) = InputName MOVE PostCode(StateIdx) TO PrintPostCode END-SEARCH. Post Codes and Names 01 StateTable. 02 StateValues. 03 FILLER PIC X(20) VALUE ?????????????? Post Codes and Names 03 FILLER PIC X(20) VALUE ?????????????? 02 FILLER REDEFINES StateValues. 03 States OCCURS 50 TIMES ASCENDING KEY IS StateName INDEXED BY StateIdx. 04 PostCode PIC X(6). 04 StateName PIC X(14). SEARCH ALL States AT END DISPLAY "State not found" WHEN StateName(StateIdx) = InputName MOVE PostCode(StateIdx) TO PrintPostCode END-SEARCH.