Module 1 Flashcards

(52 cards)

1
Q

What is an Abstract Data Type (ADT)?

A

An ADT is a model for data characterized by a known set of behaviors (operations or methods). It defines what operations are to be performed

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

Why is an Abstract Data Type called ‘abstract’?

A

Because it provides an implementation-independent view of data

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

What does an ADT specify and not specify?

A

It specifies what operations can be performed

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

Give an example showing that an ADT can have multiple implementations.

A

The List ADT can be implemented using arrays

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

What is the process of providing only essentials and hiding details called?

A

Abstraction.

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

List the main characteristics of an Abstract Data Type (ADT).

A
  1. Facility to create a container to hold data; 2. Facility to add a new element; 3. Facility to remove an element that meets a criterion; 4. Facility to find an element that meets a criterion; 5. Facility to destroy the container when no longer needed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ‘implementation-independent’ mean in the context of ADTs?

A

It means that the ADT describes operations and behavior without depending on any specific way of implementing or storing the data.

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

How does abstraction help in programming with ADTs?

A

It simplifies development by focusing on what operations an ADT performs rather than how it performs them

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

Stack

A

A linear data structure where elements are arranged in order and all operations occur at one end called the top; follows the LIFO (Last In

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

Stack Operations

A

Push (insert)

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

Stack Underflow

A

Occurs when attempting to pop an element from an empty stack.

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

Stack Overflow

A

Occurs when attempting to push an element onto a full stack.

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

Real-life Example of Stack

A

A pile of plates — the last plate added is the first to be removed (LIFO).

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

Time Complexity of Stack Operations

A

All primary stack operations (push

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

Applications of Stack

A

Undo/Redo operations

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

Queue

A

A linear data structure where insertion happens at the rear and deletion happens at the front; follows the FIFO (First In

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

Queue Operations

A

Enqueue (insert)

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

Difference Between Stack and Queue

A

Stack is LIFO (last in

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

Time Complexity of Queue Operations

A

All basic queue operations (enqueue

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

Real-life Examples of Queue

A

People standing in a line

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

Linked List

A

A linear data structure consisting of nodes connected by pointers; each node contains data and a pointer to the next node.

22
Q

Linked List Operations

A

Get (retrieve)

23
Q

Difference Between Linked List and Array

A

Arrays use contiguous memory and allow random access; linked lists use pointers

24
Q

Advantages of Linked List

A

Dynamic size and easy insertion/deletion of nodes.

25
Disadvantages of Linked List
No random access
26
Singly Linked List
A list where each node has data and a pointer to the next node only.
27
Linked List Representation
Each node has two parts: data (stores element) and next (stores address of next node); the list starts with a pointer called head.
28
Searching
The process of finding the location of a specific element in a collection of data.
29
Linear Search
A simple search algorithm that checks each element of the list sequentially until the desired element is found or the list ends.
30
How Linear Search Works
Starts from the first element and compares each one with the target until a match is found or the list is fully traversed.
31
Time Complexity of Linear Search
O(n) — where n is the number of elements in the list.
32
Limitation of Linear Search
It is inefficient for large data sets because it checks every element.
33
Binary Search
A search algorithm that works on sorted lists by repeatedly dividing the search interval in half.
34
How Binary Search Works
Compare the target element with the middle element; if it matches
35
Condition for Binary Search
The list must be sorted in ascending or descending order before performing the search.
36
Time Complexity of Binary Search
O(log n) — where n is the number of elements.
37
Advantage of Binary Search
Much faster than linear search for large
38
Disadvantage of Binary Search
Requires the data to be sorted before searching.
39
Sorting
The process of arranging data elements in a specific order
40
Selection Sort
A simple comparison-based algorithm that repeatedly selects the smallest (or largest) element and swaps it into its correct position.
41
How Selection Sort Works
Find the smallest element and place it at the beginning; repeat for the remaining unsorted portion until the list is sorted.
42
Time Complexity of Selection Sort
O(n²) — for both best and worst cases.
43
Space Complexity of Selection Sort
O(1) — sorts in place using no extra space.
44
Advantage of Selection Sort
Simple to understand and implement.
45
Disadvantage of Selection Sort
Inefficient for large lists due to its O(n²) time complexity.
46
Bubble Sort
A simple sorting algorithm that repeatedly steps through the list
47
How Bubble Sort Works
On each pass
48
Flag in Bubble Sort
A Boolean variable used to track if any swaps occurred during a pass; if no swaps occur
49
Time Complexity of Bubble Sort
Worst and average case: O(n²); Best case (already sorted): O(n).
50
Advantage of Bubble Sort
Easy to implement and understand.
51
Disadvantage of Bubble Sort
Very inefficient for large lists.
52
Stability of Bubble Sort
It is a stable sort — equal elements retain their relative order.