Searching and Sorting

0.0(0)
studied byStudied by 3 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/54

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.

55 Terms

1
New cards

What is a simple sort?

Selects the smallest number in one list and moves it to another list.

2
New cards

What is a Simple (Selection) Sort?

Marker is on first item and swaps said item with the smallest item in the list. Marker moves ahead once

3
New cards

What is an insertion sort?

There's a border between the first and second items. Move the next item and move the items to the left of the marker.

4
New cards

In an insertion sort, which side is unsorted?

Right

5
New cards

In an insertion sort, which side is sorted?

Left

6
New cards

What is a bubble sort?

Compares items beside each other. Swaps them if they are in the wrong order. Continues through the list until they're sorted

7
New cards

Is the Bubble Sort efficient?

No, too many comparisons

8
New cards

Algorithm (definition)

A series of finite, unambiguous steps followed to solve a problem. E.g. recipe

9
New cards

What are the essential features of algorithms?

Accuracy and precision

10
New cards

Algorithm process

Input →processing → output

11
New cards

What do rule-based algorithms use?

A set of predefined rules to make decisions.

12
New cards

What does a machine learning algorithm use?

They learn from datasets to create their own rules based on statistical randomness

13
New cards

Are rule-based algorithms simple or complex?

Simple

14
New cards

What is the problem with rule-based algorithms?

Error filled

15
New cards

Are machine learning based algorithms simple or complex?

Complex

16
New cards

What is the feature of machine learning algorithms?

Opportunity for non-deterministic behaviors

17
New cards

What is non-deterministic behaviors?

What's logical to you may not be the outcome. Not based on human biased

18
New cards

Best case time complexity for Linear Search

O(1)

19
New cards

Average case time complexity for Linear Search

O(n)

20
New cards

Worst case time complexity for Linear Search

O(n)

21
New cards

Best case time complexity for Binary Search

O(1)

22
New cards

Average case time complexity for Binary Search

O(log2n)

23
New cards

Worst case time complexity for Binary Search

O(log2n)

24
New cards

Best case time complexity for Simple (Selection) Sort

O(n²)

25
New cards

Average case time complexity for Simple (Selection) Sort

O(n²)

26
New cards

Worst case time complexity for Simple (Selection) Sort

O(n²)

27
New cards

Best case time complexity for Bubble Sort

O(n)

28
New cards

Average case time complexity for Bubble Sort

O(n²)

29
New cards

Worst case time complexity for Bubble Sort

O(n²)

30
New cards

Best case time complexity for Insertion Sort

O(n)

31
New cards

Best case time complexity for quick sort

O (n log2n)

32
New cards

Average case time complexity for quicksort

O (n log2n)

33
New cards

Worst case time complexity for quick sort

O (n2)

34
New cards

Does a log in the time complexity mean it is more or less efficient?

More efficient

35
New cards

What does O(1) mean?

That the time complexity is the same no matter how long the list is

36
New cards

How does a linear search work?

It iterates (goes through the list) until it finds the required item.

37
New cards

What does a linear search return when it finds the value required

The element’s index in the list

38
New cards

What value does a linear search return if it doesn’t find the value in the list?

-1

39
New cards

Disadvantage of binary search

List must be sorted for it to work

40
New cards

Explain a binary search

Divides a sorted list in half at each step. Compares the middle element (floor division) of the list with the target value. If the middle element is greater, it’ll search the left half of the list. If the middle element is smaller, it’ll search the right half. It’ll continue finding the middle and splitting the list until then target value is found or the base case is reached.

41
New cards

Why is binary search more efficient

It divides the list at each step, eliminating multiple items at once

42
New cards

What is a pivot?

The item of the list which we use to compare to the rest of the items in order to split the list

43
New cards

Unless stated otherwise, which item is the pivot?

The last item

44
New cards

What is the base case of quick sort?

When the length of the list becomes 1

45
New cards

What is recursion?

When a function calls itself in the function

46
New cards

Explain quicksort

Pivot is selected and separated from the list. Items are split into two list depending on if they’re bigger than or smaller than the pivot. Repeat the process with each individual list until they are split into one item per list.

47
New cards

Name two ways to improve quicksort

Sort in place without making new lists since it takes up storage. Select a middle pivot

48
New cards

How would Sort in place without making new lists improve quick sort?

Making new lists requires storage

49
New cards

How would selecting a middle pivot improve the efficiency of quick sort?

Ensures list is split evenly, making it take less time due to the amount of cycles being split between the two lists and not one list having to be split multiple times

50
New cards

Advantages of sorting a data set (2)

More user friendly. Easier to analyse

51
New cards

Disadvantages of sorting a data set (2)

Wastes time. Consumes memory and CPU

52
New cards

How to improve bubble sort? (2)

Algorithm stops early to reduce comparisons if no swap occurs. Do not do an extra check at the end of the program to reduce comparisons

53
New cards

Why would the highest number as a pivot not work? (2)

All items less than it will not be split making it less efficient and increasing the time taken to complete the algorithm

54
New cards

Two properties of recursive functions

Must call itself. Base case triggers end of the recursion

55
New cards

What is a base case?

Smallest problem that can be solved without further recursion