1b

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/29

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:44 PM on 8/26/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

30 Terms

1
New cards

The main idea of Bubble Sort

A sorting algorithm that repeatedly compares adjacent elements and swaps them if they are in the wrong order, continuing until no swaps are needed.

Start by comparing the first pair of elements and swap them if the first element is greater than the second (assuming ascending order). Repeat for all pairs in the list. Repeat this whole iteration n-1 times (or until the whole list is sorted by checking if no swaps were done in the current iteration (optimisation 1)). There is no need to check the elements that were already sorted in subsequent iterations so reduce the range by 1 in each iteration (optimisation 2).

2
New cards
  1. What is the largest number of swaps performed by Bubble Sort per item in the list?

The maximum number of swaps performed by Bubble Sort per item in the list is n-1, where n is the number of elements in the list.

3
New cards

Complexity of Bubble Sort 1

The overall complexity of Bubble Sort 1 in both best and worst cases is O(n^2), where n is the number of elements in the list.

4
New cards

Complexity of Bubble Sort 2

The best-case complexity of Bubble Sort 2 is O(n) when the list is already sorted, and the worst-case complexity is O(n^2) when the list is in reverse order.

5
New cards

Best and Worst Case Explanation

Bubble Sort 1 has two loops leading to O(n^2) complexity, while Bubble Sort 2 can exit early if no swaps occur, leading to O(n) in the best case.

6
New cards

One Iteration Result

After one iteration of Bubble Sort on [5, 20, -5, 10, 3], the result is [5, -5, 10, 3, 20].

7
New cards

Stopping Condition

Bubble Sort stops after n-1 iterations for Bubble Sort 1 and when no swaps occur for Bubble Sort 2.

8
New cards

Incremental Sorting Algorithm

An algorithm is incremental if it can sort a list with minimal recomputation after a small change; Bubble Sort is incremental when adding an element to the front.

9
New cards

Stability of Sorting Algorithm

A sorting algorithm is stable if it maintains the relative order of equal elements; Bubble Sort is stable due to its strict comparison.

10
New cards

Selection Sort

A sorting algorithm that finds the minimum value in the unsorted portion and swaps it with the first unsorted element until the list is sorted.

11
New cards

Selection Sort Iteration

In one iteration of Selection Sort on [5, 20, -5, 10, 3], the result is [-5, 20, 5, 10, 3].

12
New cards

Complexity of Selection Sort

The best and worst-case complexity of Selection Sort is O(n^2), where n is the length of the list.

13
New cards

Stability of Selection Sort

Selection Sort is not stable as it may disrupt the relative order of equal elements during swaps.

14
New cards

Insertion Sort

A sorting algorithm that builds a sorted list by repeatedly taking the next unsorted element and inserting it into the correct position in the sorted portion.

15
New cards

Complexity of Insertion Sort

The best-case complexity is O(n) when the list is already sorted, and the worst-case complexity is O(n^2) when the list is in reverse order.

16
New cards

Incremental Nature of Insertion Sort

Insertion Sort is incremental as it can insert a new element into a sorted list with minimal operations.

17
New cards

Stability of Insertion Sort

Insertion Sort is stable as it maintains the relative order of equal elements during insertion.

18
New cards

Algorithm Expectations

An algorithm is expected to have a finite set of well-defined instructions and produce correct outputs for valid inputs.

19
New cards

Input Size in Algorithms

The input size can refer to the number of elements, the number of bits for integers, or the number of vertices/edges in graphs.

20
New cards

Time Complexity Measurement

Algorithmic time complexity should be measured with respect to the input size, focusing on the number of elementary operations performed.

21
New cards

Big O Notation

f(n) = O(g(n)) means that f(n) grows at a rate less than or equal to a constant multiple of g(n) for sufficiently large n.

22
New cards

Worst-case vs

Worst-case complexity describes the maximum time/resources required, while best-case complexity describes the minimum.

23
New cards

Abstract Data Type (ADT)

An ADT defines the values and operations without specifying implementation; examples include Stack ADT and Queue ADT.

24
New cards

Stack ADT

A Last In First Out (LIFO) data structure with key operations like push(), pop(), and peek().

25
New cards

Queue ADT

A First In First Out (FIFO) data structure with key operations like append(), serve(), and is_empty().

26
New cards

List ADT

A data structure that stores items in order, allowing operations like insert(), delete(), and access.

27
New cards

Sorted List ADT

A list that maintains elements in sorted order, allowing efficient searching and insertion.

28
New cards

Linked Nodes vs

Linked nodes allow for efficient insertion/deletion but have slower access times compared to arrays.

29
New cards

Bit-Vector

A compact representation of a set using bits, where each bit indicates the presence or absence of an element.

30
New cards

Complexity of Set Operations

The complexity of operations like add(), remove(), and union varies based on the underlying data structure (array vs. bit-vector).