Time Complexity and Algorithm Classifications

studied byStudied by 3 people
5.0(1)
Get a hint
Hint

what is a selection sort?

1 / 25

flashcard set

Earn XP

Description and Tags

26 Terms

1

what is a selection sort?

Selection Sort algorithm repeatedly finds the smallest element in the unsorted tail region of a list and moves it to the front

New cards
2

what is the time complexity for a selection sort?

With an array of size n, count how many primitive operations are needed: 1st run = n + 2 2nd run = (n -1) elements + 2 operations 3rd run = (n-2) elements + 2 operations 2 is the swapping operations minus 1 from n each time because biggest value at the end so doesn't need to be swapped

simplified to O(n²)

New cards
3

what is a search algorithm?

check for an element from any data structure where it is stored

New cards
4

what are the 2 main search algorithms?

sequential search interval search

New cards
5

what is a sequential search + example?

eg. linear search list traversed sequentially and every element checked list does not need to be sorted brute force algorithm

New cards
6

what is an interval search + example?

eg. binary search divide and conquer algorithm list must be sorted

New cards
7

what is the time complexity for binary search?

O(log₂n)

New cards
8

what is the time complexity for linear search?

O(n)

New cards
9

is binary search or linear search faster?

binary search

New cards
10

for an unsorted list of millions of elements, is binary or linear search better + why?

  • binary search needs an already sorted array so combined with selection sort, time complicity = n² causing overall algorithm slower

  • if performing search multiple times, use binary as we only have to sort once

  • if performing search once, better to use linear

New cards
11

what is polynomial time?

an algorithm is solvable in polynomial time if the number of steps required to complete the algorithm for a given input is O(nᵏ) for some non-negative integer k, n being the complexity of the input

New cards
12

for algorithms with high computational complexity, how do we know there isn't a better algorithm with a lower time complexity?

we are dividing algorithms into classifications which limits the lowest time complexity it can have

New cards
13

what are the ways a problem can be classified

computable non-computable

P problems NP problems NP-complete problems NP-Hard problems

New cards
14

what is a computable problem?

problem can be solved using computer

New cards
15

what is a non computable problem?

can't be solved using computer eg. halting problem

New cards
16

what are P problems?

  • solved in polynomial time aka. a reasonable amount of time

New cards
17

what are examples of P problems?

eg. search and sort algorithms

New cards
18

what are NP-Complete problems?

The hardest problems in NP set

  • No polynomial-time algorithm is discovered for any NP-complete problem

  • Verifiable in polynomial time but time complexity is greater than polynomial time

New cards
19

what are examples of NP-complete problems?

travelling salesperson?

knapsack problem

finding shortest common superstring

Given three positive integers a, b, and c, do there exist positive integers (x and y) such that ax2 + by2 = c

New cards
20

what are NP problems?

  • difficult to solve in polynomial time

  • easy to verify the solution in polynomial time

New cards
21

what are examples of NP problems?

eg. network routing, database problems, scheduling

non-deterministic algorithms

decision-making problems

New cards
22

why are NP-Complete problems the intersection of P and NP problems?

Nobody was able to prove that no polynomial-time algorithm exist for any of the problems even though there currently aren't any

New cards
23

what are NP-Hard problems?

  • Difficult to solve problems which cannot be solved in polynomial time

  • difficult to verify in polynomial time

New cards
24

what is the main structure of algorithm classification?

P problems are a subset of NP problems Non-computable problems are a subset of NP-Hard problems NP-Complete problems are the intersection of NP and NP-Hard problems

<p>P problems are a subset of NP problems Non-computable problems are a subset of NP-Hard problems NP-Complete problems are the intersection of NP and NP-Hard problems</p>
New cards
25

what are the consequences if a polynomial time algorithm is found for any problem in the NP-Complete set?

every problem in NP can be solved in polynomial time NP-Complete would no longer be in intersection and would be a proper subset of NP

New cards
26

what are the consequences if P problems are equal to NP problems?

all problems we have would be solvable in polynomial time no security possible as any encryption could be decrypted in polynomial time

New cards

Explore top notes

note Note
studied byStudied by 2 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 22 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 36 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 57 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 50 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 24 people
Updated ... ago
4.0 Stars(2)

Explore top flashcards

flashcards Flashcard239 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard78 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard23 terms
studied byStudied by 16 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard218 terms
studied byStudied by 42 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard37 terms
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard52 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard35 terms
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard26 terms
studied byStudied by 204 people
Updated ... ago
5.0 Stars(1)