DSA Flashcards

1
Q

What is an Array

A

An array is a collection of homogeneous elements or values that can be identified and accessed using their index or position within the array.

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

Array Operations

A
  1. Accessing an Element: This operation involves retrieving the value of an element at a specific index in the array.
  2. Isertion: Insertion refers to adding an element to the array at a specific position or appending it to the end of the array.
    Example: Inserting the value 60 at the end of an integer array
  3. Deletion involves removing an element from the array, either by specifying its index or its value.
    Example: Deleting the second element (value 20) from an integer array arr
  4. Search: Search involves finding the index or position of a specific element within the array.
    Example: Searching for the value 30 within an integer array
  5. **Update: Updating an element means modifying its value at a specific index in the array.
    Example: Updating the fourth element (value 40) to 45 in an integer array arr in Java:
    java
    int[] arr = {10, 20, 30, 40, 50};
    arr[3] = 45;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Divide and Conquer

A

a problem-solving technique in computer science and mathematics that involves breaking a problem into smaller, more manageable subproblems, solving the subproblems independently, and then combining their solutions to solve the original problem.

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

Greedy Algorithms

A

These algorithm makes the locally optimal choice at each step with the hope of finding a globally optimal solution. In other words, a greedy algorithm makes the best choice at each step without considering the consequences of that choice on future steps.

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

Dynamic Programming

A

Dynamic programming is defined as a computer programming technique where an algorithmic problem is first broken down into sub-problems, the results are saved, and then the sub-problems are optimized to find the overall solution — which usually has to do with finding the maximum and minimum range of the algorithmic

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

Bubble sort Algorithm

A

Bubble Sort Algorithm:
Bubble Sort is a simple comparison-based sorting algorithm. It repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, indicating that the list is sorted.

Steps:

Start from the first element (index 0) and compare it with the next element (index 1).
If the first element is greater than the second element, swap them.
Continue this process for all adjacent pairs in the list, moving from left to right.
After the first pass, the largest element will have “bubbled up” to the end of the list.
Repeat steps 1-4 for the remaining unsorted portion of the list (excluding the last element).
Continue these passes until no more swaps are needed.
Complexity:

Time Complexity: O(n^2) in the worst case.
Space Complexity: O(1).

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

Quick Sort

A

Quick Sort:

Algorithm:
Quick Sort is a divide-and-conquer sorting algorithm. It works by selecting a “pivot” element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then recursively sorted.

Steps:

Choose a pivot element from the array (e.g., the last element).
Partition the array into two sub-arrays: elements less than the pivot and elements greater than the pivot.
Recursively apply Quick Sort to the sub-arrays.
Combine the sorted sub-arrays and the pivot to produce the sorted array.
Complexity:

Time Complexity: Average-case time complexity is O(n log n), while the worst-case time complexity is O(n^2) (if a bad pivot choice is consistently made).
Space Complexity: O(log n) in the average case for the recursive call stack.

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

Queue Structure

A

A Queue is a linear data structure that follows the First-In-First-Out (FIFO) principle, meaning that the first element added to the queue will be the first one to be removed.

Key characteristics and operations of a Queue:

Enqueue (Insertion): This operation is used to add an element to the back or end of the queue. It is also referred to as “push” in some contexts.

Dequeue (Removal): This operation is used to remove and return the element from the front or head of the queue. It is also referred to as “pop” in some contexts.

Front: The front of the queue refers to the element that will be removed next (the oldest element).

Rear (or Back): The rear of the queue refers to the element that was most recently added (the newest element).

Empty Queue: A queue is considered empty when it contains no elements.

Full Queue: Depending on the implementation, a queue can be bounded (with a maximum capacity) or unbounded (with dynamic resizing). A queue is considered full when it reaches its maximum capacity in bounded implementations.

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

Queue vs Stack

A
  1. Order of Elements:

Queue: Follows the FIFO (First-In-First-Out) order, meaning the first element added is the first one removed.
Stack: Follows the LIFO (Last-In-First-Out) order, meaning the last element added is the first one removed.
Insertion and Removal Points:

  1. Queue: Elements are inserted at the rear (end) and removed from the front (head).
    Stack: Elements are pushed onto the top and popped from the top (last-in, first-out).
    Usage:

Q3. ueue: Used in scenarios where order preservation matters, such as task scheduling, print job management, and breadth-first search algorithms.
Stack: Used when the order of processing or undo operations is important, such as function call stack in recursion and backtracking algorithms.
Applications:

  1. Queue: Used in scenarios where multiple entities need to access a resource in a fair and ordered manner.
    Stack: Used in scenarios where the most recent item should be accessed first, such as keeping track of function calls and their local variables in programming languages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Hashing

