DSA Flashcards

1
Q

What is Stack and where it can be used?

A

A stack is a linear data structure that follows the LIFO principle, which means that the element inserted first will be removed last. It is commonly used in managing function invocations, undo/redo, and routing.

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

Can Binary Search be used for linked lists?

A

Binary Search cannot be used for linked lists in its traditional form, as linked lists are not random access data structures. Binary Search works by dividing the array into two halves and checking the middle element to determine which half to search in. This approach is not applicable to linked lists because we cannot access the middle element directly, we have to traverse the list one by one to reach the middle element.

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

What is a Linked List and What are its types?

A

A linked list is a linear data structure in which each element (node) contains a value and a reference to the next element in the list. The first node is called the head of the list, and the last node is called the tail. Linked lists can be used to implement various abstract data types such as stacks, queues, and associative arrays.

There are two main types of linked lists:

Singly-linked list: In a singly linked list, each node has a reference to the next node in the list, but not to the previous node. The last node in the list points to a null value to indicate the end of the list.

Doubly linked list: In a doubly linked list, each node has references to both the next and previous nodes in the list. This allows for more efficient traversal in both directions, but requires more memory to store the additional reference.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly