Stacks Flashcards

1
Q

What is a stack implementation?

A

it is like a container that stores a collection of elements, they adopt a LIFO last in first out method of accessing the elements.

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

what are supported operations that can be done with stack?

A

return the size, determine if its empty, empty the stack

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

what are operations that you cant do with stack?

A

search the stack for a specific element, remove specific element, deal with specific elements.

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

what does push() do

A

stores an element at the top of the stack pointed to by parameter stack

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

what does pop() do

A

removes the elements at the top of the stack, returns true when complete of false if the stack is empty

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

what does peek() do

A

retrieves the element from the top of the stack and returns true as long as the stack is not empty when peek is called

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

what is the computational time for a stack?

A

size() O(1)
check_empty() O(1)
empty() O(n)
peek() O(1)
push(data) O(1)
pop() O(1)

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

what are some applications of stack implementation?

A

◼ Page-visited history in a Web browser
◼ Undo sequence in a text editor
◼ Chain of method calls in the Java Virtual Machine

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

What is a stack?

A

A stack is a collection of elements that maintains the order in which they were added, following the last-in, first-out (LIFO) principle

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

What are the fundamental operations provided by stacks?

A

The fundamental operations provided by stacks include push (add an element to the top of the stack), pop (remove and return the top element from the stack), and peek (return the top element without removing it)

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

How can you implement a stack using a linked list?

A

You can implement a stack using a linked list by treating the head node of the linked list as the top of the stack and performing push and pop operations by inserting and removing nodes at the head of the list, respectively.

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

What additional operations are typically not provided by stack implementations?

A

Additional operations typically not provided by stack implementations include searching for a specific element, removing a specific element, and accessing elements at specific positions in the stack, as these operations contradict the stack’s LIFO protocol

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

How can you determine if a stack is empty?

A

You can determine if a stack is empty by checking if the size of the stack is 0.

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

What is the computational time complexity of common stack operations?

A

Common stack operations such as push, pop, and peek typically have a computational time complexity of O(1), meaning their execution time does not depend on the size of the stack

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

What are some applications of stacks in computing?

A

Some applications of stacks in computing include maintaining page-visited history in web browsers, implementing an undo sequence in text editors, and managing the chain of method calls in the Java Virtual Machine.

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