The document discusses data structures and algorithms. It defines key concepts like primitive data types, data structures, static vs dynamic structures, abstract data types, algorithm design, analysis of time and space complexity, and recursion. It provides examples of algorithms and data structures like stacks and using recursion to calculate factorials. The document covers fundamental topics in data structures and algorithms.
this is a briefer overview about the Big O Notation. Big O Notaion are useful to check the Effeciency of an algorithm and to check its limitation at higher value. with big o notation some examples are also shown about its cases and some functions in c++ are also described.
this is a briefer overview about the Big O Notation. Big O Notaion are useful to check the Effeciency of an algorithm and to check its limitation at higher value. with big o notation some examples are also shown about its cases and some functions in c++ are also described.
Introduction to datastructure and algorithmPratik Mota
Introduction to data structure and algorithm
-Basics of Data Structure and Algorithm
-Practical Examples of where Data Structure Algorithms is used
-Asymptotic Notations [ O(n), o(n), θ(n), Ω(n), ω(n) ]
-Calculation of Time and Space Complexity
-GNU gprof basic
Special Edition with Dr. Robin Bloor
Live Webcast September 9, 2015
Watch the Archive: https://bloorgroup.webex.com/bloorgroup/onstage/g.php?MTID=e8b9ac35d8e4ffa3452562c1d4286a975
Do the math: algebra will transform information management. Just as the relational database revolutionized the information landscape, so will a just-released, complete algebra of data overhaul the industry itself. So says Dr. Robin Bloor in his new book, the Algebra of Data, which he’ll outline in this special one-hour webcast.
Once organizations learn how to express their data sets algebraically, the benefits will be significant and far-reaching. Data quality problems will slowly subside; queries will run orders of magnitude faster; integration challenges will fade; and countless tedious jobs in the data management space will bid their farewell. But first, software companies must evolve, and that will take time.
Visit InsideAnalysis.com for more information.
•Common Problems Needs Computers
•The Search Problem
•Basic Search Algorithms
–Algorithms used for searching the contents of an array
•Linear or Sequential Search
•Binary Search
•Comparison Between Linear and Binary Search
•Algorithms for solving shortest path problems
–Sequential Search Algorithms
•Depth-First Search
•Breadth First Search
–Parallel or distributed Search Algorithms
•Parallel Depth-First Search
•Parallel Breadth First Search
The Health Benefits of Dogs. A presentation about the mental and physical health benefits owning a dog can bring you.
This is my special way of saying thank you to my lovely dog for all those 'walkies' we've had together.
Introduction to datastructure and algorithmPratik Mota
Introduction to data structure and algorithm
-Basics of Data Structure and Algorithm
-Practical Examples of where Data Structure Algorithms is used
-Asymptotic Notations [ O(n), o(n), θ(n), Ω(n), ω(n) ]
-Calculation of Time and Space Complexity
-GNU gprof basic
Special Edition with Dr. Robin Bloor
Live Webcast September 9, 2015
Watch the Archive: https://bloorgroup.webex.com/bloorgroup/onstage/g.php?MTID=e8b9ac35d8e4ffa3452562c1d4286a975
Do the math: algebra will transform information management. Just as the relational database revolutionized the information landscape, so will a just-released, complete algebra of data overhaul the industry itself. So says Dr. Robin Bloor in his new book, the Algebra of Data, which he’ll outline in this special one-hour webcast.
Once organizations learn how to express their data sets algebraically, the benefits will be significant and far-reaching. Data quality problems will slowly subside; queries will run orders of magnitude faster; integration challenges will fade; and countless tedious jobs in the data management space will bid their farewell. But first, software companies must evolve, and that will take time.
Visit InsideAnalysis.com for more information.
•Common Problems Needs Computers
•The Search Problem
•Basic Search Algorithms
–Algorithms used for searching the contents of an array
•Linear or Sequential Search
•Binary Search
•Comparison Between Linear and Binary Search
•Algorithms for solving shortest path problems
–Sequential Search Algorithms
•Depth-First Search
•Breadth First Search
–Parallel or distributed Search Algorithms
•Parallel Depth-First Search
•Parallel Breadth First Search
The Health Benefits of Dogs. A presentation about the mental and physical health benefits owning a dog can bring you.
This is my special way of saying thank you to my lovely dog for all those 'walkies' we've had together.
19. Java data structures algorithms and complexityIntro C# Book
In this chapter we will compare the data structures we have learned so far by the performance (execution speed) of the basic operations (addition, search, deletion, etc.). We will give specific tips in what situations what data structures to use.
19. Data Structures and Algorithm ComplexityIntro C# Book
In this chapter we will compare the data structures we have learned so far by the performance (execution speed) of the basic operations (addition, search, deletion, etc.). We will give specific tips in what situations what data structures to use. We will explain how to choose between data structures like hash-tables, arrays, dynamic arrays and sets implemented by hash-tables or balanced trees. Almost all of these structures are implemented as part of NET Framework, so to be able to write efficient and reliable code we have to learn to apply the most appropriate structures for each situation.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
2. 2
The logical or mathematical model of a particular
organization of data is called a data structure
DATA STRUCTURES
3. 3
A primitive data type holds a single piece of data
–e.g. in Java: int, long, char, boolean etc.
–Legal operations on integers: + - * / ...
A data structure structures data!
–Usually more than one piece of data
–Should provide legal operations on the data
–The data might be joined together (e.g. in an array): a
collection
DATA STRUCTURES
4. 4
Static vs. Dynamic StructuresStatic vs. Dynamic Structures
A static data structure has a fixed size
This meaning is different than those associated with the static
modifier
Arrays are static; once you define the number of elements it can
hold, it doesn’t change
A dynamic data structure grows and shrinks as required by the
information it contains
5. 5
An Abstract Data Type (ADT) is a data type together
with the operations, whose properties are specified
independently of any particular implementation.
Abstract Data Type
6. 6
Abstract Data Type
In computing, we view data from three perspectives:
Application level
View of the data within a particular problem
Logical level
An abstract view of the data values (the domain) and the
set of operations to manipulate them
Implementation level
A specific representation of the structure to hold the data
items and the coding of the operations in a programming
language
7. 7
Problem Solving: Main Steps
1. Problem definition
2. Algorithm design / Algorithm specification
3. Algorithm analysis
4. Implementation
5. Testing
6. [Maintenance]
8. 8
Problem Definition
What is the task to be accomplished?
Calculate the average of the grades for a given student
What are the time / space / speed / performance requirements?
9. 9
. Algorithm Design / Specifications
Algorithm: Finite set of instructions that, if followed, accomplishes a
particular task.
Describe: in natural language / pseudo-code / diagrams / etc.
Criteria to follow:
Input: Zero or more quantities (externally produced)
Output: One or more quantities
Definiteness: Clarity, precision of each instruction
Finiteness: The algorithm has to stop after a finite (may be very
large) number of steps
Effectiveness: Each instruction has to be basic enough and
feasible
10. 10
Implementation, Testing, Maintenances
Implementation
Decide on the programming language to use
C, C++, Lisp, Java, Perl, Prolog, assembly, etc. , etc.
Write clean, well documented code
Test, test, test
Integrate feedback from users, fix bugs, ensure compatibility
across different versions Maintenance
12. 12
Space Complexity
Space complexity = The amount of memory required by an
algorithm to run to completion
[Core dumps = the most often encountered cause is “memory
leaks” – the amount of memory required larger than the
memory available on a given system]
Some algorithms may be more efficient if data completely loaded
into memory
Need to look also at system limitations
E.g. Classify 2GB of text in various categories [politics, tourism,
sport, natural disasters, etc.] – can I afford to load the entire
collection?
13. 13
Space Complexity (cont’d)
1. Fixed part: The size required to store certain data/variables, that
is independent of the size of the problem:
- e.g. name of the data collection
- same size for classifying 2GB or 1MB of texts
2. Variable part: Space needed by variables, whose size is
dependent on the size of the problem:
- e.g. actual text
- load 2GB of text VS. load 1MB of text
14. 14
Space Complexity (cont’d)
S(P) = c + S(instance characteristics)
c = constant
Example:
float sum (float* a, int n)
{
float s = 0;
for(int i = 0; i<n; i++) {
s+ = a[i];
}
return s;
}
Space? one word for n, one for a [passed by reference!], one
for i constant space!
15. 15
Time Complexity
Often more important than space complexity
space available (for computer programs!) tends to be larger
and larger
time is still a problem for all of us
3-4GHz processors on the market
researchers estimate that the computation of various
transformations for 1 single DNA chain for one single protein
on 1 TerraHZ computer would take about 1 year to run to
completion
Algorithms running time is an important issue
16. 16
Running Time
Problem: prefix averages
Given an array X
Compute the array A such that A[i] is the average of elements
X[0] … X[i], for i=0..n-1
Sol 1
At each step i, compute the element X[i] by traversing the array
A and determining the sum of its elements, respectively the
average
Sol 2
At each step i update a sum of the elements in the array A
Compute the element X[i] as sum/I
17. 17
Running time
Input
1 ms
2 ms
3 ms
4 ms
5 ms
A B C D E F G
worst-case
best-case
}average-case?
Suppose the program includes an if-then statement that
may execute or not: variable running time
Typically algorithms are measured by their worst case
18. 18
Experimental Approach
Write a program that implements the algorithm
Run the program with data sets of varying size.
Determine the actual running time using a system call to measure
time (e.g. system (date) );
Problems?
19. 19
Experimental Approach
It is necessary to implement and test the algorithm in order to
determine its running time.
Experiments can be done only on a limited set of inputs, and may
not be indicative of the running time for other inputs.
The same hardware and software should be used in order to
compare two algorithms. – condition very hard to achieve!
20. 20
Use a Theoretical Approach
Based on high-level description of the algorithms, rather than
language dependent implementations
Makes possible an evaluation of the algorithms that is
independent of the hardware and software environments
21. 21
Algorithm Description
How to describe algorithms independent of a programming
language
Pseudo-Code = a description of an algorithm that is
more structured than usual prose but
less formal than a programming language
(Or diagrams)
Example: find the maximum element of an array.
Algorithm arrayMax(A, n):
Input: An array A storing n integers.
Output: The maximum element in A.
currentMax ← A[0]
for i← 1 to n -1 do
if currentMax < A[i] then currentMax ← A[i]
return currentMax
22. 22
Properties of Big-Oh
Expressions: use standard mathematical symbols
use ← for assignment ( ? in C/C++)
use = for the equality relationship (? in C/C++)
Method Declarations: -Algorithm name(param1, param2)
Programming Constructs:
decision structures: if ... then ... [else ..]
while-loops while ... do
repeat-loops: repeat ... until ...
for-loop: for ... do
array indexing: A[i]
Methods
calls: object method(args)
returns: return value
Use comments
Instructions have to be basic enough and feasible!
23. 23
Asymptotic analysis - terminology
Special classes of algorithms:
logarithmic: O(log n)
linear: O(n)
quadratic: O(n2
)
polynomial: O(nk
), k ≥ 1
exponential: O(an
), n > 1
Polynomial vs. exponential ?
Logarithmic vs. polynomial ?
24. 24
Some Numbers
log n n n log n n
2
n
3
2
n
0 1 0 1 1 2
1 2 2 4 8 4
2 4 8 16 64 16
3 8 24 64 512 256
4 16 64 256 4096 65536
5 32 160 1024 32768 4294967296
25. 25
Relatives of Big-Oh
“Relatives” of the Big-Oh
Ω (f(n)): Big Omega – asymptotic lower bound
Θ (f(n)): Big Theta – asymptotic tight bound
Big-Omega – think of it as the inverse of O(n)
g(n) is Ω (f(n)) if f(n) is O(g(n))
Big-Theta – combine both Big-Oh and Big-Omega
f(n) is Θ (g(n)) if f(n) is O(g(n)) and g(n) is Ω (f(n))
Make the difference:
3n+3 is O(n) and is Θ (n)
3n+3 is O(n2
) but is not Θ (n2
)
26. 26
More “relatives”
Little-oh – f(n) is o(g(n)) if for any c>0 there is n0 such that f(n) <
c(g(n)) for n > n0.
Little-omega
Little-theta
2n+3 is o(n2
)
2n + 3 is o(n) ?
27. 27
Example
Remember the algorithm for computing prefix averages
compute an array A starting with an array X
every element A[i] is the average of all elements X[j] with j < i
Remember some pseudo-code … Solution 1
Algorithm prefixAverages1(X):
Input: An n-element array X of numbers.
Output: An n -element array A of numbers such that A[i] is the
average of elements X[0], ... , X[i].
Let A be an array of n numbers.
for i← 0 to n - 1 do
a ← 0
for j ← 0 to i do
a ← a + X[j]
A[i] ← a/(i+ 1)
return array A
28. 28
Example (cont’d)
Algorithm prefixAverages2(X):
Input: An n-element array X of numbers.
Output: An n -element array A of numbers such that A[i] is the
average of elements X[0], ... , X[i].
Let A be an array of n numbers.
s← 0
for i ← 0 to n do
s ← s + X[i]
A[i] ← s/(i+ 1)
return array A
29. 29
Back to the original question
Which solution would you choose?
O(n2
) vs. O(n)
Some math …
properties of logarithms:
logb(xy) = logbx + logby
logb (x/y) = logbx - logby
logbxa = alogbx
logba= logxa/logxb
–properties of exponentials:
a(b+c)
= ab
a c
abc
= (ab
)c
ab
/ac
= a(b-c)
b = a log
a
b
bc
= a c*log
a
b
30. 30
Important Series
Sum of squares:
Sum of exponents:
Geometric series:
Special case when A = 2
20
+ 21
+ 22
+ … + 2N
= 2N+1
- 1
Nlargefor
36
)12)(1( 3
1
2 NNNN
i
N
i
≈
++
=∑=
-1kandNlargefor
|1|
1
1
≠
+
≈
+
=
∑ k
N
i
kN
i
k
1
11
0 −
−
=
+
=
∑ A
A
A
NN
i
i
∑=
+==+++=
N
i
NNiNNS
1
2/)1(21)(
32. 32
Solving recursive equations by repeated substitution
T(n) = T(n/2) + c substitute for T(n/2)
= T(n/4) + c + c substitute for T(n/4)
= T(n/8) + c + c + c
= T(n/23
) + 3c in more compact form
= …
= T(n/2k
) + kc “inductive leap”
T(n) = T(n/2logn
) + clogn “choose k = logn”
= T(n/n) + clogn
= T(1) + clogn = b + clogn = θ(logn)
33. 33
Solving recursive equations by telescoping
T(n) = T(n/2) + c initial equation
T(n/2) = T(n/4) + c so this holds
T(n/4) = T(n/8) + c and this …
T(n/8) = T(n/16) + c and this …
…
T(4) = T(2) + c eventually …
T(2) = T(1) + c and this …
T(n) = T(1) + clogn sum equations, canceling
the terms appearing
on both sides
T(n) = θ(logn)
34. 34
RECURSION
Suppose P is a procedure containing either a CALL statement to
itself or a CALL statement back to original procedure P .Then P
is called a recursive procedure
Properties:
1. There must be certain criteria called basic criteria, for
which the procedure does not call itself.
2. Each time the procedure does call itself (directly or
indirectly), it must be closer to the base criteria.
35. 35
FACTORIAL WITHOUT RECURSION
FACTORIAL(FACT,N)
This procedure calculates N! and return the vale in the variable FACT
.
1. If N ==0,then :Set FACT:=1, and Return.
2. Set FACT:=1[Initialize FACT for loop]
3. Repeat for K:=1 to N
Set FACT:=K*FACT
[END of loop]
4. Return.
36. 36
FACTORIAL WITH RECURSION
FACTORIAL(FACT,N)
This procedure calculates N! and return the vale in the variable FACT .
1. If N ==0,then :Set FACT:=1, and Return.
2. Call FACTORIAL(FACT,N-1).
3. Set FACT:=N*FACT.
4. Return.
48. 48
Stack
A stack is a list that has addition and deletion of items only from one
end.
It is like a stack of plates:
Plates can be added to the top of the stack.
Plates can be removed from the top of the stack.
This is an example of “Last in, First out”, (LIFO).
Adding an item is called “pushing” onto the stack.
Deleting an item is called “popping” off from the stack.
49. 49
STACK OPERATION (PUSH)
PUSH(STACK,TOP,MAXSTK,ITEM)
This procedure pushes an ITEM onto a stack.
1.[Stack already filled]
If TOP== MAXSTK, then: Print:OVERFLOW, and Return.
2. Set TOP:=TOP+1.[ Increases TOP by 1]
3. Set STACK[TOP]:=ITEM. [Inserting ITEM in new TOP position]
4. Return.
50. 50
STACK OPERATION (POP)
POP(STACK,TOP,ITEM)
This procedure deletes the top element of STACK and assigns it to the
variable ITEM .
1.[Stack has an item to be to removed]
If TOP== 0, then: Print:UNDERFLOW, and Return.
2. Set ITEM:=STACK[top].[ Assigns TOP element to ITEM ]
3. Set TOP:=TOP-1. [Decreases TOP by 1]
4. Return.
60. 60
INFIX to POSTFIX
Properties while transforming infix to postfix expression
1. besides operands and operators, arithmetic expression contains
left and right parentheses
2. We assume that the operators in q consist only of
1. Exponent
2. Multiplication
3. Division
4. Addition
5. Subtraction
61. 61
INFIX to POSTFIX
3. We have three levels of precedence
precedence operators
high right parentheses
exponent
multiplication, division
low addition, subtraction
62. 62
INFIX to POSTFIX
POLISH(Q, P)
Suppose Q is an arithmetic expression written in infix notation.
This algorithm finds the equivalent postfix expression P.
1. Push “(“ into STACK and add “)” to the end of Q.
2. Scan Q from left to right and repeat Step 3 to 6 for each
element of Q until the STACK is empty:
3. If an operand is encountered add it to P.
4. If a left parenthesis is encountered, push it onto STACK.
5. If an operator is encountered then:
(a) repeatedly pop from STACK and to P each operator
(on the top of STACK) which has the same precedence as or
higher precedence this operator
(b) Add operator to STACK
63. 63
INFIX to POSTFIX
6. If a right parenthesis is encountered then:
(a) Repeatedly pop from STACK and add to P each
operator( on the top of STACK) until a left parenthesis is
encountered
(b) Remove the left parenthesis .[Do not add the left
parenthesis to P]
7. Exit
72. 72
POSTFIX EXPRESSION SOLVING
This algorithm finds the VALUE of an arithmetic expression P
written in postfix notation
1. Add a right parenthesis “)” at the end of P
2. Scan P from left to right and repeat step 3 and 4 for each
element of P until the sentinel “)” is encountered.
3. If an operand is encountered, put it on STACK.
4. If an operator is uncounted then:
a. Remove the two elements of Stack, where A is the top
element and B is the next top element
b. Evaluate B operator A
c. Pace the result of (b) back on STACK
77. 77
POSTFIX EXPRESSION SOLVING
POSTFIX Expression: * +
Here we pop two time and perform
multiplication on elements (4*2) and
push the Result in to the stack
7
6
5
4
2
1 3
4
2
80. 80
The N-Queens Problem
Can the queens be placed on the
board so that no two queens are
attacking each other in chess
board
81. 81
The N-Queens Problem
Two queens are not allowed in the same rowTwo queens are not allowed in the same row
82. 82
The N-Queens Problem
Two queens are not allowed in the same row, or in the same column...Two queens are not allowed in the same row, or in the same column...
83. 83
The N-Queens Problem
Two queens are not allowed inTwo queens are not allowed in
the same row, or in the samethe same row, or in the same
column, or along the samecolumn, or along the same
diagonal.diagonal.r along the same
diagonal.
84. 84
The N-Queens Problem
The number of queens,
and the size of the board
can vary.
The number of queens,
and the size of the board
can vary.
N Queens
N columns
85. 85
The 3-Queens Problem
The program uses aThe program uses a
stack to keep track ofstack to keep track of
where each queen iswhere each queen is
placed.placed.
86. 86
The 3-Queens Problem
Each time the program
decides to place a
queen on the board,
the position of the new
queen is stored in a
record which is placed
in the stack.
ROW 1, COL 1
87. 87
The 3-Queens Problem
We also have an integer
variable to keep track of
how many rows have been
filled so far.
ROW 1, COL 1
1
filled
88. 88
The 3-Queens Problem
Each time we try to place
a new queen in the next
row, we start by placing
the queen in the first
column
ROW 1, COL 1
1
filled
ROW 2, COL 1
89. 89
The 3-Queens Problem
if there is a conflict with
another queen, then we
shift the new queen to
the next column.
ROW 1, COL 1
1
filled
ROW 2, COL 2
90. 90
The 3-Queens Problem
ROW 1, COL 1
1
filled
ROW 2, COL 3
When there are noWhen there are no
conflicts, we stop andconflicts, we stop and
add one to the value ofadd one to the value of
filled.filled.
91. 91
The 3-Queens Problem
When there are no
conflicts, we stop and
add one to the value of
filled.
ROW 1, COL 1
2
filled
ROW 2, COL 3
92. 92
The 3-Queens Problem
Let's look at the third row.
The first position we try has
a conflict
ROW 1, COL 1
2
filled
ROW 2, COL 3
ROW 3, COL 1
93. 93
The 3-Queens Problem
so we shift to column 2.
But another conflict
arises
ROW 1, COL 1
2
filled
ROW 2, COL 3
ROW 3, COL 2
94. 94
The 3-Queens Problem
and we shift to the third
column.
Yet another conflict arises
ROW 1, COL 1
2
filled
ROW 2, COL 3
ROW 3, COL 3
95. 95
The 3-Queens Problem
and we shift to column 4.
There's still a conflict in
column 4, so we try to
shift rightward again
ROW 1, COL 1
2
filled
ROW 2, COL 3
ROW 3, COL 4
97. 97
The 3-Queens Problem
When we run out of
room in a row:
pop the stack,
reduce filled by 1
and continue
working on the previous
row.
ROW 1, COL 1
1
filled
ROW 2, COL 3
98. 98
The 3-Queens Problem
Now we continue working
on row 2, shifting the
queen to the right.
ROW 1, COL 1
1
filled
ROW 2, COL 4
99. 99
The 3-Queens Problem
This position has no
conflicts, so we can
increase filled by 1, and
move to row 3.
ROW 1, COL 1
2
filled
ROW 2, COL 4
100. 100
The 3-Queens Problem
In row 3, we start again
at the first column.
ROW 1, COL 1
2
filled
ROW 2, COL 4
ROW 3, COL 1
101. 101
The 3-Queens Problem
In row 3, we start again
at the first column.
ROW 1, COL 1
3
filled
ROW 2, COL 4
ROW 3, COL 2
102. 102
QUEUES
A queue is a data structure that maintains a “first-in first-out”
(FIFO) ordering.
In contrast, a stack maintains a “last-in first-out” (LIFO) ordering.
A queue adds new elements at the end. An element can only be
removed at the front.
This is an abstraction of the “first-come first-served” practice.
103. 103
QUEUE OPERATIONS
A queue has two operations:
QINSERT
QDELETE
An enqueue operation adds new elements at the end of the queue
or its tail. This is similar to the stack operation push; only that push
now is done at the end of the array instead of at the front (or top).
A dequeue operation removes an element from the front of the
array or its head.
106. 106
QUEUE
OFFSET
DATA
0 1 2 3
0
rear
0
OFFSET
DATA
0 1 2 3
A
front
1
rear
1
OFFSET
DATA
0 1 2 3
A B
front
1
rear
2
OFFSET
DATA
0 1 2 3
B
front
2
rear
2
front
Insert A
Insert B
delete
107. 107
CIRCULAR QUEUE
When a new item is inserted at the rear, the to rear moves
upwards.
Similarly, when an item is deleted from the queue the front arrow
moves downwards.
After a few insert and delete operations the rear might reach the
end of the queue and no more items can be inserted although
the items from the front of the queue have been deleted and
there is space in the queue.
108. 108
CIRCULAR QUEUE
To solve this problem, queues implement wrapping around. Such
queues are called Circular Queues.
Both the front and the rear wrap around to the beginning of the
array when they reached the MAX size of the queue.
It is also called as “Ring buffer”.
109. 109
CIRCULAR QUEUE INSERTION
QINSERT (QUEUE, N, FRONT, ITEM)
This procedure insert an element ITEM into a queue.
1. [Queue already filled?]
IF ( FRONT==1 and REAR==N ) or FRONT ==REAR + 1,then:
write: overflow, and Return
2.[Find new value of REAR]
IF FRONT==NULL then [Queue initially empty.]
Set FRONT=1 and REAR=1
ELSE IF REAR ==N then
Set REAR=1
ELSE
set REAR=REAR+1
[End of if structure]
111. 111
CIRCULAR QUEUE DELETION
QDELETE(QUEE, N, FRONT, REAR, ITEM)
This procedure deletes an element from a queue and assigns it to the
variable ITEM
1.[Queue already empty]
if FRONT=NULL then write UNDERFLOW, and Return
2. Set ITEM=QUEUE[FRONT]
3. [Find new value of FRONT]
If FRONT =REAR then [Queue has only one element to start]
Set FRONT=NULL and REAR=NULL
115. 115
PRIORITY QUEUE
A priority queue is a collection of elements such that each
element has been assigned a priority and such that the order
in which elements are deleted and processed comes from the
following rules
1. An element of a higher priority is processed before any
elements of lower priority
2. Two elements with the same priority are processed according
to the order in which they were added to the queue
116. 116
ARRAY REPRESENTATION PRIORITY QUEUE
Use a separate queue for each level of priority
Each such queue will appear in its own circular array and must
have its own pair of pointers FRONT and REAR
In fact, if each queue is allocated the same amount of space in
two-dimensional array QUEUE can be used instead of linear
array
117. 117
DELETION ON PRIORITY QUEUE
Deletion
This algorithm deletes and processes the first element in a
priority queue maintained by a two-dimensional array QUEUE
1.[Find the first nonempty queue]
Find the smallest k that FRONT!=NULL
2.Delete and process the front element in row K of QUEUE
118. 118
INSERTION ON PRIORITY QUEUE
Insertion
This algorithm adds an ITEM with priority number M to a priority
queue maintained by a two-dimensional array QUEUE
1. Insert ITEM as the rear element in row M of QUEUE
2. Exit
119. 119
LINKED LIST
Linked list
Linear collection of self-referential class objects, called
nodes
Connected by pointer links
Accessed via a pointer to the first node of the list
Subsequent nodes are accessed via the link-pointer member
of the current node
Link pointer in the last node is set to null to mark the list’s
end
Use a linked list instead of an array when
You have an unpredictable number of data elements
Your list needs to be sorted quickly
120. 120
TYPES OF LINKED LIST
Types of linked lists:
Singly linked list
Begins with a pointer to the first node
Terminates with a null pointer
Only traversed in one direction
Circular, singly linked
Pointer in the last node points back to the first node
Doubly linked list
Two “start pointers” – first element and last element
Each node has a forward pointer and a backward pointer
Allows traversals both forwards and backwards
Circular, doubly linked list
Forward pointer of the last node points to the first node
and backward pointer of the first node points to the last
node
121. 121
linked list
Start Node
A placeholder node at the beginning of the list, used to simplify
list processing. It doesn’t hold any data
Tail Node
A placeholder node at the end of the list, used to simplify list
processing
122. 122
Singly linked list
Single Linked List
Consists of data elements and reference to the
next Node in the linked list
First node is accessed by reference
Last node is set to NULL
A B C
Start Tail
123. 123
SINGLE LINKED LIST INSERTION
INSFIRST(INFO, LINK, START, AVAIL, ITEM)
This algorithm inserts ITEM as the first node in the list
1. [OVERFLOW?] If AVAIL=NULL then :Write OVERFLOW
and Exit
2. [Remove first node from AVIL list]
Set NEW =AVAIL and AVAIL=LINK[AVAIL]
3. Set INFO[NEW]=ITEM [Copies new data into new node]
4. Set LINK[NEW]=START [new node now points to original
first node]
5. Set START=NEW [Changes START so it points to the
node]
6. Exit
129. 129
SINGLE LINKED LIST INSERTION
INSLOC(INFO, LINK,START, AVAIL, LOC, ITEM)
This algorithm inserts ITEM so that ITEM follows the node with
location LOC or inserts ITEM as the first node when LOC=NULL
1. [OVERFLOW ?] If AVAIL==NULL then write OVERFLOW and
EXIT
2. [Remove first node from AVAIL list]
3. Set INFO[NEW]=ITEM[copies new data into new node]
4. If LOC==NULL then :[insert as first node]
Set LINK[NEW]=Start and START=NEW
else [insert after node with location LOC]
Set LINK[NEW]=LINK[LOC] and LINK[LOC]=NEW
end of if structure
5. exit
134. 134
SINGLE LINKED LIST DELETION
DELETE(INFO, LINK,START, AVAIL, ITEM)
This algorithm deletes from a linked list the first node N which
contains the given ITEM of information
1. [Use procedure FIND given after this algorithm]
FIND(INFO, LINK, START, ITEM, LOC, LOCP)
2. If LOC==NULL then:
Write ITEM not in list and exit
3. If LOCP==NUL then
Set START=LINK[START]
else :
Set LINK[LOCP]=LINK[LOC]
3. {Return deleted node to the AVAIL list]
Set LINK[LOC]=AVAIL and AVAIL=LOC
4. Exit
135. 135
SINGLE LINKED LIST DELETION
FINDB(INFO, START, ITEM, LOC, LOCP)
This procedure finds the location LOC of first node N which
contains ITEM and the location LOVP of the node preceding N. if
ITEM does not appear in the list then the procedure sets
LOC=NULL and if ITEM appears in the first node then it sets
LOCP=NULL
1. [list empty?] if START==NULL then
Set LOC =NULL and LOCP==NULL and return
2. [ITEM in first node ] if INFO[START]==ITEM then
Set LOC=START and LOCP=NULL and return
3. Set SAVE=START and PRT=LINK[START]
4. Repeat steps 5 and 6 while PTR!=NULL
5. If INFO[PTR]==ITEM then
Set LOC=PTR and LOCP=NULL
136. 136
SINGLE LINKED LIST DELETION
6. Set SAVE=PTR and PTR=LINK[PTR]
7. Set LOC=NULL
8. Return
140. 140
Double Linked Lists
Consists of nodes with two linked references one points to the
previous and other to the next node
Maximises the needs of list traversals
Compared to single list inserting and deleting nodes is a bit
slower as both the links had to be updated
It requires the extra storage space for the second list
A B C
start
Tail
141. 141
Insertion Double Linked Lists
INSERTWL(INFO,FORW, BACK, STACK,AVAIL,LOCA,LOCB, ITEM)
1. [OVERFLOW?] If AVAIL==NULL then write OVER FLOW and exit
2. [Remove node from AVAIL list and copy new data into node]
Set NEW=AVIAL, AVIAL=FORW[AVAIL] INFO[NEW]=ITEM
3. [Insert node into list]
Set FORW[LOCA]=NEW, FORW[NEW]=LOCB
BACK[LOCB]=NEW BACK[NEW]=LOCA
4. Exit