Sorting Algorithms Flashcards
(64 cards)
Which sorting algorithms are stable
Merge Sort, Insertion Sort, Counting Sort (basic forms)
Which sort is the best for nearly-sorted data
insertion sort
What is the worst-case complexity for Quick sort
O(n²), if the pivot is always the worst element.
What does it mean if a sort is stable
it preserves the relative order of equal elements
What are the properties for a linear structure
- There is a unique first and last element
- Every component has a unique predecessor and successor except the last or first
What are the properties of a non-linear structure
if one linear feature is false
In a linear structure what are the two methods for accessing stored data
- sequential structures
- Direct access structures
What is a sequential structure
we can only access the nth element if we have accessed all elements preceding n
What is direct access structure
any element can be accessed direction, no need to access any others.
what are the features of arrays
they are fixed size and provide direct access to elements
What are arrays as ADTs
a collection of fixed number of components of the same type
What are the operations of Arrays as ADTs and what do they do
- ValueAt(i) - accessed value at position I
- store(I,v) - stores value v at position i
Define a list
a linear structure that only provides sequential access to its elements
What two special elements does a list have
- head: point to first element of list
- tail: pointer to last element of the list
What is the advantage a list
it is not of fixed size
What is the difference between delete(v) and deleteAll(v) in a list
delete removes the first instance of v
DeleteAll removes all occurrences of v
What are linked listed
a collected of records called nodes each containing one member that gives the location of the next node in the list
What do the nodes contain in a linked list
- a data member representing the value
- a link member representing the location of the successor of this node
What are the advantages of linked lists
- Fair use of memory
- size of the structure does not need to be declared in advance
- common operations are cheaper
What are the disadvantages of linked lists
- Algorithms are more complex, harder to read and debug
- allocation of memory space causes over head
How do u insert a node in a linked list
add to the head so its new the first in the list
What is the added feature with circular linked lists compared with linked lists
the link member of the last node points to the head(the first node)
What is a stack
a collection of values of the same type
What rule does stack operations follow
Last in First Out