CompSci - Algorithms Flashcards

whjat (27 cards)

1
Q

Recursion

A

Occurs when a function calls itself (not subroutine; no return value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Stack Overflow

A

While recursion occurs, memory is filled with return addresses and local variables. If these exceed allocated memory capacity, stack overflow occurs, causing the program or device to crash.

For this reason, stopping conditions must be included in recursive algorithms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Stopping Condition

A

A condition in a recursive algorithm that stops it once some criteria has been reached.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Validation

A

Automatic proccess that is done by an algorithm to ensure that data input by the user is appropriate and follows set rules.

Length, Lookup, Range, Presence, Type, Format

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Verification

A

Manual process that is done by the user themselves to check that data input is correct.

Double-Keying, Proofreading

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Authentication

A

Automatic process done by an algorithm that compares data input by the user with appropriate previously entered data to check that data is correct.

2FA, Biometrics, Password

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Trace Tables

A

IDE tool that helps to keep track of variables’ values as an algorithm runs. Useful for debugging by comparing with expected values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Dry-Running

A

Manually working through an algorithm without the use of a computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Dry-Running Benefits

A

Uses pseudocode, which is more easy to understand and write
Helps the programmer to become familliar with the process
Low stakes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Search Algorithms

A

Linear

Binary

Binary Tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Sort Algorithms

A

Bubble

Insertion

Merge

Quicksort

Variety in recursion needed for more memory control and speed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Algorithm Definition Methods

A

Flowcharts, pseudocode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

General Benefits & Drawbacks

A

ACCESS MDC

Accessibility
Cost
Convenience
Efficiency
Security
Scalability

Maintenance
Depencence
Complexity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Bubble Sort

A

Repeatedly compares two consecutive elements in a list, swapping them if they are in the wrong order.

Requires multiple passes.

Pseudocode
Two flags
Reset swap at start of each pass, if no swaps all pass, sorted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Insertion Sort

A

Separates the unsorted array into a “sorted” left side and “unsorted” right side. It iteratively compares values left to right and orders them appropriately.

Pseudocode
Starts from second element
Define current element and previous index
While current < prev & prev exists
Replace current with prev
Define previous previous index
OUTSIDE FOR replace prev with current
[i] only used in initial for, then in terms of [prev]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Quicksort

A

Select an arbitrary value as a pivot, then separate the list into two sublists of elements lesser and greater than the pivot. These sublists are then sorted and ordered correctly.

Recursive.

Pseudocode
a,start,end parameters, if start>=end else,def pivot, low,high,sorted while while obv go closer, if obv swap low high. outside swap start high. quicksort start high -1 and high+1 start

17
Q

Merge Sort

A

Select the middle element of the list and separate it into two sublists with the middle element part of the left sublist. Keep separating the sublists until they all contain one element each.
Compare elements left-to-right when merging sublists until an ordered list is formed.

Recursive

Pseudocode
Two functions, merge & sort
merge: def i_l/r=0 and merged, compare from left to right and append if true. return merged
sort: if len <= 1, def mid,l,r, sort each and merge both. return merged

18
Q

Algorithm Definition

A

A defined set of sequential operations to apply to data in order to achieve a useful output.

19
Q

Sorting Algorithm Efficiency Factors

A

Extra memory needed in addition to the input data
How many comparisons the CPU makes between data
How often two elements are swapped
How many times the algorithm scans the entire dataset

20
Q

Data Compression

A

Representing the same information using fewer bits for more efficiency

21
Q

Data Compression Algorithms

A

Run-Length Encoding - Replace repeated values with an instance and a count. Lossless

Huffman Encoding - Binary tree created based on character frequency, where traversal is optimised for most frequent characters. Lossless

Truncation - Redundant data is removed. Lossy

Dictionary Encoding - Dictionary created, containing frequently repeating patterns and their keys. Lossless

22
Q

Lossy and Lossless Algorithms

A

Lossy - JPEG, MP3

Lossless - PNG, ZIP

23
Q

Shortest Path Algorithms

A

Djikstra’s Algorithm - Find smallest weighing of adjacent nodes from the start until the end node is reached.

A* Algorithm - Estimates the smallest weighing heuristically until the shortest path is found.

24
Q

Binary Search

A

Compare searched value with midpoint of sorted list. If greater of smaller than it, compare it with the midpoint of the respective sublist. Repeat until a midpoint is equal or not found.

Pseudocode
Def left,right, while left<right compare value with array[mid]

25
Big O Notation In Order of Efficiency
E(k) E(logn) E(n) E(n^2) E(k^n)
26
Determining Time Efficiency of Algorithm
Count the basic operations and consider how they grow with n. No of operations within loops become coefficients and outside constants. To represent using big O notation, only use the largest order term. O(1+n) = O(n) (if loop is to n-1, assume n)
27
Determining Space Efficiency of Algorithm
Consider how each variable grows in memory with respect to n.