Pseudocode to Memorise

studied byStudied by 2 people
5.0(1)
Get a hint
Hint

how does selection sort work?

1 / 29

flashcard set

Earn XP

Description and Tags

30 Terms

1

how does selection sort work?

  1. finds the minimum element from unsorted part of the array and puts it at the beginning (i = 1)

  2. repeats (searches i+1 → n values since you don’t need to check the front values) until the whole list is sorted

<ol><li><p>finds the minimum element from unsorted part of the array and puts it at the beginning (i = 1)</p></li><li><p>repeats (searches i+1 → n values since you don’t need to check the front values) until the whole list is sorted</p></li></ol>
New cards
2

what is the code for a bubble sort?

knowt flashcard image
New cards
3

how can the code for a bubble sort be improved?

reduce the list size at each iteration

n - 2 - i

New cards
4

what algorithms are needed for a quick sort?

  • QuickSort(list,first,last)

  • PivotList(list,first,last)

New cards
5

what is the code for a QuickSort?

knowt flashcard image
New cards
6

what is the code for a PivotList?

knowt flashcard image
New cards
7

how does radix sort work?

  1. first sort by the least significant bit

  2. the input is split into different sets based on the bit

    • for binary: 2 sets (digit is 0 or digit is 1)

    • for integer: 10 sets (0,1,2,3,4,5,6,7,8,9) → or,, int values need to be converted to a binary digit????

    • the ordering of the data as they are put into the sets must be maintained

  3. going from left to right, take out the values in each set to reform the list (eg. each set is a queue, clear queue 0 first, then queue 1)

  4. repeat the process by looking at the next least significant bit

  5. continue until we run out of bits to analyse

<ol><li><p>first sort by the least significant bit</p></li><li><p>the input is split into different sets based on the bit</p><ul><li><p>for binary: 2 sets (digit is 0 or digit is 1)</p></li><li><p><em>for integer: 10 sets (0,1,2,3,4,5,6,7,8,9) → or,, int values need to be converted to a binary digit????</em></p></li><li><p>the ordering of the data as they are put into the sets must be maintained</p></li></ul></li><li><p>going from left to right, take out the values in each set to reform the list <em>(eg. each set is a queue, clear queue 0 first, then queue 1)</em></p></li><li><p>repeat the process by looking at the next least significant bit</p></li><li><p>continue until we run out of bits to analyse</p></li></ol>
New cards
8

what is the code for a depth first search?

knowt flashcard image
New cards
9

what is the code for an exhaustive search?

knowt flashcard image
New cards
10

how does a breadth first search work?

uses a heuristic (improved process) to decide which node is explored next eg. expanded in order of lowest cost

New cards
11

how does an A* search work?

2 estimates must be made

  • G the cost of the partial path (from the start to the node we are currently at)

  • H estimated cost of how far is left from the current path node [NOT START] to the goal state - underestimate used/ lower bound on how far to travel

  1. select the start

  2. select the partial path point

  3. do g + h = f for each neighbour

  4. choose the path with the lowest f value (eg. A chosen instead of B)

  5. repeat the steps until the end goal is reached

<p>2 estimates must be made</p><ul><li><p><mark data-color="red">G</mark> the cost of the partial path (from the start to the node we are currently at)</p></li><li><p><mark data-color="red">H</mark> estimated cost of how far is left from the current path node [NOT START] to the goal state - underestimate used/ lower bound on how far to travel</p></li></ul><p></p><ol><li><p>select the start</p></li><li><p>select the partial path point</p></li><li><p>do g + h = f for each neighbour</p></li><li><p>choose the path with the lowest f value (eg. A chosen instead of B)</p></li><li><p>repeat the steps until the end goal is reached</p></li></ol>
New cards
12

what is the code for Prims Algorithm for MST

knowt flashcard image
New cards
13

Example of Prims Algorithm

knowt flashcard image
New cards
14

what is the code for Dijstra’s Algorithm?

implemented with 3 stacks

<p>implemented with 3 stacks</p>
New cards
15

what is the code for the Floyd-Warshall algorithm?

