COM1009 Algorithms and Data Structures

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

1/10

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.

11 Terms

1
New cards

Insertion Sort Algorithm

Runtime:

  • Best case: Sorted ascending => n-1

  • Worst case: Sorted descending =>

<p>Runtime:</p><ul><li><p>Best case: Sorted ascending =&gt; n-1</p></li><li><p>Worst case: Sorted descending =&gt;</p></li></ul><p></p>
2
New cards

Merge Sort

A divide and conquer algorithm that sorts an array by recursively dividing it into halves, sorting each half, and then merging the sorted halves back together.

<p>A divide and conquer algorithm that sorts an array by recursively dividing it into halves, sorting each half, and then merging the sorted halves back together. </p>
3
New cards

Priority Queue Naïve Implementation

Each element x of a set M, has priority x.key. Array position containing the highest priority is at A[iM] which is checked each time an element is inserted into an array with a priority (Insert(priority p)), FindMax() returns A[iM]. ExtractMax() removes the element with highest priority and sets the new maximum as needed.

<p>Each element x of a set M, has priority x.key.  Array position containing the highest priority is at A[iM] which is checked each time an element is inserted into an array with a priority (Insert(priority p)), FindMax() returns A[iM]. ExtractMax() removes the element with highest priority and sets the new maximum as needed.</p>
4
New cards

Heap

A heap is an array corresponding to a binary tree, for which all levels are full except the last and is filled left to right.

A heap ‘A’

  • Has the max-heap property,, if…

  • For every node i > 1

  • A[parent(i)] >= A[i]

  • Called a max-heap

  • Has the min-heap property if…

  • For every node i > 1

  • A[parent(i)] <= A[i]

  • Called a min-heap

5
New cards

MaxHeapify

Is a procedure to maintain the max-heap property in a binary heap. It ensures that the subtree rooted at a given node follows the property by comparing the node with its children and swapping if necessary.

Trees are stored in arrays where the child nodes of an element are at index x2 and index x2 +1

<p>Is a procedure to maintain the max-heap property in a binary heap. It ensures that the subtree rooted at a given node follows the property by comparing the node with its children and swapping if necessary. </p><p>Trees are stored in arrays where the child nodes of an element are at index x2 and index x2 +1</p>
6
New cards

Heap Sort Algorithm

A comparison-based sorting algorithm that utilizes a binary heap data structure to sort elements. It first builds a max-heap from the input data and then repeatedly extracts the maximum element from the heap, placing it at the end of the sorted array.

<p>A comparison-based sorting algorithm that utilizes a binary heap data structure to sort elements. It first builds a max-heap from the input data and then repeatedly extracts the maximum element from the heap, placing it at the end of the sorted array. </p>
7
New cards

Probability Modelling Trick

knowt flashcard image
8
New cards

Quicksort

knowt flashcard image
9
New cards

Growth Orders

knowt flashcard image
10
New cards

CountingSort

A linear time algorithm

  • For every x of the input, count numbers <= x

  • Use this to write x into correct position in output

  • A - input array

  • Z - output arrat

  • C - work array (where we count)

  • K - limit of the universe: {0,..,K}

Runtime for n numbers: O(n + k)

<p>A linear time algorithm</p><ul><li><p>For every x of the input, count numbers &lt;= x</p></li><li><p>Use this to write x into correct position in output</p></li><li><p>A - input array</p></li><li><p>Z - output arrat</p></li><li><p>C - work array (where we count)</p></li><li><p>K - limit of the universe: {0,..,K}</p></li></ul><p></p><p>Runtime for n numbers: O(n + k)</p><p></p>
11
New cards

In-Order Traversal

  • Recursively travel left subtree of the root

  • Output value of the root

  • Recursively traverse the right subtree of the root

<ul><li><p>Recursively travel left subtree of the root</p></li><li><p>Output value of the root</p></li><li><p>Recursively traverse the right subtree of the root</p></li></ul><p></p>