searching algorithms

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

linear search

  • can be used on an unsorted list

  • quick and easy to develop

  • the search takes anywhere between immediately finding the item, and checking every item in the list

  • if the item is not in the list you have to check every item

2
New cards

for loop linear search

knowt flashcard image
3
New cards

while loop linear search

knowt flashcard image
4
New cards

time complexity of linear search

for a for loop, the time is always n checks, in Big O notation this would be described as O(n). in a while loop it is at least O(1) and at most O(n). to find the average time is the sum up to n all divided by n, which simplifies to (n+1)/2, but this is still written as O(n) as n+1/2 tends to n as n gets larger.

5
New cards

binary search

  • needs an ordered list

  • the half chosen will change if the list is ascending or descending

  • checks the midpoint of the list and checks it. if the item is the item your looking for, then you have found it. if the item is greater than the item your looking for then pick the half that is lower. if the item is lower than the item your looking for then pick the half that is greater. repeat until you find the item.

  • the list must be in some form of ascending or descending order

6
New cards

iterative binary search

this works for list in ascending order. div returns a whole number, if the input is even div will round down to the middle left

<p>this works for list in ascending order. div returns a whole number, if the input is even div will round down to the middle left</p>
7
New cards

recursive binary search

knowt flashcard image
8
New cards

binary search efficiency

the best case scenario is when the first midpoint is the item

worst case happens when the item is either index 0 or index n, or isn’t in the list. in this case the algorithm goes through all possible midpoints.

a list with 10 items has at most 4 comparisons (3 midpoints and 1 to check at the end), but a 52 item list has only 6 comparisons. the number of searches is log2​(n) comparisons + 1 (final comparison)

9
New cards

binary search time complexity 

In the worst case, the main operation will be carried out log2​(n)+1. the time complexity in big O notation is this time complexity is defined as O(logn) because the cost of the final comparison is negligible when searching large data sets because the final check is negligible for large n, this is known as logarithmic complexity

In the best case, the time complexity will be O(1).

the average case has O(logn) time complexity.

10
New cards

binary search space complexity

For the iterative version of binary search have a space complexity of O(1) since the only additional memory used will be a few variables to keep track of the elements being checked.the recursive version of binary search has a higher space complexity, as recursion places more demand on the call stack. Therefore, the space complexity will depend on the recursion method, and at its most efficient is O(logn).

11
New cards

binary search tree 

  • a search tree of ordered nodes, where each node has at most 2 nodes

  • to be as efficient as a binary search, the tree must be balance: every final node (leaf node) is about the same distance from the root

<ul><li><p>a search tree of ordered nodes, where each node has at most 2 nodes</p></li><li><p>to be as efficient as a binary search, the tree must be balance: every final node (leaf node) is about the same distance from the root</p></li></ul><p></p>
12
New cards

recursive binary search tree

knowt flashcard image
13
New cards

binary search tree time complexity

depends on the balance of the tree

balanced tree:

  • In the best case, the time complexity will be O(1)

  • In the worst case, the maximum number of comparisons needed will be O(logn)

unbalanced tree

  • In the best case, the time complexity will be O(1).

  • In the worst case, the maximum number of comparisons needed will be O(n) because all nodes will be on one branch and you are looking for the leaf node

14
New cards

binary search tree space complexity

The standard binary search tree algorithm is recursive. This will effect the space complexity since recursion places more demand on the call stack than an iterative algorithm. Therefore, the space complexity will depend on the recursion method, and at its most efficient is O(logn).

15
New cards

linear vs binary 

the binary search is much more efficient because it checks for a range where the item might be, and looks through that so the number of maximum checks is less that checking every item. 

the binary search only works on ordered lists.

<p>the binary search is much more efficient because it checks for a range where the item might be, and looks through that so the number of maximum checks is less that checking every item.&nbsp;</p><p>the binary search only works on ordered lists.</p>
16
New cards

search arrays

knowt flashcard image
17
New cards

search hash maps

When you want to find a single item in a hash table, you generate a hash value for the key. The hash value is then used to directly locate the item in the hash table. In the best case, where there have been no collisions, and the item is where you expect to find it or the position is empty, a hash table allows searching, adding and deleting an item in constant time O(1).

<p>W<span><span>hen you want to find a single item in a hash table, you generate a hash value for the key. The hash value is then used to directly locate the item in the hash table.&nbsp;In the best case, where there have been no </span></span><strong>collisions</strong><span><span>, and the item is where you expect to find it or the position is empty, a hash table allows searching, adding and deleting an item in constant time </span></span><span style="font-family: KaTeX_Main, &quot;Times New Roman&quot;, serif; line-height: 1.2; font-size: 1.1em;"><span>O(1)</span></span><span><span>.</span></span></p>
18
New cards

search linked lists

knowt flashcard image

Explore top flashcards

Medical terma quiz 4
Updated 409d ago
flashcards Flashcards (44)
Skull
Updated 5h ago
flashcards Flashcards (47)
Integrals
Updated 665d ago
flashcards Flashcards (41)
Ch13-14 Civics
Updated 1034d ago
flashcards Flashcards (45)
List 35
Updated 1098d ago
flashcards Flashcards (35)
Medical terma quiz 4
Updated 409d ago
flashcards Flashcards (44)
Skull
Updated 5h ago
flashcards Flashcards (47)
Integrals
Updated 665d ago
flashcards Flashcards (41)
Ch13-14 Civics
Updated 1034d ago
flashcards Flashcards (45)
List 35
Updated 1098d ago
flashcards Flashcards (35)