Searching Algorithms Finding what you are looking for.

Slides:



Advertisements
Similar presentations
Heuristic Search techniques
Advertisements

College of Information Technology & Design
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
CSC 423 ARTIFICIAL INTELLIGENCE
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
HST 952 Computing for Biomedical Scientists Lecture 9.
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
Ver. 1.0 Session 5 Data Structures and Algorithms Objectives In this session, you will learn to: Sort data by using quick sort Sort data by using merge.
Advanced Tree Data Structures Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
Advanced Tree Data Structures Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
B + -Trees (Part 1) Lecture 20 COMP171 Fall 2006.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 20: Sorting.
Alyce Brady CS 510: Computer Algorithms Depth-First Graph Traversal Algorithm.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
B + -Trees (Part 1) COMP171. Slide 2 Main and secondary memories  Secondary storage device is much, much slower than the main RAM  Pages and blocks.
CHAPTER 11 Searching. 2 Introduction Searching is the process of finding a target element among a group of items (the search pool), or determining that.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
1 Algorithms and Analysis CS 2308 Foundations of CS II.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
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.
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
Introduction to Data Structures. Data Structures A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
B+ Tree What is a B+ Tree Searching Insertion Deletion.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
1 State Space of a Problem Lecture 03 ITS033 – Programming & Algorithms Asst. Prof.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
WAES 3308 Numerical Methods for AI
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Lecture 5: Backtracking Depth-First Search N-Queens Problem Hamiltonian Circuits.
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
Multi-way Trees. M-way trees So far we have discussed binary trees only. In this lecture, we go over another type of tree called m- way trees or trees.
Searching Given a collection and an element (key) to find… Output –Print a message (“Found”, “Not Found) –Return a value (position of key ) Don’t modify.
CS 162 Intro to Programming II Searching 1. Data is stored in various structures – Typically it is organized on the type of data – Optimized for retrieval.
SEARCHING. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
TRAVERSING AN ARRAY My friend, the FOR loop Analyze an array in other ways than max,min,sort… 11.
CSC 211 Data Structures Lecture 13
Starting at Binary Trees
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
Lecture on Binary Search and Sorting. Another Algorithm Example SEARCHING: a common problem in computer science involves storing and maintaining large.
CS 61B Data Structures and Programming Methodology Aug 7, 2008 David Sun.
ALGORITHMS.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
Breadth First Search and Depth First Search. Greatest problem in Computer Science Has lead to a lot of new ideas and data structures Search engines before.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
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.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
1 Data Structures CSCI 132, Spring 2014 Lecture23 Analyzing Search Algorithms.
Unit 2 Day 11 FOCS – Human Computer Interaction. Tower Building Presentation Explain your solution.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
The Linear and Binary Search and more Lecture Notes 9.
INTRODUCTION TO DATA STRUCTURES 1. DATA STRUCTURES A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
Searching Given a collection and an element (key) to find… Output
Data Structures and Database Applications Binary Trees in C#
Searching.
Algorithms September 28, 2017.
Searching and Sorting Arrays
Standard Version of Starting Out with C++, 4th Edition
Searching CLRS, Sections 9.1 – 9.3.
BEST FIRST SEARCH -OR Graph -A* Search -Agenda Search CSE 402
Backtracking and Branch-and-Bound
Unit 2: Computational Thinking, Algorithms & Programming
Presentation transcript:

Searching Algorithms Finding what you are looking for.

What’s an Algorithm? A step by step procedure to solve calculations and process data A set of rules that precisely defines a sequence of operations Like a Flowchart!

Searching algorithms are algorithms for finding an item in a collection of items used for calculations, procedures, etc. Some searches involve looking for something in a database (real space), like looking up something in the Artemis records. Some search algorithms look through a virtual space, like looking for the best chess move among all the possible moves that can be made. Searching Algorithms?

Types of Searching Algorithms 1. Linear Search 2. Tree Search 3. Binary Search

