cs paper 2 Flashcards
(133 cards)
What is Dijkstras algorithm?
a shortest path algorithm used to find the shortest distance between 2 nodes in a network
How is Dijkstras algorithm implemented?
use a priority queue which has the shortest lengths at the front of the queue
What is the A* algorithm?
a general path-finding algorithm which has 2 cost functions: 1. actual cost 2. approximate cost
How does the A* algorithm differ from Dijkstras algorithm? ( 2 things)
A* algorithm has 2 cost functions: 1. actual cost 2. approximate cost
Why are heuristics used in the A* algorithm? (2 things)
- to calculate an approximate cost from node x to the final node 2. this aims to make the shortest path finding process more efficient
What data structure can be used to implement Dijkstras algorithm?
priority queue
What is an advantage of using the A* algorithm?
the speed of the algorithm is constrained by the accuracy of the heuristic
What searching algorithm reuqires data to be sorted before starting?
binary search
C
Perform a linear search for 9 on the values: 1, 3, 6, 7, 9, 12, 15
What is the time complexity of binary search?
O(log n)
B
Perform a binary search for 6 on the values: 1, 3, 6, 7, 9, 12, 15
What searching algorithm has a time complexity of O(n)?
linear search
What sorting algorithm makes comparisons and swaps between pairs of elements?
bubble sort
B
C
Perform the first pass of bubble sort on the values: 4, 2, 3, 5, 1
What sorting algorithm can be improved by adding a flag record to record whether or not a swap has occured?
bubble sort
What are the 2 functions in merge sort?
MergeSort() Merge()
In what sorting algorithm is the largest element in place after the first pass?
bubble sort
What sorting algorithm uses pivots?
quick sort