compsci midterm

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/61

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

62 Terms

1
New cards

What is a Stack?

A Stack is a Last-In, First-Out (LIFO) Abstract Data Type (ADT) that supports operations like push (add an element) and pop (remove the most recently added element).

2
New cards

What are ADT Bags?

An ADT Bag (or multiset) is a collection of items where the order of elements does not matter, and duplicate elements are allowed. It supports operations like adding an item, removing an item, and checking the number of occurrences of an item.

3
New cards

To expand the size of an array bag, the common practice is to:

Double the size of the array

4
New cards

When removing from an ArrayBag dealing with a gap the most common practice is to:

Replace entry being removed with the last entry in array and replace last entry with null

5
New cards

A new node is added at the:

Beginning of a list

6
New cards

A call to remove() Linkedbag will:

Remove the first node

7
New cards
8
New cards

Removing a node that is not first in a LinkedBag:

Replaces it with the first node

9
New cards

What big O notation represents exponential time

O(2^n)

10
New cards
11
New cards

What are Links (in data structures)?

In data structures, 'links' typically refer to references or pointers that connect nodes in a linked data structure (e.g., a linked list or tree). Each node contains data and one or more links to other nodes.

12
New cards

What is a Queue?

A Queue is a First-In, First-Out (FIFO) Abstract Data Type (ADT) that supports operations like enqueue (add an element to the rear) and dequeue (remove the element from the front).

13
New cards

What is the primary way elements are added and removed from a Stack?

Elements are added using the 'push' operation and removed using the 'pop' operation, both typically affecting the 'top' of the stack.

14
New cards

How does an ADT Bag handle duplicate elements compared to a Set?

An ADT Bag allows and keeps track of duplicate elements, whereas a Set only stores unique elements.

15
New cards

What is the role of a 'link' when implementing a singly linked list?

In a singly linked list, each node contains a 'link' (or pointer) that points to the next node in the sequence, forming a chain.

16
New cards

When an element is 'dequeued' from a Queue, from which end is it removed?

An element is always removed from the 'front' of the Queue.

17
New cards

Name one advantage of using a Deque over a traditional Queue or Stack.

A Deque offers greater flexibility as elements can be added or removed from both ends, accommodating scenarios where both LIFO and FIFO behavior might be needed.

18
New cards

How is the order of removal determined in a Priority Queue?

Elements are removed based on their assigned priority, typically with the highest (or lowest) priority element being removed first, regardless of its insertion order.

19
New cards

What are the two essential components every recursive method must have?

Every recursive method must have a 'base case' (a condition that stops the recursion) and a 'recursive step' (which calls the method itself with a modified input that moves closer to the base case).

20
New cards

What is the main benefit of using an Iterator to access elements in a collection?

Iterators provide a standardized way to traverse a collection without exposing its underlying internal structure, promoting encapsulation and allowing consistent traversal across different collection types.

21
New cards

What is a Stack?

A Stack is a Last-In, First-Out (LIFO) Abstract Data Type (ADT) that supports operations like push (add an element) and pop (remove the most recently added element).

22
New cards

What are ADT Bags?

An ADT Bag (or multiset) is a collection of items where the order of elements does not matter, and duplicate elements are allowed. It supports operations like adding an item, removing an item, and checking the number of occurrences of an item.

23
New cards

What are Links (in data structures)?

In data structures, 'links' typically refer to references or pointers that connect nodes in a linked data structure (e.g., a linked list or tree). Each node contains data and one or more links to other nodes.

24
New cards

What is a Queue?

A Queue is a First-In, First-Out (FIFO) Abstract Data Type (ADT) that supports operations like enqueue (add an element to the rear) and dequeue (remove the element from the front).

25
New cards

What is the primary way elements are added and removed from a Stack?

Elements are added using the 'push' operation and removed using the 'pop' operation, both typically affecting the 'top' of the stack.

26
New cards

How does an ADT Bag handle duplicate elements compared to a Set?

An ADT Bag allows and keeps track of duplicate elements, whereas a Set only stores unique elements.

27
New cards

What is the role of a 'link' when implementing a singly linked list?

In a singly linked list, each node contains a 'link' (or pointer) that points to the next node in the sequence, forming a chain.

28
New cards

When an element is 'dequeued' from a Queue, from which end is it removed?

An element is always removed from the 'front' of the Queue.

29
New cards

Name one advantage of using a Deque over a traditional Queue or Stack.

A Deque offers greater flexibility as elements can be added or removed from both ends, accommodating scenarios where both LIFO and FIFO behavior might be needed.

30
New cards

How is the order of removal determined in a Priority Queue?

Elements are removed based on their assigned priority, typically with the highest (or lowest) priority element being removed first, regardless of its insertion order.

31
New cards

What are the two essential components every recursive method must have?

Every recursive method must have a 'base case' (a condition that stops the recursion) and a 'recursive step' (which calls the method itself with a modified input that moves closer to the base case).

32
New cards

What is the main benefit of using an Iterator to access elements in a collection?

Iterators provide a standardized way to traverse a collection without exposing its underlying internal structure, promoting encapsulation and allowing consistent traversal across different collection types.

33
New cards

Imagine you are managing the "undo" functionality in a text editor. Which data structure would be most suitable to keep track of previous states for undo operations?

A Stack, because the last action performed is the first one to be undone (LIFO principle).

34
New cards

If you're counting the frequency of words in a document (e.g., "apple", "banana", "apple", "orange") and you want to store these words allowing duplicates, which ADT would you use?

An ADT Bag (or multiset), as it effectively stores all occurrences, allowing you to count them later.

35
New cards

In a linked list, if a node's 'link' reference is set to 'null', what does this typically signify?

It signifies that this node is the last node in the linked list, as it points to no subsequent node.