Linear Search Usually for a small list of items First, look at the first item to see if that is what you were looking for If yes, then you’re done. If not, Then move to the second item Repeat until you have either found the item being searched or reached the end of the list For each item in the list: if that item has the desired value, stop the search and return the item's location. Return Λ.

Search Item: Anie Index (box): 1 BukkyJessiAnieLauren 1234 Does box 1 = Anie? Linear Search

Search Item: Anie Index: 2 BukkyJessiAnieLauren 1234 Does box 2 = Anie? Linear Search

Search Item: Anie Index: 3 BukkyJessiAnieLauren 1234 Does box 3 = Anie? YES! Linear Search

Process of visiting each node (branch) of a tree structure, exactly once, in a systematic way When visiting the nodes (branches), the computer either examines and/or update the items in the nodes Two Types of Tree searching: BF (breadth first search) and DF (depth first search) Tree Search or “Tree Traversal”

Tree Search Depth First Search A B C G E F DH With Linear search you started with box 1 then box 2 and so on, with DF search you start with the chosen circle (A) and then go through the branches Start with A Move to the next branch in alphabetical order (B, D, G), so B Then choose between the branches on B (A, E, F), so E because A has already been chosen Repeat until all branches have been chosen Result: A

Tree Search A B C G E F DH Result: A B Depth First Search Check the B branches Which would be the next item?

Tree Search A B C G E F DH Result: A B E Depth First Search Check the E branches Which would be the next item?

Tree Search A B C G E F DH Result: A B E G Depth First Search Check the G branches Which would be the next item? Think of a maze: Now that we have reached a dead end, we have to retrace our steps

Tree Search A B C G E F DH Result: A B E G Depth First Search Since both E and A have been already been chosen go back to the E branches, B branches...? Which would be the next item?

Tree Search A B C G E F DH Result: A B E G F Depth First Search Check the F branches Which would be the next item?

Tree Search A B C G E F DH Result: A B E G F C Depth First Search

Tree Search A B C G E F DH Result: A B E G F C H Depth First Search

Tree Search Result: A B E G F C H D A B C G E F DH Depth First Search

So the result for this one would be... Result:

Tree Search Start with A Move to the next branch in alphabetical order (B, D, G), so B Then the next letter between the branches, so D then, G After all the A branches have been completes, move to the B branches, then the D branches.... Tree Search BREADTH First Search A B C G E F DH Result: A

Tree Search Breadth First Search A B C G E F DH Result: A B Tree Search A B C G E F DH

Breadth First Search A B C G E F DH Result: A B D Tree Search A B C G E F DH

Breadth First Search A B C G E F DH Tree Search A B C G E F DH Result: A B D G

Tree Search Breadth First Search A B C G E F DH Tree Search A B C G E F DH Result: A B D G E

Tree Search Breadth First Search A B C G E F DH Tree Search A B C G E F DH Result: A B D G E F

Tree Search Breadth First Search A B C G E F DH Tree Search A B C G E F DH Result: A B D G E F C

Tree Search Breadth First Search A B C G E F DH Tree Search A B C G E F DH Result: A B D G E F C H

So the result for this one would be... Result:

Tree Search A B E G F C H D A B C G E F DH Depth First Search Breadth First Search A B C G E F DH A B C G E F DH A B D G E F C H Different paths

Popular search and good for large databases Binary search helps find a specific item in an array (group of items) Binary Search or “Half-interval search”

Binary Search The Phonebook Lets say we are looking for a number in a phonebook with 1000 pages We can use the Linear search and look through the book from page 1 to page 1000 (but that will take forever) OR we can use binary search. Open the middle of the book. If the number is on the left side, forget about the other 500 pages Then split the first section of the phone book, and keep splitting in half until you find the number! Santa’s Sock

Binary Search Another Example: Can you find the number 38? 32

3250 Binary Search Another Example: Can you find the number 38?

Binary Search Another Example: Can you find the number 38? For the phonebook search, we could have had to do at worst 1000 tries for the 1000 pages, but with Binary search, we could have found the number in no more than 10 tries using a formula. (log_2[n]= ans) where 2^ans = n

Now we can find what we are looking for