Algorithm Theories Flashcards
Steps to solve programming problems
- Read the problem completely twice.
- Solve the problem manually with 3 sets of sample data.
- Optimize the manual steps.
- Write the manual steps as comments or pseudo-code.
- Replace the comments or pseudo-code with real code.
- Optimize the real code.
Solving Problems, Breaking it Down - Simple Programmer
What is an Algorithm?
Instructions (recipes) for completing a task.
Time Complexity of Select Sort
Best: O(n^2)
Average: O(n^2)
Worst: O(n^2)
Time Complexity of Quick Sort
Best: O(n log(n))
Average: O(n log(n))
Worst: O(n^2)
Time Complexity of Merge Sort
Best: O(n log(n))
Average: O(n log(n))
Worst: O(n log(n))
Time Complexity of Bubble Sort
Best: O(n)
Average: O(n^2)
Worst: O(n^2)
Space Complexity of Quick Sort
O(n)
Space Complexity of Merge Sort
O(n)
Space Complexity of Bubble Sort
O(1)
Space Complexity of Select Sort
O(1)
Space Complexity of Insertion Sort
O(1)
Time Complexity of Insertion Sort
Best: O(n)
Average: O(n^2)
Worst: O(n^2)
What is data structure?
A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.
List out the areas in which data structures are applied extensively?
- Compiler Design,
- Operating System,
- Database Management System,
- Statistical analysis package,
- Numerical Analysis,
- Graphics,
- Artificial Intelligence,
- Simulation
What are the major data structures used in the following areas : RDBMS, Network data model and Hierarchical data model.
- RDBMS = Array (i.e. Array of structures)
- Network data model = Graph
- Hierarchical data model = Trees
What is the data structures used to perform recursion?
Stack. Because of its LIFO (Last In First Out) property it remembers its ‘caller’ so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls.
Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.
De Morgan’s Laws
// Negation of conjunction (!a && !b) == !(a || b)
// Negation of disjunction (!a || !b) == !(a && b)
http://eddmann.com/posts/understanding-de-morgans-laws-to-simplify-propositions/