36
New cards

When printing multiple documents, they are usually processed in the order they were sent to the printer. Which data structure models this behavior?

A Queue, as it processes tasks on a First-In, First-Out (FIFO) basis.

37
New cards

Consider a web browser's history feature, where you can go 'back' or 'forward'. Which ADT could efficiently manage both recent pages (for 'back') and future pages (for 'forward') by adding/removing from both ends?

A Deque (Double-Ended Queue), as it allows adding and removing elements from both front (for 'forward') and rear (for 'back').

38
New cards

In a hospital emergency room, patients are often treated based on the severity of their condition, not necessarily their arrival time. Which data structure design principle does this situation exemplify?

A Priority Queue, where elements (patients) are removed and processed based on their priority (severity of condition).

39
New cards

When calculating the factorial of a number n (i.e., n! = n \times (n-1)!), the calculation for n! depends on the calculation for (n-1)!. This is an example of which programming concept?

Recursion, where a function calls itself to solve a smaller instance of the same problem until a base case (e.g., 0! = 1) is reached.

40
New cards

You have a list of students' names stored in an ArrayList and another list in a LinkedList. What mechanism allows you to process each student's name in both lists using the same loop structure, without knowing their underlying implementation?

An Iterator, which provides a standard way to traverse elements in any collection that implements the Iterable interface.

41
New cards

What is a Stack?

A Stack is a Last-In, First-Out (LIFO) Abstract Data Type (ADT) that supports operations like push (add an element) and pop (remove the most recently added element).

42
New cards

What are ADT Bags?

An ADT Bag (or multiset) is a collection of items where the order of elements does not matter, and duplicate elements are allowed. It supports operations like adding an item, removing an item, and checking the number of occurrences of an item.

43
New cards

What are Links (in data structures)?

In data structures, 'links' typically refer to references or pointers that connect nodes in a linked data structure (e.g., a linked list or tree). Each node contains data and one or more links to other nodes.

44
New cards

What is a Queue?

A Queue is a First-In, First-Out (FIFO) Abstract Data Type (ADT) that supports operations like enqueue (add an element to the rear) and dequeue (remove the element from the front).

45
New cards

What is the primary way elements are added and removed from a Stack?

Elements are added using the 'push' operation and removed using the 'pop' operation, both typically affecting the 'top' of the stack.

46
New cards

How does an ADT Bag handle duplicate elements compared to a Set?

An ADT Bag allows and keeps track of duplicate elements, whereas a Set only stores unique elements.

47
New cards

What is the role of a 'link' when implementing a singly linked list?

In a singly linked list, each node contains a 'link' (or pointer) that points to the next node in the sequence, forming a chain.

48
New cards

When an element is 'dequeued' from a Queue, from which end is it removed?

An element is always removed from the 'front' of the Queue.

49
New cards

Name one advantage of using a Deque over a traditional Queue or Stack.

A Deque offers greater flexibility as elements can be added or removed from both ends, accommodating scenarios where both LIFO and FIFO behavior might be needed.

50
New cards

How is the order of removal determined in a Priority Queue?

Elements are removed based on their assigned priority, typically with the highest (or lowest) priority element being removed first, regardless of its insertion order.

51
New cards

What are the two essential components every recursive method must have?

Every recursive method must have a 'base case' (a condition that stops the recursion) and a 'recursive step' (which calls the method itself with a modified input that moves closer to the base case).

52
New cards

What is the main benefit of using an Iterator to access elements in a collection?

Iterators provide a standardized way to traverse a collection without exposing its underlying internal structure, promoting encapsulation and allowing consistent traversal across different collection types.

53
New cards

Imagine you are managing the "undo" functionality in a text editor. Which data structure would be most suitable to keep track of previous states for undo operations?

A Stack, because the last action performed is the first one to be undone (LIFO principle).

54
New cards

If you're counting the frequency of words in a document (e.g., "apple", "banana", "apple", "orange") and you want to store these words allowing duplicates, which ADT would you use?

An ADT Bag (or multiset), as it effectively stores all occurrences, allowing you to count them later.

55
New cards

In a linked list, if a node's 'link' reference is set to 'null', what does this typically signify?

It signifies that this node is the last node in the linked list, as it points to no subsequent node.

56
New cards

When printing multiple documents, they are usually processed in the order they were sent to the printer. Which data structure models this behavior?

A Queue, as it processes tasks on a First-In, First-Out (FIFO) basis.

57
New cards

Consider a web browser's history feature, where you can go 'back' or 'forward'. Which ADT could efficiently manage both recent pages (for 'back') and future pages (for 'forward') by adding/removing from both ends?

A Deque (Double-Ended Queue), as it allows adding and removing elements from both front (for 'forward') and rear (for 'back').

58
New cards

In a hospital emergency room, patients are often treated based on the severity of their condition, not necessarily their arrival time. Which data structure design principle does this situation exemplify?

A Priority Queue, where elements (patients) are removed and processed based on their priority (severity of condition).

59
New cards

When calculating the factorial of a number n (i.e., n! = n \times (n-1)!), the calculation for n! depends on the calculation for (n-1)!. This is an example of which programming concept?

Recursion, where a function calls itself to solve a smaller instance of the same problem until a base case (e.g., 0! = 1) is reached.

60
New cards

You have a list of students' names stored in an ArrayList and another list in a LinkedList. What mechanism allows you to process each student's name in both lists using the same loop structure, without knowing their underlying implementation?

An Iterator, which provides a standard way to traverse elements in any collection that implements the Iterable interface.

61
New cards

What is UML?

UML stands for Unified Modeling Language, which is a standardized general-purpose modeling language in the field of software engineering. It is used to visualize, specify, construct, and document the artifacts of a software system.

62
New cards