Data structures and algorithsm Flashcards
What is a linked list
A dynamic data structure where each node consists of data and a pointer. The pointer gives the location of the next node.
What is a tree
A data structure that consists of nodes and sub nodes. The first node is called the root and lines that join nodes are called branches.
What is a binary tree
A type of tree where each node has a maximum of two sub nodes. If a child node is less than the parent node, to goes to the left of the parent and if a child node is greater than the parent node is goes to the right of the parent.
What is depth-first traversal?
Dept-first traversal is an algorithm for searching a graph/tree. It goes to the left child node when it can and if there is no left child it goes to the right child. When there are no child nodes, the algorithm backtracks to the parent node. It uses a stack.
What is breadth-first traversal?
Breadth-first traversal is an alghorithm for searching a graph/tree. It visits all nodes connected directly to the start node, then visits all nodes directly connected to each of those nodes directly connected to each of those nodes and so on. it uses a queue.
What are the advantages of depth-first traversal in comparison to breath-fiorst traversal
Depth-first traversal require less memory than breath-first tranversal. It is also quicker if you are looking at deep parts of the tree.
What are the disadvantages of depth-first traversal in comparison to breadth-first traversal.
Depth-first isn’t guarateed to find the quickest solution and possibly many never find the solution if we don’t take precautions not to revisit previously visited state.s
What is a Stack.
A data structure that operates on a first in last out basis.
What is a queue.
A data structure that oerates on a first in first out basis,.
What is a hash table?
A data structure that maps keys to values. It uses a hash function to generate the key.
What is the difference between an Array and a linked list.
An array is static yet a linked list is dynamic
Elements in arrays can be accessed directly but has to be traversed ina linked list.
Contents of array are stored contiguously in memory nit a linked list might not be.
What is meant by a graph structure?
A collection of data (nodes) and connections (edges) are made between nodes. Edges can directional, bi-directional directed or undirected.
Define Big O notiation
The Big O notation describes the complexity of an algorithm, It evalutates the worst-case scenario for an algorithm and shows how time/ memory increase as data size increases.
What is meant by logarithmic growth in terms the complexity of an algorithm
As the size of an array increases, the rate at which the algorithm runs increases more slowly. This is the inverse of exponential growth, the rate of increase is a logarithmic function of the size of an array.
When might a linear search perform better than a binary search?
If the data set is small or if the item being search for is close to the start of the array.