Data Structure and Algorithm Flashcards

1
Q

What is a data structure?

A

A data structure is a format for arranging, processing, accessing, and storing data. It is designed to organize data for specific uses, making it easier for users to access and manipulate the data they need.

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

What is Big-O notation?

A

Big-O notation describes the performance or complexity of an algorithm, indicating the worst-case scenario for how the running time grows as the input size increases.

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

What are the types of time complexity in Big-O notation?

A

O(1): Constant time complexity (operation takes the same time regardless of input size).
O(n): Linear time complexity (time grows linearly with input size).
O(log n): Logarithmic time complexity (time grows logarithmically, dividing the search interval).
O(n²): Squared time complexity (time grows quadratically as input size increases).

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

What is an array data structure?

A

An array is a data structure containing items of similar data types. It allows for efficient access to elements using indices.

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

What is a linked list?

A

A linked list is a linear data structure where each element (node) contains two items: the data and a reference to the next node. It is dynamic and can grow/shrink in size as needed.

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

What is the difference between stacks and queues?

A

Stacks follow Last-In-First-Out (LIFO). Operations: push (add element), pop (remove element).
Queues follow First-In-First-Out (FIFO). Operations: enqueue (add element), dequeue (remove element).

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

What is a HashMap?

A

A HashMap stores key-value pairs, where each key is hashed to a hash code for efficient access.

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

What is a tree data structure?

A

A tree is a hierarchical data structure with nodes connected by edges. Each node contains a value and may have child nodes. A binary tree is a special type of tree where each node has at most two children.

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

What is O(1) complexity in an algorithm?

A

O(1), or constant time complexity, refers to operations that take a fixed amount of time regardless of the size of the input.

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

How does a binary search tree (BST) work?

A

A binary search tree allows inserting numbers and searching for specific values. Each node has at most two children, with the left child being less than the parent node, and the right child being greater. It allows efficient searching, insertion, and deletion.

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

What is the purpose of a queue?

A

A queue is used for handling data in a First-In-First-Out (FIFO) order, which is ideal for scheduling tasks, managing resources, or processing data streams.

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

What is the push operation in a stack?

A

The push operation adds an element to the top of the stack in a Last-In-First-Out (LIFO) order.

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

What is the pop operation in a stack?

A

The pop operation removes the top element from the stack, adhering to the Last-In-First-Out (LIFO) principle.

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

What does enqueuing mean in a queue?

A

Enqueuing means adding an element to the end of the queue, following the First-In-First-Out (FIFO) order.

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

What does dequeuing mean in a queue?

A

Dequeuing means removing an element from the front of the queue, adhering to the First-In-First-Out (FIFO) principle.

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

What is the insert operation in a binary search tree (BST)?

A

The insert operation adds a new node in the correct position in the tree, ensuring that the left child is smaller and the right child is larger than the parent node.

17
Q

How would you search for an element in a binary search tree?

A

To search for an element in a BST, start at the root and compare the element with the current node’s value. If the element is smaller, move to the left child; if it is larger, move to the right child. Continue this process until the element is found or the search reaches a null node.

18
Q

What is the peek operation in a stack or queue?

A

The peek operation retrieves the top element of a stack or the front element of a queue without removing it, allowing you to view the next element to be processed.

19
Q

What is dynamic memory allocation in the context of a linked list?

A

Dynamic memory allocation refers to the process of allocating memory as needed during runtime, allowing the size of the linked list to grow or shrink dynamically without the need for a predefined size.

20
Q

Why would you choose a linked list over an array for a collection of items?

A

A linked list is more suitable for frequent additions or deletions since it doesn’t require resizing or shifting elements like an array does. It dynamically grows and shrinks, unlike fixed-size arrays.