0% found this document useful (0 votes)
5 views26 pages

N1Chapter6 Student

The document compares tree search and graph search, highlighting that tree search does not remember visited states while graph search does, making the latter more efficient. It explains the breadth-first search (BFS) algorithm, which is effective for finding the shortest path in unweighted graphs, and contrasts it with depth-first search (DFS). Additionally, the document discusses various applications of graphs, such as web crawling, citation graphs, and task scheduling using directed acyclic graphs (DAGs).

Uploaded by

ypt8p82wcd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views26 pages

N1Chapter6 Student

The document compares tree search and graph search, highlighting that tree search does not remember visited states while graph search does, making the latter more efficient. It explains the breadth-first search (BFS) algorithm, which is effective for finding the shortest path in unweighted graphs, and contrasts it with depth-first search (DFS). Additionally, the document discusses various applications of graphs, such as web crawling, citation graphs, and task scheduling using directed acyclic graphs (DAGs).

Uploaded by

ypt8p82wcd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

1.Tree Search vs.

Graph
Search
2.Breadth-FirstSearch (BFS)
vs.Depth-First Search
(DFS) Instead 0f
Chapter 6: Using Heuristic in Games
Tree Search vs. Graph Search
Tree Search:
• Does NOT remember visited states
• May revisit the same state via different paths
• Can create redundant paths and loops

Graph Search:
• Keeps track of visited states
• Avoids revisiting the same states
• More memory efficient and faster
• Unweighted Graph: In unweighted graphs, all edges have the same weight (or
cost).
• BFS algorithm is well-suited for finding the shortest path in unweighted
graphs. This is because BFS systematically explores the graph level by level,
ensuring that the first path found to any node is the shortest path.
• BFS's Level-by-Level Exploration: BFS starts at a source node and explores all its
immediate neighbors, then their neighbors, and so on, in a layer-by-layer fashion.
• Shortest Path Guarantee: Because BFS visits all nodes at a given level before
moving to the next, the first time it reaches a target node, it has found the
shortest path from the source.
• Analogy‫تشبيه‬: Think of it like exploring a maze. BFS systematically checks all
paths at each step before moving to a deeper level, ensuring it doesn't miss the
shortest route.
• Use BFS when you want to compute a shortest-path tree (for a graph with edges all
with weight 1) where the path length is the minimum number of edges. This is
computed exactly by BFS, the forward/discover edges form exactly such a tree
(following the forward edges will get you such a shortest path).
• Remember that BFS will explore the graph in layers/levels, so any path you find
between two vertices via forward edges will use a minimum number edges. Well,
if the graph is unweighted, then you can imagine each edge having weight 1,
meaning the length of a path is simply the number of edges.
• Both DFS and BFS ensures that they don't visit any vertex
twice. In DFS or BFS, if a node is visited, it won't be processed
again.
• It is a common misconception though, people saying "DFS"
when they mean backtracking.
• Beware that the number of paths may be huge, in worst case
there may be O (N!) paths.
• Question: What is the best algorithm in finding the shortest path?
Answer: There is no ‘best’ algorithm in general, it depends on
you actual problem.
• DFS can be obtained from the BFS algorithm by using a stack K
in place of Q, and by writing new paths at the top rather than at
the bottom of K.
• In BFS, we insert first node in a queue then we keep removing
nodes from rear and keep inserting their adjacent nodes in the
same queue if they are not already visited. This restricts visiting
a non adjacent node before all adjacent ones.
Can the shortest path problem for cyclic graphs be
solved by BFS?
• Yes, BFS works on cyclic graphs. You maintain a
set of vertices you've already seen, and when a
vertex that has previously been seen is seen again,
you avoid adding it to the queue of vertices to
explore. Thus, we guarantee that each vertex will
be added to the queue and hence explored only
once.
• Remember that the time complexity is O (V + E).
The BFS algorithm is particularly useful for one thing: Finding the shortest path on unweighted graph

https://www.youtube.com/watch?v=oDqjPvD54Ss
How many distinct possible states are there
in a 2×2 Rubik’s Cube?
A 2x2 cube has 3,674,160 distinct possible states. This is
because:
 There are 8 corner pieces that can move around 8! =
40,320 ways.
 Each corner can twist in 3 directions, but only 7 can
twist freely (the last one is fixed) → 3^7 = 2,187 ways.
 But we don’t count cube rotations (like turning the
whole cube in your hands) → so we divide by 24.
 8!*38/24/3= FACT(8)*POWER(3;8)/24/3= 3,674,160 different positions.
Trees in CS are upside
down. The roots are at
the top. The leaves are at
the bottom because we
want to think about
starting at the beginning
of the tree. Furthermore,
any pair of nodes are ‫حقيب‬
connected. ‫ة‬

