Study Notes

Algorithms & Data Structures: Exam Essentials

daedsa@bigonedULTRA
0 imports

Free ยท 2 imports included

Study Notes Preview

8 sections locked
Section 1

Algorithms & Data Structures: Exam Essentials

STUDY GUIDE

๐ŸŽ“ CSE1305 Algorithms and Data Structures Exam - Study Guide

๐Ÿ“‹ Course Structure

code
๐Ÿ“š Algorithms and Data Structures โ”œโ”€โ”€ ๐Ÿ“– Chapter 1: Time and Space Complexity Analysis โ”œโ”€โ”€ ๐Ÿ“– Chapter 2: Linear Data Structures: Arrays, Linked Lists, Stacks, and Queues โ”œโ”€โ”€ ๐Ÿ“– Chapter 3: Trees โ”œโ”€โ”€ ๐Ÿ“– Chapter 4: Priority Queues โ”œโ”€โ”€ ๐Ÿ“– Chapter 5: Sorting Algorithms โ”œโ”€โ”€ ๐Ÿ“– Chapter 6: Maps โ”œโ”€โ”€ ๐Ÿ“– Chapter 7: Sets โ”œโ”€โ”€ ๐Ÿ“– Chapter 8: Search Trees โ””โ”€โ”€ ๐Ÿ“– Chapter 9: Graphs
Section 2

๐Ÿ“– Chapter 1: Time and Space Complexity Analysis

What this chapter covers: This chapter introduces how to analyze the efficiency of algorithms, focusing on both empirical and theoretical approaches. It covers asymptotic notations (Big-Oh, Big-Omega, Big-Theta) and their applications in determining algorithm performance.

๐Ÿ”‘ Essential Concepts & Formulas

Concept/FormulaDefinition/EquationWhen to UseExample
Big-Oh Notationf(n)=O(g(n))f(n) = O(g(n)) if there exist constants c>0c > 0 and n0>1n_0 > 1 such that f(n)โ‰คcโ‹…g(n)f(n) \leq c \cdot g(n) for all nโ‰ฅn0n \geq n_0Worst-case scenario3n2+2n+1=O(n2)3n^2 + 2n + 1 = O(n^2)
Big-Omega Notationf(n)=ฮฉ(g(n))f(n) = \Omega(g(n)) if there exist constants c>0c > 0 and n0โ‰ฅ1n_0 \geq 1 such that f(n)โ‰ฅcโ‹…g(n)f(n) \geq c \cdot g(n) for all nโ‰ฅn0n \geq n_0Best-case scenario3n2+2n+1=ฮฉ(n2)3n^2 + 2n + 1 = \Omega(n^2)
Big-Theta Notationf(n)=ฮ˜(g(n))f(n) = \Theta(g(n)) if there exist constants cโ€ฒ>0c' > 0, cโ€ฒโ€ฒ>0c'' > 0, and n0โ‰ฅ1n_0 \geq 1 such that cโ€ฒโ‹…g(n)โ‰คf(n)โ‰คcโ€ฒโ€ฒโ‹…g(n)c' \cdot g(n) \leq f(n) \leq c'' \cdot g(n) for all nโ‰ฅn0n \geq n_0Average-case scenario3n2+2n+1=ฮ˜(n2)3n^2 + 2n + 1 = \Theta(n^2)
Time Complexity of Recursive FunctionT(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n)Analyzing recursive algorithmsDivide and conquer algorithms

๐Ÿ› ๏ธ Problem Types

Type A: Determining Big-Oh Complexity

Setup: "Given a code snippet or algorithm description."

Method: "Identify the dominant operations, count the number of operations as a function of input size nn, and express the result using Big-Oh notation."

Type B: Comparing Growth Rates

Setup: "Given two functions f(n)f(n) and g(n)g(n)."

Method: "Determine which function grows faster as nn approaches infinity by comparing their asymptotic behavior."

๐Ÿงฎ Solved Example

Problem: Determine the Big-Oh complexity of the following code:

java
for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.println(i + j); } }

Given: Nested loops, each iterating nn times.

Steps:

  1. The outer loop runs nn times.
  2. The inner loop also runs nn times for each iteration of the outer loop.
  3. The System.out.println() statement executes nโˆ—n=n2n * n = n^2 times.
