Stack and Queue - Part 1: Stack

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/33

flashcard set

Earn XP

Description and Tags

Flashcards about Stacks, covering definition, operations, exceptions, applications, implementation and use cases.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

34 Terms

1
New cards

What is a Stack?

A linear data structure that can be accessed only at one of its ends for storing and retrieving data, following the Last In, First Out (LIFO) principle.

2
New cards

What are the common operations performed on a stack?

clear(), isEmpty(), push(el), pop(), top()

3
New cards

What is a Stack Exception?

An error condition that occurs when an operation of ADT cannot be executed, such as attempting to pop or top on an empty stack.

4
New cards

What are some common applications of stacks?

Parentheses nesting, evaluating arithmetic expressions, implementing function calls, backtracking, undo sequence in a text editor, auxiliary data structure for algorithms.

5
New cards

How does a Stack in computer memory actually work?

Each time a method is called, an activation record (AR) is allocated for it, containing parameters, local variables, a dynamic link, return address, and return value.

6
New cards

What is an Array-based Stack?

A simple way of implementing the Stack ADT using an array, with a variable 'top' keeping track of the index of the top element.

7
New cards

What happen if the array storing the stack elements may become full in Array-based Stack?

A push operation will throw a FullStackException

8
New cards

How is a stack implemented using a Linked List?

Implemented using nodes with references to the next node in the stack. The 'head' pointer indicates the top of the stack.

9
New cards

How can a stack be implemented using ArrayList & LinkedList classes in Java?

By using ArrayList or LinkedList classes. Both classes provide methods to implement stack operations such as push and pop.

10
New cards

How is a stack used to convert a decimal integer number to binary?

Used to convert a decimal integer number to binary by pushing remainders onto the stack and then popping them off to form the binary representation.

11
New cards

How is a stack used to validate expressions?

Used to validate that each opening symbol (parentheses, braces, brackets) matches its corresponding closing symbol in the correct order.

12
New cards

How does Matching Parentheses relate to Matching HTML Tags

Can use stack to check whether an HTML document is valid or not by check matching tags.

13
New cards

What is the Stack class in Java

A Stack class implemented in the java.util package is an extension of class Vector to which one constructor and five methods are added.

14
New cards

Summary of Stack usage

Stack is a linear data structure that can be accessed at only one of its ends for storing and retrieving data and called a Last In, First Out (LIFO) structure.

15
New cards

A linear data structure that can be accessed only at one of its ends for storing and retrieving data, following the Last In, First Out (LIFO) principle.

What is a Stack?

16
New cards

clear(), isEmpty(), push(el), pop(), top()

What are the common operations performed on a stack?

17
New cards

An error condition that occurs when an operation of ADT cannot be executed, such as attempting to pop or top on an empty stack.

What is a Stack Exception?

18
New cards

Parentheses nesting, evaluating arithmetic expressions, implementing function calls, backtracking, undo sequence in a text editor, auxiliary data structure for algorithms.

What are some common applications of stacks?

19
New cards

Each time a method is called, an activation record (AR) is allocated for it, containing parameters, local variables, a dynamic link, return address, and return value.

How does a Stack in computer memory actually work?

20
New cards

A simple way of implementing the Stack ADT using an array, with a variable 'top' keeping track of the index of the top element.

What is an Array-based Stack?

21
New cards

A push operation will throw a FullStackException

What happen if the array storing the stack elements may become full in Array-based Stack?

22
New cards

Implemented using nodes with references to the next node in the stack. The 'head' pointer indicates the top of the stack.

How is a stack implemented using a Linked List?

23
New cards

By using ArrayList or LinkedList classes. Both classes provide methods to implement stack operations such as push and pop.

How can a stack be implemented using ArrayList & LinkedList classes in Java?

24
New cards

Used to convert a decimal integer number to binary by pushing remainders onto the stack and then popping them off to form the binary representation.

How is a stack used to convert a decimal integer number to binary?

25
New cards

Used to validate that each opening symbol (parentheses, braces, brackets) matches its corresponding closing symbol in the correct order.

How is a stack used to validate expressions?

26
New cards

Can use stack to check whether an HTML document is valid or not by check matching tags.

How does Matching Parentheses relate to Matching HTML Tags

27
New cards

A Stack class implemented in the java.util package is an extension of class Vector to which one constructor and five methods are added.

What is the Stack class in Java

28
New cards

Stack is a linear data structure that can be accessed at only one of its ends for storing and retrieving data and called a Last In, First Out (LIFO) structure.

Summary of Stack usage

29
New cards

The time complexity of both push and pop operations is O(1)O(1), as they only involve accessing the top element of the array.

What is the time complexity of push and pop operations in a stack implemented using an array?

30
New cards

The space complexity is O(n)O(n), where n is the maximum number of elements that can be stored in the stack.

What is the space complexity of a stack implemented using an array?

31
New cards

The time complexity of both push and pop operations is O(1)O(1), as they only involve adding or removing the head node of the linked list.

What is the time complexity of push and pop operations in a stack implemented using a linked list?

32
New cards

The space complexity is O(n)O(n), where n is the number of elements in the stack. Each element requires a node in the linked list.

What is the space complexity of a stack implemented using a linked list?

33
New cards

Dynamic size (can grow or shrink as needed), no risk of FullStackException.

What are the advantages of using a linked list over an array for implementing a stack?

34
New cards

Better memory locality, potentially faster access, simpler implementation.

What are the advantages of using an array over a linked list for implementing a stack?