Algorithms

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

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

15 Terms

1
New cards

Linear search

  • Searching through an unordered list by checking every item, in sequence, to see if it is the desired item.

  • Worse case scenario has O(n) time complexity, best case is O(1)

  • Space complexity is O(1)

2
New cards

Binary search

  • Searching through an ordered list by calculating a midpoint position, checking the item and setting a new midpoint to continue comparisons

  • Worst case scenario has O(lg n) time complexity, best case is O(1)

  • Iterative binary search as O(1) space complexity, and recursive has O(lg n) space complexity

3
New cards

Binary search tree

  • A rooted tree where the nodes are ordered

  • Balanced trees: O(lg n) time complexity

  • Unbalanced trees: O(n) time complexity

  • Both have O(lg n) space complexity

4
New cards

Considerations you should have when choosing a data structure

  • Keeping data maintained

  • Adding, deleting, updating and sorting data

5
New cards

How does working with arrays change depending if it’s ordered or not?

  • Ordered:

  • To add a new item, the specific position will have to be searched for

  • To delete and update an item, a binary search will need to be done

  • Doesn’t need to be sorted

  • Unordered:

  • To add an item, it will be added at the end of the list

  • For deleting and updating, linear search will be needed

  • Sorting algorithms will be needed

6
New cards

How does working with hash tables change depending if it’s ordered or not?

Hash tables are always ordered

7
New cards

How do you work with a hash table?

  • To add a new item, you would use the hashing algorithm

  • Deleting and updating an item would use the hashing algorithm

  • No sorting would be needed.

8
New cards

How do you work with binary search trees?

  • You can add, delete or update items by using the binary search

  • No sorting is needed

9
New cards

How does working with linked lists change depending if it’s ordered or not?

  • Ordered:

  • Linear search will be needed to locate the correct position

  • Linear search will be needed to delete and update items

  • No sorting needed

  • Unordered:

  • Items can easily be added infront of the list

  • Linear search will be needed to delete or update nodes

  • Sorting the list would require to traverse the list, write each element in an array and use an algorithm on said array

10
New cards

Bubble sort and example of {9,3,10,2,8,5,1}

  • Compares each element of the list in “passes”

  • First pass: {3,9,2,8,5,1,10}

  • Second: {3,2,8,5,1,9,10}

11
New cards

Bubble sort complexity

  • Time complexity: O(n²)

  • Space complexity: O(1)

12
New cards

Insertion sort and example of {2,8,5,3,9,4}

  • Compares the left-most element with the other elements to the left, and sorts it

  • 1st iteration: {2, 8, 5, 3, 9, 4}

  • 2nd: {2, 8, 5, 3, 9, 4}

  • 3rd: {2, 5, 8, 3, 9, 4}

13
New cards

Insertion sort complexity

  • Time complexity: O(n²)

  • Space complexity: O(1)

14
New cards

Merge sort and example of {2,8,5,3,9,4,1,7}

  • Continuously dividing an array into sections of n/2 arrays, until they have individual items, then recreating arrays whilst comparing them

  • Divide: {2}, {8}, {5}, … , {7}

  • Merge: {2,8}, {3,5}, {4,9}, {1,7}

  • Merge: {2,3,5,8}, {1,4,7,9}

15
New cards

Merge sort complexity

  • Time complexity: O(nlg n)

  • Space complexity: O(n)