"
โœ…
Answer: O(n2)O(n^2)

โš ๏ธ Common Mistakes

โŒ Mistake: Incorrectly identifying the dominant term in a polynomial function.

โœ… How to avoid: Focus on the term with the highest power of nn as nn approaches infinity.

๐Ÿ“– Chapter 2: Linear Data Structures: Arrays, Linked Lists, Stacks, and Queues

What this chapter covers: This chapter explores fundamental linear data structures and their respective operations. It covers arrays, singly and doubly linked lists, stacks (LIFO), queues (FIFO), and their implementations.

๐Ÿ”‘ Essential Concepts & Formulas

Concept/FormulaDefinition/EquationWhen to UseExample
Array AccessAccessing an element at index iiWhen you need direct access to elementsarray[i]
Linked List Insertion at HeadAdding a new node at the beginning of the listWhen you need to insert elements at the beginning frequently
Stack (LIFO)Last-In-First-OutManaging function calls, undo operationspush(), pop()
Queue (FIFO)First-In-First-OutManaging tasks, print queueenqueue(), dequeue()

๐Ÿ› ๏ธ Problem Types

Type A: Implementing a Stack

Setup: "Implement a stack using an array or linked list."

Method: "Define the push() and pop() operations, ensuring LIFO behavior."

Type B: Detecting a Cycle in a Linked List

Setup: "Given a linked list, determine if it contains a cycle."

Method: "Use Floyd's cycle-finding algorithm (tortoise and hare)."

๐Ÿงฎ Solved Example

Problem: Implement a queue using a circular array.

Given: An array and two pointers, head and tail.

Steps:

  1. Initialize head and tail to 0.
  2. To enqueue, add the element at array[tail] and increment tail modulo array size.
  3. To dequeue, return array[head] and increment head modulo array size.
"
โœ…
Answer: Circular array implementation of a queue.

โš ๏ธ Common Mistakes

โŒ Mistake: Failing to handle edge cases in linked list operations (e.g., empty list).

โœ… How to avoid: Always check for null pointers and empty list conditions.

๐Ÿ“– Chapter 3: Trees

What this chapter covers: This chapter introduces tree data structures, focusing on binary trees, their properties, and traversal algorithms. It covers abstract base classes, binary tree properties, and implementations.

๐Ÿ”‘ Essential Concepts & Formulas

Concept/FormulaDefinition/EquationWhen to UseExample
Binary TreeA tree where each node has at most two childrenRepresenting hierarchical data
Preorder TraversalVisit root, left subtree, right subtreeCreating a prefix expression from a tree
Inorder TraversalVisit left subtree, root, right subtreeCreating an infix expression from a tree
Postorder TraversalVisit left subtree, right subtree, rootCreating a postfix expression from a tree

๐Ÿ› ๏ธ Problem Types

Type A: Tree Traversal

Setup: "Given a binary tree, perform a specific traversal (preorder, inorder, postorder)."

Method: "Recursively visit the nodes in the specified order."

Type B: Checking if a Tree is Balanced

Setup: "Given a binary tree, determine if it is balanced."

Method: "Calculate the height of the left and right subtrees for each node and check if the difference is within a certain limit (e.g., 1 for AVL trees)."

๐Ÿงฎ Solved Example

Problem: Perform an inorder traversal of the following binary tree:

code
1 / \ 2 3 / \ 4 5

Given: A binary tree.

Steps:

  1. Visit the left subtree of 1: The left subtree is rooted at 2.
  2. Visit the left subtree of 2: 4
  3. Visit 2
  4. Visit the right subtree of 2: 5
  5. Visit 1
  6. Visit the right subtree of 1: 3
"
โœ…
Answer: 4, 2, 5, 1, 3

โš ๏ธ Common Mistakes

โŒ Mistake: Confusing the order of nodes in different tree traversals.

โœ… How to avoid: Remember the specific order for each traversal (root, left, right).

8 more sections

Create a free account to import and read the full study notes โ€” all 10 sections.

No credit card ยท 2 free imports included

    Algorithms & Data Structures: Exam Essentials โ€” Cheatsheet | Evrika | Evrika Study