Programming and Data Structures Flashcards

(45 cards)

1
Q

What is a data structure?

A

A data structure is a way of organizing and storing data so that it can be accessed and modified efficiently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Arrays are fixed in size.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the time complexity of accessing an element in an array?

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: A __________ is a collection of elements that can be added or removed in a last-in-first-out (LIFO) manner.

A

Stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which data structure uses FIFO (First In First Out) ordering?

A

Queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the primary use of a linked list?

A

To allow for dynamic memory allocation and efficient insertion/deletion of elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between a singly linked list and a doubly linked list?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a binary tree?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the average time complexity for searching an element in a balanced binary search tree?

A

O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a hash table?

A

A hash table is a data structure that implements an associative array, a structure that can map keys to values using a hash function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Fill in the blank: In hash tables, __________ occurs when two keys hash to the same index.

A

Collision

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the time complexity of inserting an element into a hash table on average?

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the two primary types of trees used in computer science?

A

Binary trees and n-ary trees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of a priority queue?

A

To manage a collection of elements where each element has a priority, and elements with higher priority are served before those with lower priority.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the space complexity of an array of size n?

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is recursion?

A

Recursion is a programming technique where a function calls itself to solve smaller instances of the same problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Fill in the blank: The __________ algorithm is used to traverse a tree in a depth-first manner.

A

DFS (Depth-First Search)

20
Q

What is the best-case time complexity for quicksort?

21
Q

What is a graph?

A

A graph is a collection of nodes (vertices) and edges that connect pairs of nodes.

22
Q

True or False: A directed graph has edges with a direction, while an undirected graph does not.

23
Q

What is the time complexity of Dijkstra’s algorithm for finding the shortest path in a graph?

A

O(V^2) with a simple array, O(E + V log V) with a priority queue.

24
Q

What does Big O notation represent?

A

Big O notation describes the upper bound of an algorithm’s time or space complexity in terms of input size.

25
Fill in the blank: The __________ sort algorithm divides the array into sub-arrays and recursively sorts them.
Merge
26
What is the time complexity of bubble sort in the worst case?
O(n^2)
27
What is an adjacency matrix?
An adjacency matrix is a square matrix used to represent a finite graph, where the element at row i and column j indicates whether there is an edge from vertex i to vertex j.
28
Fill in the blank: A __________ is a data structure that allows for dynamic memory allocation.
Linked list
29
What is the purpose of a stack?
To store data in a last-in, first-out manner, allowing for efficient access and manipulation of the most recently added element.
30
True or False: A queue can be implemented using two stacks.
True
31
What is a circular linked list?
A circular linked list is a linked list where the last node points back to the first node, creating a circular structure.
32
What is a trie?
A trie is a special type of tree used to store associative data structures, primarily used for storing strings.
33
What is the worst-case time complexity for accessing an element in a linked list?
O(n)
34
What is the purpose of a binary search?
To efficiently find the position of a target value within a sorted array.
35
True or False: In a binary search tree, the left subtree must contain only nodes with values less than the node’s value.
True
36
What is a self-balancing binary search tree?
A self-balancing binary search tree automatically keeps its height balanced during insertions and deletions to ensure O(log n) time complexity for operations.
37
Fill in the blank: The __________ algorithm is used to find the minimum spanning tree of a graph.
Kruskal's
38
What is the time complexity of insertion in a linked list?
O(1) if the position is known, O(n) if it requires traversal.
39
What is a data structure that allows for duplicate elements?
Multiset
40
True or False: All binary trees are binary search trees.
False
41
What is the purpose of a heap?
To maintain a complete binary tree structure that allows for efficient retrieval of the maximum or minimum element.
42
What is the time complexity of breadth-first search (BFS) in a graph?
O(V + E)
43
Fill in the blank: A __________ is a specialized tree that maintains a sorted order of its elements.
Binary Search Tree
44
What is the main advantage of using a hash table?
Fast access to elements using keys, typically in O(1) time.
45
What is the time complexity of linear search?
O(n)