A

is a technique that involves the use of a mathematical function to convert input data into a fixed-length output. It is done by mapping data to specific locations or indices within a data structure, typically an array or hash table.

The goal of hashing is to quickly and efficiently retrieve data based on its key, making it a common choice for data retrieval operations.

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

Asymptotic notations

A

Asymptotic notations are mathematical notations used to analyze and describe the running time (time complexity) and space usage (space complexity) of algorithms in computer science. They provide a way to describe the growth rate of resource consumption as the input size of a problem approaches infinity.

  1. Big O notation (O()),
  2. Omega notation (Ω()), and
  3. Theta notation (Θ()).

1. Big O Notation (O()):
Concept: Big O notation represents the upper bound or worst-case scenario of an algorithm’s time or space complexity.eg. algorithm has a time complexity of O(n), it means that its running time grows linearly with the input size.

2. Omega Notation (Ω()):
Concept: Omega notation represents the lower bound or best-case scenario of an algorithm’s time or space complexity. It provides a lower limit on the growth rate of resource usage as the input size increases.
eg. if an algorithm has a time complexity of Ω(n^2), it means that its running time grows at least as fast as n^2.

3. Theta Notation (Θ()):
Concept: Theta notation represents both the upper and lower bounds of an algorithm’s time or space complexity. It provides a tight bound on the growth rate of resource usage, indicating that it neither overestimates nor underestimates the actual complexity.
Usage: It is used to express the tight bound on the time complexity of an algorithm. For example, if an algorithm has a time complexity of Θ(n), it means that its running time grows exactly linearly with the input size.

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

Advantages of array

A
  1. Contiguous memory Allocation:Elements in an array are stored in contiguous memory locations,
  2. Efficient Random Access:
  3. Easy to Implement
    4. Predictable Performance:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Disadvantages of Array

A
  1. Fixed Size
  2. Wasted Memory: Arrays allocate memory for the maximum number of elements they can hold, even if you don’t use that capacity.
  3. cant handle heterogenous data
  4. not suitable for Key-Value storage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

why do we need Linked List?

A
  1. Dynamic sizing
  2. Memory efficiency
  3. Constant time insertions
  4. No fixed size
  5. Flexible insertion and deletion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Types of Linked Lists

A
  1. Hash Linked List: used within a hash table to handle collisions
  2. Sparsed LinkedLists: used to represent sparse data structures where most of the elements are empty or have default values.
  3. Self-adjusting Lists (e.g., Move-to-Front List): Lists where accessed elements are moved to the front (head) of the list, improving access times for frequently accessed items.
  4. Skip List:
    A more complex data structure that uses multiple layers of linked lists.
  5. Circular Linked List:
    Similar to singly or doubly linked lists but with the last node pointing back to the first node (in a circular fashion).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Stack Operations

A
  1. Pop: Operation for removing elements from a stack.
  2. Push: operation for adding to a Stack
  3. IsEmpty:used in checking if a stack is empty. Returns True or False
17
Q

Stack vs Queue

A
  1. Order of operation(LIFO,FIFO)
  2. Operation types(POP and Push, enQueue and deQueue
18
Q

Defin Searching

A

The process of finding a specific item or target within a collection of data, such as a dataset, database, list, or array. The goal of searching is to determine whether the target item exists within the dataset and, if so, to locate its position or retrieve information related to it.

19
Q

Binary Search

A

Binary Search is a widely used searching algorithm that operates on sorted data.

It efficiently locates a specific target element within a sorted collection by repeatedly dividing the search interval in half, discarding the half that cannot contain the target element, and continuing the search in the remaining half.
Binary search is also known as “logarithmic search” because it has a time complexity of O(log n), making it highly efficient for large datasets.

20
Q

Hashing Problems

A
  1. Collisions - Collisions occur when two different input values produce the same hash value. Collisions can lead to data loss or incorrect retrieval if not handled properly. Solution - Open Addressing or probing

2.Hash function Overhead - Calculating hash values can introduce computational overhead, especially for complex hash functions.

  1. Hash Table size: Resizing is necessary
21
Q

Time Complexity notations

A

1 = Constant time
Log n = Logrithmic time
n = Linear time
nLogn = Linear Logrithmic time
n^2 = Quadratic time
2^n = Exponential Time

22
Q
A
23
Q
A