knowt flashcard image
New cards
16

what is the code for the fitness function for the scales problem?

knowt flashcard image
New cards
17

what is the code for Random Mutation Hill Climbing?

knowt flashcard image
New cards
18

what is needed for RMHC?

  • random start point → start solution (binary string)

  • small change operator → modify the current solution

  • number of iterations we want to run the algorithm for

New cards
19

what is the code for the RandomStart algorithm for RMHC?

used to generate a random start solution to the scales problem/ random binary string

<p>used to generate a random start solution to the scales problem/ random binary string</p>
New cards
20

what is the code for the SmallChange algorithm for RMHC?

used to choose a random weight and reverse the side it is on for the scales problem

New cards
21

how does random restart hill climbing work?

variation of random hill climbing

  1. run normal RMHC n times and get the best fitness

    1. we start off in different sections of the search space

    2. For example we might run it 10 times for 100 iterations rather than once for 1,000 iterations

New cards
22

how does stochastic hill climbing work?

improvement on random hill climbing

allows us to accept worse fitness functions in order to avoid getting stuck at local optimas

uses acceptance function to determine if we accept a solution during the search- based on how bad the change in fitness is

  1. current fitness - next fitness = change in fitness

  2. very bad change = small chance of acceptance

  3. slightly bad change = more often accepted

  4. relies on a decision function

<p><strong>improvement</strong> on random hill climbing</p><p>allows us to accept worse fitness functions in order to avoid getting stuck at local optimas</p><p>uses acceptance function to determine if we accept a solution during the search- based on how bad the change in fitness is</p><ol><li><p>current fitness - next fitness = change in fitness</p></li><li><p>very bad change = small chance of acceptance</p></li><li><p>slightly bad change = more often accepted</p></li><li><p>relies on a decision function</p></li></ol>
New cards
23

how does simulated annealing work?

improvement on random hill climbing

accepts worst solutions to circumnavigate local maximums

annealing - chance of accepting worse solution reduces as algorithm progresses

annealing process is simulated through maintaining a slow decreasing temperature

  • This temperature should reach zero at the end of the algorithm’s run

  • If temperature is very high: the algorithm is more likely to accept worst solutions

  • If temperature is zero: the algorithm behaves like HC – accepts better solutions

Note that the parameters T0 (starting temperature) and λ (cooling rate) need defining, along with the acceptance function PR

New cards
24

what is the code for simulated annealing?

knowt flashcard image
New cards
25

what is the code for Holland’s GA Algorithm?

knowt flashcard image
New cards
26

what is the code for the evolutionary programming algorithm?

knowt flashcard image
New cards
27

what is the code for the K-Means Algorithm?

knowt flashcard image
New cards
28

what algroithms are needed to solve the TSP?

  • RandomPerm - creates a random permutation of cities where each city is in the perm only once

  • Swap - makes a small change, swaps the position of 2 cities in the permutation

New cards
29

what is the code for the RandomPermutation algorithm?

knowt flashcard image
New cards
30

what is the code for the Swap algorithm?

knowt flashcard image
New cards

Explore top notes

note Note
studied byStudied by 55 people
... ago
5.0(1)
note Note
studied byStudied by 19 people
... ago
5.0(1)
note Note
studied byStudied by 8536 people
... ago
4.8(30)
note Note
studied byStudied by 7 people
... ago
5.0(1)
note Note
studied byStudied by 106 people
... ago
5.0(2)
note Note
studied byStudied by 413 people
... ago
4.5(11)

Explore top flashcards

flashcards Flashcard (79)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (31)
studied byStudied by 8 people
... ago
5.0(1)
flashcards Flashcard (58)
studied byStudied by 7 people
... ago
5.0(1)
flashcards Flashcard (23)
studied byStudied by 93 people
... ago
5.0(3)
flashcards Flashcard (20)
studied byStudied by 3 people
... ago
4.0(1)
flashcards Flashcard (183)
studied byStudied by 6 people
... ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 11 people
... ago
5.0(1)
flashcards Flashcard (22)
studied byStudied by 13 people
... ago
5.0(1)
robot