DSA Flashcards
What is a data structure?
A data structure is a way of organizing and storing data so that it can be accessed and modified efficiently.
True or False: A stack follows the Last In First Out (LIFO) principle.
True
What is the time complexity of accessing an element in an array?
O(1)
Fill in the blank: A _______ is a collection of elements that supports insertion, deletion, and searching.
data structure
Which of the following is not a linear data structure? (a) Array (b) Linked List (c) Tree (d) Stack
c) Tree
What is a queue?
A queue is a data structure that follows the First In First Out (FIFO) principle.
What is the primary purpose of a hash table?
To provide fast access to data through key-value pairs.
True or False: A binary tree can have at most two children for each node.
True
What is the worst-case time complexity for searching in a balanced binary search tree?
O(log n)
What is the difference between a binary tree and a binary search tree?
In a binary search tree, the left child of a node contains only nodes with values less than the parent node, and the right child only contains nodes with values greater than the parent node.
What is a graph?
A graph is a collection of nodes (or vertices) and edges connecting pairs of nodes.
Fill in the blank: In a directed graph, edges have a _______.
direction
What algorithm would you use to find the shortest path in a weighted graph?
Dijkstra’s algorithm
True or False: A linked list can be traversed in both directions if it is doubly linked.
True
What is a priority queue?
A priority queue is an abstract data type where each element has a priority, and elements are served based on their priority.
What is the time complexity of inserting an element in a balanced AVL tree?
O(log n)
What is dynamic programming?
Dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems and storing the results to avoid redundant calculations.
Which sorting algorithm has the best average-case time complexity?
Merge sort and Quick sort both have an average-case time complexity of O(n log n).
True or False: A complete binary tree is completely filled on all levels except possibly for the lowest level.
True
What is a trie?
A trie is a type of search tree used to store a dynamic set of strings, where the keys are usually strings.
What is the space complexity of a binary tree with n nodes?
O(n)
Fill in the blank: The _______ is the element at the top of the stack.
top
What is the average time complexity for searching an element in a hash table?
O(1)
What data structure uses the enqueue and dequeue operations?
Queue
What is the primary use of a linked list?
To allow efficient insertion and deletion of elements.
True or False: In an undirected graph, edges have no direction.
True
What is the time complexity of bubble sort in the worst case?
O(n^2)
What is a circular linked list?
A circular linked list is a linked list where the last node points back to the first node.
Which algorithm is used for finding the minimum spanning tree of a graph?
Kruskal’s algorithm or Prim’s algorithm
What is the depth of a binary tree?
The depth of a binary tree is the length of the longest path from the root to a leaf node.
Fill in the blank: A _______ is a non-linear data structure that consists of nodes connected by edges.
graph