zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion BankGlossaryGlossary

What are the general steps of Binary Search?

  1. Find the middle element. 2. If the target equals the middle, return the index. 3. If the target is less than the middle, search the left half. 4. If the target is greater than the middle, search the right half. 5. Repeat until found or the search space is empty.
Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What are the general steps of Binary Search?

  1. Find the middle element. 2. If the target equals the middle, return the index. 3. If the target is less than the middle, search the left half. 4. If the target is greater than the middle, search the right half. 5. Repeat until found or the search space is empty.

What are the steps involved in Merge Sort?

  1. Divide the list into sublists. 2. Recursively sort each sublist. 3. Merge the sorted sublists.

What are the steps in recursive Insertion Sort?

  1. Base case: If the index reaches the end of the list, the list is sorted. 2. Take the element at the current index. 3. Shift the element to the left until it's in the correct sorted position. 4. Recursively call the function for the next index.

What are the steps in recursive Selection Sort?

  1. Base case: If the index reaches the end of the list, the list is sorted. 2. Find the smallest element in the unsorted portion of the list. 3. Swap the smallest element with the element at the current index. 4. Recursively call the function for the next index.

What are the steps in recursive Linear Search?

  1. Base case 1: If the element at the current index matches the target, return the index. 2. Base case 2: If the current index is the last element and no match is found, return -1. 3. Recursive step: Call the function again with the next index.

What are the steps in iterative Insertion Sort?

  1. Assume the first element is sorted. 2. Select the next element. 3. Compare to the sorted elements and shift until correct position is found. 4. Insert the element.

What are the steps in iterative Selection Sort?

  1. Find the minimum element in the unsorted portion. 2. Swap it with the first unsorted element. 3. Repeat for the remaining unsorted portion.

What are the steps in iterative Linear Search?

  1. Iterate through each element in the array. 2. Compare the current element with the target. 3. If a match is found, return the index. 4. If no match is found after checking all elements, return -1.

What are the steps in iterative Binary Search?

  1. Initialize left and right pointers. 2. While left <= right, calculate the middle index. 3. If the middle element equals the target, return the index. 4. If the target is less than the middle element, move the right pointer. 5. If the target is greater than the middle element, move the left pointer. 6. If the target is not found, return -1.

How to call the recursiveBinarySearch method?

Call recursiveBinarySearch(array, n, 0, array.size() - 1); where array is the sorted ArrayList, n is the value to search, 0 is the starting index, and array.size() - 1 is the ending index.

What is Binary Search?

A search algorithm that finds the position of a target value within a sorted array by repeatedly dividing the search interval in half.

What is Merge Sort?

A divide-and-conquer sorting algorithm that divides the input array into smaller sub-arrays, recursively sorts them, and then merges the sorted sub-arrays.

What is Recursion?

A programming technique where a function calls itself in order to solve a problem.

What is a Base Case?

The condition that stops a recursive function from calling itself infinitely.

What is Linear Search?

A searching algorithm that sequentially checks each element of a list until a match is found or the entire list has been searched.

What is Insertion Sort?

A sorting algorithm that builds the final sorted array one item at a time by repeatedly inserting the next element into its correct position within the already sorted portion of the array.

What is Selection Sort?

A sorting algorithm that repeatedly finds the minimum element from the unsorted portion of the array and places it at the beginning.

What is an ArrayList?

A resizable array implementation of the List interface in Java.

What is an Index?

The position of an element within an array or ArrayList, starting from 0.

What is a Sublist?

A contiguous portion of a list or array.

How is Binary Search applied in real-world scenarios?

Searching for a word in a dictionary, finding a contact in a sorted phone book, searching for a value in a sorted database index.

How is Merge Sort applied in real-world scenarios?

External sorting of large datasets that don't fit in memory, sorting large files, used in various sorting algorithms in databases.

How is Linear Search applied in real-world scenarios?

Searching for an item in a small, unsorted list, finding a specific file in a directory.

How is Insertion Sort applied in real-world scenarios?

Sorting a hand of playing cards, sorting small datasets, used as a subroutine in more complex sorting algorithms.

How is Selection Sort applied in real-world scenarios?

Although not very efficient, it can be used in scenarios where memory usage is a primary concern due to its in-place sorting nature.

What are real-world applications of recursion?

File system traversal, parsing complex data structures (like XML or JSON), implementing tree-based algorithms, and solving problems that can be broken down into smaller, self-similar subproblems.

How are sorting algorithms used in databases?

Sorting is essential for indexing data, optimizing query performance, and presenting data in a structured manner.

How are searching algorithms used in databases?

Searching algorithms are used to efficiently locate specific records within a database, enabling quick retrieval of information.

How are sorting algorithms used in search engines?

Search engines use sorting algorithms to rank search results based on relevance, ensuring that the most relevant results appear at the top of the page.

How are searching algorithms used in search engines?

Search engines use searching algorithms to quickly locate web pages that match a user's search query.