Programming and Data Structures Flashcards
(45 cards)
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: Arrays are fixed in size.
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 can be added or removed in a last-in-first-out (LIFO) manner.
Stack
Which data structure uses FIFO (First In First Out) ordering?
Queue
What is the primary use of a linked list?
To allow for dynamic memory allocation and efficient insertion/deletion of elements.
What is the difference between a singly linked list and a doubly linked list?
A singly linked list has nodes that point to the next node only, while a doubly linked list has nodes that point to both the next and previous nodes.
What is a binary tree?
A binary tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child.
True or False: A binary search tree (BST) must have all left descendants less than the parent node and all right descendants greater than the parent node.
True
What is the average time complexity for searching an element in a balanced binary search tree?
O(log n)
What is a hash table?
A hash table is a data structure that implements an associative array, a structure that can map keys to values using a hash function.
Fill in the blank: In hash tables, __________ occurs when two keys hash to the same index.
Collision
What is the time complexity of inserting an element into a hash table on average?
O(1)
What are the two primary types of trees used in computer science?
Binary trees and n-ary trees.
What is the purpose of a priority queue?
To manage a collection of elements where each element has a priority, and elements with higher priority are served before those with lower priority.
True or False: In a max heap, the value of a parent node is always greater than or equal to the values of its children.
True
What is the space complexity of an array of size n?
O(n)
What is recursion?
Recursion is a programming technique where a function calls itself to solve smaller instances of the same problem.
Fill in the blank: The __________ algorithm is used to traverse a tree in a depth-first manner.
DFS (Depth-First Search)
What is the best-case time complexity for quicksort?
O(n log n)
What is a graph?
A graph is a collection of nodes (vertices) and edges that connect pairs of nodes.
True or False: A directed graph has edges with a direction, while an undirected graph does not.
True
What is the time complexity of Dijkstra’s algorithm for finding the shortest path in a graph?
O(V^2) with a simple array, O(E + V log V) with a priority queue.
What does Big O notation represent?
Big O notation describes the upper bound of an algorithm’s time or space complexity in terms of input size.