graphs b Flashcards

1
Q

types of problems

A

Decision problems: trying to decide whether a statement is true or false.
They have either yes or no as the solution.

Optimization problems: trying to find the solution with the best possible score according to some scoring scheme.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are maxmization and minmisation problems

A

Maximization problems: trying to maximize a certain score.
Minimization problems: trying to minimize a cost function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is Optimization:

A

choosing the best element from a set of alternatives

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For an optimization problem you want to find, ………, but the ………..

A

For an optimization problem you want to find, not just a solution, but the best solution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is optimization algorithm

A

is a numerical method or algorithm for finding a value x such that f(x) is as small (or as large) as possible, for a given function f, possibly with some constraints on x.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what types of algorthims we use For solving Optimization problems:

A

Greedy algorithm
Dynamic programming algorithm
Branch and bound algorithm(BFS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is the greedy algorthim way of solving a problem
give an example

A

by always making the choice that looks the best at the moment
-it makes locally optimal choices in hope that it will lead to glopal optimal solution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T or F: Greedy algorithms always yield optimal solutions

A

F
Greedy algorithms do not always yield optimal solutions, but for many problems they do.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Algorithms for optimization problems typically work as

A

a sequence of steps, with a set of choices at each step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Examples of Greedy Algorithms :

A

Minimum-spanning-tree algorithms
Shortest path problems.
Travelling salesman problem.
The knapsack problem (items are divisible).
Task scheduling problem.
Huffman Coding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

T or F: The greedy method is quite powerful and works well for a wide range of problems.

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is a tree

A

connected undiractional graph with no cycle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

problems like finding smallest , logest largest are …… problems and ……. algorthims can be used to solve them

A

problems like finding smallest , logest largest are optimazation problems and greedy algorthim algorthims can be used to solve them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is spanning tree

A

A Spanning Tree of a graph G is a subgraph of G that is a tree and contains all the vertices of G

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what are the spanning tree properties

A

1-a spanning tree of n vertix has n-1 edges
2-connected in all vertices
3-has no cycle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Minimum Spanning Trees, why?

A

To make multiple pins in an electronic circuit electrically equivalent, they are connected using wires. If there are ( n ) pins, ( n-1 ) wires are needed to connect all pins. The optimal arrangement is the one that uses the least amount of wire, as it is generally preferred to minimize the total wire length.

14
Q

why we need MST in computer networks and shipping/airlines

A

Computer Networks
To find how to connect a set of computers using the minimum amount of wire.
Shipping/Airplane Lines
To find the fastest way between locations

15
Q

what kind of approach are Kruskal’s algorithm
Prim’s algorithm

A

greedy approach/ staregy

16
Q

prim and kruksal are …… methods that ……..

A

greedy strategy is captured by the following generic method, which grows the minimum spanning tree one edge at a time

17
Q

why is kruksal qualifies as a greedy algorithm

A

each step it adds to the forest an edge of least possible weight.(choosing the best soultion ATM)

18
Q

how kruksal algorthim avoid violating MST rules

A

If it were to form a cycle, it would simply link two nodes that were already part of a single connected tree, so that this edge would not be needed (REGECTED)

19
Q

a safe edge in kruksal; algorthim is

A

always a least-weight (cheapest) edge in the graph that connects two distinct components (trees).
Without vilating MST

20
Q

a safe edge is a

A

edgde that we add to the graph witout violating MST rules

21
Q

Steps of kruksal algorithm:

A

intialze empty set A={};
create set of trees for all vertiexes in graph
sort all edges in non decresing order
for each edge (u,v) examine wether endpoint vertix belong in the same tree
-if same then edge cant be added and should be discarded
-if no edge belong to diffrent tree then add it to the tree

22
Q

Kruskal’s Algorithm psudocode and complextiy for each couble of lines and overall eomplextiy

A

The running time of Kruskal’s Algorithm is :
Line 1: initialize set A is O(1)
Line 2-3: Make-Set() is |V|.
Line 4: sort the edges is O(E lg E).
Line 5: for loop is O(E)
Line 6-8: find and union by rank is O(lg V) time
D = {c,n,b} => D2 = D x D = {c,n,b} x {c,n,b} = {(c,c), (c,n),(c,b), (n,c), (n,n), (n,b), (b,c), (b,n), (b,b)}
Overall complexity is O(E lg E + E lg V) time.
Note: lgV = lgE (Why?): E can be at most O(V2).
E→{(x,y)| (x,y)∈V 2 ∧ x≠y} every edge maps to anordered pairofdistinctvertices.
O(E lg E) = O(E lg V2) = O(E 2lg V) = O(E lg V) time.
So, overall complexity is O(E lg E) or O(E lg V)

23
Q

walk through solution and show steps find MST using kruksal

A
24
Q

walk through solution and show steps

A

final answer

25
Q

draw K4 K6

A
26
Q

Prim’s algorithm operates much like ……………. algorithm for finding shortest paths in a graph.

A

Prim’s algorithm operates much like Dijkstra’s algorithm for finding shortest paths in a graph.

27
Q

Prim’s Algorithm discription

A

ما اتفق بس:. ة
- - Prim’s algorithm builds a single tree, set A, to find the minimum spanning tree.
- At each step, it adds the least-weight edge that connects the tree to a vertex not yet in the tree.
- The tree starts from an arbitrary root vertex and expands until it includes all vertices.
- Each added edge connects the current tree to an isolated vertex.
- Prim’s algorithm is similar to Dijkstra’s algorithm, but instead of finding shortest paths, it finds the edges of the minimum spanning tree.

28
Q

Steps of Prim’s Algorithm :

A
  • Start with any vertex, v.
  • Choose the shortest edge from v to a vertex w that is not part of the tree.
  • Add edge (v, w) to the (MCST).
  • At each step, add the shortest edge from a vertex in the MCST to a vertex outside the MCST, without considering the overall graph structure.
  • Stop once all vertices are included in the MCST.
29
Q

The running time of Prim’s algorithm depends on how we implement the ………

A

**min-priority queue Q. **

30
Q

whats the diffrence in running time between prim and kruksal algorthim

A

The running time of Prim’s algorithm is asymptotically same as for Kruskal’s algorithm.

31
Q

write prim algorthim psuodocode and analyzie its running time

A
  • Lines 1-5: Initializing key, parent, and queue takes ( O(V) ) time (using BUILD-MIN-HEAP).
  • Line 6: The body of the while loop is executed (|V|) times.
  • Line 7: Each Extract-Min() operation takes ( O(\log V) ) time, with total cost ( O(V \log V) ).
  • Line 8: The for loop runs ( O(E) ) times.
  • Lines 9-10: Constant time ( O(1) ).
  • Line 11: Decreasing key value in min-heap takes ( O(\log V) ).
  • Total running time: ( O(V \log V + E \log V) = O(E \log V) ).
32
Q

solve MSCT using PRIM

A
33
Q

solve with table

A