Australian tree is a Search Trees in AI (used in decision-making like the


Knapsack problem) used to represent all possible combinations (states) in problems
like knapsack. This tree grows with branches representing different decisions (e.g.,
"take item" vs "skip item"). These trees are explored using search strategies like
BFS, DFS, or branch-and-bound.
• How do I maximize the destruction of
water in an appropriate way?
• Commuting ‫ التنقل‬problem…?
• Let’s represent the nodes in the graph as
objects. So node is a class instance. And
once I’ve got that, addNode is a method on
the graph. And then i use the method from
the graph to add edge.
Knapsack Problem
The Knapsack Problem is a classic problem in computer science and optimization. It models
a situation where you must choose a subset of items to include in a knapsack (a kind of bag)
to maximize total value without exceeding a weight limit. This problem is widely used in
areas like resource allocation, budgeting, logistics, and decision-making. Here's the basic
version (0/1 Knapsack):
You are given: A set of items. Each item has:
– a weight (how heavy it is)
– a value (how much it's worth)
A knapsack with a weight limit (maximum weight it can carry)
Goal: Select a combination of items so that:
– The total value is as high as possible
– The total weight does not exceed the knapsack’s limit
Example: Suppose you have 3 items:
– Item 1: weight = 2 kg, value = 3
– Item 2: weight = 3 kg, value = 4
– Item 3: weight = 4 kg, value = 5
And your knapsack can carry at most 5 kg. You have to choose the best combination of items
that fits in the 5 kg limit and gives you the highest total value.
Variants ‫ المتغيرات‬:
– 0/1 Knapsack: You can either take an item or leave it (no fractions).
– Fractional Knapsack: You can take parts of an item (like half an apple).
– Multiple Knapsack / Unbounded: You can take unlimited copies of each item.
What is a digraph
A digraph, short for directed graph, is a type of graph in which:
• Nodes (also called vertices) represent entities (like cities, tasks, or webpages).
• Edges (or arcs) are directed, meaning they go from one node to another in a
specific direction.
Example:
• If you have two nodes, A and B:
• In a digraph, you could have an edge from A → B, but not necessarily from B
→ A.
• This direction matters. A → B is different from B → A.
Real-Life Examples:
• Webpages: A link from Page A to Page B, but not necessarily back.
• Tasks in a project: Task A must be done before Task B.
• Roads: A one-way street from city A to city B.
Digraphs are used in:
• Search algorithms (like DFS, BFS)
• Topological sorting (for task scheduling)
• Modeling networks (e.g., internet links, citation graphs)
• Representing finite automata
Application of graphs
• Web crawling
• Social networking.
• Network broadcast.
• Garbage collection.
• Model checking.
• Checking mathematical conj.
• Solving puzzles.
• Games.
Web Crawling
• Web crawling is the process of automatically browsing and collecting
information from web pages on the internet. A program called a "web
crawler" or "spider" visits web pages, reads their content, and follows
the links on those pages to find more content.
– A web crawler:
– Starts at a webpage (like a homepage)
– Downloads the content of that page
– Finds all the hyperlinks (links to other pages)
– Visits those new pages
– Repeats the process again and again
• It builds a map or index of the web, which is often used by search
engines like Google to help users find information.
• The diagrams likely shows:
– Circles or nodes representing websites or pages
– Arrows or edges showing how the crawler moves from one page to
another via links
Citation Graph
A citation graph is a type of directed graph (digraph) used to
represent how academic papers or other documents reference (cite)
each other.
Structure:
– Nodes (vertices) represent individual papers, articles, or patents.
– Directed edges (arcs) point from one paper to another that it cites. Each
arrow points to a paper that is cited.
Example:
If Paper A cites Paper B, the graph has a directed edge: A → B .
This means Paper A depends on or builds upon Paper B.
Uses:
– To measure the influence or impact of a paper.
– To identify key works or highly cited researchers.
– To detect trends or research communities (e.g., clusters of related work).
– To build recommendation systems for academic reading (e.g., “You may also like”).
Finite Automaton ‫إنسان آلي‬
• Finite Automaton (plural: Finite Automata "‫ “آلة محدودة الحاالت‬or "‫أتمتة محدودة‬
‫ )"قطعية‬is a simple mathematical model used to recognize patterns or process
input strings in computer science, especially in the fields of automata theory
and formal languages.
• Basic Idea: A finite automaton is like a machine with a limited number of
states. It reads an input one symbol at a time and changes its state based on what
it reads.
• Components: A Finite Automaton (FA) typically includes:
– States: A finite set of conditions the machine can be in.
– Alphabet: A finite set of symbols (input characters).
– Transition Function: Rules that describe how to move from one state to
another based on input.
– Start State: Where the machine begins.
– Accept (Final) State(s): If the machine ends in one of these after reading the
input, the input is accepted.
https://www.youtube.com/watch?v=uYV-bYeBLc4
Task scheduling
Task scheduling refers to the process of deciding which tasks should run and when, especially in a
computer system or in project management. In Computer Science (especially Operating Systems or
Distributed Systems):
• Task scheduling means managing the order of execution of multiple tasks or processes by a system
(such as CPU, cloud server, or task manager) to achieve goals like efficiency, fairness, or speed.
• Key Concepts:
– Tasks: Units of work (like processes or threads).
– Resources: CPU, memory, etc. used by tasks.
– Dependencies: Some tasks must be completed before others (shown in the image you uploaded
using arrows).
– Execution Order: The scheduler decides in what sequence tasks run.
• Examples of Scheduling Techniques:
– First Come First Serve (FCFS)
– Shortest Job First (SJF)
– Round Robin (RR)
– Priority Scheduling
– Multilevel Queue
• In the Diagram: The diagram is a Directed Acyclic ‫ غير دوري‬Graph (DAG). Each circle is a task,
and arrows show dependencies — e.g., Task A must finish before Task B can start.
• Applications:
– CPU task scheduling
– Project management (like Gantt charts)
– Parallel computing
– Cloud computing task assignments
– Workflow automation
How Directed Acyclic Graph (DAG) Helps in Task Scheduling
• Nodes (circles): Represent tasks (like Task A, Task B, etc.).
• Edges (arrows): Represent dependencies. For example, an arrow from Task A to
Task B means Task A must be completed before Task B can start.
• No cycles: A DAG (Directed Acyclic Graph) never loops back. You can't have a
task depending on itself eventually.
• Example (From Your Diagram)
Let’s assume your diagram has nodes like:
a) A→B→D
b) A→C→D
c) D → E, D → F
Then:
– You must complete A first.
– Then you can do B and C.
– Once B and C are done, you can do D.
– After D, you can proceed with E and F.
• Real-World Use:
– In project management tools like Microsoft Project or Gantt charts, task
dependencies are planned using similar graphs.
– In computers, schedulers use this logic to determine execution order of jobs in
CPUs or workflows.
🎯 Example: Making a Cup of Tea
Let’s say you want to make a cup of tea. There are tasks you need to do in a specific order:
• Tasks:
– A: Boil water
– B: Put tea bag in cup
This structure is a DAG because:
– C: Pour boiled water into cup  It’s directed (tasks have a clear order)
– D: Steep tea(‫)نقع الشاي‬  It’s acyclic (no loops-you can’t go back
– E: Add sugar or milk
from drinking to boiling water)!!!
– F: Stir(‫ )يقلب‬and drink
• Dependencies (edges):
a) A → C (You can’t pour until the water is boiled)
b) B → C (Tea bag must be in cup before pouring)
c) C → D (Tea steeps only after water is poured)
d) D → E (Add milk/sugar after steeping)
e) E → F (Stir and drink after adding extras; after everything is ready)
• DAG Representation:
– Each task is a node, and arrows show which task depends on which. The graph has no
cycles and flows from the start to the end.
– This helps computers and systems in knowing:
 What to do first
 What tasks can run in parallel (e.g., A and B can happen at the same time)
 What must wait for other tasks to finish
