Grade 12 Exam  >  Grade 12 Notes  >  Information and Communication Technology for Grade 12  >  Chapter Notes: Binary Search

Binary Search Chapter Notes | Information and Communication Technology for Grade 12 PDF Download

Introduction

Binary search is an important concept in AP Computer Science Principles, offering an efficient way to find items in a sorted list. This chapter explains how binary search works by comparing it to the simpler linear search method. It describes the process of binary search, which divides a sorted list in half repeatedly to narrow down the search area. The chapter also highlights the importance of sorted data for binary search and its advantages in modern programming. Understanding binary search helps programmers create faster and more efficient search algorithms.

Traversing a List

  • Traversing a list means going through its items to find a specific value.
  • Linear search (sequential search) checks each item in order, one by one, until the target is found or the list ends.
  • Binary search is another method to search a list, but it requires the list to be sorted.

Binary Search Algorithm

  • Binary search starts at the middle of a sorted list and compares the middle value to the target.
  • If the target is greater than the middle value, the algorithm ignores the lower half of the list.
  • If the target is less than the middle value, the algorithm ignores the upper half of the list.
  • The process repeats, dividing the remaining list in half each time, until the target is found or all values are checked.
  • Example:
    • List: 1, 1, 2, 3, 3, 4, 5, 7, 9, 11, 12
    • Searching for 12:
      • Step 1: Check middle value (4). Since 12 > 4, ignore 1, 1, 2, 3, 3, 4.
      • Step 2: New list: 5, 7, 9, 11, 12. Check middle value (9). Since 12 > 9, ignore 5, 7, 9.
      • Step 3: Continue until 12 is found.
  • Binary search is faster than linear search because it eliminates half the list each step.
  • It is commonly used in modern programs due to its efficiency.
  • The list must be sorted (ascending or descending) before using binary search.

Question for Chapter Notes: Binary Search
Try yourself:
What does a binary search begin by examining?
View Solution

Key Terms

  • Binary Search Algorithm: An efficient method that repeatedly halves a sorted list, discarding half of the remaining elements each time, until the target is found or determined to be absent.
  • Linear Search Algorithm: A basic method that checks each element in a list one by one until the target is found or the list is fully traversed.
  • Sequential Search: Another term for linear search, where elements are examined in order until the target is located or the end is reached.
  • Sorted Data Set: A collection of data organized in a specific order, such as ascending or descending, based on numerical or alphabetical criteria.
The document Binary Search Chapter Notes | Information and Communication Technology for Grade 12 is a part of the Grade 12 Course Information and Communication Technology for Grade 12.
All you need of Grade 12 at this link: Grade 12
18 docs|9 tests

FAQs on Binary Search Chapter Notes - Information and Communication Technology for Grade 12

1. What is binary search and how does it work?
Ans.Binary search is an efficient algorithm used to find a specific value in a sorted list. It works by repeatedly dividing the list in half. The algorithm starts by checking the middle element of the list. If this element is equal to the target value, the search is complete. If the target value is less than the middle element, it continues searching in the left half; if greater, it searches in the right half. This process is repeated until the target value is found or the sub-list is empty.
2. Why is binary search more efficient than linear search?
Ans.Binary search is more efficient than linear search because it reduces the search space by half with each comparison. In linear search, each element is checked one by one, which can take a lot of time for large lists. Binary search, on the other hand, has a time complexity of O(log n), making it much faster for large sorted lists, whereas linear search has a time complexity of O(n).
3. What are the key requirements for using binary search?
Ans.The key requirements for using binary search are that the list must be sorted, and it should be accessible by index. If the list is not sorted, binary search cannot be applied effectively since the logic relies on the order of the elements. Also, the list should be capable of random access, which means that the algorithm can quickly access the middle element.
4. Can binary search be applied to data structures other than arrays?
Ans.Yes, binary search can be applied to other data structures, such as binary search trees (BST). In a binary search tree, each node has a value greater than all values in its left subtree and less than those in its right subtree. This property allows for an efficient search, similar to binary search in arrays, but with a different structure.
5. What are some real-world applications of binary search?
Ans.Binary search is used in various real-world applications, including searching for elements in large databases, finding specific entries in a sorted list of names or numbers, and implementing search functions in software applications. It is also utilized in algorithms for searching in libraries, programming languages, and even in search engines to quickly retrieve relevant information.
Related Searches

study material

,

ppt

,

pdf

,

video lectures

,

mock tests for examination

,

Extra Questions

,

Binary Search Chapter Notes | Information and Communication Technology for Grade 12

,

shortcuts and tricks

,

Summary

,

practice quizzes

,

Objective type Questions

,

Important questions

,

Binary Search Chapter Notes | Information and Communication Technology for Grade 12

,

Viva Questions

,

past year papers

,

Previous Year Questions with Solutions

,

Exam

,

MCQs

,

Binary Search Chapter Notes | Information and Communication Technology for Grade 12

,

Free

,

Semester Notes

,

Sample Paper

;