Basic questions about data structures and algorithms Flashcards

(25 cards)

1
Q

Define data structure.

A

A way to organize and store data for efficient access and modification.

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

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

A

O(1), meaning constant time regardless of the array size.

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

True or false: A linked list allows for efficient insertions and deletions.

A

TRUE

Linked lists can insert or delete nodes without shifting elements.

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

Fill in the blank: A stack follows the _______ principle.

A

Last In, First Out (LIFO)

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

What is a queue?

A

A data structure that follows the First In, First Out (FIFO) principle.

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

Define binary tree.

A

A tree data structure where each node has at most two children.

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

What is the height of a tree?

A

The length of the longest path from the root to a leaf node.

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

True or false: A hash table provides average O(1) time complexity for lookups.

A

TRUE

This efficiency depends on a good hash function and low collision rate.

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

What is merge sort?

A

A divide-and-conquer algorithm that sorts by merging sorted subarrays.

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

Define graph.

A

A collection of nodes connected by edges, representing relationships.

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

Fill in the blank: In a binary search tree, the left child is _______ than the parent.

A

less than

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

What is Big O notation?

A

A mathematical notation to describe the upper limit of an algorithm’s time or space complexity.

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

True or false: Depth-first search explores all neighbors before going deeper.

A

FALSE

Depth-first search goes as deep as possible before backtracking.

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

What is the space complexity of an algorithm?

A

The amount of memory space required by the algorithm as a function of input size.

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

Define dynamic programming.

A

An optimization technique that solves problems by breaking them down into simpler subproblems.

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

Fill in the blank: A priority queue allows elements to be processed based on their _______.

17
Q

What is a trie?

A

A tree-like data structure used to store a dynamic set of strings.

18
Q

True or false: Breadth-first search uses a stack for traversal.

A

FALSE

Breadth-first search uses a queue to explore nodes level by level.

19
Q

What is a subarray?

A

A contiguous portion of an array.

20
Q

Define algorithm.

A

A step-by-step procedure for solving a problem or performing a task.

21
Q

Fill in the blank: The selection sort algorithm repeatedly selects the _______ element.

22
Q

What is the worst-case time complexity of quicksort?

A

O(n^2), occurring when the pivot is the smallest or largest element.

23
Q

True or false: A balanced tree maintains its height to be logarithmic in relation to the number of nodes.

A

TRUE

Balanced trees ensure efficient operations like insertion and deletion.

24
Q

What is a singly linked list?

A

A linked list where each node points to the next node and has no backward link.

25
Define **insertion sort**.
A simple sorting algorithm that builds a sorted array one element at a time.