CS 3303 Programming Assignment Unit 3
CS 3303 Programming Assignment Unit 3
Algorithm Design.
Algorithm Design.
Basic stack data structure Algorithm Design.
manufacturing assembly line, I came up with a stack implementation using either an array or
linked list. Here is a Java implementation for both methods, along with a brief explanation on
Algorithm Design.
class Node {
int value;
Node next;
class Stack {
private Node top;
4
Algorithm Design.
Algorithm Design.
Push Operation: O(1)- Pushing an item onto the stack is a constant time operation
because it involves appending an item to the end of the array.
Pop Operation: O(1)- Popping an item from the stack is also a constant time operation because it
involves removing an item from the end of the array.
It will always take constant time to Insert and delete a node. The time complexity of
push() and pop() operations in a stack using linked list is O(1).
Both implementations serve their purpose but of course using the array-based implementation
has both its advantages and disadvantages.
The time complexity of both the implementations are the same but the linked list
implementation has a slightly better space complexity.
When posting an algorithm, it is always expedient to compare its efficiency with other
algorithms, focusing on the impact of the implementation choice (array vs. linked list) and how it
affects the performance and memory usage.
Algorithm Design.
References:
Shaffer, C. (2011). A Practical Introduction to Data Structures and Algorithm Analysis. Blacksburg:
Virginia. Tech.