Sorting Algorithms Flashcards

(64 cards)

1
Q

Which sorting algorithms are stable

A

Merge Sort, Insertion Sort, Counting Sort (basic forms)

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

Which sort is the best for nearly-sorted data

A

insertion sort

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

What is the worst-case complexity for Quick sort

A

O(n²), if the pivot is always the worst element.

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

What does it mean if a sort is stable

A

it preserves the relative order of equal elements

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

What are the properties for a linear structure

A
  • There is a unique first and last element
  • Every component has a unique predecessor and successor except the last or first
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the properties of a non-linear structure

A

if one linear feature is false

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

In a linear structure what are the two methods for accessing stored data

A
  • sequential structures
  • Direct access structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a sequential structure

A

we can only access the nth element if we have accessed all elements preceding n

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

What is direct access structure

A

any element can be accessed direction, no need to access any others.

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

what are the features of arrays

A

they are fixed size and provide direct access to elements

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

What are arrays as ADTs

A

a collection of fixed number of components of the same type

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

What are the operations of Arrays as ADTs and what do they do

A
  • ValueAt(i) - accessed value at position I
  • store(I,v) - stores value v at position i
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define a list

A

a linear structure that only provides sequential access to its elements

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

What two special elements does a list have

A
  • head: point to first element of list
  • tail: pointer to last element of the list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the advantage a list

A

it is not of fixed size

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

What is the difference between delete(v) and deleteAll(v) in a list

A

delete removes the first instance of v

DeleteAll removes all occurrences of v

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

What are linked listed

A

a collected of records called nodes each containing one member that gives the location of the next node in the list

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

What do the nodes contain in a linked list

A
  • a data member representing the value
  • a link member representing the location of the successor of this node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the advantages of linked lists

A
  • Fair use of memory
  • size of the structure does not need to be declared in advance
  • common operations are cheaper
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the disadvantages of linked lists

A
  • Algorithms are more complex, harder to read and debug
  • allocation of memory space causes over head
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do u insert a node in a linked list

A

add to the head so its new the first in the list

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

What is the added feature with circular linked lists compared with linked lists

A

the link member of the last node points to the head(the first node)

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

What is a stack

A

a collection of values of the same type

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

What rule does stack operations follow

A

Last in First Out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What operation does Push(v) perform in a stack
puts value v on top of the stack
26
what does the operation pop() perform on a stack
removes and returns the value on the top of the stack
27
What does the operation top() perform on a stack
returns the value on top of the stack
28
what is a queue
also a collection of variables of the same type
29
What rule does queue operation follow
first in first out
30
What is the definition of a stable sorting method
a sorting method is said to be stable if it preserves the relative order of the items with duplicated keys on the list
31
How does selection sort work
points start of at last element (last) and largest element (maxPos), keeps switching last with max pos till in order
32
How does insertion sort work
creates order list from right to left while saving variable out of order in viable then placing then moving to the next variable
33
How does bubble sort work
work from left to right swaping pos with pos + 1 if pos 1 is less than pos. keep doing so til in order
34
How does quick sort work
Quick Sort is a divide-and-conquer sorting algorithm that works by partitioning an array around a pivot element, so that: Elements less than the pivot go to the left Elements greater than the pivot go to the right It then recursively sorts the left and right subarrays.
35
How does merge sort work
Merge Sort is a divide-and-conquer algorithm that recursively divides the array into halves, sorts each half, and then merges the sorted halves into a fully sorted array.
36
Why do we avoid direct access structures
we have to allocate its size in advance which could result in an overestimate and waste of space
37
What is the division method for hash functions
k mod m
38
what is the multiplication method to hash functions
m * (kAmod1)
39
What is the best case scenario for bubble sort
omega (n)
40
What is the worst case scenario for bubble sort
O(n^2)
41
What is the best case scenario for selection sort
omega(n^2)
42
What is the worst case scenario for selection sort
O(n^2)
43
What is the best and worst case scenario for insertion sort
Best: omega(n) Worst: O(n^2)
44
What is the best and worst case scenario for merge sort
Best: omega(nlogn) Worst: O(nlogn)
45
What is the best and worst case scenario for quick sort
Best: omega(nlogn) worst: O(n^2)
46
What is the best and worst case scenario for Heap sort
best: omega(nlogn) worst O(nlogn)
47
What is the best and worst case scenario for Radix sort
best: omega(nk) worst: O(nk)
48
Which two pairs of sets have the same time complexity
- Bubble sort - Insertion sort - heap sort - Merge sort
49
What is the the order of the increasing time complexities
O(1) --> O(logn) --> O(n) --> O(nlogn) --> O(n^c) ---> O(n^2)
50
what are the minimum number of fields for a doubly linked list
3 Prev - Pointer to previous node Data Next - pointer to next node
51
Which sorting algorithms have average case performance of O(n^2)
Insertion sort Bubble sort selection sort
52
which sorting algorithm has all performances for time complexity at n^2
selection sort tho bubble and insertion had it for average and worse but their best is O(n)
53
What do merge sort, quick sort, and heap sort have in common with their time complexities
all time complexity the same at O(nlogn) but worst case quick sort is n^2
54
In the context of sorting algorithms, what is the key characteristic of a stable sorting algorithm
it maintains the relative order of equal elements
55
56
What are the two collision resolutions techniques for hashing
- Separate Chaining - Open Addressing
57
What does separate chaining do
the table points to structures holding the elements that collide
58
Define a tree
A collection of nodes connected by edges
59
define a node
a unit that contains data and pointers to other nodes
60
define an edge
a connected between two nodes
61
define a path
a sequence of nodes connected by edges
62
define a rooted tree
a tree with a single designated root node
63
define a forest
a set of disjoint trees
64
define a leave
a node with no children