DSALG Flashcards
Name the 3 linear data structures
Array, Linked list, Hash table
Name all the hierarchical data strucutres
Binary Tree
Binary Search Tree
AVL Tree
Splay Tree
Heap
2-3 Tree
B Tree
Name the 3 graphical data structure algorithms
Tree traversal(Breadth first and Depth first search)
Shortest Path Trees( Dijkstra’s algorithm)
Spanning Trees(Prim and Kruskals algorithm)
What are the 2 types of arrays
Sorted and unsorted arrays
What are the special cases of arrays
Stacks ADT, Queue ADT, Priority queue
What are the special cases of linked lists
Double linked list
Circularly linked lists
Skip list
What is a doubly linked list
A linked list in which every node has a forward and a backward link
What is a circularly linked list
A SLL in which the last node contains the
reference to the first node in the SLL
What is a skip list
A probabilistic data structure, based on parallel linked lists, with an improved efficiency
What is a Hash table
A searching tool that uses hashing for the time-space trade off
What are the special cases for a B tree
B * Tree
B+ Tree
How is the heap structure applied
Priority Queue
Huffman coding
What is an algorithm
A set of instructions on how to complete a specific task
What are the different classifications of algorithms?
Brute force
Divide and Conquer
Backtracking
Greedy
What is a backtracking algorithm
Keep trying but when you a reach a point where things don’t work out you go back and try a different possibility
What is a greedy algorithm
An algorithm where a decision is made that is deemed good but no consideration is given to future consequences
What is a data structure
A way to store and organise data in order to facilitate access and modifications
What is a hierarchical data structure
A data structure where each node has a unique predecessor and many successors
What is a linear data structure
A data structure where each node has a unique predecessor and a unique successor
What is a graphical data structure
A data structure where each node has many predecessors and many successors
What is a set structure
No predecessor and no successor
What does ADT stand for
Abstract data type
What is an ADT
A collection of data and associated methods stored as a single module
Can data be accessed directly in an ADT
No data is accessed indirectly through its methods to access and modify
Compare an ADT and a data structure
ADT:
What it can do
Implementation independent
Data structure:
How it does it
Implementation dependent
What is a stack
A collection of objects where only the most recently inserted object (Top) can be removed at anytime works on LIFO(Last in first out) basis.
Name some stack methods
- Push-Add an item to the top of the stack
- Pop-Remove an item from the top of the stack
- Peek-Examine item at the top of the stack
- Empty-Determine if the stack is empty
- Full-Determine if the stack is full
What is a queue
A collection of objects organised such that the object that has been stored in the queue the longest is the next one removed.
Works on a FIFO (First in First Out)
Name some ADT
Stack
Queue
Linked lists
Hash Table
Where are elements inserted and removed in a queue
Elements are inserted to the tail(back) of the queue and elements are removed from the head(front)
Name some queue methods
- Enqueue - Add to tail of queue
- Dequeue - Remove from the queue
- Full - See if its full
- Empty - See if its empty
- First - See what element is first
What is the big O notation for Constant complexity?
O(1) - The time taken does not grow no matter how the input n varies or when you find the element immediately
What is the big O notation for Linear complexity?
O(n) - As the input end gets bigger the time also increases e.g linear search
What is the big O notation for Polynomial complexity?
O(n^2) - the time it takes increases at a faster rate than the rate of increase in the size of input n e.g bubble sort
What is the big O notation for Logarithmic complexity?
O(log n) - As the input size grows the number of operation grows very slowly
What does complexity of O(logn) mean
An algorithm that repeatedly excludes half the variables during its execution
Name all the searching algorithms
Linear search
Binary Search
What happens in linear search
You search in order until you find what you want
What happens in binary search
Check the middle element. Discard the left or right in the list that doesn’t contain the item. List must be sorted tho
What is the worst, best and average case of binary search
○ Best case O(1)
○ Worst Case O((log2n)
Average O(log2n)
What is the worst, best and average case of linear search
○ Best case O(1)
○ Worst case O(n)
○ Average case N/2
Name the 5 sorting algorithms
Selection Sort
Insertion sort
Bubble sort
Quick sort
Merge Sort
What happens in selection sort
Smallest/largest element is selected from the unsorted array and swapped with the leftmost element of the unsorted section. Item now in its correct final position with the ascending/descending order. Repeat on unsorted side until all are in order
What happens in insertion sort
Item is inserted into the correct position
What happens in bubble sort
Works by swapping the items via comparison. At the end of each pass the largest item is at the end
What is the best and worst case of Insertion
- Best case O(n)
- Worst Case O(n^2)
What is the best and worst case of bubble sort
○ Best case O(n^2)
○ Worst case O(n^2)
What is the best and worst case of selection sort
○ Best case O(n^2)
○ Worst case O(n^2)
What is recursion
Recursion is a alternative method of repeating a code
Its when a function calls itself
When is recursion applied
○ Solution is easy to specify for certain conditions–stopping case.
Rules for proceeding to a new state which is either a stopping case or eventually leads to a stopping case–recursive steps
What happens in merge sort
Merge sort is when you break apart the list then in the final bit you merge so in order
What is the worst, average and best case for merge sort
- Best case O(n log n)
- Worst case O(n log n)
What happens in quick sort
You choose a pivot then compare your pointers and swap accordingly. Then you repeat this for either side of the pivot treating either side as its own list
What is the best, worst and average case of quicksort
- Best case is O(n log n)
- Worst case is n^2
- Average case is O( n logn)
What is a static array
A fixed array
Give some advantages and disadvantages of static arrays
Advantage:
Faster access to each entry as long as the index is known - O(1)
Disadvantage:
Fixed size - can not be easily extended
Can be expensive to maintain
What is a linked list
A collection of objects, called nodes
Its a dynamic data structure
What are the 2 components of nodes
Information to be stored (the data)
Reference to the next node (often called a link
In code its written as
○ head.data
§ Accesses data sorted in the first node.
○ head.link
§ Reference to the second node
Name some advantages and disadvantages of dynamic data structures
Advantages:
○ Easily extended or reduced to fit the data set.
Efficient - O(1) to insert/delete item, once located
Disadvantages:
Does not allow direct access
Uses more memory
What is the difference between a general tree, binary tree and a binary search tree
General Trees: No restriction on the number of child nodes a parent can have
Binary Trees: At most two children per node, with ordering.
Binary Search Trees: At most two children per node but left node < parent and right node > parent makes search and retrieval efficient
What is the formula for the max number if nodes in a binary search tree of height n
(2^n) -1
What is the formula for the height of a balanced binary tree
h=⌊log2(n)⌋+1