Linked Lists & Sorting Algorithms Flashcards
What is the complexity for inserting at the head in a singly linked list?
O(1)
What is the complexity for removing at the head in a singly linked list?
O(1)
What is the complexity for inserting at the tail in a singly linked list?
O(1)
What is the complexity for removing at the tail in a singly linked list?
O(n)
What changes between a singly linked list and a double linked list?
The complexity for deletion at the tail is now reduced to O(1)
What is the basic idea of bubble sort?
Cycle through the array over and over again until no swaps are made. You take two elements next to each other, and you compare them. If the swap triggers, you then perform it and move on, otherwise you move on regardless. This repeats until no swaps are made in a single loop.
What is sorting ‘stability’?
A sort is stable if it preserves the original order of duplicate elements i.e. 3, 2, 2’, 1 would be sorted into 1, 2, 2’, 3. If it preserved the order of two and two prime, then it is stable, otherwise it is unstable.
What is the complexity of bubble sort?
Worst case complexity - O(n^2)
What is the basic idea of selection sort?
Similar to bubble sort, but on each scan, you remember what element has to be swapped and then move it at the end of the scan/loop directly to the spot.
What is the complexity of selection sort?
O(n^2)
What is the basic idea of insertion sort?
Keep the front of the list sorted, and then as you move through the back, we insert elements from there into the correct place at the front
What is the complexity of insertion sort?
In worst case, also O(n^2), but in best case, O(n)
What is the complexity of bubble sort on linked lists?
Also O(n^2)
What is the complexity of selection sort on linked lists?
Also O(n^2)
What is a preorder traversal regarding linked trees?
A node is visited before its descendants
What is a postorder traversal in linked trees?
A node is visited after its descendants
What is a proper binary tree?
Each internal node has either two children or no children
The children of a node are an ordered pair
What is an arithmetic expression tree?
Binary tree associated with an arithmetic expression:
internal nodes - binary operators
external nodes - operands
What is a decision tree?
A linked tree which has connections associated with a decision process
What is an inorder traversal with a linked tree?
A node is visited after its left subtree and before its right subtree
In simple terms, goes from left to right
How is a linked tree actually stored?
For each node, it will have a segment for the node data, a segment which refers to the previous node, and possibly a third segment which leads to the next node/s if it has any
How is a node stored in a linked tree?
A node stores its data, its parent node, and if it is applicable, both its left and right child nodes
What is an ADT?
Abstract Data Type - specifies the data stored, the operations on the data, and the error conditions associated with operations
What are CDTs?
Concrete Data Types - specifies the actual data structure that will be used
The choice of CDT will affect the runtime and space usage