Why is the task scheduling structure for making tea
considered as a Directed Acyclic Graph (DAG)?
Simple DAG Example: Building a Bookshelf
• Ordered Tasks (Nodes in the DAG):
– Buy wood
– Cut wood
– Sand wood(‫)صنفرة الخشب‬
– Assemble parts
– Paint the bookshelf
– Place it in the room
• Dependencies (Edges between Tasks):
a) Buy wood → Cut wood
b) Cut wood → Sand wood
c) Sand wood → Assemble parts
d) Assemble parts → Paint the bookshelf
e) Paint the bookshelf → Place it in the room
• This structure is a DAG (Directed Acyclic Graph) because:
 It has directed edges (each task flows to the next)
 It has no cycles (you never go back to a previous task)
 It shows clear dependencies (you can't skip or go out of order)
Why is the structure of these bookshelf-building
tasks considered as a DAG?
CC and Other Styles of Computing
CC and Other Styles of Computing
Please have a look at the followings:
• Grid Computing (GC), Utility Computing (UC), Multi-processor systems,
Multicore architectures, Internet, Cluster Computing, and Distributed Systems
• Parallel computing, Threads &Threading
• Big Data
• Cloud Computing (CC)
• Digital Image Processing
• Internet-of-Things (IoT)
• Infrastructure-as-a-Service (IaaS),Platform-as-a-Service (PaaS), Software-as-
a-Service (SaaS)
• Virtualization.
• Machine Learning, It is the last chapter, Chapter 7
For more information, I suggest the following article: Nidhal El-Omari, “Cloud IoT as a Crucial Enabler: a Survey and Taxonomy‫” تصنيف‬, Modern
Applied Science, The Canadian Center of Science and Education, published by Canadian Center of Science and Education, Canada, p-ISSN: 1913-1844, e-
ISSN: 1913-1852, DOI:10.5539/mas.v13n8p86, 13(8):86-149, 2019.
Summary
• Tree Search: explores all paths, may
repeat.
• Graph Search: avoids loops by checking
visited states
• BFS: explores level-by-level, always finds
the shortest path (if cost is uniform).
• Graph Search are used in many
applications.

You might also like