comp 2503 midterm Flashcards
What is computational complexity?
The amount of resources (time and space) required by an algorithm to solve a problem as a function of input size
What is Big-O notation used for?
To describe the upper bound or worst-case growth rate of an algorithm’s resource usage
What is the difference between LIFO and FIFO?
LIFO (Last In First Out) is used by stacks where the last element added is the first removed. FIFO (First In First Out) is used by queues where the first element added is the first removed
What are the main operations of a Stack?
push (add to top), pop (remove from top), peek (view top without removing), isEmpty
What are the main operations of a Queue?
enqueue (add to rear), dequeue (remove from front), peek (view front without removing), isEmpty
What makes Binary Search more efficient than Linear Search?
Binary Search divides the search space in half each time (O(log n)), while Linear Search checks each element sequentially (O(n))
What is the purpose of generics in Java?
To enable classes to work with different data types while maintaining type safety at compile time
What is the Comparable interface used for?
To define a natural ordering for a class by implementing the compareTo method
What is the Comparator interface used for?
To define multiple different ways to compare objects of a class without modifying the class itself
What are the key differences between arrays and linked lists?
Arrays have fixed size and continuous memory with direct access, while linked lists have dynamic size, scattered memory, and sequential access
What is the time complexity of adding to the front of an array vs. linked list?
Array: O(n) due to shifting elements, Linked List: O(1) by changing the head pointer
What is the time complexity of accessing an element by index in array vs. linked list?
Array: O(1) direct access, Linked List: O(n) must traverse from start
What are traversal pointers in linked lists used for?
To move through the list one node at a time, often used to search, modify, or perform operations on nodes
What is the difference between Singly and Doubly Linked Lists?
Singly Linked Lists have nodes with one pointer to the next node, Doubly Linked Lists have nodes with pointers to both next and previous nodes
Why use a Doubly Linked List over a Singly Linked List?
Doubly Linked Lists allow backward traversal and easier deletion of nodes, but use more memory per node