Documente Academic
Documente Profesional
Documente Cultură
Overflow Book
April 2016
GATE Overflow April 2016 1 of 2244
Table of Contents
Algorithms
Access Time
Ace Test Series
Activity Selection
Algorithm
Algorithms
Asymptotic Notations
B Tree
Bfs
Binary Heap
Binary Search
Binary Search Tree
Binary Tree
Bst
Chaining
Cyclomatic Complexity
Dfs
Dijkstras Algorithm
Dynamic Programming
Gcd
Geek Mock 2016
Generating Functions
Graph Algorithms
Greedy Algorithm
Hashing
Heap
Heap Sort
Huffman Code
Inversions
Knapsack
Loop
Loop Invariants
Madeeasy
Madeeasy Testseries
Master Method
Master Theorem
Merge Sort
Merging
Minimum Spanning Trees
Mst
P Np Npc Nph
Placement Questions
Quicksort
Recurrence
Recurrence Eqation
Recurrence Equation
Recursion
Recursion Tree
Shortest Path
Sorting
Space Complexity
Spanning Tree
Stack
Testbook
Time
Time Complexity
Topological Sort
Why
Programming & DS
Arrays
Programming In C
Engineering Mathematics
Compiler Design
Compiler Tokenization
Derivation Tree
Grammar
Intermediate Code
Lexeme
Lexical Analysis
Live Variable
Ll1
Lr Parser
Marks
Parsing
Programming In C
Register Allocation
Regular Language
Scope
Sdd
Shift
Shift Reduce
Syntax Directed Translation
Target Code Generation
Testbook
Tokens
Top Parsing
Variable Binding
CO & Architecture
Access Time
Ace Test Series
Address Translation
Addressing Modes
Arrays
Associative Memory
Average Stall Cycle Per Ins
Branch Conditional Instructions
Byteaddressable
Cache
Cache Memory
Car
Cisc
Clock Time
Clockcycle
Coa
Computer Organization
Control Unit
Cpu
Cycle
Data Dependencies
Data Hazards
Data Path
Direct Mapping
Disk
Dma
Dram Refreshing
Effective Memory Access
Fault
Floating Point Representation
Gmr
Horizontal
Ieee Representation
In
Instruction Format
Interrupts
Io
Io Organization
Lockup Free Cache
Look Aside
Machine Instructions
Madeeasy
Madeeasy Testseries
Memory
Memory Interfacing
Memory Management
Microprogramming
Misses
Multiplexer
Number
Number Representation
One
One Task Execution
Operand Forwarding
Page Replacement
Pipeline
Preparation
Priority
Ram
Reference Book
Secondary Storage
Speedup
Stack
Stall
Stealing
Testbook
Throughput
Tlb
Track
Virtual Memory
Virtualgate
Write_through
Operating System
Ace Test Series
Address
Bitmap
Cache Memory
Computer Organization
Concurrency
Context Switch
Deadlock
Demandpaging
Disk
Disk Scheduling
Dram Refreshing
Effective Memory Access
Exponential Averaging
File System
Fork
Inode
Inter Process Communication
Internal Fragmentation
Io Handling
Linked Lists
Madeeasy
Maths
Memory Allocation
Memory Management
Misses
Multitasking
Mutex
Operating_system
Page
Page Fault
Page Replacement
Page Table
Paging
Process
Process Schedule
Process Synchronization
Resource Allocation
Resource On
Secondary Storage
Segmentation
Semaphore
Set Associative
Software Testing
Testbook Test Series
Thrashing
Tlb
Virtual Memory
Virtualgate
Databases
B
B Tree
Bcnf Decomposition
Candidate
Canonical Cover
Canonical Normal Form
Cartesian Product
Concurrency
Conflict_serializable
Data
Data Isolation
Database
Database Constraints
Database Normalization
Dbms
Ddl
Decomposition
Dependency Preserving
Er
Er Diagram
Er Model
File
File System
Foreign
Form
Functional Dependencies
Indexing
Minimal Cover
Multivalued Dependency 4nf
Natural Join
Query
Referential Integrity
Regular Language
Relational Algebra
Relational Calculus
Relations
Sql
Testbook
Transactions
Tree
Update
View_serializable
Virtual
Virtualgate
Where
Theory of Computation
Automata
Cbt 1
Chomsky Normal Form
Closure Property
Combinations
Compound Automata
Context Free
Context Sensitive
Counting
Csl
Dcfl
Decidability
Dfa
Finite Automata
Flip Flop
Grammar
Identify Class Language
Inherently Ambiguous
Ldentify Language
Made
Madeeasy
Madeeasy Testseries
Minimal State Automata
Myhill Nerode
Nfa
Non Regular
Normal Pda
Number Of Dfa
Pda
Pumping Lemma
Pushdown Automata
Rank Of Nonterminal
Recurrence
Recursive Recursively Enumerable
Reduction
Regular Expressions
Regular Language
Regular Set
Rel
Testbook
Time Complexity
Turing Machine
Virtualgate
Computer Networks
Number Representation
Overflow
Pla
Radix
Self
Sequential
System
Systems
General Aptitude
Cbt 1
Verbal Ability
Algebra
Made Easy_test Series
Mocktest
Number Series
Testbook
Venn Diagrams
Numerical Ability
Ace Pregate
Ace Test Series
Algebra
And
Binary Tree
Cat2009
Combinations
Combinatorics
Expectation
Geometry
Logarithms
Logical Reasoning
Modular Arithmetic
Probability
Probability Using Tree Method
Quadratic Equations
Ratios
Test Cases
Virtualgate
Work Time
Mathematical Logic
Eigen Value
Equivalence Classes
First Order Logic
Groups
Kenneth Rosen
Mathematical Logic Virtualgate
Matrices
Probability
Random Variable
Probability
Bayes Theorem
Binomial Theorem
Coin
Conditional Probability
Expectation
Independent Events
Made Easy_test Series
Mode
Modular Arithmetic
Pgee
Probability
Random Variable
Statistics
Testbook
Variance
Set Theory & Algebra
Ace Test Series
Boolean Algebra
Equivalence Classes
Functions
Generators
Group
Groups
Hasse Diagram
Kenneth Rosen
Lattice
Madeeasy
Partial Order
Pigeonhole
Relations
Sets
Summation
Theory
Combinatory
Combinatory
Arrangement
Combinations
Combinaton
Combinatorics
Counting
Generating Functions
Made Easy_test Series
Permutation
Pigeonhole
Placement Questions
Probability
Recurrence
Recurrence Eqation
Graph Theory
Ace Test Series
Bfs
Graph Coloring
Graph Isomorphism
Graph Matching
Graph Planarity
Haming Distance
Recurrence
Linear Algebra
Complex Number
Eigen Value
Eigen Vector
Lu Decomposition
Matrices
Number Series
Polynomials
Calculus
Complex Number
Integration
Limits
Maxima Minima
Mocktest
Parabola
Study Resources
Virtualgate
Programming
Ace Test Series
Array Of Pointers
Arrays
Avl Tree
B Tree
Barc2016
Binary Tree
Bst
Compiler Tokenization
Confusing
Divide And Conquer
Functions
Geeks
Graph Algorithms
Hashing
Heap Sort
Identify Function
Linked Lists
Loop
Memory Management
Minimum Spanning Trees
Output
Parameter Passing
Pointers
Programming In C
Recurrence Equation
Recursion
Scope
Sorting
Stack
Storage Classes In C
Structures
Syllabus
Time Complexity
Variable Binding
DS
Arrays
Asymptotic Notations
Avl Tree
B Tree
Binary Heap
Binary Search
Binary Search Tree
Binary Tree
Bst
Chaining
Clrs
Combinatorics
Dfs
Hashing
Linked Lists
Permutation
Pointers
Postfix
Programming In C
Queues
Recursion
Rmo
Sorting
Stack
Trees
Universal Hash
Admissions
IISc/IITs
Admissions
Area Of Interest
Cse
Cutoffs
Eligibility
Iisc
Iit
Iit Bombay
Iit Madras
Ms
Obc Ncl
Qualify
NITs
Cutoffs
Placements
IIITs
Other Colleges
Ism Dhanbad
Others
Psu
Study Resources
Arjunsir
Guidance
Mocktest
Preparation
Repeating Gate
Study Resources
GATE Application
Eligibility
Registration
Revision
Associative Memory
Lru
Null
Written Exam
Iisc
Interview Questions
Iitd 2011
Puzzles
Puzzle
Puzzles
Algorithm Challenges
Algorithm Challenge
Placement Questions
1 Algorithms top
1.1 Access Time: Arranging files to optimize access time ISRO_2015 gateoverflow.in/37207
top
Six files F1, F2, F3, F4, F5 and F6 have 100, 200, 50, 80, 120, 150 records respectively. In what order should they be stored
so as to optimize act. Assume each file is accessed with the same frequency
The answer is A. However, why should we search sequentially? Can't we arrange the files as F1,F2...F6, and then do binary
search?
Ans.A
A. Binary insertion sorting (insertion sort that uses binary search to find each insertion point) requires O(nlogn) total
operations.
B. In the merge-sort execution tree, roughly the same amount of work is done at each level of the tree.
C. In a min-heap, the next largest element of any element can be found in O(logn) time.
D. In a BST, we can find the next smallest element to a given element in O(1) time.
Selected Answer
Insertion Sort with Binary search : yes no comparison surely reduced bt no of swaps still be there.. Time complexity
remain O(n2).
Time complexity of Merge Sort T(n) = T(n/2) + O(n) here O(n) is level cost.
In min heap for next max it will take O(n) time .
Let element is X .. then Find X will take O(n) in worst case then constant time to find next min. Total O(n)
only B is correct .
1.4 Activity Selection: What is the time complexity of job sequencing with
deadline using greedy algorithm? top gateoverflow.in/28992
What is the time complexity of job sequencing with deadline using greedy algorithm?
O(n)
O(log n)
O(n log n)
O(n2)
Made Easy
Q 19
2) Take each job and start where the deadline is given ans keep searching for the vaccant location. So if there are N jobs
for each job we need to search N slots. i.e O(n^2)
http://www.geeksforgeeks.org/job-sequencing-problem-set-1-greedy-algorithm/
1.6 Algorithm: what will be the time complexity for the below question ? top
gateoverflow.in/41775
Let an array A[1,....n] has n elements, and every element of an array is less than or equal to n. An element is said
to be "majority element" if it is occurred in more than n/2 positions of an array. what is the time complexity to check
whether the majority element exist or not?
algorithm time-complexity
//Deleted
algorithms- recursion
http://gateoverflow.in/32159/complexity-recurrence-relation-using-substitution-method
1.8 Asymptotic Notations: Let n = m!. Which of the following is true? gateoverflow.in/30720
top
(c) m = Θ ( (logn)^2)
(e) m = Θ ( (logn)^1.5)
tifr2016 asymptotic-notations
1.9 Asymptotic Notations: Let f(x), g(x) and h(x) be function which of
following statement is false? top gateoverflow.in/36477
Q16). Let f(x),g(x) and h(x) be functions which of the following statement is false?
asymptotic-notations algorithms
Selected Answer
A.
f(x) = O(g(x)) i.e. f(x) <= g(x) ...........(1)
g(x) = O(h(x)) i.e. g(x) <= h(x) ...........(2)
B.
f(x) = Ω(g(x)) i.e. f(x) >= g(x) ...........(1)
g(x) = Ω(h(x)) i.e. g(x) >= h(x) ...........(2)
a. O(2n ) = O(3n )
b. O(logn2 ) = O(logn)
(
c. f(n) = O (f(n))2 )
d. 22log n (logn) = O(n2 logn)
algorithms asymptotic-notations
Selected Answer
What is O(g(n))?
O(g(n)) =
{ f(n):
there exist positive constants c and n 0 such that
0 ≤f (n ) ≤c⋅g (n ) for all n ≥n 0 }
What does it mean to say f(n) = O(g(n))?
When we say f(n) = O(g(n)), we actually mean f(n) ∈ O(g(n)), that is, the function f(n) is an element of the set of all functions
that grow no faster than g(n). In other words, f(n) doesn't grow faster than g(n)
Note: We are allowed to abuse the notation because it makes life easier. However, we must take care not to misuse the
notation!
We should make sure, however, to understand the precise meaning of the notation so that when we abuse, we
do not misuse it. - CLRS (3rd edition, Page 44)
It means that every element in A also exists in B, and every element in B also exists in A.
Option A: False
Consider the function 2.5n . It belongs in O(3n ), but not in O(2n ). Hence, the two sets can't possibly be equal.
Option B: True
( )
log n2 = 2logn.
Since constant multiplicative factors do not matter in asymptotic complexity, O(log(n2 )) = O(logn)
Option C: False.
1 1
2
As mentioned by amarVashishth, x grows faster than x . Hence, f(x) ∉ O(f2 (x))
Options D: True.
(
22log n ⋅ logn = 2log n )2
⋅ logn = (n)2 ⋅ logn.
∑ (range − > 1 <= k <= n)O(n), where O(n) stands for order n is -
a) O(n) b) O(n 2)
c) O(m 3) d) O(3n 2)
asymptotic-notations
1<= k<= n => we have add O(n) 'n' times since 'k' is 1 to n. 'K' is like iterator .
asymptotic-notations algorithms
All options are abusing asymptotic notations. Please change the source of your practice :(
1.13 Asymptotic Notations: Let f(n) , g(n) be two functions of n , which one
the following is correct top gateoverflow.in/15289
f(n) = n2 logn
g(n) = n (logn) 10
asymptotic-notations
Selected Answer
Since any polynomial function grows faster than any logarithmic function, we have:
1.14 Asymptotic Notations: Let f(n) = O(n), g(n) = θ(n), and h(n) = Ω(n).
Then f(n). h(n) + g(n) is_______________ top gateoverflow.in/7224
since logn<= n
but when we substitute n+((logn)(n2) = O(n2) but ans is Ω(n) can somebody wxplain this plz
algorithms asymptotic-notations
You can also take h(n) = n 3, and then the upper bound changes. But whatever you take the lower bound of f(n) won't
change and remains n because of the θ(n) term.
Describe a Θ(nlgn)-time algorithm that, given a set S of n integers and another integer x, determines whether or not there
exists two elements of S whose sum is exactly x.
asymptotic-notations algorithms
Consider two natural-valued functions f: N N, and g:N N. Which of the following statements canNOT be True?
asymptotic-notations
asymptotic-notations
Selected Answer
then T1(n) + T 1(n) = 2 O (n 2) = O (n2) (constant term dont affect the complexity )
eg :
O (F(n))= n 2
1.17 Asymptotic Notations: Let f(n)= Ω(n), g(n)= O(n) and h(n)= Ѳ(n). top
gateoverflow.in/11232
Let f(n) = Ω(n), g(n) = O(n) and h(n) = Ѳ (n). Then [f(n). g(n)] + h(n) is:
A. Ω (n)
B. O (n)
C. Ѳ (n)
D. None of these
asymptotic-notations
Selected Answer
f(n). g(n) - here the individual bounds are ≥n and ≤n respectively. So, for their product we can just say it is ≥ n or Ω(n)
provided g is a non-decreasing function. But h = Θ(n) h = O(n) ∧ h = Ω(n). So,
(whatever be the complexity of f(n). g(n), h(n) grows at least at the rate of n and hence the whole expression too, due to '+')
Why is this order true.... 2^sqrt (log n) is exponential.. so it should be greater than n^1/4?
algorithms asymptotic-notations
6553616 (256k)18
= 2256 = 2324
We can see that the growth of the first function is the least, then the second and the last one is growing the fastest. So,
(a) choice is correct.
n^(1/(2^(log2log2n)))
asymptotic-notations
Ans: 2
algorithms asymptotic-notations
1.20 Asymptotic Notations: let f(n) and g(n) be asymptotically non negative
functions which of the following is correct? top gateoverflow.in/13101
If f(n) and g(n) be asymptotically non negative functions then which of the following is correct?
asymptotic-notations algorithms
so max(f(n), g(n)) ∈ Θ(f(n) ∗ g(n)) (i`m not sure please correct me if i`m wrong :) )
REF: http://math.stackexchange.com/questions/267252/how-to-prove-that-maxfn-gn-thetafn-gn
1.21 Asymptotic Notations: which function has higher growth rate among n 3
and (logn)! ? top gateoverflow.in/27704
According to me n3 should be asymptotically greater since (logn)! is computed like logn will be a small constant less than n and
when I calculate its factorial it will obviously be less than n3 .
asymptotic-notations
Selected Answer
You should not say "small constant"- "much smaller value than n" is correct. But after taking factorial how can we be sure
this will remain smaller?
( )
log n3 = 3 ⋅ logn
( )
We also know that log(x!) = Θ x ⋅ log(x) (Stirling's approximation)
( ) (
log (logn)! = Θ logn ⋅ log(logn) )
So, the second one (2) is asymptotically larger than (1), as log(logn) is asymptotically larger than 3.
The fact that (logb n)! grows faster than n3 can be somewhat counterintuitive.
So, here's a way you can make it more sensible.
Think of what would happen if instead of having a factorial, we had an exponential. That is, instead of having (logb n)!, we
had e logb n.
Since exponentials and logarithms are inverses of each other, we can simplify it a bit.
(
e logb n = b logb e ) logb n
(
= b logb n ) logb e
= n logb e
This means that is we use an exponential instead of a factorial, we get a polynomail with degree logb e. Depending on the
value of b, this degree could be anything between ( − ∞, ∞), and thus, even greater than 3!
But that is not all. We also know that factorials grow faster than exponentials! That is, x! = ω(cx). So, if we have a factorial
with the (logn), we are already growing faster than any polynomial nc!
1.21 Asymptotic Notations: Let f(n) = Ω(n), and g(n) = O(f(n)). Then g(n) =
_______ [Assume n > 0] 1. Ω(n) 2. O(n) 3. θ(n) 4. Ω(1) top gateoverflow.in/36807
asymptotic-notations algorithms
1.22 Asymptotic Notations: Given two positive functions f(n) and g(n).If
f(n)/g(n)=c , for some constant c >=0 , which of the stmts are true ? gateoverflow.in/38379
top
1.f(n)=O(g(n))
2.f(n)=⊖(g(n))
According to me :
it is saying that c is non-negative and not infinite so if g(n) tends to zero then c will tend to infinite but it is given that it is not infinite therefore clearly g(n) should be larger than f(n) , so more
precisely we can say f(n)=O(g(n)) ,plz correct me ,if I am wrong
asymptotic-notations
It could be (-)g(n) as c is a constant and > 0 i.e. F(n) has same order of growth as g(n)
T1(n)=O(f(n))
T2(n)=O(f(n))
.T1(n)+T2(n)=O(f(n))
.T1(n)=O(T2(n))
.T1(n)=ω(T2(n))
.T1(n)=Θ(T2(n))
asymptotic-notations
Selected Answer
T1(n)=O(f(n)) => T1(n) < c 1 * f(n) where c 1 is +ve constant (from Big O Def)
T2(n)=O(f(n)) => T 2(n) < c 2 * f(n) where c 2 is +ve constant (from Big O Def)
a] True
Since T1(n) + T 2(n) < (c 1+c2) * f(n), So we can say T 1(n) + T 2(n) = O(f(n))
b] False
c] False
d] False
(logn)1/2=O(loglogn)
asymptotic-notations
Selected Answer
i geeting ans 1 and 2 are true but ans given only 2 is true explain it
asymptotic-notations
(1/2)* log2n ≤ (1/2)* log 2n ≤ log 2n => (1/2)* log 2n = ⊝(log 2n) => log 4n = ⊝(log2n) Hence (!!) is correct.
1.26 Asymptotic Notations: How do O and Ω relate to worst and best case? top
gateoverflow.in/32570
I am unable to get the actual significance of the asymptotic notations with respect to best , worst and average
case , for instance why is worst case of insertion sort theta(n^2) , why not O(n^2) more specifically .
Also why does Binary search takes Theta(log n ) time and not O(log n ) time ,since in best case we may find the element at
first position only so it will take omega(1) time then so why do we consider Theta(log n) .
Even I am not getting that do we have to associate best and worst cases with these asymptotic notations , say If I have to
insert an element into an unsorted linked list , then what is the terminology of best case ,worst case here , it is obvious that
it will always take O(n) ,Now even if I have one node here and I am inserting an element after that node ,it will take
constant time ,it will take so what should I say that time complexity is omega(1) or O(1) or theta(1) more tightly .
I have gone through this link but still I am under lots of confusions ,please clarify this precisely .
http://cs.stackexchange.com/questions/23068/how-do-o-and-%CE%A9-relate-to-worst-and-best-case
asymptotic-notations
An algorithm does nt take same amount of time for all possible instances of input.for some instances it could be larger
than for the other instance.so,if we have 2 algo for same problem ,we decide their relative awsmness by asymptotic
analysis. if we know that for the worst instance on input the algo will take f(n) time or lesser then we can say that T(1st
algo)=0(f(n))
so,by calculating the T(2nd) algo and comparing their value we can decide that which one is better.
for most of the instance of the i/p ,what is the time complexity of the problem is called average case.ssso,it will be less
than the worst case and greater than the best case.
similliarly ,for the best instance of i/p,the T(algo) is the bes case.
in worst case ,binary search will recurse till there will be only one element in the divided subproblem(element does nt exit
in the array or it exists in a pos which will be find out in the last recursion of bst) and then it will produce the result.no of
comparision in this case= height of the tree 0(logn) => worst case =>gives the upper bound of the algo
in best case,the element will be present in the middle,which will be find out in first iteration.time complexity=omega(1)
Ans given is D. Is it because, in analyzing this we would ignore the constants involved in the equation?
asymptotic-notations algorithms
No its not the case. Its because all options a,b,c are correct so ans is option d.
f(n) = ⊖(g(n)) means there exist two constant C1 and C2 such that
f(n)>=C2 g(n)
just take C1 = C2 = 2 7 and you will get the both the conditions are satisfying.
clearly f(n) is exponential and n 1000 is polynomial so it is also true. or you can put a number n = 1000000 or more than
this get this. This one you may find that 'n' value is large but anyway we do analysis of functions asymptotically so no
issue with large number.
g(n) = 2n-10
b-tree
Selected Answer
h=O(logtN)
1.29 Bfs: Breadth-first search time for given vertex in complete graph gateoverflow.in/38611
top
Argument: As it a complete tree, maximum BFS level possible are log(n). And as BFS time is O(n+E) , taking E as path cost ,
it will give O(n+logn) which is O(n). So, I ticked B. Answer is given as C. But, if we take a vertex just in the first level , so
the time cost will be Omega(1). So, C must not be true. Where am I going wrong??
consider a binary tree in which 1,2,3,4,5,6,7 are inserted in level order.Then node 7 will be the last one to get inserted.
Now we want to find the worst case search time to find 7. Consider this BFS order 1,2,3,4,5,6,7 in which we need to
traverse all the 7 nodes to reach 7 i.e O(n). And the best case BFS order to find 7 is is 1,3,2,7,6,4,5 I hope this helps!
1.30 Binary Heap: What is the complexity of finding 50th smallest element in
an already constructed binary min-heap? top gateoverflow.in/5915
What is the complexity of finding 50th smallest element in an already constructed binary min-heap?
a. θ(1)
b. θ(logn)
c. θ(n)
d. θ(nlogn)
Selected Answer
Deletion of min element from min-heap can be done in logn time. To find the 50th min element we have to perform 49
deletion of min element from the binary min-heap.
= theta(lgn)
Consider the problem of searching an element x in an array arr of size n. When can the problem can be solved in O(logn) time?
1. Array is sorted
2. Array is sorted and rotated by k. k is given to you and k ≤ n.
3. Array is sorted and rotated by k. k is NOT given to you and k ≤ n
4. Array is not sorted
(A) 1 Only
(B) 1 & 2 only
(C) 1, 2 and 3 only
(D) 1, 2, 3 and 4
algorithms binary-search
1> Clearly binary search can be implemented if the array is sorted. Hence search can be performed in O(logn).
Consider an array with elements 1234567. Now, suppose the array is rotated by 2 then the new array will be 3456712.
Here k is 2. As, k is known to us finding the pivot point is easy it will be just = (n-1)-k ;where n is the size of the array.
Here it is 4. Now, to search for an element divide the array in two subarrays . Now compare the number with the 0th
element, if the number is greater than the 0th element then apply binary search in left subarray to pivot else apply binary
search to right subarray...Hence searching can be performed in O(logn).
3>Here k is not known. Hence the pivot point is not known, if we can get the pivot point then we can apply the same
method as above.
Now cosider the above example. The pivot point has the property that the pivot point element is the only element whose
next element is smaller than it in the array.Hence we can find the pivot in O(logn) applying binary search like seaching.
and the rest are same as above Hence the total complexity becomes O(logn)+O(logn)=O(logn).
1.32 Binary Search: how many searches are required on the average ,if
binary search is employed ? top gateoverflow.in/16124
suppose there are 11 items in sorted order in an array.how many searches are required on the average ,if binary search is
employed and all searches are successful in finding the item?
binary-search
if binary search tree is constructed, for root element one comparison for level 1, two comparisons and so on. There are 1,
2, 4 and 4 elements at levels 1, 2, 3, 4 respectively. So, avg. no of comparisons = (1*1+ 2*2+4*3+4*4)/11 = 3 as for
level we need comparisons to reach there.
Ans is a.
1.33 Binary Search: #doubt on heaps and binary search top gateoverflow.in/31046
Consider the process of inserting an element into a max heap, where the max heap is represented by an array.Suppose we
perform a binary search on the path from the new leaf to the root to find the position for newly inserted element, the
number of comparisons performed is? # i m getting as O(logn) as upon applying binary search we wud compare O(logn)
elements(neighbours and its own root only) plz clr my confusion
Yes, number of comparisons would be O(log n). But if you apply binary search, then there is no use of heap and actual
insertion is much costlier, comparison O(log n) + O(n)shifting.
If you use heapify procedure you'll get O(log n) in total for insertion.
binary-search
Selected Answer
Array is [1,2,3,4,5,6,7,8,9,10].
Average number of comparisons depend on how likely each element is to be searched. Suppose each element is equally
likely to be searched i.e. every element has 1/10 prob of being searched.
Now searching 5 takes only 1 comparison (it will be found in first trial only).
Then searching 2 or 8 takes 3 comparisons (1 for equality with 5, which was failed, then 1 for less than or greater than,
then 1 for equality with 2 or 8).
Then searching 1 or 3 or 6 or 9 takes 5 comparisons (again 1 for less than or greater than, and 1 for equality)
1 +2 ∗ 3 +4 ∗ 5 +3 ∗ 7
10
So average number of comparisons = = 4.8.
Its 2.9 on average; the question asked average number of comparisons on binary search; so as per algo first the middle,
then since it is sorted while computing for the middle and equating to it at the same time it is determined which way to go
further left or right;
1 2 3 4 5 6 7 8 9 10
For 5: 1
For 2,8 : on second comaprison, i.e., 2
And similarly
For 1,3,6,9: 3
And for 4,7,10: 4
top
Let you are given an array of nine elements in increasing order. If you want to implement binary search on the given array of
element then the number of comparisons per successful search on an average will be:
Average is 2.78,
should I answer this question with or without rounding off 2.78, as number of comparisons is an integral value?
binary-search algorithms
Selected Answer
It is to be answered without rounding off, i.e, 2.78 or whatever you calculated being the correct answer.
When searching for the key value 50 in a binary search tree, node containing the key values 10, 30, 40, 70, 90, 120, 150, 175 are traversed, in any order. The number of
different orders passing in which these keys values can occur on the search path from the root to node containing the value 50 are ________.
binary-search-tree algorithms
1.36 Binary Tree: What will be the recurrence relation of the given below
program for Preorder traversing technique? top gateoverflow.in/32314
Preorder(root)
Printf("root.data");
Preorder(root.leftsidetree);
Preorder(root.rightside);
binary-tree
Selected Answer
T(n)=2T(n/2)+c
binary-tree
The first inserted element must become the root and as per question we have p elements on right subtree which means p
elements are larger than the root. So, out of n elements, the root must be n − p.
1.38 Binary Tree: The maximum number of nodes on level i of a binary tree
top gateoverflow.in/36354
Level of a node is distance from root to that node. For example, level of root is 1 and levels of left and right children of root is 2. The maximum
number of nodes on level i of a binary tree is
a) 2^i-1
b)2^i
c)2^i+1
d)2^(i+1/2)
binary-tree data-structure
Selected Answer
1.39 Bst: how to construct BST by given preorder and postorder traversal top
gateoverflow.in/29918
data-structure bst
Selected Answer
Try this:
Preorder: 50, 27, 16, 4, 12, 34, 29, 44, 88, 65, 52, 77, 93, 92
Postorder: 12, 4, 16, 29, 44, 34, 27, 52, 77, 65, 92, 93, 88, 50
Inorder: 4,12,16,27,29,34,44,50,52,65,77,88,92,93
50 - root
Consider a hash table with n buckets, where external(overflow) chaining is used to resolve collision. The hash function is
1
n
such that the probability that a key value is hashed to a particular bucket is . The hash table is initially empty and k distinct
values are inserted in the table.
Q) What is the probability that bucket number 1 is empty after the kth insertion?
a. n
b. (n − 1)k
c. ((n − 1)/n)k
d. ((n − 1)/k)n
Q). What is the probability that no collision has occurred in any of the k insertions?
Q1) If bucket no 1 is empty after k insertions that means keys must have mapped to remaining n − 1 locations. k insertions
n −1
n −1
n −2
n − (k−1 )
n
Insertion k:
so we get
n . (n −1 ) . (n −2 ) … (n −k+1 )
nk
probability of no collision =
ans a
Q.1] probability that the hash fun mapping a key to a bucket number 1= 1/n
probability that the hash fun not mapping a key to a bucket number 1= 1-(1/n)
probability that the bucket no. 1 is empty after 2 iteration= First Time Missed And Second Time Missed = (n-
1/n) (n-1/n)
none of these k keys mapped to bucket no. 1 after k Iteration=(n-1/n) (n-1/n) (n-1/n)...k times =
(n-1/n)^k Option C
For K=1, it's 1. For K=2, the second item must miss the bucket of the first item.
So it has n−1 places it can go safely. The probability of success is therefore n−1/n
So the probability for K=3is 1*n−1/n*n−2/n.
similarly for P(k) = 1*n−1/n*n−2/n*n-3/n............n+1-k/n
hashing chaining
Probability will be .2
hashing chaining
Selected Answer
In this case, we have two clusters of size 3 (abc, efg). Worst case can occur when we are searching for a non-existent
element, that should have mapped to either the location of a:0, or the location of e:6.
So, number of comparisons in worst case for this Hash Table are:
If we are inserting an element in chaining(outside) hashing technique, then what will be the time complexity in best case,
average case and Worst case.
chaining hashing
If we are using chaining technique for collision resolution in hashing, then the minimum chain length will be 1 (not zero,
since then there will be no chain). The maximum chain length will be Ο(n) since we can have all the elements in one slot.
An example of this worst case could be: hash function h(k) = k mod 10 and the elements as 2,12, 22, 32, 42, 52, 62, 72,
82, 92
The average case would be an average of all the intermediate cases, (best case + worst case)/2 i.e., Ο(n).
while (m
if (x>y) and (a
a= a+1
y=y-1
end if
m=m+1
end while
a. 2
b. 3
c. 4
d. 5
cyclomatic-complexity
Selected Answer
=3+1
One for while, two for if bcoz of two conditions as if first condition then if second condition then do given.
1.45 Dfs: Does a DFS produce same no of tree edges in an undirected graph
? top gateoverflow.in/12485
Does a DFS for an undirected graph always produce the same number of tree edges irrespective of the order in which we
visit the vertices ?
dfs
Yes , it will produced same number of edges in an undirected graph . The minimum edges required to visit all vertices is n-
1 ( for n vertices ) . For a connected graph with n vertices DFS required n-1 edges and it form a tree .
Selected Answer
(b) 6
You can achieve the maximum depth of 6 recursive calls when you have following elements on the stack :
0, 1, 2, 3, 4, 6
(6 being the element on the top and 0 being the element at the bottom.)
Once you reach this state, you have to start popping the elements from the stack.
Q). Consider the vertices V1 and V2 that are simaltaneously on the function call stack at some point during the execution of
depth -first search from vertex S in a digraph.Which of the following must be true?
II. There exist both a directed path from V1 to V2 and a directed path from V2 toV1 .
III. If there is no directed path from V1 to V2 then there exist a directed path from V2 to V1 .
dfs
1.48 Dfs: Edge type in Undirected Graphs on Depth First Tree top gateoverflow.in/20525
Assume WHITE vertices that are yet to be discovered, BLACK vertices are finished vertices and GRAY vertices are frontier
betweeen WHITE and BLACK in Depth First Search.
Now, What are the various edge types like TREE-EDGE and BACK-EDGE possible between any pair of vertices during a Depth
First Search in an Undirected graph.
Confused about the edge type between WHITE and GRAY type vertices.
If we can have a TREE-EDGE between any pair of types of vertices in an undirected graph, we can also have BACK-EDGE
in that same pair of types of vertices.
Answer given: C
Please explain
algorithms dfs
Selected Answer
But there is a possibility that there exists some code which does not push the last node on the stack,
for doing such a thing it is required, say, to maintain a counter for number of nodes being pushed to the stack. Its good to
maintain such a counter, this saves us from unnecessary push and checks for visited marked nodes, once nodes except
one are already traversed.
Adjacent element of v7 i.e. 6 and 8 already visit by v4 and v6..thats y need nod to push inti stack
1.50 Dfs: Which of the following statement is correct regarding DFS? gateoverflow.in/5424
top
Which of the following statement is correct regarding DFS? 1) All the vertices are pushed in the stack during DFS Traversal.
2) No vertex is pushed more than once in the stack during traversal.
Assume priority queue in Dijkstra’s algorithm is implemented using a sorted link list and graph G (V, E) is represented using
adjacency matrix. What is the time complexity of Dijkstra’s algorithm (Assume graph is connected)?
How to solve this kinds of problems ? Changing DS used in one algorithm . Do I need to study the entire algorithm ?
algorithms dijkstras-algorithm
Selected Answer
1.Build heap->O(V)
2.extract min->O(log V)
extract min will be on maximum as the number of vertices(O(V logV) and relax operation will be in Worst case on the
number of edges(O(E logV)..
extract min(O(1))
decrease key-O(V)
now from above concept extract min will be on V vertices i.e O(V^2) and decrease key on maximum E edges O(EV)
so time complexity=O(V^2*V)=O(V^3)
Answer is given as (B). But, shouldn't it relax point 'c' via 'a' .. So, i guess answer should be D. Is it?
At the end of it's 5 th Successful season,The siruseri Permier league is planning to give an award to most improved bowler
over 5 years . For this an important Index will be computed for each bowler,This is defined as the longest Subsequence of
strictly decreasing economy rate's by the bowler among all his matches over 5 season's.For example seasons are
(10.0,5.0,8.9,6.7,4.2,5.5,2.2,3.4,6.0,2.3,2.0) so his improvement index is 7 based on sequence (10.0 ,8.9, 6.7, 5.5, 3.4,
2.3, 2.0)
Now let E[1...........N] Donates a sequence of n economy rates for which improvement index is to be calculated
for 1 ≤ j ≤ n,Let I[j] denotes the improved index for the prefix of score E[1.......j ] ending at E[j]
a) I(1)=1
for j ∈ 2,3,......,n I(j) = 1+ max {I(k)/ 1 ≤ K<j, E[k] > E[j]}
b) I(1)=1
for j ∈ 2,3,......,n I(j) = 1+E(j-1) if E(j-1)<E(j)
1 otherwise
C) I(1)=1
for j ∈ 2,3,......,n I(j) = 1+ max {I(k)/ 1 ≤ K<j, E[k] < E[j]}
d)I(1)=1
for j ∈ 2,3,......,n I(j) = 1+E(j-1) if E(j-1) > E(j)
1 otherwise
2. How to evaluate this Recursive definition Using Dynamic programming?
a) A 2-D table T of Size N X N to be filled row wise from T[1][1] to T[n][n]
Selected Answer
The current considered element must be smaller than ALL previous entries. So, b, c, and d are false.
3. O(n)
Let (x ′, y ′) correspond to gcd(b, a mod b), i.e. gcd(b, a mod b) = x ′ ·b + y ′ · (a mod b). Then show that gcd(a, b) = y ′ · a + (x ′ − q)b where q is the quotient of the integer
division of a by b.
Selected Answer
See how many function calls are active in the stack. Here, function 'fun(n)' can give a call to fun(n-1), which inturn will
call fun(n-2) and so on.. till n=0.
When n becomes 0, fun will start returning, ie, it starts popping out of the stack. So, at max, there are n to 0, functions in
the stack. Hence space complexity is O(n).
1.56 Generating Functions: Below is the question that was asked in GATE
1987, can you give the answer with explanation for the same? top gateoverflow.in/33228
What is the generating function G(z) for the sequence of Fibonacci numbers?
generating-functions
What will be the time complexity of an efficient algorithm which will calculate the no of articulation points?
algorithms graph-algorithms
Selected Answer
http://www.eecs.wsu.edu/~holder/courses/CptS223/spr08/slides/graphapps.pdf
I mean if we run prim's algorithm on a weighted directed graph, will it give the same shortest path? And vice-versa?
Also if we run dijkstra's algorithm on a graph with negative weight cycle reachable from source, what will happen?
What if we run kruskal's MST algorithm on a graph with negative weights and negative weight cycles?
Thanks in advance.
graph-algorithms
Selected Answer
from dijsktra algo - we will get shortest path from source(i.e single source) to destination.
2. if we run dijsktra on graph with negative weight edges then dijsktra algo is going to compute the shortest path but it
may or may not be correct .since it is not a sin to run dijsktra algo with graph having negative weight edges .And becoz of
this demerit of dijsktra algo. we switch to bellman ford algo.
since practically it is not possible to have negative wieght edges (for ex -travelling salesman problem ) therefore dijskta
algo is more practically used as compared to bellman ford algo.
3. kruskal algo is also an algo so u can run it with graph containing negative weight edges and negative weight cycles
since the output will be an tree(without cycles) not an graph.
1.59 Graph Algorithms: Single source shortest path problem top gateoverflow.in/26906
graph-algorithms
I am referring http://www.geeksforgeeks.org/union-find/
I am getting worst case complexity as O(V2), whereas on geeksforgeeks it is given O(ElogV).
My Approach:-
Consider a graph 1---->2----->3----->4------>5------>6------>7------->.......V
1+2+3+.....V = O(V 2).
1.61 Graph Algorithms: single source shortest path algorithm top gateoverflow.in/11994
When can we have single source shortest path algorihm runs in Big Oh of number of edges.
Options are like weighted graph, undirected graph, undirected and weighted, not possilbe (i dont remember all the options)
graph-algorithms
http://cseweb.ucsd.edu/~kube/cls/100/Lectures/lec12/lec12-28.html
1.62 Greedy Algorithm: In Optimal merge pattern when do we get more than
one tree? top gateoverflow.in/31011
In Optimal merge pattern when do we get more than one tree(Sub trees) when creating a merge pattern?
Can you explain/draw optimal merge tree for n=7, <8,15,3,10,20,2,30>
algorithms greedy-algorithm
Selected Answer
Caption
1.63 Greedy Algorithm: Optimal solution with greedy algorithm top gateoverflow.in/36539
Q: There are n white dots and n black dots, equally spaced in a line. We want to each white dot with some black dot in on-
to-one fashion with a minimum total length of the wire. (See diagram above). Greedy algo. gives optimal solution for..
A) Only i
B) Only ii
C) Both
D) None
There are n white dots and n black dots. Equally spaced in a line. You want to connect each white dot with some block dot in one to one fashion with a minimum total
length of wire.
Consider 2 examples:
Greedy algorithm gives optimal solution for
a. Only (i )
b. Only (ii)
c. Both (i) and (ii)
d. None of these
A hash table of size M = 8 (0 to 7) is using open addressing for hashing the binary strings. Assume finding an empty slot
directly without collision or after collision is also a probe. Calculate the total number of probes that occur while hashing five
strings using linear probing.
hashing
Selected Answer
In linear probing if the hashed location is not empty, a linear probe is done to find an empty slot.
10011010 mod 8 = 010 = 2 (3 probes, goes to slot 4, unsuccessful probes at slots 2 and 3)
11111011 mod 8 = 011 = 3 (3 probes, goes to slot 5, unsuccessful probes at slots 3 and 4)
01110010 mod 8 = 010 = 2 (5 probes, goes to slot 6, unsuccessful probes at slots 2, 3, 4, and 5)
http://webdocs.cs.ualberta.ca/~holte/T26/open-addr.html
1.66 Hashing: Consider a hash table with ‘m’ slots that uses chaining for
collision resolution. top gateoverflow.in/13601
Consider a hash table with m slots that uses chaining for collision resolution. The table is initially empty. What is the
probability that after 4 keys are inserted that at least a chain of size 3 is created? (Assume simple uniform hashing is used)
A. m – 2
B. m – 4
C. m – 3 (m– 1)
D. 3m – 1
data-structure hashing
Selected Answer
1 1 1 m−1 m−1
3
Probability of length exactly 3 = No. of ways of selecting a slot × Probability of exactly 3 hashing going to that slot = mC1 × 4C1 × m m m m = 4 m
1 1 1 1 1
3
Probability of length 4 = No. of ways of selecting a slot × Probability of 4 hashing going to that slot = mC1 × m m m m = m
m−1 1 4.m−3
m3 m3 m3
So, our required probability = 4. + = .
Consider any one slot among N slots.The probability that three elements will be entered in same slot is 1/m*1/m*1/m =
m^-3.As there are m slot you can choose any slot among m slot.So answer is m*m^-3 = m^-2
Chain of three means , all 4 elements are hashed into single slot ,
So , is it (1/m)^4 ?
A Hash table has space for 100 records. Then the probability of collision before the table is 10% full is?
A 0.45
B 0.5
C 0.3
D 0.34 (approximately)
hashing probability
Selected Answer
Table has 100 slots. So, for 10% filling it must take 10 slots. Now, the question is like this- collision before 10% full. This
should mean the first collision happened before the 10th entry is made. So, the first collision can happen from 2nd entry
(for 1st entry there won't be a collision) to 10th entry. So required probability
Consider a hash table using uniform hashing with number of slots as m = 6 and number of keys, k = 8. Collisions are resolved
by chaining. Assuming direct hashing is used, what is the expected number of slots that ends not being empty?
Selected Answer
(6 −1 )8 58
Alternative way
Since, collisions are resolved by chaining, if 8 keys go to the same slot, 5 other slots will be empty.
Now, number of favourable cases for P(i) is equal to the number of ways in which we can place 8 distinct balls into i
distinct bins such that no bin is empty. This is given by i!. S(8, i) where S is the Stirling's number of second kind.
1
1 1
1 3 1
1 7 6 1
1 15 25 10 1
1 31 90 65 15 1
1 63 301 350 140 21 1
1 127 966 1701 1050 266 28 1
F(1) = 6 C1 . 1. 1! = 6
= 4.604
the prob. is same for all slot & hence expected no. will be same for all slots = m[1-[(m-1)/m] k ]
& m=6, & k=8 is given....So put the values you will get = 4.604
hashing
Consider the following "Max Heapify" algorithm. Array has atleast n and 1<=i<=n. After applying the Max-heapify rooted at
A[i], the result will be subtree of A[1,....n] rooted at A[i] is max heap. [Assume that except root A[i], all its children satisfied
heap property]
int p,m;
p=i;
while(X)
if(Y&&Z)
m=2p+1;
else m=2p;
if(A[p]<A[m])
Swap(A[p],A[m]);
p=m;
else
return;;
Find missing statements at X, Y and Z respectively to apply the heapify for subtree rooted at A[i].
heap
should be b
A. O(1)
B. O(n)
C. O(nlogn)
D. O(logn)
Selected Answer
option C. Best, average and worst case time complexity of heap sort is O(nlogn).
In a tree where each node has exactly either 0 or 2 children, the number of nodes with 0 children is one more than the number of nodes with 2
children.
ROOT
L R
/ \ / \
/ \ / \
----- -----
Let k be the number of nodes in R. The number of nodes in L is k + (k + 1) = 2k + 1. The total number of nodes is n = 1 + (2k + 1) + k = 3k + 2 (root
plus L plus R). The ratio is (2k + 1)/(3k + 2), which is bounded above by 2/3. No constant less than 2/3 works, because the limit as k goes to infinity is
2/3.
K sorted lists of n/k elements each. What is time complexity to sort them?please specifiy ur ans in detail
heap-sort
Selected Answer
Time Complexity = O(k) {min heap construction} +O(nlogk) {n time extract min from heap} = O(nlogk).
huffman-code algorithms
Selected Answer
Alice needs to send a large message to Bob using only five words. Seeing that the message is too long she decides to
compress the message using Huffman coding algorithm.
If the respective frequencies of words are given in the table, what would be the hamming code for w 3 w1 w2 that she was
supposed to use?
a 100011011
b 100011101
c 100001101
d 111011000
Hint : try with the two smallest frequency and then iterate for the next two and go on. now to the left branch assign 0 and
right branch assign 1.
1.74 Huffman Code: Average code length using Huffman coding top gateoverflow.in/34187
A file contains characters a,e,i,o,u,s and t with frequencies 10,15,12,3,4,13 and 1 respectively. If we use Huffman Coding for
data compression then the average code length will be -
a) 140/58
b) 146/58
c) 150/58
d) 174/58
huffman-code
B is right option
A) 192
B) 120
c) 188
D) 176
Selected Answer
(n-1)+(n-2)+.........+1=n*(n-1)/2
Here n=16
The difference between maximum possible profit for 0/1 Knapsack and fractional Knapsack problem with capacity (W) = 20.
Solution Given:
I know how to do both the greedy and Dynamic programming. But i know only tabulation method,the solution above given shows some easy way to do it. don't know what
shortcuts they used above. please suggest is there any easy way to other than tabulation method ?
algorithms knapsack
1.77 Loop: How many number of times '0' is printed ? top gateoverflow.in/36512
Selected Answer
FIRST LOOP:intializes i=1 SECOND LOOP:intializes i=1; THIRD LOOP intializes i=1 and run till i=n^6 .. and when i checks
for second iteration for 1st loop get.. condition failed ..and loops out ... THATS WHY ONLY n^6 times it get printed.
int n,rev;
rev=0;
while(n>0)
{
rev=rev*10+n%10;
n=n/10;
}
(C)n!=rev
algorithms loop-invariants
Loop invariant must hold at the end of the iteration. In the given code, the least significant digit is taken from n and
added to rev. So, at the end of ith iteration, n will have its least significant bits removed and they will be seen in rev. So,
answer is (A).
(a.) O(n)
(b.) O(nlogn)
(c.) O(n(logn)2 )
(d.) O(n2 )
But if we do with Master's theorem, then we will get option (b.) and this a case for Master's theorem, right?
Selected Answer
This is not the case for master theorem because after applying master theorem the 2 expr are not polynomial time to
each other so....by using substitution ans is C.
T(n)=2T(n/2)+nlogn
=2(2T(n/2^2)+n/2logn/2)+nlogn
n+n(1+2+3+4+5..........+log n)
Given an array of n numbers, give an algorithm for finding a contiguous subsequence A(i) ...A(j) for which the sum of
elements is maximum.
If dynamic programming approach is used then what is time complexity and space complexity?
Let f(n) = Ω(n) and g(n) = O(f(n)). Then g(n) = _______ [Assume n>0 ]
(a.) Ω(n)
(b.) O(n)
(c.) θ(n)
(d.) Ω(1)
According to me, the answer should be (b.) since, f(n) has lowest bound n and g(n) has f(n) as upper bound. Answer given
is (d.)
Selected Answer
Ans is omega(constant) because f(n)>=c.n and g(n)<=c1.n and g(n)=O(f(n)) .Take a scenario where g(n) s a constant
value so it is loosely bounded by Bigoh of f(n) then g(n)= omega(1) stands ..
take another scenario where g(n)=n+1 and f(n) be n+1/n^2/n^3 ,still omega(1) holds. since we cannot be sure of the
upper limit of f(n) so g(n) cannot be O(n).
Solve Recurrence
A) T(n) = T( √ n) + Θ(lg lg n)
C) T(n) = T(n − 2) + lg n
D) T(n) = √ n T( √ n) + 100n
There are different versions of master theorem available. I want to know whether the version given in Cormen book is
sufficient for GATE?
algorithms master-theorem
Selected Answer
http://www.iitg.ernet.in/psm/indexing_ma353/y09/LectureNoteMA515Aug7.pdf
algorithms master-theorem
1.86 Master Theorem: Recurrence, master theorem not applicable top gateoverflow.in/41232
T(n) = T(2n/3) + 1
recurrence master-theorem
2n
T(n) = T
( )3
+1
So, at level n of the algorithm we are recursively calling the problem for 2n/3 and the cost specific to a level is 1. So, we
just need to count the number of levels (recursive calls) and that will be the total cost.
2n 4n
T(n) = T
( )3
+1=T
( )
9
+ 2 = … = T(1) + k.
(We need not reach T(1), but the smallest value possible for a given n where recursion ends. But using T(1) is fine for
asymptotic analysis).
2 2 2 3
k 3
Here, k is such that 3 n ≤ 1 klg 3 + lgn ≤ 0 − klg 3 ≥ lgn klg 2 ≥ lgn k ≥ lg 2 n.
Alternatively we can use Extended Master theorem (easier for this question though previous method is needed for some
questions).
(i) T(n) = T( 2 ) + 2n
(ii) T(n) = 2n T( 2 ) + nn
master-theorem
T(n) = T(n/2)+2 n
f(n)=2 n
Here 2n >1
T(n)=2n.T(n/2)+nn
f(n)=n n
1.88 Master Theorem: Solve recurrence using Master theorem top gateoverflow.in/42285
T(a) = 0 if a = 1
where a = k
Selected Answer
Forget all the complex part and just focus on the given recurrence relation.
T(a) = 0 if a = 1
Since we are applying Master's theorem and in the above recurrence relation independent variable is 'a' (not 'n') we
calculate alog b (c) = alog 2 (2 ) = a
Note here that we are comparing the above recurrence relation to the following generalized recurrence relation.
T(n) = T(n/2) + n1 / 2 .
recurrence master-theorem
Selected Answer
1. if a > bk
T(n) = Θ nlogb a ( )
2. if a = bk
( )
a. if p > − 1, T(n) = Θ nlogb a logp +1 n
3. if a < bk
(
a. if p ≥ 0, T(n) = Θ nklogp n )
b. if p < 0, T(n) = O (n ) k
so T(n) = Θ nklogp n ( )
T(n) = Θ n1 / 2 ( )
af
()
b
≤ cf(n)
Here, we get
n n n1 / 2
af
() ()
b
=f 2
=
√2
≤ cf(n),
1
√2
for any c ≤ .
( )
So, regularity condition also satisfied and we get T(n) = Θ(f(n)) = Θ n1 / 2 .
= 2(2T(n/4) + 6n/2 − 1) + 6n − 1
= n + 6n log n − (2log n − 1)
= 6n log n + 1.
given Recurrence satisfy aT(n/b) + f(n) where a>=1, b>1, f(n) is polynomial of 'n'.
1.91 Merge Sort: Merge sort state after 2 recursive calls top gateoverflow.in/38604
I don't find any option to be correct: Argument (a check for option B): For a straight merge sort, it is not possible to sort
directly 2 halves. In a two way merge sort. say if items are greater than 8, then in just two calls, it is not possible to sort
two halves.
time complexity for merging m sorted lists, each with n/m elements
o(nlog(n/m))
1.93 Minimum Spanning Trees: Do Prim’s and Kruskal’s algorithms still work
if the edge weights are allowed to be negative? top gateoverflow.in/19537
Selected Answer
The concept of MST allows weights of an arbitrary sign. The two most popular algorithms for finding MST (Kruskal's and
Prim's) work fine with negative edges.
Actually, you can just add a big positive constant to all the edges of your graph, making all the edges positive. The MST
(as a subset of edges) will remain the same.-ref:http://stackoverflow.com/questions/10414043/is-minimum-spanning-
tree-afraid-of-negative-weights
An undirected graph G has n nodes. Its adjacency matrix is given by an n × n square matrix whose (i)
diagonal elements are 0‘s and (ii) non-diagonal elements are 1‘s. which one of the following is TRUE?
Selected Answer
algorithms p-np-npc-nph
As per i know travelling salesman problem is a Np hard not p . if the traveling salesman problem can be solved in
polynomial time using backtracking then it will become a P . So its false , it cant be solved in polynomial time by
deterministic way .
1.95 Placement Questions: How to manipulate the given linked list in the
following manner in O(n) time ? top gateoverflow.in/42252
If we are given a linked list then we have to manipulate such that even indexed node are arranged together and odd
indexed nodes are arranged together after even indexed nodes
2-->4-->6-->1-->3-->5
Firstly we place a pointer at middle element of the link list.This can be done in n/2 or O(n) by
initially keeping two pointers pointing to start node.Incrementing one ptr by 1(let say p=p->next) and other
by 2(let say q=q->next->next) till (q!=null && q->next!=null&& q->next->next!=null).When this loop
terminates ptr p will be at middle of link list(LL).
This middle node will be even numbered node if there are even no. of node in LL.Now we need to increment
p by 1 and need a new ptr (let say odd) which points to starting node.After this we just need to swap the
data (of node to which ptrs are pointing ) and increment both ptrs( odd and p) by 2 .
If no. of nodes in LL are odd then the (extra)increment of p by 1 which was done previously is not needed .
finding if LL contains even or node no. of nodes can be done in the same loop which is used to
find middle ele of LL .So no extra time required.
pls correct me if I am wrong.
p = LL->HEAD
odd=p
p = p->NEXT
even = p
p = p->NEXT
while(p!=NULL)
{
odd->next = p
p=p->NEXT
odd = odd->next
even->next = p
p=p->NEXT
even = even->next
}
even->next = odd_orig
LL->HEAD = even_orig
1.96 Quicksort: Give the result of partitioning the keys after the 1st pass of
quicksort. top gateoverflow.in/13696
THISCOURSEISOVER
Choose the last elements as pivot elements (R). Also for duplicates, adopt the convention that both pointers stop.
a) EHIOCOIERRUSSVTS
b) EHISCOIERRUSOVTS
b) EHIOCOUESRTSSVTR
c) EHIOOCIERRUSSVTS
the answer is hicoeioerssuvrs prany datta is right. and saurabh sharma the question may be wrong or it must be incomplete because they may ave used some other
implementation of quick sort.
Consider an array with the following elements: 12, 18, 17, 11, 13, 15, 16 and 14.
How many element will change their initial position after completion of partition algorithm by choosing 15 as pivot?
My approach
12, 18, 17, 11, 13, 15, 16 and 14. 15 is pivot swap it with leftmost element
15 | 14, 12, 11, 13, 17, 16 , 18 i and j meet each other at 13 so swap with pivot value
13 14 12 11 15 17 16 18
So 11 and 16 are not changed all other elements have changed their position
Correct me if i am wrong
algorithms quicksort
the worst case time complexity of quicksort for an elements when the median is selected as the pivot
a. o(n^2)
b.o(n)
c.o(nlogn)
d.o(logn)
Selected Answer
Answer C) O(nlogn), when median selected as pivot, partition method will divide array into equal halves.. so logn level
recursion tree will form with cn work(partition method) at each level..
The recurence would be..
T(n) = 2T(n/2) + Θ(n)
Therefore total time complexity =Θ(nlogn) in all cases
suppose you are given n bit integers asuming for common sense n as power of 2 .it is required to multiply them using divide
and conquer method .what is the divide and conquer recurrence that would arise for the problem
a) T(n)=4T(n/2)+c
b) a) T(n)=2T(n/2)+n
c) a) T(n)=4T(n/2)+n2
d) a) T(n)=4T(n)+n
algorithms recurrence
Selected Answer
T(n) = T(n/2) + n
T(n) = T(n-1) + cn
Ans) O(n^2)
int R(int n) {
if(n<=1)
return 1;
else {
int sum=0;
for(int i=1;i<=n;i=i*2)
for(j=1;j<=i;j=j*2){
sum=sum+i;
sum=sum*R(n/2);
}
}
return sum;
}
time-complexity recurrence
For(int i=1;i<=n;i=i*2){
For(j=1;j<=i;j=j*2){
Sum=sum+i;
Sum=sum*R(n/2);
}
}
First of all recursive call happens inside the inner loop, so solving will be difficult. Still, lets try.
Outer loop runs log2 n times and inner loop runs log2 i times for each i and i is multiplied by 2 after each iteration. So, the no.
of times the inner loop runs will be
(lg n ) . (lg n +1 )
( ) [ ]
lg1 + lg2 + lg4 + … + lgn = lg(1.2.4.…. n) = lg 20 . 21 . 22 . …2lg n = lg 2 (0 +1 + … +lg n ) = 2
T(1) = 1
T(2) = 2
T(4) = 6
T(8) = 36
T(16) = 360
T(32) = 5400
I suppose all choices should be eliminated by now - the growth rate is higher than that of n2 .
#include<stdio.h>
int count = 0;
int R(int n) {
if(n<=1) {
count++;
return 1;
}
else {
int sum=0,i,j;
for(i=1;i<=n;i=i*2)
for(j=1;j<=i;j=j*2){
sum=sum+i;
count++;
sum=sum*R(n/2);
}
return sum;
}
}
int main(int argc, char* argv[]) {
R(atoi(argv[1]));
printf("count = %d\n", count);
}
time-complexity recurrence
T(n) = 2T(n-1) + c
So by recursive method
T(n) = 2^n + nc
So O(2^n)
T(n) =T(n-3)+5n- 9
T(n)=T(n-3)+O(n)
So and is O(n^2)
T(n)=2kT(n-k)+2 (k-1)(n-(k-1))+2(k-2)(n-(k-2))+.......+n
Now k=n-1
T(n)=2(n-1)(1)+2(n-2)(2)+2(n-3)(3)+.......+2(n-n)(n)
recurrence algorithms
it is said that it falls between the case 2 & 3 and no solution possible with this method .can anyone explain it clearly ?
algorithms recurrence
Selected Answer
nlogb a = nlog2 4 = n2
(
i.e. f(n) = Ω nlogb a . )
( )
Now, to apply Master theorem case 3, we need a positive constant ϵ such that f(n) = Ω nlogb a +ϵ . But here we can't get any
such constant and hence we can't apply Master theorem. So, solving by expansion:
T(n) = 4T () 2
+ n2 logn
n n
= 16T 2
2
() + n2 logn + n2 log
() 2
n n
[
= 4lg n + n2 logn + log 2
() + … + log 2
lg n
( )]
n n
= n2 + n2 ⋅ log
( 2lg n ⋅ (lg n +1 ) / 2
)
nlg n +1
= n2 + n2 ⋅ log n
(
(lg n +1 ) / 2
)
(
= n2 + n2 ⋅ log n (lg n +1 ) / 2 )
lgn + 1
= n2 + n2 ⋅ 2 ⋅ logn
(
T(n) = Θ n2 log2 n )
Actually we can even use Extended Master theorem which directly gives the asymptotic bound as Θ n2 log2 n . ( )
a=4,b=2,k=2,p=1
if a=b k then
so,here 4=22
and p>-1
so,T(n)=Θ(n2.log2n)
1.106 Recurrence: How to remove recurrence relation when two or more are
combined top gateoverflow.in/37883
(A) Θ(n2 )
(B) Θ(n2 log n)
(C) Θ(2 (log n)2)
(D) Θ(n (log n)2)
algorithms recurrence
How to solve ?
My Attempt:
= 3(3T(n − 2) - 15) - 15
= 9(3T(n − 3) - 15) - 15 · 3 - 15
Selected Answer
Each substitution is giving us a new way of expressing T(n) in terms of some T(n − k) where k is an integer between 1 & n.
We know the value of T(1) so we should try to write T(n) in terms of T(1).
It is not possible to start with T(n) & exhaustively back substitute until we reach 1, since n is unknown to us.
So we have to observe & generalise the changing pattern in the expression for T(n).
To observe the pattern, instead of multiplying numbers it would be better to keep them apart.
so we get
T(n) = 31 ⋅ T(n − 1) − 30 × 15 ( )
after first substitution.
(
T(n) = 32 ⋅ T(n − 2) − 31 × 15 − 30 × 15 ) ( )
after second substitution.
( ) ( ) (
T(n) = 33 ⋅ T(n − 3) − 32 × 15 − 31 × 15 − 30 × 15 )
after third substitution.
( ) ( ) (
T(n) = 34 ⋅ T(n − 4) − 33 × 15 − 32 × 15 − (3 × 15) − 30 × 15 )
after fourth substitution and so on.
……
( ) (
T(n) = 3k ⋅ T(n − k) − 3k × 15 − 3k−1 × 15 … − 32 × 15 − 31 × 15 − 30 × 15 ) ( ) ( ) ( )
we can also write it as
( 3 −1 )
k
2
T(n) = 3k ⋅ T(n − k) − 15 ⋅
T(n − k) = T(1)
or (n − k) = 1
⇒ k = (n − 1)
(3 (n − 1 )
−1 )
2
T(n) = 3 (n −1 ) ⋅ T(n − (n − 1)) − 15 ⋅
(3 (n − 1 )
−1 )
2
⇒ T(n) = 3 (n −1 ) ⋅ T(1) − 15 ⋅
(3 (n − 1 ) −1
)
⇒ T(n) = (3 (n −1 ) )
× 8 − 15 ⋅ 2
( ) (
⇒ T(n) = 8 × 3 (n −1 ) − 7.5 × 3 (n −1 ) + 7.5 )
(
⇒ T(n) = 0.5 × 3 (n −1 ) + 7.5 )
1
(
⇒ T(n) = 2 3 (n −1 ) + 15 )
= 3(3T(n − 2) - 15) - 15
= 9(3T(n − 3) - 15) - 15 · 3 - 15
...........
=3 n-1(8 - 15/2)+15/2
=1/2(3n-1+15)
please explain ..
recurrence algorithms
1.109 Recurrence: Solve the recurrence relation B(n) = 3B(n/log (n)) + θ(n)
2 gateoverflow.in/41833
top
$B(2) = 1$
................=3B(2^k/k^x) + (2^k)/k^(x-1)
put 2^k/k^x=2...........eq-2
=3+(2^k)[(1-(1/k)^x)/1-1/k]
=(k.2^K)/(k-1)
a) O(1)
b) O(n)
c) O(log n)
d) O(log log n)
algorithms recurrence
...
Ref: https://en.wikipedia.org/wiki/Harmonic_series_(mathematics)
1.111 Recurrence: How to solve this using recursion tree method top gateoverflow.in/41608
algorithms recurrence
---
HTH
Please explain the difference between the following question or are they same..??
T(n)=2*T(n-1)-1 if n>0
1 otherwise
N otherwise
If in the first question it means that given recurrence is for value and in second it means to directly solve the recursion, then
how could a running time recurrence have a negative term...??
time-complexity recurrence
T(1) = a
T(2) = b
T(3) = ab
T(4) = ab2
T(5) = a2 b3
T(6) = a3 b5
T(n) = a * T(n/b) + c
Selected Answer
we are able to reduce it into 'a' number of SubProblems each of size (n/b)
by doing O(n) amount of work [Divide time(constant)+combine Time(merge algo ->O(n) time) later ] we are
able to devide a large n array size sorting problem to two smaller size array sorting problems each of size
(n/2)
recurrence algorithms
top
I am having some problems in calculating time complexities for recurrence relations. In one of the books, I saw two
questions-
1.
A(n)
else
Q2.
A(n)
else
algorithms recurrence
Let h be the homomorphism defined by h(a) = 01, h(b) = 10, h(c) = 0, and h(d) = 1. If we take any string w in
(0+1)*, h-1(w) contains some number of strings, N(w). For example, h -1(1100) = {ddcc, dbc}, i.e., N(1100) = 2. We
can calculate the number of strings in h-1(w) by a recursion on the length of w. For example, if w = 00x for some
string x, then N(w) = N(0x), since the first 0 in w can only be produced from c, not from a.
Complete the reasoning necessary to compute N(w) for any string w in (0+1)*. Then, choose the correct value of
N(10100101).
a) 15
b) 34
c) 128
d) 25
Given answer: A
Please explain
Selected Answer
r3 = r2 + r − 1
(r + 1)(r − 1)3 = 0
You can now solve it on your own and get T(n) = O(n)
answer = option A
ans will be O(3 n).. quetion asking about time complexity not value..
evry time 3 call ..and maximum we have n level.. because T(n-1) is given.
T(n)=T(n-1)+T(n-2)-T(n-3) n>3
=n otherwise
T(4)=T(3)+T(2)-T(1)
=3+2-1=4
Similarly,T(5)=T(4)+T(3)-T(2)
=4+3-2=5
and T(6)=T(5)+T(4)-T(3)=5+4-3=6;
so in general,we get,T(n)=T(n-1)+T(n-2)-T(n-3)=(n-1)+(n-2)-(n-3)=n
Therefore,T(n)=o(n)
recurrence algorithms
2. if a=b^k then
3. if a<b^k then
1)) T(n)=T(n/2)+2^n
2)) T(n)=2T(n/2)+n/logn
3)) T(n)=16T(n/4)+n!
algorithms recurrence
3. f(n) = n! , a = 16, b = 4
4. f(n) = log n , a =
√2, b = 2
T(n)=2√nT(√n)+n
In this If we take n=2m then and I divide the entire equation by n so I will get
recurrence algorithms
O( n log log n )
Using Back substitution
1.122 Recurrence: What will be the time complexity of below code? top gateoverflow.in/18734
main(){
while(n>2)
n=n/log(n);
}
recurrence time-complexity
T(n) = T lg n
( ) +1
=T
( lg nlg (n / lg n )
) + 2 (Going 1 level into recursion)
( )
n
lg2 n −lg nlg lg n
=T +2
Since the second term (lgnlglgn) is asymptotically lower than lg2 n, we can ignore it and assume that the recurrence stops
when the denominator is half of the numerator (when we get T(2)) which happens after k steps and since the complexity
at each step is 1, the total complexity will be k.
lgkn = n/2
lgn = (n/2)1 / k
lglgn = (1/k)(lgn − 1)
k = (lgn − 1)/lglgn
lg n
1.123 Recurrence: How can one solve the following recurrence? top gateoverflow.in/18652
T(n) = T(n − 1) + T
()
2
+n
n ≥ 1, T(1) = 1
recurrence time-complexity
every time while finding recurence solution (in CLRS book , page 88) a statement "Floors and ceilings usually do not matter
when solving recurrences" but my doubt is when they matter ?
algorithms recurrence
Whenever we need to find exact recurrence expression then floor and celing matters.. otherwise it is useless because one
or two, in general constant people doesn't affect time Complexity..
Let , (n/2) and n is odd then we can take value as Floor (n/2) or Ceil (n/2).. difference between floor and ceil value is one
.. here n is no of input.. one less or one more input doesn't affect asymptotic complexity..
But whenever we need to find something like exact no of comparison then we need floor ceil precisely..
Selected Answer
O(2^N)
T(N)=2T(N-1) +1
draw a recurrce tree.here you will get a complete(perfect tree) and splitting a node into 2 will take o(1) time.
so at head n is split into 2 (n-1),(n-1) size subproblems(nodes) doint work of contsant time(o(1)).
at any level work done will be constant *no . of subproblems at that level.
so its 2^0+2^1+2^2+2^3+......2^n.
and forming some recurrecre relations directly looking at the question required some experience.
so just forget if you are not able to derive the relation below directly.
T(N)=2*T(N-1) +o(1)
set up a recurrence relation for the number of n digit sequences on integers 0,1,2,3 having an even number of 0's
recurrence
an=3C1an-1+ (4n-1-an-1)
3C a
1 n-1= where a n-1 valid and last bit as 1/2/3
algorithms recurrence
Selected Answer
Since we have a sqrt term, considering only perfect squares and those which are multiple of 2 as that can take care of log.
T(2) = 1//assume
T(22 ) = T(2) + 1 = 2
2
T(22 ) = T(4) + 1 = 3
T 22( ) 3
= T(16) + 1 = 4
T 22( ) 4
= T(256) + 1 = 5
log (logn)
1.128 Recurrence Eqation: Order and run time of the algorithm? top gateoverflow.in/37206
Running time of an algorithm T(n), where n is input size is given by T(n) = 8 T(n/2) + qn, if n>1 T(n) = p, if, n=1 where p and q are constants. The order of algorithm
is
A. n2
B. nn
C. n 3
D. n
Selected Answer
( ) (
f(n) = O nlogb a −ϵ = O nlog2 8 −ϵ = O n3 −ϵ ) ( )
is true for any 0 < ϵ ≤ 2.
It's a question from Cormen book Exercise 4.4-5 and is described like this:
Use a recursion tree to determine a good asymptotic upper bound on the recurrence T(n) = T(n − 1) + T( 2 ) + n
asymptotic-notations recurrence-equation
it think it will be O(n^2)..bcozT(n/2)+n->time complexity is O(n) by master's theorem and let O(n)=Cn where C is any
constant
Now T(n)=T(n-1)+Cn
Given answer: B
Please explain
Selected Answer
the outer loop is multiplicative decrease, this makes shrinkage as O(log2 (n))
(
both are in serial connection, therefore Time Complexity = O nlog2 (n) )
answer = option B
jm = jm−1 + m
an = an −1 + n ; rewriting the relation
an = apn + ahn
= Particular Solution + Homogeneous Solution
if the input string constant is of length n then what is the time complexity?
A. O(2n )
B. O(n2 )
C. O(n)
D. O(nlogn)
recursion
Selected Answer
Since in the output is of length 7 it means that there were 7 non trivial function calls in total which is (2 n - 1) and hence
the time complexity is O(2n ).
A(n)
{
if(n>=1)
{
A(n-1); // statement 1
print n; //statement 2
A(n-1);// statement 3
}
}
recursion
Selected Answer
Size of stack is of the order of the number of recursive calls which are currently live. (It is not equal because we save
many info on the stack during a call like local variables, return address etc. )
Here, we have two recursive calls with value (n-1) for input n. But before the second one starts, the first one finishes. So,
total number of recursive calls for n can be given by
Solve recurrence T(n) = 2T(n-1) + 1 (1 for the stack space required for the current process) with T(0) = 1.
The answer to the above problem is A but I am expecting it to be D as constant amount of work is required to solve each
subproblem.
Selected Answer
THIS IS WELL KNOW FLYOD WARSHAL PROBLEM WHICH IS HAPING COMPLEXITY 3 N WITHOUT DYNAMIC PROGRAMMING
BUT USING DYNAMIC O(n3).
1.134 Recursion Tree: How to solve the following Recurrance top gateoverflow.in/31860
⟨
T(n) = T(n/4) + T(3n/4) + n ⟩
a) Using Varience of master theorem
b) Using Recursion Tree
recursion-tree time-complexity
graph-algorithms shortest-path
3)yes because for each vertex call extract min which is take O(log v) i.e total O(v log v) and in that for each edge we have
relax all the adjacent edge which internally call decrease function call which take O(log v) i.e for each edge relaxation will
be done only once so tatal for this O(e logv)
so total time O((v+e)logv) but in worst case there may be chance that no relaxation performed in that case time O(vlogv
+e).
4)when no relaxation will performed in that case all vertices have cost infinity so simply extract one of them
If input is sorted in reverse order , then which sorting algorithm will perform best -
A) Insertion Sort
B) Merge Sort
C) Heap Sort
D) Quick Sort
C) HeapSort
Reference:http://www.sorting-algorithms.com/reversed-initial-order
1.137 Sorting: In quick sort , for sorting n elements , the (n/4)th smallest
element top gateoverflow.in/18925
In quick sort , for sorting n elements , the (n/4)th smallest element is selected as pivot using an O(n) time algorithm. What
will be the time complexity?
it is Θ(n2 ) , right ?
Selected Answer
It would be Θ(nlogn).
At each level, the array of size n is getting divided in to 2 sub arrays of size (n/4) and (3n/4) along with an extra work for
choosing pivot which requires O(n) time.
n 3n
( ) ( )
Lower bound for this recurrence will be Ω nlog4 n , & upper bound will be O nlog 3 n ,
4
T(n)=T(n/4)+T(3n/4)+O(n)
T(n)=O(nlogn)
To sort n randomly generated numbers. One should prefer which sorting algo ,Quick or Heap?
sorting
Quick sort performs very gud if the elements are randomly generated. even if Quick Sort and Merge Sort have same
complexity on average and in best case scenario, the constants (hidden by the big-O notation) are much smaller in Quick
Sort leading to a smaller running time on average. looking at the table we can easy know that the comparision is between
mege and quick . heap is not so efficient to be compared,(http://ddeville.me/2010/10/sorting-algorithms-comparison/)
I feel heap sort is preferable as at any moment if we wish to add any randomly generated element to the list then the list
needs to be sorted after it to get the element in sorted order. so we can just add the element and call maxheapify or
minheapify as our requirement and get it sorted for the randomly added element
I feel if our list is static i.e data need not be added later then we can go ahead with sorting as the sorted order wont be
affected later
but if we want to make any changes either add or delete any element then i feel heap is the best as it does minimal work
for moving element and even maintaining the property
1.139 Sorting: Which of the following sorting methods will be the best if
number of swapping top gateoverflow.in/18924
Which of the following sorting methods will be the best if number of swapping done is the only measure of efficiency
algorithms sorting
Selected Answer
Selection sort is best if efficiency is in terms of swaps.No of swaps in selection sort is of O(n)
1.140 Sorting: Insertion sort on small arrays in merge sort top gateoverflow.in/29493
Although merge sort runs in Θ(n lg n) worst-case time, and insertion sort runs in Θ(n 2 ) worst-case time, the
constant factors in insertion sort make it faster for small n. Thus, it makes sense to use insertion sort within
merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k
sublists of length k are sorted using insertion sort and then merged using the standard merging mechanism,
where k is a value to be determined.
a. What is the worst-case time to sort the n/k sublists (each of length k)?
b. Show that the sublists can be merged in Θ(n lg(n/k)) worst-case time.
c. What is the largest asymptotic (Θ-notation) value of k as a function of n for which the modified algorithm
has the same asymptotic running time as standard merge sort?
sorting algorithms
According to the algo specified If I consider the case for the 1st sub-array right=1 and left=0 so B[0]=A[left]=4 ,Now using
this algo when will the array size become 1 ,I am not getting the base condition here ,plz clarify this where is the mistake ?
sorting
1.142 Sorting: What is the proper order in which we can arrange the sorting
algos in terms of the number of swap operations they do ? top gateoverflow.in/13320
I am not getting which algorithm has minimum no of swap operations , acc to me both selection and insertion should be at
the lowest level as well as merge sort since after dividing the arrays we merely merge them where do we swap in that ,
please clarify this , I am a bit confused regarding counting the no of swap operations .
sorting
Selected Answer
In the worst case answer should be selection sort. Because we use a temp variable for finding the maximum value in each
iteration and do a swap only once for the inner loop. In this way we swap only n times for the whole algorithm in any
case.
Think of it like sorting a structure containing multiple objects. So, swap operation is heavy. So, here selection sort makes
sense.
In insertion sort- for each element after finding its position we are shifting all elements to the right. These shifts can also
be considered as swaps as they are swapping the positions.
For merge sort we are using an auxiliary array and we can assume all elements are swapped.
http://gatecse.in/wiki/Complexities_of_Basic_Sorting_Algorithms
I am not getting points 2 and having confusion in point 3 that how quicksort can be tail-recursive since we have 2 function
calls at the end , and why is option 4 wrong ,since if we pick the pivot as median then surely It will divide the array equally
into two halves therefore worst case time complexity must be O(n log n ) , plz correct me where am I wrong ?
sorting
Selected Answer
http://www.geeksforgeeks.org/iterative-quick-sort/
http://stackoverflow.com/questions/12454866/how-to-optimize-quicksort
https://en.wikipedia.org/wiki/Quicksort#Optimizations
in 4th option we can use in theory but not in practice bcoz choose median as pivot in large array has many overhead ...
1.144 Sorting: why is merge sort better if we try to do sorting on linked lists
and also insertion sort and why not any other algo like quick sort or
selection sort ? top gateoverflow.in/13353
If we talk about that since since we cant access any random element in a linked list for that reason quick sort cant be used
for linked lists ,then in merge sort also we need a middle element for splitting so then how do we actually use merge sort
then , also even if chosing the pivot takes O(n) time then it will only add up with the time taken for partition as such no
issue in it then why can't we use quicksort for implementing linked lists?
sorting
There is no issue in implementing quick sort with link list but it does not enhance performance of quick sort while in case
of merge sort the time complexity being the same it improves space complexity and through link list it can be done in-
place (without using extra space)
Which of the following sorting algorithms has the minimum running time complexity in the best and average case?
isro2013 sorting
Selected Answer
Ans (A)
1.146 Sorting: How does partitioning step acts as a conquering step in quick
sort ? top gateoverflow.in/30096
T(n)=aT(n/b) +f(n) here f(n) is the cost of conquering the sub-problems i.e. cost of merging
all the sub-problems in order to solve the problem but in case of partioning we are dividng the array around
a particular pivot point so while calcualting the time complexity of quick-sort why do we take O(n)
time for f(n) ,how is acting as a conquering step?
sorting
Selected Answer
and partition algo { O(n) } is the cost for dividing the big problem into small sub-problems.
1.147 Sorting: CLRS 8-2 Sorting in place in linear time top gateoverflow.in/41735
n
Suppose that we have an array of n data records and that the key of each record has the value 0 or 1. An algorithm for
sorting such a set of records might posses some subset of the following three desirable characteristics:
1. The algorithm runs in O(n) time
2. The algorithm is stable.
3. The algorithm sorts in place, using no more than a constant amount of storage space in addition to the original array.
Do the following:
1. Give an algorithm that satisfies criteria 1 and 2 above
2. Give an algorithm that satisfies criteria 1 and 3 above
3. Give an algorithm that satisfies criteria 2 and 3 above
n
4. Can you use any of your algorithms from parts (a)-(c) as the sorting method used in line 2 of RADIX-SORT , so that RADIX-SORT sorts records with b-bit keys
in O(bn) time? Explain how or why not.
n
5. Suppose that the n records have keys in the range 1
to k
. Show how to modify counting sort so that it sorts the records in place in O(n+k) time. You may use O(k) storage outside the input array. Is your algorithm
stable? (Hint: How would you do it for k=3? )
Can somebody please provide solution with an example?
sorting data-structure
1.149 Sorting: Below is the question, Please explain it.. top gateoverflow.in/32944
A sort method is said to be stable if the relative order of keys is the same after the sort as it was before the sort. In which of
the following pairs both sorting algorithms are stable?
sorting
Selected Answer
There are algorithms which are stable naturally like Bubble sort and Insertion sort. And there are algorithms which need
modification to exhibit this stable sorting property, example of such sorting algorithm is Quick Sort.
The only way to know if the sorting algorithm is stable is to execute the algorithm on an input with more than one
duplicate elements. And check if their ordering is preserved after complete execution of the algorithm.
If the number of records to be sorted is small, then ...... sorting can be efficient.
A. Merge
B. Heap
C. Insertion
D. Bubble
algorithms sorting
Selected Answer
Insertion Sort
The constants in the time function in insertion sort is small. When the input size is small ,other algos prove to take greater
time .
1.151 Sorting: Assume that a CPU can process 10 8 operations per second.
Suppose you have to sort an array with 10 6 elements. Which of the following
is true? top gateoverflow.in/13259
Assume that a CPU can process 108 operations per second. Suppose you have to sort an array with 106 elements. Which of
the following is true?
1. Insertion sort will always take more than 2.5 hours while merge sort will always take less than 1 second.
2. Insertion sort will always take more than 2.5 hours while quicksort will always take less than 1 second
3. Insertion sort could take more than 2.5 hours while merge sort will always take less than 1 second.
4. Insertion sort could take more than 2.5 hours while quicksort will always take less than 1 second.
Selected Answer
Merge sort complexity is Θ(nlgn), and so we need 106 lg106 ≈ 20 × 106 and assuming the constant factor is less than 5, number
of instructions would be less than 108 and can be run within a second.
Worst case complexity of insertion sort is O(n2 ) and to sort 106 elements it needs 1012 operations and with 108 operations
per second this would need 104 seconds = 2 hours 46 minutes.
Now, best case complexity of insertion sort is O(n). So, "always" in options 1 and 2 make them false.
Similarly worst case of quick sort is O(n2 ) and this makes option 4 false.
1.152 Sorting: Given the sequence of n integers in the order: top gateoverflow.in/34562
algorithms sorting
1. The number of swappings needed to sort the numbers: 8, 22, 7, 9, 31, 19, 5, 13 in ascending order using bubble sort is—
(a) 11 (b) 12
(c) 13 (d) 14
What I did was to write every pass and check the swappings. But , it takes too much time.
sorting algorithms
Selected Answer
In Bubble sort, largest element moves to right. So a swapping is done, when a smaller element is found on right side.
So to count number of swaps for an element, just count number of elements on right side which are smaller than it.
For 22 : 5 (7,9,19,5,13)
Array of n elements with first 10 and last 50 elements unsorted..find an algo which runs faster a)merge sort b)quick sort
c)insertion sort d)bubble sort Explain
Insertion Sort.
Next, n − 60 elements take Θ(n − 60) time as these would involve no shifting among themselves)
Final 50 elements take Θ(50n) = Θ(n) time in worst case to place each of the 50 elements in position.
1.155 Sorting: Time Complexity of a Custom Quick Sort Design top gateoverflow.in/13680
Given an instance of custom quick sort in which the Pivot element is always the
n
()4
th
smallest element. GIven a large array
th
()
as input and an implementation of this custom quick sort such that the 4 smallest element is found in O(n) time. What is
Selected Answer
algorithms sorting
Selected Answer
Internal sorting . when the elements to be sorted are all in the main memory while in external sort all are not present in
memory during sorting . as in internal sort all elements are in main memory the time to read write is not that much
significant as compared to external sorting .
so true false
double foo(int n)
{
int i;
double sum;
if(n == 0)
{
return 1.0;
}
else
{
sum = 0.0;
for(i = 0; i < n; i++)
{
sum += foo(i);
}
return sum;
}
}
Selected Answer
Answer is O(2n )
T(0) = 1
T(1) = 2
T(2) = 5
T(3) = 11
T(4) = 23
T(5) = 47
So,
T(n) = 2n + 2n −1 − 1 = O(2n )
1.158 Spanning Tree: Calculation of the number of spanning trees top gateoverflow.in/30141
Hi,I just encountered problems about calculation of the number of spanning trees,like this one:
http://gateoverflow.in/10154/find-out-the-no-of-spanning-tree-possible
I am able to proceed to choose the number of edges.But I am unable to understand the calculation of the number of cycles
to subtract.Can anyone help me in understanding the same?Also,Kirchoffs theorem leads to calculation of large determinants
for such problem,which is not feasible.Are you aware of any other method to do the same?
spanning-tree
algorithms spanning-tree
Ans: because we have given wavy edges form MST So, for verification of option A we have to check that with MST how
many cost to reach at a->b then we will get a->e->d->b = -2+5+3 = 6 so in given option a with cost(a,b)>= 6 this is
posible coz , cost equal then we can reach at a to b with that edge but we don't consider that edge while making MST so
cost must be >6 not equal to 6 so option A is Need Not HOLD. Like wise if you check for other option then enequality is
holding...
stack
begin :
now if count==2 pop top two elements and top operand and make count=0
apply operation and push the result into stack and increment count
end:
stack:: - + + x count=1
- + + x y count=2 and now pop xy and + add them letrs say m=x+y
- + m push z - + m z
now pop and add them as above y=m+z and put it back on stack
- y l
B. Quick sort - Ads the array is in reversed order, it is worst case for it, so time complexity O(n^2)
C. Merge sort - time complexity is O(nlogn), but takes additional time for unnecessary division.
I got that Statement 3 can be false in case we have function 1/n, then its square become 1/n^2. But I don't think statement
2 is true either. Please prove whether I'm correct or wrong.
a. f(n) = O (f(n))2 ( )
b. f(n) = O(g(n)) ⇒ 2f (n ) = O 2g (n ) ( )
c. f(n) + O(f(n)) = θ(f(n))
d. Both (a) and (b)
Selected Answer
time-complexity
Selected Answer
= n2 − n + (n − 1)2 − (n − 1) + (n − 2)2 − (n − 2) + . . .
n (n +1 ) (2n +1 ) n (n +1 )
6 2
= −
n (n 2 −1 )
3
=
Note:
n (n +1 )
∑ni=1 i = 2
n (n +1 ) (2n +1 )
∑ni=1 i2 = 6
Why [logn]! is not polynomial bounded where [loglogn]! is polynomial bounded? Note [ ] is greatest integer function
time-complexity
int fun(int n)
{
int count = 0;
for (int i = n; i > 0; i /= 2)
for (int j = 0; j < i; j++)
count += 1;
return count;
}
what is the time complexity
time-complexity
Selected Answer
Where c is constant.
time-complexity algorithms
Selected Answer
I am getting Θ (2^n) .
a) Order of finding k th Root ( express in terms of k and n where k represent 3 for cube root , n represent size of input )
algorithms time-complexity
n n n
Q1 ) j = 2 + 4 + 8 + ....... + 1 = O ( ?? )
1 1 1
Q 2 ) j = 1 + + + 4 +..... = O ( ?? )
2 3
Q3 )
time-complexity algorithms
1. O(n)
2. O(log n)
3.O(n)
4.O(n)
5. O(log n)
int f(int x)
{ if(x<1) return 1;
int g (int x)
if(x<2) return 1;
a) logarithm b) quadratic
c) linear d) exponential
time-complexity
It is exponential only.
When you are calling f(n), if you will draw a tree it will be at least n level tree on left most and (log n) level tree on right most.
if you want to take upper bound then take the maximum level possible and assume the tree to be complete binary tree in worst case so this way, there will be
O(2^n) function call. In each fn call takes constant time so time complexity will be O(2^n) i.e exponential.
The time complexity of computing the transitive closure of a binary relation on a set of n elements is know to be a -
1) O(n) 2) O(nlogn)
3) O(n3/2) 4) O(n 3)
time-complexity
Ans : O(n3)
Transitive closure of relation can be represented using directed graph. And in that graph ,using Floyd-Warshall
algorithm,one can find out transitivity in time complexity of O(n3)
for (i = 1 to j )
x = x + 1 ;
j = n/2 ;
}
What is the time complexity?
O(nlogn)
O(n logn)
O(n )
time-complexity
if n>=1
then j will never change and always be true.
Q). What is the complexity of finding the 50th smallest elements in an already constructed binary min-heap?
1. θ(1)
2. θ(logn)
3. θ(n)
4. θ(nlogn)
solution:
Exact complexity would be 50logn for heapify when we do heap sort iteration 50 times
Selected Answer
We need to find 50th smallest integer in min heap. Which can be easily done by checking first 2 50 no in arrays (Checking
first 50 levels of heap !) . It does not depend on size of heap. We can have min heap of size n = 2^250000000000still no of
comparisons is fixed. It does not change with no of elements in heap.
algorithms time-complexity
Q.19
What is the worst case running time of the function f for any positive value of n?
O(1)
O(n)
O(n2)
O(n3)
Selected Answer
f (n )
g (n )
Given two positive functions f(n) and g(n). If = c, for some constant c ≥ 0 and c is non-negative but not infinite then
which of the following is correct?
f(n) = O(g(n))
f(n) = θ (g(n))
f(n) = Ω (g(n))
None of these
------------------------------------------------------------------------------------------------------------------------------------------------
-------------------
Here I strongly believe that Answer should be the f(n) = θ (g(n)). Other two are correct, but this is strongest statement !
In that case they are both upper & lower bounds of each other !
Q 47
algorithms time-complexity
In that case f(n) can be 0, & in that case g(n) is always bigger than f(n).g(n) = 0 is not allowed, otherwise whole thing will
go to infinity & it is said c can not be 0.
So A is correct answer.
f1 (n) = n0.999999logn / /logn is not power of nf2 (n) = 10000000 ∗ nf3 (n) = 10000000n f4 (n) = n2
algorithms time-complexity
Selected Answer
Incorrect Solution:
critical problem in this question is to find out which is greater between f1 and f2 , for that purpose we take log on both functions:
for f1 :
loglogn + 0.999999logn
for f2 :
logn + log107
in f1 we are adding a non-constant entity but that's not the case with f2 . Hence, f1 is greater.
we get answer = option C like this. BUT this is FALSE. Even after taking log we cannot deduce a meaningful conclusion coz Product terms
cannot be ignored, See discussion in comments below.
Correct Solution:
let us assume that 0.999999 = 0.5, just to make things simple, it is a constant & also a fraction so it will continue to maintain its nature
during this process, so this move is ok. Now, we have:
f1 (n) √nlogn
n →∞ 2
| |
lim f (n) lim
= n →∞ n
1 log n
√n 2 √n
+
lim
= n →∞ 1
2 + logn
lim 2√ n
= n →∞
1
0+ n
1
lim 2 √n
= n →∞ 2 ×
1
lim n
= n →∞
√
=0
since, at n → ∞ shows that the value of the expression = 0 this means that for sufficiently large n the denominator has to be a much bigger
value that is making the expression = 0. So, f2 is asymptotically bigger.
Q:- which one is the best among heap sort ,quick sort and merge sort in terms of complexity ? please answer with explanation!!
algorithms time-complexity
algorithms time-complexity
algorithms time-complexity
1.180 Time Complexity: Find time complexity of following code: top gateoverflow.in/33406
time-complexity algorithms
This question can be solved by taking first some initial values of k={1,2,3,4,5.....} and then using the coming relation find
out the relationship between k and n.
for k=1 ,n will be 4 so i will iterate for 4 times(ie..,n times) and j=2 and each time incrementing in terms of square(j). so j
will be 2 and 4 i.e., pf will be printing 2 times for each i thus it will be printed total of n*2.
for k=2 ,n will be 16 so i will iterate for 16 times(ie.. n times) and j=2 and each time incrementing in terms of square(j).
so j will be 2 and 4 and 16 i.e., pf will be printing 3 times for each i thus it will be printed total of n*3.
for k=3 ,n will be 256 so i will iterate for 256 times(ie.. n times) and j=2 and each time incrementing in terms of
square(j). so j will be 2 and 4 and 16, and 256 i.e., pf will be printing 4 times for each i thus it will be printed total of n*4
or(n*(3+1)).
n= square(square(k))
time complexity will be O(log log (n)) for each n and thus printing will be done =n *(K+1)=O(n*k) =O(n*log*log (n))
1.181 Time Complexity: Fill the complexity table and correct mistakes if any
top gateoverflow.in/30554
worst
name best avg space work soace
N3
Matrix multiplication N3 N3
n2
Integer
multiplication
n1.58
Anatolli karatsuba logn
nlog k (2k-1)
Toom and cooks
n2
quicksort n log n n log n logn
log n (
complete
Binary Search 1 log n tree ) n+ logn log n
n ( skewed
Tree)
time-complexity algorithms
n 4/3
n
F(n) = G(n) = 22
2
H(n) = 2n I(n) = n!
J(n) = 2n
A. F(n) = Ω G(n) ( )
B. G(n) = O H(n) ( )
C. F(n) < J(n) < I(n) < G(n) < H(n)
D. I(n) = O H(n) ( )
time-complexity algorithms
Selected Answer
Answer is Option D.
F(n) = n 4 / 3 (
Θ logn ) 3
is a const.
G(n) = 2 2
n
( )
Θ 2n
H(n) = 2 n
2
( )
Θ n2
I(n) = n! (
Θ nlogn ) Striling ′ s
Approximation
J(n) = 2 n ()
Θ n
Arrange the following functions in ascending order according to their order of growths.
f1 = 100000 ⋅ n
f2 = 30 ⋅ n2
f3 = (logn)200
f4 = 2n
f5 = n ⋅ logn
time-complexity algorithms
Selected Answer
16
( )
Now, f3 is actually growing smaller than n. For example, take n = 22 = 265536 , log2 n200 = 216
200
= 23200.For all larger n, f3 has
lower value than n. (This is true for lognk for any constant k. So,
Given answer: C
Please explain
algorithms time-complexity
At depth k suppose the division would be like n 2 / (2k) which should be equal to the size of list at that time . According to
the question it is given as n.
1.185 Time Complexity: Fill the Complexity Table From Greedy Strategy top
gateoverflow.in/30555
n2 (conventional)
Prims Algorithm nn
n+e log n (heap)
Kruskal e log n
Dijikstra n2
Bellman-Ford ne
time-complexity algorithms
main()
{
for(i=1;i<=n;i++)
{
for(i=1;i<=n*n;i++)
{
for(i=1;i<=n*n*n;i++)
{
x=y+z;
}
}
}
}
time-complexity
Selected Answer
0(n^3) because the internal loop runs n^3 times and now it does not satisfy the condition of 1st and 2nd loop so it comes
out of the loop
1.187 Time Complexity: What is the growth function of every case (a-d)? top
gateoverflow.in/4624
a)
b)
c)
d)
time-complexity
Selected Answer
(a)
i is multiplied by 2 in each iteration and stops when equals √N. So, loop will run for lg (√N) times and time complexity =
Θ(lg(√ N))
(b)
Outer loop runs for lg(N) times. For each i, Inner loop runs for i times. So, total number of iterations
(c)
The outer loop runs for √N times. For each i, the inner loop runs i times. So, number of iterations
= 1 + 2 + ... + √N
= √N * (√N+1) /2 = Θ(N)
(d)
The outer loop runs for √N times. For each i the inner loop runs lg i times. So, total number of iterations
= lg 1 + lg 2 + lg 3 + ... lg √N
=lg (1 * 2 * 3 * ... *√N)
=lg ((√N)!)
= Θ(√Nlg√N) using Stirling's approximation)
http://mathworld.wolfram.com/StirlingsApproximation.html
1.188 Time Complexity: What is the worst case time complexity of this
function? top gateoverflow.in/14419
int fun(int n)
{
int count=0;
for (int i= n; i> 0; i/=2)
for(int j=0; j< i; j++)
count+= 1;
return count;
}
Selected Answer
n n
n n
Solving,
n n
2
n+ + 4 +…+1
log n terms
1 − (1 / 2 )log n
1/2
=n⋅ (using GP, first term = 1 and common ratio = 1/2)
= 2n(1 − n ) = 2n − 2
complexity = O(n)
The worst case time complexity of this function is O(n)..... the outer loop iterates for O(logn) as the value of n is changing
like this.....n,n/2,n/4......1(assuming n is power of 2). Therefore say the ith term will be n/2^(i-1)...now equating this to 1
we get i as O(logn). Hence the number of iterations of the outer loop(the total number of terms in the series) is O(logn).
Now for each iteration of the outer loop the inner loop is iterating depending on the value of i i.e for 1st iteration of outer
loop inner loop is iterating n times, for 2nd iteration of the outer loop inner loop is iterating n/2 times ..like..this.
Therefore the total time complexity becomes ...n+n/2+n/4+.....+1(assuming n power of 2)......therfore, its the sum of
g.p series with logn number of terms in it....hence the sum becomes 1.(2^(logn)-1)/(2-1)...which equates to O(n)...
Consider two natural-valued functions f : N → N and g : N → N . Which of the following statements cannot be true?
time-complexity
Algorithm Power(n)
Pre: n :: Integer, n > 0
i = 1
while (i < n)
print i
i = i * 3
done
time-complexity
Selected Answer
In each iteration i is multiplied by 3. So, the loop will iterate log 3 n times and O(log n) is the complexity.
time-complexity
Selected Answer
Counting the number of times the inner most loop gets executed equals,
= O(n3) as there are n terms and n 2 is the dominating term in each of them.
We are given a sequence of n nos. a1, a2, a3,.......an, we will assume that all the nos. are distinct. We say two indices i < j
form an inversion if ai > aj .
How much time will it take to find total no. of inversions in the given array?
algorithms time-complexity
Selected Answer
Sorted: 1 2 3 4 5
Number of inversions:
for 1: 1 (how many numbers larger than 1 are on the left side of 1 in initial array)
for 2: 3
for 3: 1
for 4: 0
for 5: 0
Now, given the initial array and the final sorted array we can get the number of inversions for an element at position i in
the initial array and position j in sorted array as max(i-j,0). So, we can find the number of inversions in an array by
sorting the array. Similarly, we can also say that if we are given all the inversions in an array (to count we need to find an
inversion), we can very well sort the array. So, the complexity of finding the total no. of inversions in an array should be
same as complexity for sorting the array- O(nlogn)
http://stackoverflow.com/questions/21933717/counting-number-of-inversions-in-an-array
for(i=1;i<=n;i++,x=1)
{
for(j=1;j<=i;j++)
{
for(k=1;k<=j;x+=a,k*=a)
{
}
}
}
algorithms time-complexity
http://gateoverflow.in/4560/timecomplexity
1.194 Time Complexity: The time complexity of producing a sorted list? top
gateoverflow.in/16103
Suppose there are logn sorted lists and each list contains n/logn elements. The time complexity of producing a sorted list of all
these elements is (using merge algorithm)?
algorithms time-complexity
assume that there are k sorted files and each file contain n/k elements.To sort all these k files in to a single files we use merge algorithm that is first merge file1 and file 2 and later
resultant file will be merged with third file continue this process until all files are merged.and we know that time taken for merging two sorted files of length m and n is O(m+n).
O(2n/k)+O(3n/k)+O(4n/k)+O(5n/k)+-------------------+ O(kn/k)
=O(n/k)(2+3+4+5+6+----------------------+k)
=O(n/k)(k(k+1)/2)
=O(nk)
here k=logn
time complexity=O(nlogn)
a. Θ(n)
b. Θ(log2 n)
c. Θ(n/log2 n)
d. Θ(nlog2 n)
time-complexity
Selected Answer
The outer while loop runs logn times because every time n is getting divided by 2 ie {n/2 , n/4 , n/8 , ......1 }
Ans : Option D.
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.time complexity using DAC ??.
time-complexity
f(n) = 3n√ (n )
g(n) = 2√ (n ) logn2
h(n) = n!
time-complexity
Option D. we can also prove it by saying that all other options are false
Sum=0
for(i=1; i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(j%i==0)
{
for(k=1;k<=n;k++)
{
sum=sum+k;
}
}
}
}
algorithms time-complexity
alternatively :
complexity = 1<i<n { summation of (i + n } // for each i (j loop running i times and k loop n times
=O(n*n) +n*O(n)
= O(n*n)
i=1
J=1 time
K=n time
i=2
j=1,2(2time)
k=n time
i=3
j=1,2,3(3 time)
k=n time
i=4
j=1,2,3,4(4 time)
k=n time
i=5
j=1,2,3,4,5( 5 time)
k=n time
i=6
j=1,2,3,4,5,6,(6 time)
k=n time
i=7
j=1,2,3,4,5,6,7(7 time)
k=n time
….
i=n
j=1 ton
k=n time
T(n)=n+n+n+………n times
=n* n
=O(n^2)
Given n linearly ordered distinct elements. What is the worst case running time to find i th smallest element (1<=i<=n) from
those n elements?
a) O(log n)
b) O(n)
c) O(n log n)
d) O(n2)
algorithms time-complexity
The worst case for this would be to traverse the array from i = 1 to n and stop when you've found the number equal to or
Assuming n>2
A()
while(n>1)
n = n/2;
algorithms time-complexity
Selected Answer
log n
algorithms time-complexity
Selected Answer
2k
2k−1 = 2
()
2k
T ( ) = 3T
2k 2
+1
T(n) = 3T 2
() +1
We know that any constant is bounded by Θ(1), so 1 = Θ(1) & We get the recurrence :
T(n) = 3T 2
() + Θ(1)
(
Θ 2log2 3 .
k
)
( )
Using the property plogp q = q of logarithms we get
( )
Θ 3k as our final solution to this recurrence.
( ) ( )
Θ 3k = O 3k and Ω 3k . ( )
( )
Hence Option B i.e. O 3k will be the correct answer.
algorithms time-complexity
1) 1^2+2^2+3^2+.......n^2= n(n+1)(2n+1)/6
So it's O(n^3)
2) 1+1/2+1/3+......1/n =log no
So it's O (log n)
3)1/2+1/4+1/8+.... 1/2^n
4) x+x^2+x^3+.......x^x
5) x+2x+...... To infinity
Here O(infinity)
Log n! = O of Log n^n and ( log n!)! = O((log n^n) ^ log n^n)
Assume n is even Let T(n) denote the number of times 'foobar' is printed as a function of n.
time-complexity
Selected Answer
a. T(n) = ∑ni =1
/ 2 n −1 j
∑j =i ∑k=1 1
The 1 is used for constant no. of operations. We can also use c for it.
1 1
b. ∑ni =1
/ 2 n −1 j
∑j =i ∑k=1 1 = ∑ni =1
/ 2 n −1
∑j =i j = 2
∑ni =1
/2
(n − 1)n − i(i + 1) = 2 ∑ni =1
/2 2
n − n − i2 − i
n3
We need not solve further as the first term itself gives our answer which is 4 = Θ n3 . ( )
n . (n +1 )
PS: In the summation formula for the sum of first n natural numbers
( 2
) and the sum of the squares of first n
n . (n +1 ) . (2n +1 )
natural numbers ( 6
) are used.
algorithms time-complexity
https://en.wikipedia.org/wiki/Binary_logarithm
int fun(int n)
{
int count=0;
for(int i=n; i>0; i/=2)
for(int j=0; j<i; j++)
count += 1;
return count ;
}
algorithms time-complexity
Selected Answer
T(n) = 1 + 2 + 4 + 8 + … + n times.
T(n) = 1 + 2 + 4 + 8 + … + n = 2n − 1 = O(n)
or k=log 2n
L2 iterrates total = n + n/2 + n/2 2 + ... + n/2 log 2n (for log2n time) (it is finite series)
=n x ( (1-1/n) / (1/2) )
= 2n-2
So it is O(n) ...
The outer loop iteration variable i is halved in each iteration. The inner loop will execute i times for each iteration of the
outer loop. So, the
count += 1;
statement, which is the most repeated one and hence the one contributing to time complexity will be done
n + n/2 + n/4 + .... 1 times, which is a GP and we can approximate it as an infinite GP, so the summation will be a/(1-r),
where a is the first term and r is the common ratio.
n/(1-1/2) = 2n = O(n)
i=0
for(i=1;i<=n;++i)
for(j=1;j<=i*i;++j)
if((j%i)==0)
for(k=1;k<=j;++k)
c=c+1;
algorithms time-complexity
Selected Answer
(The third loop executes only when j%i == 0, which will be true for j = i, 2i, 3i, ... i*i. i.e., it also executes i times. )
for i = 1, 2, 3, 4, ... n
(We can assume the sum to the cubes of first n natural numbers)
i = 1 | 2 | 3 | 4 | 5 | 6 ........................n
which is O(N4).
time-complexity
Selected Answer
T(n) = 2T(n) + n = 22 T(n − 2) + 2(n − 1) + n = 23 T(n − 3) + 22 (n − 2) + 2(n − 1) + n. . . = 2n −1 T(n − (n − 1)) + 2n −2 (n − (n − 2)) + 2n −3 (n − (n − 3)) + … + 2(n − 1
→ (1)
2T(n) = 2n + 2n −1 .2 + 2n −2 .3 + … + 22 (n − 1) + 2n → (2)
Now
(2 n −1 )
Alternatively,
T(1) = 1
T(2) = 2.1 + 2 = 4
T(3) = 2.4 + 3 = 11
T(4) = 2.11 + 4 = 26
T(5) = 2.26 + 5 = 57
T(6) = 2.57 + 6 = 120
…
T(n) = 2n +1 − (n + 2)
I have one doubt. Like we say some program have BigO(N3). So it is right to say that same program can have
BigO(N4) or BigO(N5) or any more than cubic. What i think is we can only say it with small O notation not big O
because if some procedure will have order of cubic polynomial how it can reach more higher order polynomial
with just multiplication of constants.
time-complexity
It feels like you haven't read these topics from any standard book. Honestly, have you?
( )
O n3 is the set of all functions whose growth is upper bounded by n3 . What are some such functions?
f(n) = logn, g(n) = 61n3 / 2 , h(n) = 9n3 , ϕ(n) = (n/logn) are some of them.
( )
When we say that f(n) = O n3 , we actually mean that f(n) ∈ O n3 ( )
It is good that you're trying to think about these things, but you should first read the definition of it from a standard book
(like CLRS). Unless you know what the Big-Oh notation means formally, there is no point in thinking about how it works.
main() {
for(i=1;i<=n;i++) {
if(n%i==0) {
for(j=1;j<=n;j++) {
x=y+z;
}
}
}
}
time-complexity
Selected Answer
O(n) since prime number is divisible by 1 and itself so inner loop will execute only two time i.e 2n
top
time-complexity algorithms
Selected Answer
C o n s i d e r X = 101010…10. Now, f will be called for 1, 2, 3, …n/2 and the time complexity will be
(( ) ) ( ( ))
n n
2 2
( ) ( ) ( )
O 12 + O 22 + O 32 + … + O 2
=O 1+4+9+…+ 2
n . (n +1 ) . (2n +1 )
( )
We know that sum of the squares of first n natural numbers is Θ n3 as this is equal to 6
.So, here we get
( ) ( )
O (n/2)3 = O n3 and hence option C.
http://gateoverflow.in/1076/gate2004_82
1.210 Time Complexity: Consider the following three claims for time
complexity top gateoverflow.in/18926
algorithms time-complexity
Selected Answer
2n should not bound be an upper bound for n n + 1 since n is a variable & 2 is a constant.
(III) is trying to bound square of a function by the function itself so it should be wrong.
time-complexity algorithms
Selected Answer
We have to count the maximum no. of times any instruction is executed- which would be inside the inner most loop. So,
we can count the no. of times for loop and while loop execute independently and their product will be our answer.
for loop:
j = 1, 1 + 2, 1 + 2 + 3, . . . , 1 + 2 + . . . + l, where l is the no. of times the loop iterates (for one iteration of while loop).
1+2+…+l>n
l . (l +1 )
2
>n
(See, I used Θ meaning l and √ n have the same order of growth. If LHS has lower or same growth rate we should use big-
O and not big-Theta)
while loop
Now, we have to solve the outer while loop. Here i goes like n, n/2, n/4, …n/2m, where m is the no. of times the loop iterates.
As per the loop exit condition, we can get
m > logn
m = Θ(logn).
As per definition of big O, even options A and B are correct though D is the best pick.
algorithms time-complexity
Selected Answer
.....................................................
.....................................................
On Adding all the above recurrences, all the red terms of a recurrence will be cancelled out with the red terms of
consecutive recurrences, similarly all the blue terms of a recurrence will be cancelled out with the blue terms of
consecutive recurrences.
Thus we get
T(1) = 1
T(2) = 2
T(3) = 3
T(4) = T(3) + T(2) − T(1) = 3 + 2 − 1 = 4
T(5) = T(4) + T(3) − T(2) = 4 + 3 − 2 = 5
T(6) = T(5) + T(4) − T(3) = 5 + 4 − 3 = 6
We can observe the pattern. It looks like T(n) = n, but we need to prove it.
Then,
QED
1.213 Time Complexity: What is the time complexity of the following C code?
top gateoverflow.in/19027
int Test(int n) {
if (n<=0) return 0;
else {
int i = random(n-1);
return Test(i) + Test(n-1-i);
}
Suppose the function random() takes constant time, then what is the time complexity of T(n)?
algorithms time-complexity
Selected Answer
This function looks very close to recurrence of QUick Sort . It is recurrence of Quick Sort ! Just instead of partitioning
function, we are calling function which has O(1) time. I.e. Constant
T(N) = 2(N/2) +c
1.214 Time Complexity: Time and Space Complexity of the following function
top gateoverflow.in/26470
algorithms time-complexity
Selected Answer
Since this is the recurrence relation for merge sort, we know the answer as Θ(nlogn).
For space complexity if we see the code there is only constant amount of space used (no array usage) and hence the
recursion depth will give the space usage (in stack). Don't confuse this with the total no. of recursive calls as when a
function returns, that space (space use by it on stack for its activation record) can be reused.
If we draw a tree for recursive calls, we can get the longest branch going like T(n) − T(n/2) − T(n/4) − … − T(1), and its length
will be lgn and so the space usage will be c. lgn for some constant c, = Θ(logn).
Now what if B(n) uses space which is not constant? Insufficient data to answer that.
log(n!) = Θ(nlogn)
top gateoverflow.in/179
Selected Answer
n! corresponds to n*(n-1)*(n-2)*....*1 which is Θ(nn ). So by taking log to both terms, the answer comes out to be Θ(nlogn).
assume that the division operation takes constant time and sum is global variable. what is the time
complexity of find(n) ?
time-complexity algorithms
Recurrence equation:
T(n)=4T(n/2)+n^2
algorithms time-complexity
Selected Answer
If the given array is already sorted and maximum n inversion is possible then insertion sort gives best case for that array
because array is already sorted.i.e O(n)
e.g. = 10 20 30 40 50 60 1 :
here 6 inversion and array is almost sorted so it will take 6 comparison and 6 swaps
if array is of n element and 1 element is not sorted then : O(n) for searching the position
n swap
O(2n)
for n element n*2n = O(n 2)
So we can say if in array there are I inversion is there then Time Complexity = O(n + I)
O(n) for best case for I= n
O(n2) for worst case if I is more than n
optiion A
Insersion sort will take O( n 2 ) using merge sort complexity will be O(nlogn)
maxmin(a,n,max,min)
{
max=min=a[1];
for i=2 to n do
{
if a[i]>max then
max:=a[i];
else if a[i]<min then
min:=a[i];
}
}
1.Average case complexity of the above algo given that the first if conditions fails for n/2 elements
2.Average case complexity of the above algo if the first condition fails 1/2 times
plz xplain
Selected Answer
Complexity of the algorithm is O(n) and is irrespective of the success of if case as both if as well as else are O(1)
operations.
If you say exactly, the complexity in terms of comparisons will be
1. n − n/2 − 1 (number of elements for which first if succeeds) +2 × (n/2) (number of elements for which first if fails)
= 3n/2 − 1
2. (n − 1)/2 + 2 × (n − 1)/2
= 3(n − 1)/2
How many topological sorts of the following directed graph are possible?
topological-sort
Selected Answer
The topological sorts can exchange the position of any pair node which have no directed path between them. So nodes
(b,c) , (e,f) , (h,i) are interchangeable as there is no path between them . So for each pair there are 2 permutation so
total no of permutations are 2^3 = 8
Take , n=5 (say) and see what values j assumes. You will find that , j assumes values like 1,3,6 for k=1,2,3 , thus j
assumes values like k(k+1)/2. Now the for loop runs for k times , and j=k(k+1)/2, so equating with n on RHS , k^2=n or
k=sqrt(n). So for loop runs sqrt(n) times.
Outer while is of the form [where i=n]
while(i>0){
i=i/2
} and so complexity is log n. Hence for each of these log n times the for runs sqrt(n) times , complexity=O(logn*sqrt(n)).
If
f(n)=ϴ(n),g(n)=ϴ(n)
and
h(n)=Ω(n)
I am getting expression such that it is equivalent to O(n^2 ) , since f(n)g(n)=theta(n^2),Now I am just confused at one point that how to proceed for
calculating f(n)g(n)+h(n) ,theta(n^2)+h(n) ?
algorithms
Selected Answer
f(n)=ϴ(n) =>
g(n)=ϴ(n) =>
h(n)=Ω(n) =>
From (c) and (D), we can find only lower limit of f(n)*g(n) + h(n) since we don't know the upper bound of h(n).
=> f(n)*g(n) + h(n) = Ω(n2) (Taking only asymptotically tight lower bound)
Let G be a simple undirected complete and weighted graph with vertex set V={0,1,2..99}.Weight of edge (u,v) is |u-v|
where 0<=u,v<=99 and u not equal to v.Weight of the corresponding maximum weighted spanning tree is
(a)4950(b)4451(c)7350(d)7351
and v0 is connected to v50 to v99 and weights are (we will not include 99 again as we have already added) 98+97+....+
50 = 3626
So finally Weight of the corresponding maximum weighted spanning tree is = 3725 + 3626= 7351
An international cellphone company provides service on 7 different frequencies. They wish to set up business in Tamil Nadu
and have fixed the locations of 100 towers for their new service. The company has to ensure that two towers broadcasting
on the same frequency are at least 100 km apart, so that there is no interference of signals.
(ii) Describe an algorithm which will answer the question “Is it feasible to set up towers at the given locations and provide
service on 7 different frequencies?”. Your algorithm should say “feasible” if it is feasible, otherwise output the minimum
number of frequencies needed to utilize all 100 towers.
algorithms descriptive
7 different frequencies will act as 7-color problem ...and towers within 100 Km ...will be considered adjacent
Selected Answer
3. A weight-balanced tree is a binary tree in which for each node. The number of nodes in the left sub tree is at least half and at most
twice the number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the
farthest leaf) of such a tree on n nodes is best described by which of the following?
a) log2 n
b) log4/3 n
c) log3 n
d) log3/2 n
Answer is D
A hash table can store a maximum of 10 records.Currently there are records in locations 1,3,4,7,8,9,10.The probability of a
new record going into location 2,with a hash function resolving collisions by linear probing is?
Selected Answer
For the New Record to go to location number 2 it has the choices as 1,2,7,8,9,10
Total number of Records is 10
Probablity is (6/10)
Selected Answer
ANSWER: O(logn)
Solution:
T(n) = T(n − 1) + n
1
n −1
Substituting T(n − 1) = T(n − 2) + in above equation
1 1
n −1
T(n) = T(n − 2) + +n
Assuming T(1) = 1
T(n) = O(logn)
1.226 How many element will change their initial position after completion of
partition algorithm ? top gateoverflow.in/33387
Consider an array with the following elements: 12, 18, 17, 11, 13, 15, 16 and 14.
How many element will change their initial position after completion of partition algorithm by choosing 15 as pivot?
Selected Answer
7 ans
How many real links are required to store a sparse matrix of 10 rows , 10 columns ,and 15 non zeros entries.(pick up the
closest answer)
Consider a hashing function that resolves collision by quadratic probing.Assume the address space is indexed from 1 to 8
.which of the following locations will never probed if a collision occurs at position 4?
The problem with Quadratic probing is it will not probe all the location..
We should visit 'm' location by doing m probes which is not done by quadratic probing...
4) The number of elements that can be sorted in Θ(logn) time using heap sort is
(A) Θ(1)
(B) Θ(sqrt(logn))
(C) Θ(Log n/(Log Log n))
(d) Θ(Log n)
algorithms
Consider two vertices a and b that are simultaneously on the FIFO queue at same point during the execution of breadth first
search from s in an undirected graph.
Which of the following is true?
1. The number of edges on the shortest path between s and a is atmost one more than the number of edges on the shortest
path between s and b.
2. The number of edges on the shortest path between s and a is atleast one less than the number of edges on the shortest
path between s and b.
3. There is a path between a and b.
Can you please explain this question a bit ? I can not find any counter example .
algorithms
Selected Answer
Selected Answer
The idea is to compare pairs of values (n/2 - 1 comparisons) to get an array of high values and an array of low values.
With each of those arrays we again compare pairs of values (2 * n/2 - 1 comparisons) to get the highest and lowest
values respectively.
1.233 complexity of algo for detection of universal sink in directed graph top
gateoverflow.in/32435
minimum running time of algo that determines universal sink in a directed graph G={V,E} - a vertex with
indegree |V|-1 and outdegree 0, given an adjacency matrix for G is:
http://stackoverflow.com/questions/29259365/how-to-find-the-universal-sink-of-a-directed-graph-with-an-adjacency-
matrix-repr
algorithms
Selected Answer
A splay tree is a self-adjusting binary search tree with the additional property that recently accessed elements are quick
to access again. It performs basic operations such as insertion, searching and deletion in O(log n) amortized time
So option D is correct.
Sorting is useful for both report generation and making search easier and efficient . But sorting does not minimize the
storage needed.
so Option D.
Selected Answer
Golden ratio is represented by the symbol ϕ(Phi), and its conjugate is –ϕ(phi, also called as silver ratio). Both are
satisfied by the equation, x2 – x– 1 = 0, as given in the explanation for Golden ratio. Since this equation is a quadratic
equation, we are going to solve it the usual way, by calculating its roots.
√
−b ± b 2 −4ac
2a
Roots = .
Given the equation, x2 – x– 1 = 0, value of a = 1, b = − 1 and c = − 1. So, the equation for calculating root will become
1 ± √1 +4
2
1 ± √ (5 )
2
=
If we calculate the roots we will get the value 1.61 and -0.61 which are actually the values of Golden ratio and its
conjugate. So, the Golden ratio and its conjugate both satisfy the equation x2 – x– 1 = 0. The answer is C.
If you want to know more then, Here is the reference. He has explained very beautifully. Have a look.
2T(n/2)+Theta(n)
Given an array which contains both positive and negative integers in it and asked to design an algorithm to find
the maximum sum which does not contain two consecutive numbers.What is the time comlexity of efficient
algorithm
A) Θ(nlogn)
B) Θ(n)
C) Θ(n2)
D) Θ(n2logn)
its O(n)
http://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/
A) nlg c , clg n ,
B) lg(n!) , lg(n n)
I guess both are equivalent so then how to represent them using asymptotic notation ?
A.
So,
( )
nlg c = Θ clg n .
B.
lg(nn ) = nlgn
So,
lg(n!) = Θ(lgnn ).
1.242 Algorithms ,finding the upper bound n0 and constants top gateoverflow.in/41999
2n^2 +nlogn =theta(n^2) ,I have done the lower bound..Like finding out the n0 and the constant.. Help me with the upper
bound constant and n0
1.242 c++ program to find maximum and second maximum using n+logn-2
comparisons top gateoverflow.in/41970
The optimal algorithm uses n+log n-2 comparisons. Think of elements as competitors, and a tournament is going to rank them.
|
/ \
| |
/ \ / \
x x x x
this takes n-1 comparisons and each element is involved in comparison at most log n times. You will find the largest element as the winner.
The second largest element must have lost a match to the winner (he can't lose a match to a different element), so he's one of the log n elements the
winner has played against. You can find which of them using log n - 1 comparisons.
Reference: http://stackoverflow.com/questions/3628718/find-the-2nd-largest-element-in-an-array-with-minimum-number-of-comparisons
I would like to know if there is any other Algorithm and data structure book(other than coreman) available for beginners for
Gate preparations like we have Let Us C(Y. Kanetkar) for C (Ansi version)?
graph-theory algorithms
Hi ,
Look For a N Cube graph : This graph has got its name as "N "cube because here each vertex is represented By N bits .
Say for 1 cube graph : we would have vertex represented by 1 bit . so number of vertex possible with 1 bit is 0/1 ( 2
vertex==2n where n is 1)
Similarly take for 2 cube graph : here each vertex would be represented by 2 bits . so number of vertex possible is
00,01,10,11
Hence in this way we can generalize that For N cube graph we can have vertex which is represent which is rep By N bit
and number of vertex possible is 2^N
( If you seen the dig given below ) A vertex is joined by another vertex if its both vertex bits representation differ by
atmost 1 bit .
say if A has 001 and B has 101 we can join AB but if C has 110 so here we cant join neither AC Or BC.
So if a vertex is rep by N bit then it can be associated with other (n-1) vertex with change in any of these N bit at distance
of 1 ( Only 1 bit to differ in any vertex ) . However this condition should be maintained if we are joining vertex .
Hence no of edges = N * 2 N-1 (where first N mean change in any of N bit and 2 n-1 mean it can/cant be associated with
neighbouring vertex with the above condition specified )
You see, the important point to note in this recurrence relation is that there are two unequal recursive calls. That's the
reason behind my choice of solving this recurrence relation using recursion tree method.
Another point to note here is that the cost of cost of combining the solution at the top most level of the tree is n. At the
lower level of tree the cost is computed by adding the value of n at each level.
Since the first recursive call takes 1/5th of the total input and the second call takes 7/5th of the total input, the two sub-
tree(left sub-tree and right subtree) will not have same height. But here we can make a sloppy assumption that it is a
complete binary tree with log10/ 7 n levels, this will help us in computing the upper bound of the tree.
HTH
1.246 How to solve below recurrence relation using subtitution method ? top
gateoverflow.in/32928
T(n)=T(n-3)+cn2
T(n-3)=T(n-6)+c(n-3) 2
T(n-6)=T(n-9)+c(n-6) 2
Now let k=(n-1)/3 ,I am only able to get terms like cn 2+c+4c+25c +64c, with which I am unable to reach any conclusion ,
so how to proceed through this .
algorithms
Selected Answer
I suggest ,download the image first then view it for better clarity.
a) 4
b) 5
c) 6
d) 7
Selected Answer
Ref:http://en.wikipedia.org/wiki/Comparison_sort#Number_of_comparisons_required_to_sort_a_list
1.247 how many recursive calls are there in tower of hanoi, is it 2^n-1 or
2^(n+1)-1?? top gateoverflow.in/39168
Selected Answer
Using back substitution method solve the above equation we will get
2^(n+1) -1
Suppose you implement prims algo by adjacency matrix, Then after selecting the minimum vertex, you ll have to go
through V entries corresponding to that vertex in matrix and select the minimum. So on, you do this for V vertices. So,
complexity becomes O(V2)
Consider a square matrix of N × N in which the values are located from A[1, 1] to A[N, N]. For all i and j, A[i, j] = A[i – 1, j – 1] where i > 1 and j > 1. In order to reduce the
space complexity we avoid redundant storage. All the elements of above square matrix are stored in the Linear array B starting from index 0 in row major order. The
following code is used to retrieve the (i, j)th element of A index in the array.
a. B [2N + i – j – 1]
b. B [2N + j – i – 1]
c. B [N + j – i – 1]
d. B [N + i – j – 1]
algorithms
Unsorted array: O(n) worst case. Performs in sublinear time if some structure is present.
https://en.wikipedia.org/wiki/Selection_algorithm
http://sarielhp.org/research/CG/applets/linear_prog/median.html
http://gateoverflow.in/36807/let-f-n-%CF%89-n-and-g-n-o-f-n-then-g-n-_______-assume-n-0-1-%CF%89-n-2-o-n-3-
%CE%B8-n-4-%CF%89-1
NOTA
. g(n) can be 1/N
http://stackoverflow.com/questions/905551/are-there-any-o1-n-algorithms
algorithms
There is no greedy solution to 0-1 knapsack problem. But, it is fairly easy in GATE to do substitution:
Hence, option B.
now , the question says , worst case time complexity. So, in the worst case , the inner loop condition is not satisfied , so ,
won't it be O(n 2) ?
algorithms
Selected Answer
i=1; then j=i=1 => inside A[ i ] != A[ j ] condition false => Execute 'else' part. Break inner loop
i=1; then j=i=2 => inside A[ i ] != A[ j ] condition false => Execute 'else' part. Break inner loop
repeat unto i's counter i.e., n....Thus, it only executes n times. Hence, O(n)
Assume A m × n , B n × p and Cp × q are matrices where m > n > p > q. How many minimum number of multiplications are required to perform
the following operation?
A m × n × B n × p × Cp × q [= (A B C)m × q]
a) mnp+npq
b) mnp+mpq
c)mnq+npq
d) mnq+mpq
(A*B)*C or A*(B*C)
After substitution
T1 = (x+3)(x+1)(x+2+x) = 2(x+3)(x+1)(x+1)
T2 = (x+2)x(x+3+x+1) = 2(x+2)x(x+2)
T1 - T2 = 2x^2 + 6x + 3
hence T1 > T2
{
printf("%d",i);
n=n/i;
}
}
In this one worst case will be when n is some prime number for which the loop will run O(sqrt(n) ) times but how to deal
with the best case , when n is some multiple of i then only inner loop will run , so even if I try forming some series like
i+2i+3i+.... then what should be the last term of this series for the evaluation of while loop .
yes,
Regarding the point 1 , please correct me if I am wrong - I knew Djisktra fails only if there is negative weight cycle. So , it is
correct , right ?
Also , under the same condition , the algorithm might fall into a infinite loop .
algorithms
Dijkstra fails when there are negative weights and it will not go into infinite loop because Relaxation only happens E times. Bellman ford fails when there is a
gate(n)
if(n!=0)
return gate(n-1);
else
printf("gate2016");
Gate(n)=gate(n-1)+1
Gate(n)-->gate(n-1)+.......gate(1)
logn
algorithms
Selected Answer
Final Answer
A) 15
B) 2 10 13
if path of 15 is there
then it will be considered as shortest path..dikjstra algo wont update it..updation takes place only when distance is less
than current distance
(assuming alphabetic order while processing ie removind C first from priority,2-13 path will choosen)
Here all paths from A to B are of 15 weight. But when dijkshtra's algo run,
Ans: when we run dijikshtra, taking A as source, in first iteration we are able
to reach B(but we are not selecting this in 1st Iteration, just updating the
so, it will only be updated when we get some shorter path, but it is not the case.
What is the difference between log m n and (log n) m. Can anyone explain?
algorithms
Given an array S containing n real numbers, and a real number x. We want to find any two elements p and q in the array
such that their sum is greater than the real number x. What is the best possible time complexity to find p and q ?
O(1)
O(n2 log n)
O(n)
O(n log n)
Question asks about Best case time complexity . So , if it happens , in the first and second element's sum is greater than x ,
then it can be done in O(1) time , right ?
algorithms
Selected Answer
No, in question, best time complexity means best algorithm i.e. what is worst case time complexity of best algorithm.
We can find largest and second largest numbers in S in O(n) time. Now see if their sum is greater than x, if it is, return
these two numbers, otherwise there can't be any pair whose sum is greater than x.
How does adding a vertex into a graph represented by adjacency matrix take O(n^2) time where n is no of nodes in graph?
What is the complexity of adding a vertex into a graph represented by adjacency list?
max(f(n),g(n)).
f(n)+g(n) is also correct. They are asking order. Anyway you'll get max of both.
Using Huffman code the number of bits required to have {a,b,c} with frequences 10,10,10 for each letter then the binary
codeof bits are ???
Its
a-10
b-11
c-0
1.268 what is the weight of minimum -weight spanning tree in the graph ? top
gateoverflow.in/40520
I tried by taking n=2 , and took points (1,1) ,(1,2) ,(2,2),(2,1) and I got the minimum weight to be 3 , which is n+1 but
according to answer it is n-1
The length of an MST (number of edges required to make it) in an nXn grid where each square is a vertex is always n^2-1 ...(1)
Further, if an edge is axial (vertical or horizontal), then its weight should be 1 according to the formula given in the problem. ...(2)
Now since we are taking only axial edges, the total weight of the MST from (1) & (2) comes out to be: (n^2-1)*1
So the weight of the MST of this graph should be n^2-1 according to me.
Let F1 , F2 , . . . . . . . . . . . . . . Fn be files with length L1 , L2 . . . . . . . . Ln we would like to merge all of the files together to make a single
file .The cost of merging files is m + n if the files have length m and n .Find the minimum cost of merging ten files whose
length are 5, 3, 10, 20, 15, 10, 5, 1, 2, 4 is _____________.
Selected Answer
Check this in this just merge 2 files with least cost always so we start with files whose cost is 3 (1,2 ) by this we move
forward by merging least cost files then we add all the internal nodes to have the cost of merging the files
https://xlinux.nist.gov/dads//HTML/optimalMerge.html
1.269 How to apply the master theorem to equations containing f(n) other
than n^d. For e. g. F(n) = log n. top gateoverflow.in/38979
1.269 What is the difference between double hashing and rehashing? gateoverflow.in/33924
top
algorithms
1.270 arrangements preserving the effect of first pass partition algorithm are
top gateoverflow.in/40990
consider an array consisting of following elements in an unsorted order but 60 as first element 60,80,15,95,7,12,35,90,55 quick sort partition algorithm is
applied by choosing first element as pivot total number of arrengements of array integers is possible preserving the effect of first pass of partition
algorithm are
first choosing 60 as pivot element and applying first pass of Quick Sort we get
55 15 7 12 35 60 80 90 95.
Now left side of 60 can be arrange in 5! and right side can be arrange in 3! ways.
Total ways=5!*3!=720
a) Only S2
b) Only S1
c) Both S1 and S2
Both are wrong . dijisktra algorithm i not affected by negative weights till there is a negative weight cycle.
bellman ford use the logic that in a graph .the shortest path contain atmost ( n-1) edges. it does not find all the cycles .
and i think finding all the cycles in the graph will be exponential time because in the worst case every vertex will have a
cycle . and we may have to look n vertices ( n*n)
IF ONE USES STRAIGHT MERGE SORT TO THE FOLLOWING ELEMENTS 20,47,15,8,9,4,40,30,12,17 THEN THE ORDER OF
THE ELEMENTS AFTER 2ND PASS OF THE ALGORITHM
My Answer is
How many key comparisons are there , what is the lower bound and upper bound ?
For calculating the lower bound , should we consider the case when the keys are all in non-increasing fashion and then after
n-k comparisons we shall find one of the K keys and then we are done , and for calculating upper bound then , what should
be the case considered for the order of keys ?
algorithms
Selected Answer
I suppose here the upper bound and lower bound cases would be same.
To find one of the k smallest keys, we need to look at n-k+1 elements atleast to be sure that we have chosen one among
k smallest keys.. So, total n-k comparisons
In the question nothing about the order of the keys is mentioned. so we must look for n-k+1 elements, so n-k
comparisons.
Time complexity should be ϴ(n-k).
Assume that array A and B are sorted, each contain 'N' element . What is the worst case time complexity to find the median
of A ∪ B?
a) O(log(N))
b)O(N)
c)O(Nlog(N))
d)O(N2)
Consider the following set of processes with the arrival time and CPU burst time.
Assume above processes are scheduled by RR scheduler with time quantum of 2 units. What is the average turn
around time of all processes?
10 units. Please verify the answer 'cause this question is slightly tricky....
given answer is ( A)
(A) Θ(n2 )
(B) Θ(n2 log n)
(C) Θ(2 (log n)2)
(D) Θ(n (log n)2)
Character Frequencies
a 12
b 2
c 7
d 13
e 14
f 85
Now, we encode each character using Huffman coding algorithm . What is the maximum number of bits required to encode
any character?
Selected Answer
order is 10,5,15.
10%8 = 2.
at first it will go to 2,now 2 is occupied 1st collision,next it will go 3,same happened 2nd collision,next it will go 4,3rd
collision,now it will go to 5,it is empty so 10 took that position. so for inserting 10 , 3 collision has occured.
5 % 8 = 5.
now at first it will go to 5,but it is occupied ,so it will go to 6,but it is occupied also ,next it will go to 7,it is empty,so 5 can
take that place. so for inserting 5 , 2 collision has occured.
15 % 8 = 7
now at first it will go to 7,but it is occupied ,so it will go to 0,but it is occupied also ,next it will go to 1,it is empty,so 15
can take that place. so for inserting 15 , 2 collision has occured.
total =5 + 2 + 2 =7 collisions
main()
{
int sum= 0;
for(int bound = 1;bound <= n; bound *=2)
{
for (int i=0;i<bound;i++)
{
for(int j=0;j<n;j+=2)
{
sum=sum+j;
}
for(int j=1;j<n;j*=2)
{
sum*=j;
}
}
}
}
b)O(n^2 logn)
c)O((logn)^2)
d)O(n(logn)^2)
BUT Shouldn't the answer be D ? I was thinking that if the outer loop runs logn times...the middle loop and
outer loops together should run (logn *(logn+1)) times...Am I wrong ?
Also could someone please help me understand the difference between log(logn), log^2n(log square n) and
(logn)^2 ?
Selected Answer
n n n n n n n
If two sibling loops are there we need to only consider the most critical one for time complexity. But here the middle loop
is dependent on outer loop iteration variable and so we cannot find its complexity separate and multiply.
Number of comparisions in worst case required to merge two sorted arrays of size 40 and 60 are-------
Selected Answer
algorithms
Put the job with maximum profit in last possible slot where it executes before deadline. continue this for other jobs utill u
dont find any job that can be executed within deadline. here put p1 first in slot 1-2 then put p4 in slot 0-1.
I know solving using tree method could someone help solving this in easy way
3.If there exists no directed path from V1 to V2 , then there exists a directed path from V2 to V1 .
why is option 1 always true , I think it must be true only if they mention that there is a directed path from s to V1 and s to
V2 via V1 because if we have s to V1 and s to V2 separately then also we will have V1 and V2 simulatenously on call stack if
we have a path from s to V2 via V1 .
3. same concept as 2
here only concept is the maximum depth of the graph and then only operation is backtracking
n
f2 = 22
2
f3 = 2n
f4 = n!
f5 = 2n
A). f1 is Ω(f2 )
B). f2 is O(f3 )
D). f4 is O(f3 )
f2 = 22^n
2n
f3=2n^2 n
2
f4 = n! n log n
f5=2n
n
Logarithmic growth rate of f1 is less than all other functions growth rate
I think option D is true. first of all . 1 is a linear function, secondly in exponential we have 2 functions that are f4,f5. in
which n^n has a much bigger growth than 2^n. and then we have 2 super exponential functions that are f2 and f3. as
2^n has a much greter growth than n^2. f3=O(f2). now just compare n^n and 2^ n^2.
nlogn=n2. so option d .
1.287 How to solve the below question of Directed graph ? top gateoverflow.in/12699
A path from vi to vj in G is sequence of vertices (vi, vi +1 , …, vj) such that (vk, vk+1 ) ∈ E for all k in i through j– 1.
for i = 1 to n
for j = 1 to n
for k = 1 to n
A [j , k] = max (A[j, k] (A[j, i] + A [i, k]);
Which of the following statements is necessarily true for all j and k after termination of the above algorithm?
(A) A[j, k] = n
(B) If A[j, k] = n– 1, then G has a Hamiltonian cycle
If there exists a path from j to k, then A[j, k] contains the
(C)
longest path length from j to k
If there exists a path from j to k, then every simple path
(D)
from j to k contain most A[j, k] edges.
I traced it with 4 vertex .. i didnt get logest path after terminate the algo... but option d follow ... option c may be
changed by changing in no of vertex ...
aur one more thing if directed graph has loop then option c always wrong bcoz longest path will be tends to infinite
algorithms
Selected Answer
lg *n, (Inverse Ackermann function) is the number of times we can take log repeatedly until we get 1. This function can
almost be considered constant for all practical purposes.
There shouldn't be any confusion regarding options C and D as n! is asymptotically larger than lg n.
A) lg (lg * n)
B) lg * (lg n)
lg * (lg n) = lg * n - 1.
top
For a given set of vertices , can we compute the maximum number of topological sortings possible ?
This question can be form like this , how many DAG ( Direct Acyclic Graph) are possible with a given vertex ( say with n
vertices ) .If a graph contains any cycle then topological sorting isn`t possible .
a)Both in P
b)Both NP-complete
option C
3 Sat is np complete
2 Sat is p
Let G = (V, E) be an undirected graph with a subgraph G1 = (V1, E1). Weights are assigned to edges of G as follows :
w(e) = 0 if e belongs to E1
1 otherwise
A single-source shortest path algorithm is executed on the weighted graph (V, E, w) with an arbitrary vertex v1 of V1 as the source. Which of the following can always be inferred from the path
costs computed?
(A) The number of edges in the shortest paths from ν1 to all vertices of G
(B) G1 is connected
(C) V1 forms a clique in G
(D) G1 is a tree
Answer is (B).
We can decide whether G1 is connected or not, because if it is connected then at least one path cost must be 1 because in
shortest path computed from v1 to some vertex not in G1, we must include an edge not in G1, and weight of that edge is
1.
If path cost is 0 for all vertices, that means all the edges included were of weight 0 i.e. of G1 only, hence G1 is not
connected.
I can certainly decide G1 is connected or not.initially I will set shortest distance from v1 to every vertex to infinity, then I
will try to find the shortest path from v1 to all vertices. Now after this algorithm terminates I will check if a vertex
belongs to set V1 and contains infinity as the shortest distance then G1 is disconnected graph else the graph is connected
B) Do following |V|-1 times where |V| is the number of vertices in given graph.
…..a) Do following for each edge u-v
………………If dist[v] > dist[u] + weight of edge uv, then update dist[v]
………………….dist[v] = dist[u] + weight of edge uv
Now A is topological sort and B is Bellman ford , Both are following similar steps , so then why is the time complexity of bellman-ford O(VE) while for toplogical sort
it is O(V+E) ?
algorithms
In topological sort, in the inner loop we consider only "adjacent vertex". So, the complexity at max can be O(|V| 2) which
happens when |E| = |V|2.
In Bellman Ford algorithm, the inner loop is run for each and every edge.
1.292 Why is the below expression correct for a cross edge in case of DFS ?
top gateoverflow.in/12731
Cross Edge(a,b) is defined as an edge between two non-ancestor nodes in DFS , so my query is that how is this stmt true :
algorithms
d(u)........f(u) , d(v)......f(v)
discovery and finishing time of one vertex will be different from other vertex for cross edges .
I think it must be true but answ given is false , its says that In shortest path algo, we pick the minimum distance vertex from the set of vertices for which distance is
not finalized yet. And we finalize the distance of the minimum distance vertex.
For maximum distance problem, we cannot finalize the distance because there can be a longer path through not yet finalized vertices.
Now I am nt getting that when all are initialized with minus infinty so then maximum can be found , so then whats the issue why cant we finalize it ?
algorithms
Longest simple path cannot be computed like this. To understand why you need to know that Dijikstra's algorithm works
using Greedy principle. That is, at each vertex we choose the best neighbour and include that in the shortest path. Doing
like this in end, we get the best path- greedy approach works. But this approach need not work in many cases and longest
path one is just an example. A simple example can be shown as follows.
1.294 In bellman ford algo why are the no of passes |V|-1 ? top gateoverflow.in/12729
Bellman-ford algo
1) This step initializes distances from source to all vertices as infinite and distance to source itself as 0. Create an array dist[]
of size |V| with all values as infinite except dist[src] where src is source vertex.
2) This step calculates shortest distances. Do following |V|-1 times where |V| is the number of vertices in given graph.
…..a) Do following for each edge u-v
………………If dist[v] > dist[u] + weight of edge uv, then update dist[v]
………………….dist[v] = dist[u] + weight of edge uv
in bellman ford algo v-1 times will give you the shortest path but if there is any -ve edge cycle to check you have to
perform 1 more cycle .
Why V-1times ?
simple , a vertices is connected to atmost V-1 vertices to check them you need V-1 times ( there is no -ve edge cycle ) .
Though the parent node is maximum of both the child nodes but still the procedure we follow is chosing the minimum at each step and adding them to produce a
parent node, so how come heapify procedure is called here ?
algorithms
every time we join the least two node (which are having some values)
we get a new value which need to be shifted in its correct postion in the heap thats where we need to "build heap".
aabbbbabccdddccccbbdd
ques 1. the number of bits required for huffman encoding of the above msg is-
B) 11 01 00
b d a
obviously 1st one is correct.basic arithmetic question . Refer any 10 std maths book
2 is correct
Is it =1+2+4+8+..........n/4 + n/2 +n ?
=O(2^n) ?
Is it loglog(2^2^2^2)=4
Let n=(2^(2^(2^2)))=2^16
Loglogn=4
T(n)=1+T(2^8)=2+T(2^4)=3+T(2^2)=4+T(2)=5
Let n= (2^(2^(2^(2^(2^2)))))=2^(2^65536)
Loglog n = 65536
Yes. For 2 2 (
something
)
, log2 x = 2something and log2 log2 x = something
Selected Answer
So, for n = 100, we get running time = 0.01 * 100 * lg 100 = 6.7
For 3000 comparisons we need 100s , thus for 1 comparison we need 0.033s
To sort 100 names we need 200 comparisons thus time needed is 0.033*200 s = 6.67 s
Selected Answer
Case 2.b.
Should be O(nloglogn)
http://homepages.math.uic.edu/~leon/cs-mcs401-s08/handouts/extended_master_theorem.pdf
n n
T(n) = 2T ()
2
+
lgn
n n
For Master theorem, a = 2, b = 2, nlogb a = n. f(n) = lg n . We cannot say f(n) = O(nlogb a −ϵ), as the difference between n and lg n is
not polynomial. So, we cannot apply Master theorem. So, trying substitution. Since, we have a lg term, we can try all
powers of 2.
T(1) = 1, assuming.
T(2) = 2T(1) + lg 2 = 4
T(4) = 8 + 2 = 10
T(8) = 20 + 3 = 22.66
Not able to reach a conclusion. We can see that the recurrence is between case 1 and case 2 of Master theorem. So, it is
Ω(n) and O(nlgn). So, lets solve the recurrence directly.
n n
T(n) = 2T () 2
+ lg n
n n n
()
= 22 T 4 + lg n −1 + lg n
n n n
= 2lg n T(1) + 1 + 2 + … + lg n
1 1 1
=n+n ( 1
+ 2
+…+ lg n
)
= n + n(lglgn + γ) = Θ(nlglgn)
The sum of lgn terms in HP approximated to lglgn + γ where γ is Euler Mascheroni constant.
Ref: https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant
1.303 ugc net paper 2 computer science code 87 must tell me top gateoverflow.in/11839
http://ugcnetonline.in/question_papers_december2012.php
=0
arrange the following in the increasing order of their asymptotic complexity in big theta notation
Selected Answer
Suppose we are comparing implementations of insetion sort and merge sort on the same machine. For inputs of size n,
insertion sort runs in 8n^2 steps, while merge sort runs in 64nlgn steps. For which values of n does insertion sort beat
merge sort?
algorithms
I know that Insertion sort is better as compared to Merge sort only for small set of Imputs . Here if i put n=2 then i get 32
steps for merge and 128 steps . SO here only Insertion has beat Merge sort . Continuing in this manner at n =43 i would
get 14792 steps and 147933.806 steps in merge . After this the whole scenario changes Merge Sort wins ! So the answer
for above will be from 2 to 42 right or just 42 ?
1.305 (logn)! and (loglogn)! are polynomially bounded ? anybody can prove? top
gateoverflow.in/12928
Selected Answer
logn! = Θ(nlogn)
(
So, (logn)! = elog (log n ) ! = Θ e (log nlog log n ) = Θ ) (( elog n )
log log n
) (
= Θ nlog log n . )
Hence, polynomially lower bounded but not upper bounded. For polynomial, we need nc, where c is a constant, which is
not the case here.
( )
(loglogn)! = elog (log log n ) ! = Θ e (log log nlog log log n ) = Θ (( elog log n )
log log log n
) ( ) (
= Θ (logn)log log log n = O(n) ∵ nlog log n = O(en ), detailed at end, and replace
log log n
nlog log n = elog n = elog nlog log n = O(en )
<a>. omega(n)
<b>.omega(n^2)
<c>.⊖(n)
<d>.⊖(n^2)
ANS- A,B
= omega (n)
If I have two lists of length 2 then no of comparisons in the worst case would be 2 only , since If I have say 10,20 in list A
and 5,7 in list B so then on merging 10 is compared with 5 then 20 is compared with 7 so finally in 2 comparisons I have
merged both the lists , so then how to calculate the average no of comparisons here ?
algorithms
Selected Answer
First of all, worst case would be 3 comparisons. For example, A = [10,20], B = [15,30]. Here number of comparisons
would be 3.
Now for expected number of comparisons, suppose we are given two lists A = [x1,x2], B = [x3,x4]. For simplicity,
suppose all 4 elements are distinct.
If we were to write all possible results of merging x1,x2,x3,x4, we have following ( 2 ) = 6 possibilities (Note that in each
possibility, x1 has to come before x2, and x3 before x4 because A and B are sorted)
x1,x2,x3,x4
x1,x3,x2,x4
x1,x3,x4,x2
x3,x4,x1,x2
x3,x1,x4,x2
x3,x1,x2,x4
Now we can have either 2 comparisons or 3 comparisons. We have 2 comparisons if either both x1,x2 < x3 or both
x3,x4<x1, so P(2 comparisons) = 2/6
We will have 3 comparisons in rest of the 4 cases (you can verify), so P(3 comparisons) = 4/6
2 4 16 8
=2∗ 6 +3∗ 6 = 6 = 3
2m
We can generalize it for two lists A and B of size m. Number of ways in which final merged list C can be formed is ( m ),
because we have total 2m locations in C, out of which we can choose any m locations to put elements of A, rest are filled
by B.
Now we count number of comparisons done during merging. Suppose during merging, A finishes first (other case is
symmetrical, and we will multiply the count by 2). So number of comparisons will be size of list C when A finishes. So we
argue on size of C (let we call it S when A finishes).
Minimum value of S is m because when A finishes, C must contain at least m elements, and maximum value of S is 2m − 1,
which happens when B is left with just 1 element when A finishes. So we make cases on S :
locations in C, so ( 1 ) choices.
S = m + 2 : C contains m + 2 elements, out of which m are of A, 2 are of B, those 2 elements of B can take any location out of
m+1
m + 1 locations in C, so ( 2 ) choices.
2m−2
(
= 2 ∗ m ∗ 1 + (m + 1) ∗ ( 1 ) + … + (2m − 1) ∗ ( m−1 ) )
Multiplication by 2 outside is due to symmetry.
m 2m− 2
(
2 ∗ m∗ 1 + (m+1 ) ∗ ( 1 ) + … + (2m−1 ) ∗ ( m− 1
) )
2m
m
( )
=
In Merge Procedure we generally have infinity( ∞) at the end of the array we like to merge
Here largest element of one array is smallest than the smallest element of another array
a = [10,20]
b = [5,7]
In Example 1 the smallest array(ie a) smallest element is greater than the largest element of array b.Here number of
comparsion is 5
In Example 2 the smallest array (ie b) the largest element is smaller than the smallest of array b.Here number of
comparison is 3.
Thus it depends on array that how many comparison their will be.B ut the mandatory condition that (the smallest element
of one array is larger than the largest of another) is to be fulfilled.
In your case the number of comparison is 2(as it fulfills the mandatory condition).
NOTE
*The infinity is put at the end of both the array because in (above discussed) array the element to compare with will be
over at certain time, then ∞ plays a immense role.
1.308 Given n points in the xy plane, what is the time complexity to find the
closest pair? top gateoverflow.in/14354
what is the approach of this question , Is it that first we will traverse all the pairs then find the minimum distance between
all the pairs
algorithms
T(n)= 2T(n/2)+O(n)
= O(nlogn )
ref : http://www.dcs.gla.ac.uk/~pat/52233/slides/ClosestPoints1x1.pdf
1.309 In sorting algo which has a running time that is least dependent on
initial ordering of inputs top gateoverflow.in/14296
options
A. insertion
B. quick
C. selection
D. merge
Selected Answer
ans D
insertion sort : if the initial ordering is in reverse order it takes O(n 2).
quick sort :if the initial ordering is in reverse order or sorted it takes O(n 2)
selection sort : best case and worst case O(n 2 ) it does not depend upon the order but swaping takes less (if sorted )
merge sort : in all cases O(nlogn) and its the ans ( i guess)
1.309 Hi.i need a correct explanation on binary search..how it will be log n. top
gateoverflow.in/13869
algorithms
Selected Answer
T(n) = T(n/2) + 1
This is the recurrence relation as after '1' search we eliminate n/2 elements.
Solving we get
1.309 What is the smallest value of n such that an algorithm whose running
time is 100n^2 runs faster than an algorithm whose running time is 2^n on
the same machine? top gateoverflow.in/14395
Selected Answer
1.310 For each function f (n) and time t in the following table, determine the
largest size n of a problem that can be solved in time t , assuming that the
algorithm to solve the problem takes f (n) microseconds. top gateoverflow.in/14397
lg (n) = 10^3
n=2^(10^3)
given a graph G,a matrix P k represent a matrix in which each entry p k[i][j] represent the shortest path from node i to
node j in G which uses only nodes 1,2,3.............k-1 .The corresponding graph formed by using matrix P k[i][j] is termed as
Gk .
Gk can be calculated by taking the square of adjacency matrix of G k times and replacing each multiplication and addittion
operation by AND and OR operation.(concept of warshall's algorithm of unweighted graph) .now my question is how to find
Gk if the graph G is represented by using adjacency list and what will be the time complexity to do it ??
to compute inital distances time taken will be o(v3) as suppose i am calculating a then for the idstnce to b i have to seach
all the adjency nodes of a . which may be v in worst case. and for c again and so v time i have to search v nodes which is
v2 and i have to do so for v times . so v3. now when i have calculated the initial matrix distances. and such v matrix have
to be calculated . else u may think this way .
now for distance of a to c through b we will hav to first find the distance from a to b which is v time and then from b to c
which is also v time now . and then compare with the inital distances . so time complexity will be (v+V+1)=O(v) this is
just one entry . such v^2 nodes have to calculated in worst case i.e. complete graph . and such v passes will be made so
v*v^2*v=O(V^4).
The predessor subgraph of BFS is a tree but the predecessor subgraph of DFS is a forest ?? please explain why??
1.313 How does Kruskal algorithm detect cycle in the graph and what is the
time taken ? top gateoverflow.in/14587
Does it tale constant time or the time taken proportional to search in the entire partition of elements to find whether the
component lies in that same component or not ?
algorithms
To detect if two nodes are in same partition, it calls find() function (of disjoint-set data structure) two times. Amortized
time complexity of find function is O(α(V)), where α(V) is inverse Ackermann function, which we can assume to be constant
for all practical purpose. So yes, detecting cycle takes almost constant amount of time.
In the worst case, we have 2 ∗ E find calls, and hence detecting cycles in whole algorithm is O(E), but since sorting takes
O(ElogE) time, overall complexity of algorithm is still O(ElogE).
I think, Kruskal's algorithm can be sure of a cycle when , for an edge (u,v), the condition FindSet(u) == FindSet(v)
evaluates to true, which means that both belong to same set.
The time , it would take would be atleast E*log(E) since it has to sort the edges first, before doing anything. In the worst
case , the edge causing cycle may be the last edge to be examined in the for loop(see CLRS). Thus in the worst case it is
same as running time of algo i.e E*log(V), since |E| < |V|^2.
1.314 What does fun2() do in general in the below recursive code ? top gateoverflow.in/13860
int fun(int x, int y)
{
if (y == 0) return 0;
return (x + fun(x, y-1));
}
algorithms
Selected Answer
if (b == 0) return 1;
to
if (b == 0) return 0;
If I have f(n)= omega(n) and G(n)= Big O(n) then what would be f(n)*G(n)
Selected Answer
Part 1 ans:
Let us say here "n" represent some function say h(n) so that we can more intuitively define the function,
Now, if f(n) = Ω(n) means in ours terms we can say f(n) = Ω.h(n) hence similarly g(n) = Ο.h(n)
f(n) = Ω.h(n) if
g(n) = O.h(n) if
case 2: In all cases f(n) is greater than g(n) according to the definition (1) & (2)
or c 1.h(n) > c2.h(n) so as due to the const. "c 1" f(n) becomes larger than g(n).
I just want to confirm whether all optimization problems are in NP or not say to find the shortest path this can be done in
polynomial time and If I am given a graph and I have to find whether there exists any path between 2 vertices of length K so
after calculating shortest path I can check whether path exists so that means I can do it in polynomial time but in general
given a graph and If I have to find whether path exists or not ,its an NPC problem ,so is it that the optimization version of a
problem is polynomial solvable and its similar decision version is NP.
algorithms
not all optimization problem are in p,np. some are NP hard like longest path e.t.c.
decision problem are the problem which have answer in yes or no form
we convert our optimization problem into decision problem so that it can become easy.
Take for example the Halting Problem of a Turing Machine, suppose someone asked you after how many steps the Turing
Machine will halt on a given input. To answer the exact number you first have to answer whether the Turing Machine is
going to halt or not. Then i may count the steps.
What we do is to convert our optimization problem to a decision problem. And if we are not able to give answer of that
decision problem we cannot compute it. So, computing is harder than saying yes or no. So if the problem is undecidable
then it will be also non computable.
so now u may understand where u are wrong if u can solve it in polynomial time definitely the decision problem will be
solved in polynomial time.
1.317 what is the use of reducing a problem for which no polynomial time
algorithm exist into some another problem ? top gateoverflow.in/13393
If I have a problem A for which no polynomial time algo exists then what do we achieve by reducing it to another problem
B and then proving by contradiction that if we could solve B in polynomial time then we could even solve A but since no
polynomial time algorithm exists for A hence no polynomial time algorithm can exist for B also , hence A cannot be solved
in polynomial time
algorithms
we reduce a problem which is not polynomial to some other problem because we dont have any solution for for present
time..but in future we may have a polynomial solution....and such problems are called NP problems.We change these
problems in some other problem in polynomial time called NP hard problems...so that many NP problms can be converted
into one NP hard solution..and we have to find solution for only one NP hard problem inspite of many NP problms....
1.318 How does encoding of the problem instance affects the time
complexity of the algorithm ? top gateoverflow.in/13391
If I take a problem instance in unary representation then will the algorithm take exponential time and what if the problem
instance is converted into binary representation then will the time complexity remain same or will it be polynomial in time ?
algorithms
If you change the encoding of the input, you've changed the formal definition of the problem, which means it's a different
problem. The complexity of the original problem doesn't change
1.318 Let s be a sorted array of n integers. Let t(n) denote the time taken for
the most efficient algorithm to determined if there are two elements with
sum less than 1000 in s.What will be the time complexity??????? top gateoverflow.in/13441
O(1) since the array is sorted we have to find the sum of first two elements only if their sum is less than 1000 than
output will be yes if not than since the elements are sorted if the sum of first two elements is not less than 1000 than the
sum of no two elements would be less than 1000 and output would be no.
1.319 Given an unsorted array. The array has this property that every
algorithms
Selected Answer
First, create a min-heap with first k+1 elements.Now, we are sure that the smallest element will be in this K+1
elements..Now,remove the smallest element from the min-heap(which is the root) and put it in the result
array.Next,insert another element from the unsorted array into the mean-heap, now,the second smallest element will be
in this..extract it from the mean-heap and continue this until no more elements are in the unsorted array.Next, use simple
heap sort for the remaining elements.
Time Complexity---
1.320 How many recursive calls are made by gcd function ? top gateoverflow.in/13660
I have already gone through the links of stackoverflow on this topic but still couldn't understand it clearly , so please explain
the logic behind this .
algorithms
Selected Answer
The key to understand this is to observe that "when a is divided by b, remainder is always less than or equal to a /2
". Why ? Because if remainder is more than a/2, and since divisor is always greater than remainder, then divisor is also
more than a/2, and so sum of divisor and remainder becomes more than a, which can't be possible.
Now when we find gcd(a, b), (suppose a > b, if not, swap a and b), in the first step, a is dividend and b is divisor, we find
some remainder r1 . Then in second step, r1 becomes divisor and b becomes dividend. Now again we divide b by r1 and get
some remainder r2 , but due to above property, r2 ≤ b/2.
So in two steps, remainder is at most b/2. We terminate the process once we reach remainder of 0. In the worst case,
every 2-step reduces remainder to b/2, and thus we need log2 b such 2-steps, or total 2log2 b steps.
So gcd(a, b) requires at most 2log2 b recursive calls where b is min (a, b).
It is worth noting that number of recursive calls depends only on smaller number (not larger number).
1.321 what is the tightest lower bound of the below pseudo-code ? top gateoverflow.in/13659
int isprime(int n )
{
for(int i=2;i<=sqrt(n) ; i++)
{
if(n%i==0)
{
not prime
}
}
algorithms
if you input is say 2 or 3 then it will i<=sqrt(n) become false and exit . and its worst case O(n^0.5)
this prog will be more efficient if there is break statement in the if part .
int isprime(int n )
{
for(int i=2;i<=sqrt(n) ; i++)
{
if(n%i==0)
{
not prime
break ;
}
}
I am a bit confused in this logic according to me all NPC are NP so that means all NPC are reducible to NP but since NPC are
NP-hard as well so I guess that is not possible since if x is reduced to y that means y must be harder than or equal to x that
means x cant be NPC since NP-hard is not easier than NP , so is it that all NP are reducible to NPC or all NPC are reducible to
NP , I am a bit confused in this , so please help.
algorithms
Any NP problem is reducible to any NP-Complete problem. Because that is how NP-complete problems are defined.
If a NP-complete problem is reduced to a NP problem, then that NP problem also becomes NP-complete- again, definition
of NP-complete problem.
answer is c.
Can Any body suggest some analytical approach to solve it.
http://articles.leetcode.com/2011/01/find-k-th-smallest-element-in-union-of.html
9. Yes. it varies with algorithm and hence we must choose the best possible algorithm. Here, the best algorithm given only
n/2 swaps in the worst case. All given options are wrong.
http://gatecse.in/wiki/Moving_Negative_Numbers_to_the_Beginning_of_Array
10. Probability that a given number comes to its own position = 1/n.
= n/n = 1.
f(n) = O(g(n))
So, f(n) has growth less than or equal to g(n)
g(n) ≠ O(f(n))
So, based on first condition, f(n) has growth strictly lower than g(n).
So, (b) and (c) are true. The inequality of (d) is false and it should be the answer.
if Dijkstra shorest path algorithm takes 8 second for a graph of 1000 nodes then approximatly how much time would it take
for a graph of 1000000 nodes.
a) 8000000 sec.
b) 8000 sec.
c) 16000 sec.
d)16000000 sec.
The ans is D.
Dijkstra algo take E log V (v for vertices and e for edge ) and e is o(v^2)
with 1000 node no. of comparison done is (1000^2 log 1000) = X (say) .....
with 1000000 node no. of comparison done is (1000000^2 log 1000000) = Y (say) .......
d. http://www.cs.cmu.edu/~avrim/451f11/lectures/lect1004.pdf
1.329 Best algorithm in terms of time to sort numbers within range 1 to n^5
top gateoverflow.in/5927
radix sort
Selected Answer
Q.14) http://lcm.csa.iisc.ernet.in/dsa/node112.html
for(i=1;i<=n;i++)
for(j=1;j<=n;j=j+i)
x=x+1;
i = 1 | 2 | 3 | 4 | 5 |.................n
total = n(1+1/2+1/3+1/4+1/5.............1/n)+C
O(nlogn).
f(n)= n^0.0000001
g(n)=lg n(base 2)
Is g(n)=O(f(n))...?
So I am getting f(n)=O(g(n))...
So, f(n) becomes larger. Thus for any x, we can have an n, where n x becomes larger than log n and stays larger from there
on wards for any higher n.
Selected Answer
http://www.cs.ucla.edu/classes/fall04/cs143/solutions/chap12a.pdf
1.336 What will be the complexity to find the 7th smallest element in a heap?
top gateoverflow.in/3430
1.337 DFS cross edges, forward edge and back edges top gateoverflow.in/4774
for(i=1;i<=n;i++)
for(j=n/3;j<=2n;j+=n/3)
x=x+1;
Selected Answer
it should be O(n). inner loop runs for constant number of times for every iteration of outer loop, hence we need to
consider only outer loop complexity.
outer loop run for n time and inner loop jump for n/3 which is may be logn. so total will be
O(nlogn).
1.340 fine the recurrence relation and time complexity of this question? top
gateoverflow.in/4921
5. Determine the average processing time T(n) of the recursive algorithm:
1 int myTest( int n ) {
2 if ( n <= 0 ) return 0;
3 else {
4 int i = random( n - 1 );
5 return myTest( i ) + myTest( n - 1 - i );
6 }
7 }
providing the algorithm random( int n ) spends one time unit to return
a random integer value uniformly distributed in the range [0, n] whereas
all other instructions spend a negligibly small time (e.g., T(0) = 0).
Hints: derive and solve the basic recurrence relating T(n) in average to
T(n−1), . . . , T(0). You might need the equation 1/1·2 + 1/
2·3 +· · ·+ 1/n(n+1) =n/n+1 for deriving the explicit formula for T(n).
T(n)=n/n+1 so T(n)=O(n)
regards
grv.
algorithms
Here, because of adjacency matrix it will take V 2 and because of linked list we have to traverse all nodes therefore it will
take V time.
hence O(V 3)
d) Initially all keys of nodes in priority queue are set to infinity . The root's key is set to 0.
prims algo can be implemented using without heap (O(n^2)) , with binary heap ( O(VlogV+ElogV+O(E) = O(ElogV)) and
fibonacci heap (O(VlogV+E)) so option a,c are correct .
divide and conquer approach gives min element with n-1 comparison..
for 2nd minimum element search on d root to leaf path from where max element coming.. reason is second minimum
element must compared with minimal element when we were finding minimum element.. so ,
divide and conquere based on binary tree approach so no of elements from root to leaf path is logn .. finding min from
logn elements takes logn -1 comparison..
total n-1+logn-1 = n + logn -2 comparison
In the best case, the number of comparisons needed to search a single linked list of length n for a given element is is ............
and
In the best case, the number of comparisons needed to search a double linked list of length n for a given element is ................
and is it possible to apply binary search on single linked list if the elements are sorted?
in worst case n comparison are needed to search for an element in single linked list.
in best case double linked list / single linked list ll take single comparison for an element . complexity will be O(1)..
Binary search works on linked list too but it is notefficient because it will take O(n) time to find middle element, after that
it ll take some more time to processe algo ..
O(n) time + extra time .. it is not efficient bcause O(n) time already elapsed what is use of Binary search ? same can b
done by sequential search by exact n comparison..
T(n+1)=T(n)+ceil[√(n+1)] , n>1
=1,n=1
T(1) = 1
T(2) = 1 + 2 = 3 = 2n - 1
T(3) = 3 + 2 = 5 = 2n - 1
T(4) = 5 + 2 = 7 = 2n - 1
T(5) = 7 + 3 = 10 = 2n
T(6) = 10 + 3 = 13 = 2n + 1
T(7) = 13 + 3 = 16 = 2n + 2
T(8) = 16 + 3 = 19 = 2n + 3
T(9) = 19 + 3 = 22 = 2n + 4
T(10) = 22 + 4 = 26 = 2n + 6
The term after + is growing in the order of √n. So, we can say T(n) = 2n + O(√n) = O(n).
T(n)=√nT(√n)+√n , n>2
=2 ,n=2
T(2) = 2
T(4) = 2T(2) + 2 = 6
T(16) = 4T(4) + 4 = 28
Consider a binary tree having 'n' elements or 'n' nodes the tree is organised in such a way that at every level 'i' there are 'i'
nodes assuming root to be at level 1 the height or depth of binary tree is O(......)
Selected Answer
I heard the answer as Top down why it is? can any one explain me please
What does a greedy man do? He always chooses the best available option at the moment. Similarly, greedy algorithm
chooses the best available option at the moment and proceeds further and there is no comeback. So, it is a Top Down
Approach as we start from the top of the problem and gradually reaches the bottom.
On the other hand bottom up approaches like backtracking explores a solution till the end as as soon as it finds that
unfeasible backtracks and then proceeds on a different route. So, this can be considered finding the solution from the
bottom.
Given the following table of data what are the minimum expected no.of comparisons required for an Optimal
i 0 1 2 3 4
Pi 3/16 3/16 1/16 1/16
Qi 2/16 3/16 1/16 1/16 1/16
1 * 3/16 + 2 * 3/16 + 3 * 1/16 + 4 * 1/16 + 0 * 2/16 (when no external nodes are accessed) + 1 * 3/16 + 2 * 1/16 + 3
* 1/16 + 4 * 1/16
= 1 + 12/16 ≈ 2 comparisons.
But I don't get the meaning of "optimal BST that can be constructed". Something else meant in the question?
1.349 find the running time of the following nested loop top gateoverflow.in/10444
for(i=1;i<=n;i=i*2);
for(j=1;j<=i;j=j+1);
if i*2 = 2i then :
1.350 find out the no. of spanning tree possible top gateoverflow.in/10154
find no of 4 length cycle = select 4 length cycle and for rest 1 edge select those edges which doesn't produces 3 length
cycle..
= 4 + 4 + 4 = 12
no of 5 length cycle = 3
algorithms
We can have a basic parenthesis matching algorithm were we use a stack and match each opening and closing braces.
Now, along with an opening brace we can also store its index and while matching the closing brace, we can find duplicates
if the matches are consecutive. i.e.; if the closing braces are consecutive and the indices of their matching opening braces
are consecutive, then they are duplicates.
Consider a sorted array of 'n' elements an element in the array is said to be majority element if it is occuring more than n/2
times of the array, the time complexity of algorithm which is most efficient to determine if the array contains majority
element or not is O(... )?
1.352 f(n)=n+ logn is O(n) and Ω(n) can any one explain me please top gateoverflow.in/9647
Yes. Both are true and hence we can also use theta notation. This basically means f(n) has the same order of growth
(asymptotically) as n. So, for very large n, value of f(n) will be growing same like n (log n will become negligible).
When do we say that 2 functions are polynomially comparable for applying master theorem...? We can apply the theorem for T(n)=3T(n/4)+nlgn but cant
apply it for T(n)=2T(n/2)+nlgn ...please explain..?
T(N)=3T(N/4)+NLOGN
T(N)=THETA(NLOGN)
a<b^k
AND p>0
1.354 What is the Generating function G(z) for the sequence of Fibonacci
numbers? top gateoverflow.in/6694
http://db.math.ust.hk/notes_download/elementary/algebra/ae_A11.pdf
http://www.cut-the-knot.org/blue/GeneratingFunctions.shtml
1.355 If lower bound and upper bound of a recurrence relation are not
asymptotically equal, then is it possible for it to have a theta notation? top
gateoverflow.in/6657
Is theta notation possible for all recurrence relation?
No.
See this question from CLRS 3rd edition, page 53 (page 74 if including the cover, index and all)
1.355 can any1 explain how to find maximum flow in graph from source to
sink. pls top gateoverflow.in/7351
http://en.wikipedia.org/wiki/Maximum_flow_problem
1.356 What is the worst case time complexity to find the gcd(m,n) using best
algorithm known? top gateoverflow.in/7693
What is the worst case time complexity to find the gcd(m,n) using best algorithm known?
A. O(log(min(m,n)))
B, O(log(max(m,n)))
algorithms
Check http://mathworld.wolfram.com/EuclideanAlgorithm.html
Lamé showed that the number of steps needed to arrive at the greatest common divisor for two numbers less than n is
1.357 How could you find first occurence in Logn time using a variant of BS?
top gateoverflow.in/9240
I mean i guess it should be in O(n/2) i.e. O(n) time. Because one must check for every element starting from the first one till
n/2 th element & for each of which one must whether A[i]==A[n/2 +i].
Please explain.
this is a node in decision tree. With n-1 such comparisons we can get the max element. Now, the second max element will
be compared to the max element during any one such comparison. So, to find the second largest element, we just need
to save all the elements being compared to "max" and getting the max of them.
a) n- ( lg(n)) - 2
b) n + (lg(n)-2)
Selected Answer
we can start comparing the elements pair wise and build a decision tree in which case it takes n-1 comparisons to obtain the highest element.
In order to get the second highest element we need to check only those elements which were compared with the highest element while building the decision tree, now as the height of
the tree is logn as logn comparisons are required for the highest element to reach the top, so to obtain second highest element one need logn-1 comparisons so all together n-1+logn-
1=n+logn-2 comparisons are required.
1.359 The number of leaf nodes in the recurrence tree of the recurence T(n)
= T(n/4) + T(n/2) + n^2 top gateoverflow.in/15776
Selected Answer
i think exact number of leaf nodes is somewhat hard here. what we can do is can find upper bound and lower bound .
upperbound - the greater function is n/2. so if we draw the tree of the function it will half full . for upperbound consider it
to be fuly filled . and as n/2 is going till the end .
n^0.5
no of nodes will be betwen n^0.5 to n .
Selected Answer
Should be 2^n, every node having two choices either left or right.
Degree of internal nodes should be 2 and degree of leave and root should be 1.
the answer should be none . as both 1 and 2 are true. it doesn't matter the graph is directed or undirected., the minimum
cost spanning tree will not change by adding constants till the weights are kept unique. while dijisktra gives the right
answer if made to run on a graph with no negative cycle. so c is true. 1 and 2 are wrong
1.362 O(klogk) time algorithm to find kth smallest element from a binary
heap... top gateoverflow.in/30524
time complexit..?
Q.3 how to determine if the kth largest element of the heap is greater than x____?
i'm confused where and when to use these two formula, someone explain plz
1.365 How to solve the fractional knapsack problem using heap ? top gateoverflow.in/30649
If I use the values of profit/weight and apply build-Max-heap to these values then I will get a max-heap in order(n) time
,Now the confusion is how to delete-the maximum value since after I delete the maximum value how will I come to know
what is the weight associated and the profit associated with the node stored in the heap since heap stores only the values
associated with profit/weight .
So to perform further calculations like reducing the capacity of the knapsack and adding profit values to already obtained
profit values ,how will I do these calculations ?
merge sort algo takes 30sec for input size of 64 in worst case, then max input size solvabe in 6 minutes?
Selected Answer
1.367 what is "DAC Max-Min algorithm" | ME Basic test algorithms top gateoverflow.in/30787
Selected Answer
DAC max min algo = >U sing Divide and conquer Finding maximum and minimum in a array.
T(n) = 0 if n=1
1 if n=2
2T(n/2) +2 if n>2
1.368 How to solve: Partition(Quick sort) with pivot not in center? top gateoverflow.in/30782
simply make one move in the beginning to swap the 15 to position from where u are comfortable to apply quick sort
algorithm either at middle, first position or last.
Solution for recurrence relation T(n)=T(n/2 + 2)+n using recursion tree method?
1.370 Parameter Passing | GATE 1993 | common data questions 6 marks top
gateoverflow.in/30298
Program PARAM(input,output);
var m,n:integer;
begin
m:=0; P(m,m);write(m);
n=0; Q(n*1,n);write(n)
end;
b)PARAM,P
c)PARAM,Q
d)P,Q
30. Option b, 0, because goobal m is not modified, m is just passed to formal arguments of P.
31. Option e, 0, because n is just passed to formal parameters of Q and no modification in global n.
32. Option a, since m is defined global it is visible inside all the procedures.
1.371 what is the effect of problem size of the complexity of divide and
conquer algorithms and why ? top gateoverflow.in/30187
Considering the partition algorithm in quick-sort , depending on any input sequence it will be called n times only so then
what is the usage of dividing the problem into equal halfs , through recurrence relation formation I am able to figure out that
time complexity is less if we have problem to be divided at each level in equal halfs but I am not getting logic behind this .
algorithms
Q) If the lower bound for the running time of an algorithm to solve a problem L is O(22n ) and L is in NP class. Which of the
claims is/are true?
1). P = NP
2). P! = NP
3). P <= NP
4). L is NP complete
A). only II
Selected Answer
You would need to know some examples (not all) of NP Complete problems and why they are NP Complete. For example 3SAT problem is
NPC and in GATE they have asked about 2SAT. So, just learning some examples won't be enough.
we use huffman encoding to encode a b c with frequency fa fb fc.Which of the following code sequence is not possible?
code 1={0,10,11}
code 2={0,00,1}
code 3={10,00,01}
Code 2 => 0 & 00. Here give 000, we can not distinguish 0 00 and 00 0 and 0 0 0.
Code 3 => Here issue is that this code can not be generated by Huffman algorithm in first place. It is simply not possible.
(Try to take any example you can see you can not generate this. You can generate (00,01,10,11) but not just 3 of those
!)
Huffman coding makes sure that there is no ambiguity when we decode the bit stream code .so the The variable-length
codes assigned to input characters are Prefix Codes, means the codes (bit sequences) are assigned in such a way that the code
assigned to one character is not prefix of code assigned to any other character.
so code 1 which is possible ...this follow the prefix property ... ( no prefix is otherone prefix)..
code 2 which is not possible ... bcoz 00 does not follow the prefix property , 0 is code 00 also contain 0 as
prefix ,
code 3 it follows prefix property but one of them should be only one bit code ....so its not possible..
ref :http://www.geeksforgeeks.org/greedy-algorithms-set-3-huffman-coding/
b is not posiible
http://www.cs.umd.edu/class/fall2012/cmsc132h/Projects/P7/project7.html
For X= BDCABA and Y=ABCBDAB find length of lcs and no of such lcs..(solve it using table method)
BCAB,BCBA,BDAB
https://www.youtube.com/watch?v=P-mMvhfJhu8
Q). Which of the following can we infer from the fact that the travelling salesperson problem is NP-complete.if we assume
that P is not equal to NP ?
A). There does not exist an algorithm that solves arbitrary instances of TSP problem.
B). There does not exist an algorithm that efficiently solves arbitrary instances of the TSP problem.
C). There exists an algorithm that efficiently solves arbitrary instances of the TSP problem , but no one has been able to find
it.
i think b is true. we can solve travelling salesman problem but the complexity is exponential . so can say better algorithm
does not exist
programming algorithms
Selected Answer
From i=1 to n
"if(j<i)" this condition true till only for every j=i-1 times
So, P=0+1+2....+(n-1)=n(n-1)/2
1.376 why does quick-sort work better than merge-sort for small inputs ? top
gateoverflow.in/30097
For smaller inputs quick sort perform better than the merge sort, due to the fact the merge sort is not in place unlike
quick sort. We need more amount of space in case of merge sort.
2. 2n > n√n
3. 2n > n log n
explain plz
Selected Answer
So, 2n > n √n
Here too linear value of n will be greater than logarithmic value of (log n) 2
klogk = Θ(n)
⇒ c1 ⋅ n ≤ klogk ≤ c2 ⋅ n
Now assuming n and k are greater than 1, taking log of each of the terms above will not change the inequality so we can
write,
log(logk) ≤ log(k)
we should multiply (log(c2) + log(n)) by 2, to compensate the increment in the middle term.
To make this inequality more clear let's write it using new constants as follows,
( )( ) ( )( ) ( )( )
c3 log (n )
≤ c4 log (k)
≤ c5 log (n )
.
c1 n 1 c2 n
⇒
( )( ) ( ) ( )( )
c3 log (n )
≤ c4
k≤ c5 log (n )
c1 ⋅c4 n c2 ⋅c4 n
⇒
( )( ) ( )( )
c3 log (n )
≤k≤ c5 log (n )
( )
⇒ k = Θ log (n ) .
Selected Answer
Just to give you an idea about where may be the difference of recurrence relation.Consider two functions A() & B().
A(n) {
if(n<=1) return 1;
else
B(n) {
if(n<=1) return 1;
else
return ( 2*A(n/2) + n );
In this A and B both will return the same value so for getting value for some number n,they will result in same but both
the functions having different time complexity as you can see we are getting separate recurrence relation for time
complexity.
For Function A, we are getting 2*T(n/2) because we are going to call same function 2 time but in function B,we are taking
only T(n/2) because we are calling function only one time after getting the value of T(n/2) we are simply multiplying it by
2.
105. The length of the path from �� to �� in the MST of previous question with �� = 10 is
A. 11 B. 22 C. 27 D. 31
if all edge in the graph have distinct weight the the sortest path between two vertex is unique?/
Maybe not possible if total weight from source to destination vertex is equal for two different routes.
But if you use min priority queue then may be possible that it will give same shortest path always.
consider modifying partitioning procedure of quicksort by randomly picking up three elements from array and computing
their median(middle of 3 elts). Approximate probablility of getting at worst ab a to (1-a) split in the range 0<a<1?
algorithms
Yes you will have to traverse the entire heap in worst case and then delete it, then replace that position with the last
element and then call Build-heap procedure.
probability of a split more balanced than a to (1-a) split in partitioning procedure of quicksort where 0<a<=1/2?
I am using a random variable X to denote the fractional length of smaller partition of the original array with respect to the
length of original array.
Consequently, the fractional length of the larger partition will be (1 − X) with respect to the length of original array.
For example suppose, X = 0.2 then it will indicate that our smaller sub array (among the two sub arrays that we got after
partitioning) is 0.2 time the original array.
and hence the larger sub array is (1 − 0.2) or 0.8 times the original array.
Since X is denoting the fractional length of smaller sub array after partition, its value can not exceed more than 0.5 times
the original array otherwise it will no longer be the smaller sub array.
1 1
( ]
Hence the domain of random variable X is 0, 2 , that is X can take any values between 0 and 2 .
1 1
It can be inferred that as X approaches to 2 , (1 − X) also approaches to 2 , that is the sizes of two sub arrays are being
equal or in other words the partition becomes more balanced.
X = 2 means we have got two sub arrays of equal size,and both of them are 0.5 times the original array, this is the most
desirable situation from the efficiency's point of view.
1
( ]
Now if we want a split more balanced than a ∣ (1 − a) where a ϵ 0, 2 , we have to set our random variable X ′ s value larger
1
than a, so that our random variable is more nearer to 2 , then the a is (as a value nearer to 2 implies a more balanced
partition).
1
So to get a partition more balanced than a ∣ (1 − a), X must lie in the range a, 2 .
( ]
Hence the probability of getting a more balanced split than a ∣ (1 − a) is same as P(X > a),
length of favourable domain of X
( ) 2
−a
⇒ P(X > a) =
( ) 2
−0
It can also be observed that using the above formula when a becomes 2 there is 0 probability of getting a more balanced
split, and when a tends to 0, there is almost full probability of getting a more balanced split.
1.385 finding pair of an element in the array such that diff will be given no. top
gateoverflow.in/31624
what i think the answer should be B as i am using this method in the sorting technique and also in the search approach..
well someone can do it using A so it can be the answer. what i tried is this.
now pic the middle element and subtract from the last one. ( as the difference should be positive , if negative pic the
starting element)
** further i m describing for positive difference. the algorithm can be ,modified for negative as well .
now subtract the mid and last element . if the diffrence we get is more than the difference we need. then we will set mid
as the lower and again calculate the mid , as by moving toward more big numbers only the difference will decrease.
like here
take array
6 4 9 2 1
sort .
1 2 4 6 9 .
picking middle element i.e =4. that is 9-4 = 5. . so as the answer is greter than what we ned then we have to move
toward 9 because then only we can decrease our answer, if i move toward 1 the difference will increase. so in this way i
can use the binary search type method to get . make such n iterations. each time leaving the highest element that has
been examined.
i don't think repeating subproblems are there , and divide and conquer , as used . may be the answer
By definition (as I remember) a right in-threaded tree will have a pointer for the inorder successor for a node with no right
child.
1 D -> B
2 B -> A
3 G -> H
4 J -> E
Since F is the last element in inorder sequence for the tree, there will be NULL pointer in the pointer field for the node.
Consider two vertices a and b that are simultaneously on the FIFO queue at same point during the execution of breadth first
search from s in an undirected graph.
Which of the following is true?
1. The number of edges on the shortest path between s and a is atmost one more than the number of edges on the shortest
path between s and b.
2. The number of edges on the shortest path between s and a is atleast one less than the number of edges on the shortest
path between s and b.
3. There is a path between a and b.
a.1 only
c. 2 only
d. 1, 2 and 3
data-structure
FIFO queue then must be a path between a and b. We can't say surely about the which one have more total
edges then others because in a queue all are unvisited neighbour node of some node.
Upon running quicksort on a subarray with fewer than k elements, it returns without sorting subarray. After top level call to
quicksort returns, insertion sort is run on entire array to finish sorting. Then the sorting algo runs in:
ans is C
I am unable to get the logic behind running bellman-ford for n-1 times , I have already gone through this link , but still
couldn't get it clearly .
http://cs.stackexchange.com/questions/50557/why-do-we-need-to-run-the-bellman-ford-algorithm-for-n-1-times
algorithms
When we run BellmanFord Algorithm on a connected graph what we get as an output is a single source shortest path
graph which is actually a tree. Since a tree has only n-1 edges ,so maximum the path length between a source S and its
destination will be atmost n-1 . What we do in BellmanFord is we relax edges of path length 1 , then in next iteration we
relax edges of path length 2 ......so on till we relax edges of path length n-1 . Therefore the loop runs for n-1 times.
Given two arrays of numbers a1, a2, a3,…an and b1, b2, .. bn where each number is 0 or 1, the fastest algorithm to find the
largest span(i, j) such that ai + ai+1, ….aj = bi , bi+1, .. bj . or report that there is not such span,
(b) Takes O (n3) and Ω (n2.5) time in the key comparison model
(d) Takes O (√n) time only if the sum of the 2n elements is an even number
In a permutation a1…..an of n distinct integers, an inversion is a pair (ai , aj) such that i < j and ai > aj .
What would be the worst case time complexity of the Insertion Sort algorithm, if the inputs are restricted to permutations of
1…..n with at most n inversions? A. Θ (n2 ) B. Θ (n log n) C. Θ (n1.5) D. Θ (n)
Ans is D: ⊝(n),
Insertion sort runs in Θ(n + f(n)) time, where f(n) denotes the number of inversion initially present in the array being sorted.
In a simple connected undirected graph with n nodes(where n≧2), The maximum number of nodes with distinct degrees is
1. n-1
2. n-2
3. n-3
4. 2
By these degree we can draw a simple connected undirected graph (havel hakimi theorem)
so we have n vertices
1.393 Travelling salesman problem vs. Minimum cost spanning tree vs.
Shortest path top gateoverflow.in/30914
Also I was just wondering if there was any relation of TSP to GOOGLE's maps finding shortest distance?
because travelling salesman problem in O(n!) and there is no better solution other than dynamic programming. So do they
use dynamic programming only?
Selected Answer
Selected Answer
What i thought was that, after mapping these elements using chaining, there are 5 slots left.
So any element that comes afterwards will want to be mapped to any of the 11 slots but it has only 5
available. Probability of all the 11 slts are the same since mod function is uniformally distributed.
So the required probability will be 5/11=0.45
what M.E. says: any element will map to 1 of the 5 slots so it will be 1/5=0.2
T(n) = 16T(n/4) + n!
is it correct ?
Selected Answer
Here a = 16 and b = 4 . So n ^ (log16 base 4) , which is n^2 . Comparing it with n! , we will get ans as
O(n!)
But why
Selected Answer
Find the number of bits required for Huffman encoding of the above message:
If Huffman tree coded as left child with ‘0’ and right child with ‘1’ from every node then what is the decoded message for
110100? (a) abc (b) bcd (c) acb (d) bda ans given is d
HUFFMAN :
-First calculating the frequencies of a – 3, d-5, c-6, b-7 for message string that is given.
- Huffman tree is :
11 - right – right = b
01 - left – right = d
but heapsort uses maxheapify procedure which requires extra stack ., then how it is inplace..?
The answer given is true. Heapsort indeed an inplace algorithm but not stable.
certain file system stores records as per binary search tree principles.If the preorder traversal is
90,40,30,190,140,100,290.What is the expected number of comparisons when we randomly request one of the records?
Construct bst from given sequence ..now there will be 1 node at level 0,2 at level 1 ,3 at level 2 and 1 at level 3 no of
expected comparisons=1*1+2*2+3*3+1*4/7=18/7=2.57
assume that A be an array of 16 elements.What is the difference between maximum and minimum number of inversion
pairs in worst case?
Selected Answer
first case . if it is in ascending order no inversion pair. as inversion pair means first elements should be larger and second
should be smaller.
1 2 3 4 5 6 : zero
6 5 4 3 2 1.
now 6 can be taken and combined with any (n-1) elements to pair . similarly 5 with (n-2) elements can make a inversion
pair. so
so here it is 16. so it will be 15+14+13+12....0 which is the sum of first 15 natural number , = 120.
For prim's algorithm array implementation takes O(V^2) while min heap takes O(ElogE)time. For dense graph E = O(v^2)
.....
Does the min heap would run better for graph with less edges..??
So heap implementation is suitable for sparse graph and array for dense graph
Suppose that edge weights are uniformly distributed over half open interval[0,1).Which algorithm krushkal's or prim's can
make you run faster?
In this scenario kruskal's algorithm will run faster than prim's. The time complexity of kruskal's algorithm is
O(E log E) <--(time taken to sort E edges) + (E α(V)) <-- find set and union operations
Given that edge weights are uniformly distributed over half open interval [0,1), we can sort the edge list in O(E) time
using bucket sort (see CLRS Bucket sort).
O(E) + (E α(V))
where α(V) is the inverse ackermann function whose value is less than 5 for any practical input size 'n'. (ref wiki)
so, the running time of kruskal's MST algorithm is linear, where prim's will still work in O((V+E)log V)
Six files F1,F2,F3,F4,F5 and F6 have 100,200,50,80,120,150 records respectively.In what order should they be stored so as
to optimize act.Assume each file is accessed with the same frequency
a)F3,F4,F1,F5,F6,F2
b)F2,F6,F5,F1,F4,F3
c)F1,F2,F3,F4,F5,F6
d)Ordering is immaterial as all files are accessed with the same frequency
F1,F2,F3,F4,F5,F6
12 18 17 11 13 15 16 14
Find the no of elements which will change their position when partitioning algorithm is applied on array .pivot choosen is 15
12 18 17 11 13 15 16 14
First swap the pivot element to first place of array so 15 18 17 11 13 12 16 14
{
x=a[p];
i=p;
for(j=p+1;j<=q;j++)
{
if(x>=a[j])
{
i=i+1;
swap(a[i],a[j]);
}
swap(a[i] ,a[p]);
return 0 ;
}
e.g
x
i j
15 18 17 11 13 12 16 14 condition fails
j
15 18 17 11 13 12 16 14 condition fails
i j
14 11 13 12 15 18 16 17
So 7 element changed their position after the partition algo.
I have an equation Xlog(X) = logN. Can anybody solve for X from this equation?
algorithms
Selected Answer
If you are asking this for the purpose of GATE, you have to find the (approximate) numerical value of x for a given N by
hit and trial.
You can use bisection method to quickly approach the answer (or other faster converging methods if you like).
f(x) = xx − N
Bisection Method:
Find points xlow and xhigh such that f(xlow) < 0 and f(xhigh) > 0
Repeat:
xhigh − xlow
xmid = xlow + 2
if f(xmid ) is sufficiently close to 0, exit the loop.
If f(xmid ) > 0, then xhigh = xmid
Else if f(xmid ) < 0, then xlow = xmid
We get a satisfactory answer after 8 iterations. This calculation can be easily done with a calculator within 2 minutes.
Newton Raphson:
f ′ (x) = xx(1 + logx)
f(xn )
f ′ (xn )
xn +1 = xn −
xxnn − N
xxn(1 + logxn )
= xn − n
We need to make an initial guess which is sufficiently close to the answer, else the algorithm won't converge.
We guess x = 5
The above methods are the easy ways of finding the solution.
If the value of N is nice, for example, N = 46, 656, hit and trial will only take a few steps and can be done mentally to get
x = 6.
You shouldn't be looking for formulas for x in terms of N, because your equation won't have a pretty formula.
algorithms
Selected Answer
We can find both maximum & minimum in using less than 2 ⋅ n − 2 comparisons.
Superficially, if you are doing (n - 1) comparisons to find maximum of n elements, then minimum can be found by
comparing between those numbers who lost in their first comparison.
"It is not difficult to devise an algorithm that can find both the minimum and
the maximum of n elements using Θ(n) comparisons, which is asymptotically
optimal.Simply find the minimum and maximum independently, using n − 1
comparisons for each, for a total of 2n − 2 comparisons.
In fact, at most 3 * Floor(n/2) comparisons are sufficient to find both the
minimum and the maximum. The strategy is to maintain the minimum and
maximum elements seen thus far. Rather than processing each element of the
input by comparing it against the current minimum and maximum, at a cost of
2 comparisons per element,we process elements in pairs. We compare pairs of
elements from the input first with each other, and then we compare the smaller
to the current minimum and the larger to the current maximum, at a cost of 3
comparisons for every 2 elements.
Setting up initial values for the current minimum and maximum depends
on whether n is odd or even. If n is odd, we set both the minimum and
maximum to the value of the first element, and then we process the rest of the
elements in pairs. If n is even, we perform 1 comparison on the first 2
elements to determine
the initial values of the minimum and maximum, and then process the rest of
the elements in pairs as in the case for odd n.
- Introduction to Algorithms(CLRS),
3rd Edition,Page No 184 - 185
3 ⋅ 2 − 1 comparisons will be sufficient without odd, even concern, for finding both maximum & minimum out of n numbers.
A hash table of size 10, is shown in the figure with symbols stored from a to g using some hash function with linear probing.
The worst case number of comparisons required when the symbol being searched is not in the table is?
so 3+1=4
answer is 4.cause.as it is given worst case scenario..so hash function will look for the element in the biggest cluster
available in the table..In this case,there is two case, 1.a,b,c and 2.e,f,g. In both case it will search for element,so,for 3
elements 3 comparison and one more cause it will also compare with just next available blank space in the table in both
cases.so total 4 comparison.
http://gateoverflow.in/?qa=blob&qa_blobid=11412484315430083479
What does find max subarray rwturn when all elements of array are negative?
When we implement max subarray problem. We just include maximum and minimum values a machine can have.
It depends on implementation.
What is K -way merge sort.... !!!!! i m very confused....if we say 2-way merge sort..does it mean dividing array into 2 parts
or dividing array in size of 2!!!!
Straight 2 way merge sort means take 2-set for each pass and merge sort them.
e.g. 94 27 14 17 5 2 pass 3 2 5 14 17 27 94
pass 2 14 17 27 94 2 5
94 27 14 17 5 2
1.413 what is the divide and conquer recurrence that would arise for the
problem top gateoverflow.in/16209
suppose you are given n bit integers asuming for common sense n as power of 2 .it is required to multiply them using divide
and conquer method .what is the divide and conquer recurrence that would arise for the problem
a) T(n)=4T(n/2)+c
b) a) T(n)=2T(n/2)+n
c) a) T(n)=4T(n/2)+n2
d) a) T(n)=4T(n)+n
B= 2^n/2Bmsb+Blsb
Amsb is the n/2 most significant bit of A ie n/2 leftmost bit of the no.
Alsb is the n/2 least significant bit of A ie is n/2 rightmost bit of the no.
so A*B=(2^n/2Amsb + Alsb )( 2^n/2Bmsb + Blsb ) = 2^n*A msb*Bmsb + 2^n/2(Amsb * Blsb + Alsb *Bmsb ) +
Alsb Blsb
this equation says that mul of 2 n bit no can be carried out using mul of 4 n/2 digit no +some shift operatin
ans;-theta(n)
Since,the above recurrence is homogenous linear recurrence relation of degree 3.So,we can solve these kind
of problem by a formal way...
r^3 = -1+r+r^2
so,r= -1,+1,+1
note:- u can calculate the value of the constatnts a,b,c by using the initial condition .
Ans is C
1.416 if this problem is solved using divide and conquer method ,then the
algorithm run in top gateoverflow.in/16210
given a sorted array of distinct integers A[1........n], you want to find out whether there is an index i for which A[i]=i.if this
problem is solved using divide and conquer method ,then the algorithm run in
algorithms
Selected Answer
Ans- 0(logn)
Algorithm
int mid;
if(l<r)
mid=l+(r-l)/2;
else return(a,mid+1,r)
1.417 How many comparisons are needed to sort an array of length 5 gateoverflow.in/17268
top
How many comparisons are needed to sort an array of length 5 if a straight selection sort is used and array is already in the
opposite order?
a)1
b)10
c)15
d)20
b) 10
each cell denote the total number of comparison performed to select the element to be placed in that cell.
4 3 2 1 0
if any element is present more than n/2 times in the array then that element is called majority element.The best way to
implement this is through a BST.Node of the Binary Search Tree: struct tree { int element; int count; }BST; Insert
elements in BST one by one and if an element is already present then increment the count of the node. At any stage, if
count of a node becomes more than n/2 then return. ref:http://www.geeksforgeeks.org/majority-element/
Just one query n! would be a constant rght , so in F1 we are taking factorial of a constant while in second one we are taking log of a constant so definitely F2 should be less than F1 .Am I
correct or wrong at this point ?
let logn=x
F1=x!
F2=nx
F3=x^x
now F2<F1<F3
.f(n)=O(f.(n)2)
.if f(n)=Og(n)
then 2 f(n)=O(2g(n))
.lognlogn>2logn>nlogn
Selected Answer
option c is correct
a) FALSE Since it is true for increasing function but false for decreasing function
b) FALSE let f(n) = 2n and g(n) = n then 2 2n= O(2n) which is false
c)TRUE Since exponential in bigger than polynomial therefore nk=O(2n) is true not the reverse so given statement is true
d) FALSE logn is a decreasing function put the value for n and check n^logn will be biggest among all but its given reverse
Let f(n) = Ω(n), g(n) = O(n) and h(n) = θ(n). Then [f(n) ⋅ g(n)] + h(n) is _______.
f(n) = Ω(n)
f(n) >=c. n
g(n) = O(n)
g(n) <= c1.n
h(n) = Θ(n)
h(n) = n.
So [f(n) . g(n)] + h(n)
lets take all f(n) g(n) h(n) be n
[n ⋅ n] + n
= Θn^2 + Θn = Ω(n)
Since upper bound depends f(n) value if it is n^4 then O(n^4).
A polynomial p(x) is such that p(0)=5 ,p(1)=4 ,p(2)=9 and p(3)=20 The minimum degree it can have is..
The degree can't be 0 since that will give us a constant polynomial, but we have 4 different points to satisfy.
p (1 ) −p (0 ) p (2 ) −p (1 )
1 −0 2 −1
The points that we need to satisfy aren't co-linear either. For example, = −1 ≠ 5=
a ⋅ 02 + b ⋅ 0 + c = 5
c=5
p(x) = ax2 + bx + 5
\begin{align}
a\cdot 1^2 + b\cdot 1 + 5 &= 4\\[1em]
a + b &= -1\tag{1}\label{1}
\end{align}
\begin{align}
a\cdot 2^2 + b\cdot 2 + 5 &= 9\\[1em]
4a + 2b &= 4\\[1em]
2a + b &= 2\tag{2}\label{2}
\end{align}
+( 2a + b =2 )
−( a+b = −1 )
a =3
b = −4
Testing it on our final point, we have that p(3) = 3 ⋅ 32 − 4 ⋅ 3 + 5 = 27 − 12 + 5 = 20, which is equal to the given value of p(3).
n
∑
i =0 i3 =X
1.Θ(n4 )
2.Θ(n5 )
3. O(n5 )
4.Ω(n3 )
possible values of X
=theta(n 4)
double foo(int n)
{
int i;
double sum;
if(n == 0)
{
return 1.0;
}
else
{
sum = 0.0;
for(i = 0; i < n; i++)
{
sum += foo(i);
}
return sum;
}
If n ≤ 0, the function takes Θ(1) time, because it just declares some variables, does a fixed number of logical comparisons
and then returns a value.
Thus, the recurrence for the time complexity can be given by:
{
Θ(1) if n ≤ 0
T(n) = n −1
∑
Θ(n) + i =0 T(i) if n > 0
Consider an array with the following elements 12,18,17,11,13,15,16, and 14 .how many elements will change their initial
position after completion of partition algorithm by choosing 15 as pivot.
Now 12 as pivot 11 will change its position........... here 1 element change position
11,12,13,14,15,17,16,18
Now 17 as pivot 16 will change its position.............. here 1 element change its position
hi all ,
Please tell me how much does dijkastra algoritm would take for unwaited and martix implementation
explain it
Answer will be 3
p(x)=a0+x(a1+x(a2+a3(x)))
S1: Dijkstra’s algorithm is not affected by negative edge weight cycles in the graph and gives correct shortest path.
S2: Bellman ford algorithm finds all negative edge weight cycles present in the graph.
a) Only S2
b) Only S1
c) Both S1 and S2
Ans) D how ?
algorithms
Selected Answer
Dijkstra’s algorithm is not affected by negative edge weight cycles in the graph and gives correct shortest path. = false
Reason : Dijkstra’s algorithm works correct when their negative edge weight bit when negative edge weight cycles in the
graph present then it gives incorrect MCST.. b/c do one time decrese key on one edge but we need to do n-1 time .
Bellman ford algorithm finds all negative edge weight cycles present in the graph. = false
one thing missing .. if and only if negative edge weight cycles reachable from source.
this does not satisfy the generic form of master method. It is close to the case of Master Method, where :
but fails so do other cases too. So, one of the method to do this is Akra–Bazzi Method.
here,
we need to choose p such that ∑ki=1 aibpi = 1
1
64 8 ()
p
| |
= 1satisfies for p = 2 and also, g ′ (x) ≤ xc for some c ∈ R
so,
( )
u2 log u
x p +1
T(x) = Θ xp + xp ∫ 1 u du
u2 logu
(
= Θ x2 − x2 ∫ 1
x u3 du
)
(
= Θ x2 − x2 ∫ 0
log x
t dt )
x2
=Θ
( x2 − 2 {logx}2
)
x2 1
(
= Θ x + logx . log x
2 2
)
x2 1
=Θ
( 2 x
log logx
)
n2 1
T(n) = Θ
( 2 log n logn
)
0 votes -- Amar Vashishth ( 17865 points)
is ans is a ?
given d
Selected Answer
ans is D )
x-=(y+1)
Selected Answer
DEADLINE 1 2 3 4 5 6 7 8
JOB J3 J7 J4 J5 J6 J1 J2 J8
PROFIT 15 29 17 16 24 21 0 0
2.Replace element with last element and decrese heap size by 1 = O(1)
is it correct ?
A hash table can store max of 10 records,currently there are records in locatio 1,3,4,7,8,9,10. The probability of a new
record going into location 2,with a hash function resolving collisions by linear probing is..
ASSUMING that "the hash function is fair & uniformly distributes the universe of keys to all the 10 locations",
Due to uniform distribution, the probability that the new record will be placed to any location i will be same for any
1
10
i ϵ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) & will be equal to .
Now if the hash function will try to place the new record in to any of the locations 1, 7, 8, 9, 10, the record will be redirected
to location 2 due to collision resolution by linear probing.
And if hash function will try to place the new record into 2, since location 2 is available, the record will go to location 2.
So The probability of going new record into location 2, will be same as probability that the output of hash function is any
one of (1, 2, 7, 8, 9, 10) out of (1, 2, 3, 4, 5, 6, 7, , 8, 9, 10), where each location is equally likely.
6
10
So the chances will be .
=1 otherwise
= T(n-(n-1)) + n − (n −2 ) + n − (n −3 ) + ............+ n −2 + n −1 + n
1 1 1 1
= T(1) + 2 + 3 + 3 ..........+ n
its Harmonic Series
T(n) = O(logn)
When s be a sorted array of n integers , and t(n) s the time taken for the most efficient algorithm to determine if there are 2
elements with sum less than 1000 in s, then which of the following statements is true?
t(n) is O(1)
n<=t(n)<= n logn
n logn<= t(n) <(n/2)
t(n) =(n/2)
Since S is a sorted array the smallest two elements will be at the endpoints of the array.
Also if the sum of two smallest elements is less then 1000 we can say "yes there are two elements in the array whose sum
is less than 1000".
In case their sum is greater than or equal to 1000, we can say "No" because rest all the numbers in the array must be
equal to or greater than the larger number among the two smallest numbers.
But since in the sorted array the smallest element might be at position S[0] or at S[n - 1], we should check the location of
smallest number first.
Checksum(S, n)
If (S[0] <= S[n - 1] ) //To check the position of the smallest number in Array S.
Else
Consider a hashing function that resolves collision by quadratic probing. Assume the address space is indexed from 1 to 8.If
a collision occurs at position 4, then the location which will never be probed is..
Locations are 1 to 8.
A machine took 200 sec to sort 200 names using bubble sort. In 800 sec, it can approximately sort..
Another way
=19900 comparison
n(n-1)/2=800 sec
so n(n-1)/2=79600
n=400 apx
To Find solution these kind of quetion u have to know What is the time complexity of given algorithm
Now take quetion If he say how many time to sort 800 names.
now simple math apply inplace of 40000/200 = 200 it take 200 sec
= 160000= O(n 2)
u get n= 400
Is there is any relation between bipartite graph, complete bipartite and planar graph?
graph-theory
bipartite graph, and complete bipartite graph but can not contain a cycle of odd length. that's all i know, planer is not in
syllabus i think
If f(x)=square(x)
then f(x-1)=square(x-1).
Similarly,
T(n)=2*T(n-1)+n
= 2^2*T(n-2) +2*(n-1) + n
when n=i+1,
1.442 What are the time complexities of following operatons ? Justify gateoverflow.in/31869
top
Q1) Conversion from Tree to Heap (max heap and min heap)
Q2) Conversion from Max Heap to Binary Search Tree
( NB:Please justify your answer so that one who reads could understand the concepts behind
including me :p )
isro arrays
top
B]Good by
D]None of these
programming-in-c algorithms
Selected Answer
comparison operator associativity is left to right ...SO Y will be associated with LEFT first
qu num 43nd 44
We got 13 tokens
printf
"string"
++
& &
12 tokens
My answer is
Given explanation
compiler-design compiler-tokenization
My Answer is
F--T=> ,baa
T---E =>,black
F--T=> ,baa
E+T ---E=>,sheep
compiler-tokenization compiler-design
4.4 Derivation Tree: Nodes in a derivation tree for grammar in CNF top gateoverflow.in/36558
Number of nodes in the derivation tree when a word of length 2k is derived from a grammar in CNF?
A. 2k+1 − 1
B. 3.2k+1 − 1
C. 2k+1 + 1
D. 2k+1 + 1
Selected Answer
1. A → BC
2. A → d (d is a terminal).
We are given a word of length 2k meaning we reached 2k terminals during parsing. If we consider the start symbol as root,
the parse tree will be a strict binary tree (need not be a complete binary tree, a strict binary tree is a binary tree where
every non-leaf node has two children). So, our problem now reduces to the number of nodes in a strictly binary tree with
2k leaf nodes.
If you know the property of strict binary tree answer is 2k+1 − 1. Otherwise we can see the binary tree as a graph with n
nodes and n − 1 edges. We have 2k nodes of degree 1 (leaf nods), a root node of degree 2 and n − 2k nodes of degree 3. So,
sum of degrees = 2k + 2 + 3.(n − 2k − 1).
So,
Ref: http://web-ext.u-aizu.ac.jp/~hamada/AF/Compact-L5-Final-2.pdf
I want to know which grammars are used while various phases of compiler . like we use the regular languages for
verification of tokens, and this the question why i want to know it . plz verify the question and answer given is B . and plz
explain all the grammars used in various phases .
compiler-design grammar
Selected Answer
DCFL - Parsing
CSL - Semantics
compiler-design grammar
Selected Answer
grammar is LR(0). there is no conflict. so SLR(1) , LR(1).None of the options matches except d.
Given answer: D
Solution to this problems says that the grammar is same as dangling else problem. Please explain me how.
compiler-design grammar
4.8 Grammar: the next three questions are based on the following grammar:
top gateoverflow.in/18640
E-->E/X | X
T--> T + F | F
F-->(E) | T
my doubt is how can we decide left or right associativity and another doubt was how can we decide precedence of the
operator...i got confusion
grammar
Selected Answer
Coming to precedence operators at lowe level in tree have higher precedence so + has higher precedence with respect to
* and - .- and * have equal precedence precedence of / is least
S → CCC → cC | d
theory-of-computation grammar
Which is true?
c) Both a & b
d) None
Doubt: RDP and LL(1) can go in loop if it is not left-factorized and contains left recursion. But as for constructing these
parsers themselves require unambiguous, left-factorized and left-rec. free grammer. So, how can it go to infinite loop.
Answer given was (c).
Seems they are testing verbal ability by putting the word 'may'. Yes it may go in infinite loop if the grammer is having a
left recursion.
compiler-design intermediate-code
Selected Answer
t1=-c
t2=b*t1
t3=a+t2
a=t3
so we get a=a+b*-c
so option c
During code generation, we need to do register allocation (kind of machine dependent stuff). So, I think it must be the part
of Synthesis phase?
compiler-design intermediate-code
Selected Answer
intermediate code generation is part of analysis phase...target code generation is part of synthesis phase
Code A is correct as per explanation given in question. 2 JMP instructions in statements 2 and 4 are exactly as they should
be for the given code.
Given solution:
Selected Answer
We may a have a confusion of slecting && a single token or & as 2 diff token
The concept that come "MAximal match ".If you have + and may with one look ahead you have encountered ++ then in
that case you will take maximal one . ie ++ so it would be considered ++ as token under relational operator token class
similarly a & is address operator and && is a logical so you take max of both of them so its &&
Now but in case of *** you cant have "all" of them as a single token . or we dont have any opearator (***) -we are
extending the indirection property .There is no such token class , Infact each of * will come under one token class . SO all
3 in one token class
++
&&
( count as 1 token
,count as 1 token
a count as 1 token
) count as 1 token
; count as 1 token so
A context free grammar can be used to model the lexical concerns of a HLL. This is not normally done and a regular
grammar is used for the structure of lexemes because
(A) The cfg will blow up unnecessarily
(B) The structure of lexemes can be described by the simpler regular grammar
(C) There is a separation of concerns which controls complexity.
(D) All of the above
compiler-design lexical-analysis
A) yes it is true , as we know regular languages are implemented by finite automata which is more efficient to implement
than context free languages implementation (using push down automata which is used stack ) .
Given answer: D
Please explain
compiler-design lexical-analysis
Regular expressions, Finite Automata and NFA with e-moves have the same power of lexical analyser. See the
equivalance of automata and regular expressions in ullman text.But grammars have higher power than the previous 2
models.Hence D.
as far as i think, it will pass the lexical phase.. it should b syntax error.. correct ??
compiler-design lexical-analysis
There is a specific rule in "integer constant creation" that you can not have a blank space between a number.
In the above line after 5th 1, "1 1", cause an error. because compiler consider it one single integer constant token, which
have a blank space between it.
Yes , this error will be generated at the time of syntax analyzer . you cant make a parse tree for this
A variable X has been assigned fresh values in statements numbered 6, 9 and 12 in a 25- statement program which does not have any jump instructions.This variable is used
in statements numbered 7, 8, 10, 16 and 17.the statement range where the register, used by the variable X, could be assigned to some other variable are-
live-variable
After the last use of a variable and next assignment, there is no use to preserve the variable. So, option B is the answer.
compiler-design ll1
Selected Answer
Ans) A.
4.20 Ll1: Give LL(1) parsing table. I/P ="ab*" top gateoverflow.in/36590
S → (S)S | ∊
How many conflicts occur in LR (0) parser for the above grammar?
compiler-design lr-parser
Ques:- Check whether the following grammar is clr(1) grammar or not or lalr grammar or not.
S -> (S)
S -> a
Problem-
The work( for checking the given grammar is LR(1) or not) done by me as shown in figure....is it right approach for LR(1)?
compiler-design lr-parser
By merging the common productions state but various input symbols We get the table. From this we will tell is it LALR(1)
or not. From the productions we merge the states I2 and I 5 then we get
I25:- goto(Io, ()
S->(.S), $/)
S->.(S), )
S->.a,)
Well I made the DFA but i didn't find any conflicts in any state...So the answer should be option d.
4.24 Marks: What could be the revised weightage per subject in GATE 2016
CS? top gateoverflow.in/33602
As some of the subjects are removed, is there any chance of compiler design getting more weightage?
or
Are they going to distribute those marks among all other subjects?
You'll need to wait for GATE 2016 paper for revised weightage
http://www.gatecse.in/mark-distribution-in-gate-cse/
** Although I think, I should not count it as a terminal because we do not put $ in the terminal set of CFG.
$ is also marker to identify that parsing of string has been successfully completed.
}
number of terminal=2;
follow of S will be{ ), hence included as terminal
4.26 Parsing: What happens if LALR(1) machine is constructed for the below
grammer ? Justify Each Option top gateoverflow.in/27388
Grammar
S → S1
S1 → S1 = S1 | a
parsing compiler-design
GIVEN GRAMMAR IS OPERATOR PRECEDENCE GRAMMAR,SO WE CAN CONSTRUCT THE PARSING TABLE,EVEN THOUGH IT
IS AMBIGUOUS
The Grammar E → EE | a is
1. LR(1)
2. SLR(1)
3. LR(0)
4. None
parsing theory-of-computation
4.28 Parsing: Find out the number of rightmost derivations top gateoverflow.in/20130
parsing
Selected Answer
Yeah, for sure there will be exactly two right most derivations of the sentence "a + a" from the given grammar. You are
right.
PS. Is it true for general case that LR(k) => LL(k +1)
parsing
no not necessary...
S → XYc
X → Yb | a
Y → c | ϵ
1. SLR(1)
2. Not SLR(1)
3. LR(1)
4. LALR(1)
Someone please explain me it with state diagram . I'm confused with ϵ in the I 0 Closure
parsing
At level I 0
y-> epsilon will be reduced production and with lookahead b and there will be shift production y->c with look ahead b .
so there is SR conflict .
so option B is correct .
4.31 Parsing: Given a left recursive grammar. Whether LL(1) or not? gateoverflow.in/20508
top
Do we directly say it is not LL(1) because it is left recursive or do we eliminate the left recursion, create the parsing table and
then make a decision.
parsing compiler-design
Selected Answer
Yes, you can directly say that left recursive grammar is not LL(1) .But after eliminating the Left recursion also, there is no
100% surity that it will become LL(1).
Which of the following productions eliminate left recursion in the productions given below:
S → Aa ∣ b
S → Ac ∣ Sd ∣ ϵ
A. S → Aa ∣ b, A → bdA ′ , A ′ → A ′ c ∣ A ′ ba ∣ A ∣ ϵ
B. S → Aa ∣ b, A → A ′ ∣ bdA ′ , A ′ → cA ′ ∣ adA ′ ∣ ϵ
C. S → Aa ∣ b, A → A ′ c ∣ A ′ d, A ′ → bdA ′ ∣ cA ∣ ϵ
D. S → Aa ∣ b, A → cA ′ ∣ adA ′ ∣ bdA ′ , A ′ → A ∣ ϵ
It should be
S-->Aa/d
and
S → AaAb ∣ BbBa
A→ϵ
B→ϵ
parsing
Selected Answer
http://cs.stackexchange.com/questions/6768/how-is-this-grammar-ll1
First(S)={a,b}
First(A)=First(B)={∈}
Follow(A)=Follow(B)={a,b}
LL1 Table
a b $
S S->AaAb S->Baba
A A->∈ A->∈
B B->∈ B->∈
A. Bottom up parsing.
B. Top down parsing.
C. Recursive parsing.
D. Predictive parsing.
isro2013 parsing
Selected Answer
1) Recursive
2) Predictive
4.35 Parsing: Verifying Shift-Reduce conflicts in this SLR grammer top gateoverflow.in/33960
S -> BB
B -> aB | bB | a | b
How many SLR conflicts will occur when we try make parsing table for it.
a) 0 b) 1 c) 2 d) None of these
----------------------------------------------------------------
Doubt: Do we count 2 SR conflicts for the same state as 2 separate conflicts. I mean to say that 'SR conflicts in parse table
and SR conflicts in states can vary?' i.e, Suppose, as in one cell of parse table if we have 3 productions [ B -> a. ; B -> .a
; B -> .aB ] Then as you can see there are 2 SR conflicts in 1 state. So, do we count it as 1 conflict or 2 conflicts.
So, in the above parse table for given grammer (in Qstn). As you can see, there is such a situation in I3 (left-bottom) and in
I4 (right-bottom). So, how many SR conflicts are there 2 or 4 ??
compiler-design parsing
Selected Answer
My Answer is
We have 2 SR conflicts
i.e at I3 we have both final and non final items
such as B->a. and all other productions
so we get both shift and reduce under a (since follow of B is a,b)--its 1 conflict
and (same as I3 we have conflict at I4 ) -- 2nd conflict
parsing
Given solution:
After reducing two 1's of expression to E, E*E should be reduced not the 3rd 1. So final output will be 112*311+2 instead of
the given output. Please check.
compiler-design parsing
Consider the SLR(1) and LALR(1) parsing tables for a context free grammar. Which of the following statements is/are true?
main()
int gate,exam;
gate=exam=10.3;
printf("%c",gate);
Lexical
Syntax
Semantic
None of these
programming-in-c compiler-design
1. ->
2. int *ptr = &x;
3. ++a
4. >=
5. !=
6. x += 10;
from my experience only, I'm able to identify what are considered as tokens are and what not. I want a reliable reference to know what all
tokens are there in C. Does a token depends on what compiler is in use?
programming-in-c compiler-design
1. -> token = 1
2. int *ptr = &x; token = 7
3. ++a token = 2
4. >= token = 1
5. != token = 1
6. x += 10; token= 3
register-allocation
If you'll use a good compiler then it'll find that both expressions can be evaluated as compile time since operands are
constants. So there is not any need of executing any expression at runtime.
But if constant propagation optimization is restricted, then it can be evaluated with the help of two registers.
d= a+b;
c= e+d;
R1 <- R1 + R2 //before execution R1 contains value of variable d and R2 contains variable e, result will be in register R1
Could someone explain me register allocation algorithm in simple manner . I referred some text books but couldn't
understand properly . Please help me
register-allocation
OR
For Every Regular Language there exist atleast one LL(1) Grammar . True /False
Selected Answer
programming-in-c scope
static scoping will print 3,7 (as here static scoping printing local to the scope)
dynamic scoping will print 3,7 (it will be like call by reference)
Attributes calculated from children are synthesized, while attributes calculated from parents and/or siblings is inherited. And
S-attributed are purely synthesized, while L-attributed are synthesized+inherited, is this right?
compiler-design sdd
Selected Answer
Answer is D.
In L-attribute grammar we can have both synthesized as well as inherited attributes, but the inherited attributes must
come from left side (not from right side) only. Here, Ri = Ti, Fi = Ri, Ei = Fi violate this making this not L-attributed grammar,
shift parser
Answer is c
It suffer from both . infact all the Bottom up parser can suffer from both these conflicts !
4.47 Shift Reduce: When to shift and when to reduce? top gateoverflow.in/38017
3. Why are we not reducing E-->E+E, instead we are shifting. But incase of E-->id, we are reducing.
when you can not derive any precedence out of the gramaar rules, use the general precedence of operators.
now if you know how the above algorithm works you will certainly know why i) has not been reduced and ii) also not
reduced
4.48 Syntax Directed Translation: SDT output expression evaluation top gateoverflow.in/36664
Assume a shift reduce parser. The output is treated as an arithmetic expression in C & evaluated. The input is 1 ∗ 1 + 1.
4.49 Syntax Directed Translation: For the below SDT, what will be the output
for the input string aaacb ??? top gateoverflow.in/31782
For the below SDT, what will be the output for the input string aaacb?
S → aAa {print "0"}
S → b {print "1"}
A → Sc {print "2"}
How to approach as S→ aAa then how we will get the string aaacb .
syntax-directed-translation compiler-design
The above grammar and the semantic rules are fed to a yacc tool (which is an LALR(1) parser generator) for parsing and
evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar?
-----------------------------------------
I have little confusion in drawing the states for such recursive grammers. And what does it mean to resolve a conflict in
favour of something???? (It will be very helpful if you also attact pic of state diagram along with the answer) Thnx
Selected Answer
4.51 Syntax Directed Translation: Tracing sdt for output top gateoverflow.in/35420
E1 → E out( ∗ 2)
E → + T out( ′ 1 ′ )
E → T out(10 ∗ )
E → T ∗ F out( ′ ∗ ′ )
T → F out( ′ 100 + ′ )
The input is 1 + 1 ∗ 1 and the output generated is evaluated as an arithmetic expression . The value obtained is
_____________.
Ans =2200
I am not getting the answer, plz help. [SDT tracing by default is left-recursive, right??]
4.52 Syntax Directed Translation: Test Series: Compiler: SDT top gateoverflow.in/31459
What is the output of the expression “10 + 4 ∗ 6”?
a. 29
b. 32
c. 30
d. 28
I Calculated I got 34 so I selected nearest answer 32. But the given answer is 30.
compiler-design syntax-directed-translation
10+4*6
10+24
34
4.53 Syntax Directed Translation: Consider the following SDT. A → BC *(I) B.i
= f(A.i) (II) B.i = f(A.S) (III) A.S = f(B.s) top gateoverflow.in/16165
A → BC *
compiler-design syntax-directed-translation
ans:(b) II only
A->BC*
as L attributed sdd can contain both left inherited and synthesized attributes
(II) B.i = f(A.S) inherited attribute i is dependent on synthesized attribute s of A so its not a valid L Attributed sdd rule
//ur at B and want to calculate B.i but its dependent on A.s which will be calculated once u finish B and move up in syntax tree, so its a
cycle.
also a syntax-directed definition is Lattributed if each inherited attribute of Xj on the right side of A → X 1 X2 … Xn depends only on
reference:https://www.cs.fsu.edu/~engelen/courses/COP562107/Ch5a.pdf
4.54 Syntax Directed Translation: Consider the SDT , where S ->TR, R->
+TR|empty {print ("+")} , And T-> num {print(num)} And if the input is
given "9+5+2" What is output ? top gateoverflow.in/9019
Consider the SDT , where S ->TR, R-> +TR|empty {print ("+")} , And T-> num {print(num)} And if the input is given
"9+5+2" What is output ?
compiler-design syntax-directed-translation
Selected Answer
Input 952++
S-> TR
Answer is 95+2+
See this -
4.55 Target Code Generation: Links to study Data flow analysis and register
allocation using graph coloring. top gateoverflow.in/25137
All the links that I could find on the web were too long. Kindly refer a video or a web link that you may find easier to grasp
from?
compiler-design target-code-generation
Here n = > 2 k
is my ans correct !
Selected Answer
1) Every regular grammar may or may not be LL1. Regular grammar can be left linear or right linear grammar and though
righ linear grammar is guaranteed to be recursion free as well as factoring free, left linear grammar allows both and such
a grammar cannot be parsed by LL1 parser. So it is false. (Even not all right linear grammars can be parsed by LL(1)- see
part 3)
3) Ambiguity can even come from inherent property of language. So it need not be true always. counter eg :
s--> iEts/iEtses/a
s-->b
s--> iEtss'/a
s'---> E/es
E--->b after removing left factoring we still come with ambiguity ..so this is true
1) if it is ambiguous and right linear then also it will not be parsed by LL1 ..becoz LL1 does not parse ambiguous and left
recursive grammer
3) if language is not inherently ambiguous after then it could be ambiguous ..bcoz inherently ambiguous property says for
given grammar , every language derived from it will be ambiguous .. while without this property , may also ambiguous ...
bcoz ambiguous means for same language or string we have 2 or more parse tree structure .. so if there is single
language from given grammar , for which we have more than 1 parse tree then it will be ambiguous.
check whether the following grammer is ll(1) grammar or not and also find the table entry of [A,a].
S ->A,
A->aB/Ab,
B->bBC/d,
C->d
compiler-design top-parsing
Selected Answer
It is not LL(1). For a grammar to be LL(1), it should be unambiguous, should be deterministic and should not have left
recursion.
First(B)={b}⋂{d}=∅
First(C)={d}
for First(A) it will be not LL(1), because for LL(1) there First(A) should be NULL
What does it print if the language uses dynamic scoping with deep binding?
A. 2
B. 3
C. 4
D. 5
Deep binding binds the environment at the time the procedure is passed as an argument.
So using Dynamic scoping with deep acess it wil find global variable x and update x to 4 .
While Shallow binding binds the environment at the time the procedure is actually called.
Shallow binding just traverses up until it finds the nearest variable that corresponds to the name so the answer would be 2+3=5
4.61 ugc net paper 2 computer science code 87 must tell me top gateoverflow.in/11840
http://ugcnetonline.in/question_papers_december2012.php
Q18 how to find precedence the operator wch is near to leaf having hightest precedense but here how to implement ? must
reply
Q49 ans shd both na B & D bcz NAND & NOR both commutative but not associtave ..
Q18 yes which is near the leaf gets the highest precedence .
Precedence in a grammar is enforced by making sure that a production rule with higher precedence operator will never produce an expression with operator with lower
precedence.
In the given grammar ‘-’ has higher precedence than ‘*’
Q49 yes you are right . NAND & NOR both commutative but not associtave
q. 23 : can anyone explain why both statements are false? I thought option B is correct?
Isn't same true with ll(k)? Try constructing dfa for k>=5.
4.63 Why is left recursion not a problem for bottom up parsers? top gateoverflow.in/13282
I know the parsing logic of bottom up parsers, that they start from the terminal and reduce it to the start symbol. But what
really confuses me is the construction of LR(0)/LR(1) sets :
Eg : S->Sa|a
S'->.S
S->.Sa
S->.a
Now the dot is in front of S , so shouldn't the S production be generated again and again and make it go to an inf. loop?
The main reason why Bottom up parser doesnt have any problem with Left recursive is that it start building tree from
leaves . After seeing through a input you will check the next lookahead , if that lookahead lies in follow of a NT then you
will reduce and if not then shift .So by any mean you are not doing that recursive work Hence it doesnt have problem with
Left recursive .
s->Saa
s-->Saaa
and so on
you may run to infinite ( or to precise till stack doesnt get full )
http://gateoverflow.in/?qa=blob&qa_blobid=6419625116648850773
compiler-design
Selected Answer
Live variable means those which will be used again- not necessarily by same block.
int a = 5;
if(a < b)
{
b = 7;
}
c = a;
Here the statements inside the if are in a separate basic block and a is live there because a is used again though in a
different block. Compiler use live variable analysis to see for which all variables it can free the registers.
4.65 To allow only one process in the critical section, value of a binary
semaphore is initialized to __? top gateoverflow.in/7708
operating-system
Doubt : L attributed has both types, synthesized as well as left inherited grrammer. So in L attributed grammer how will be
left inherited attributes be evaluated (which need preorder traversal)?
compiler-design
Could someone please help me check the conflicts in LALR parser. I never understand the difference between these CLR and
LALR. and because of this i even forget the SLR parser. please if someone can explain it easily?
in clr we have to find lr(1) items first and we identify final items and check for conflicts
in lalr we have to merge equal states with lookaheads diffrent and find conflicts
https://www.youtube.com/playlist?list=PLEbnTDJUr_IcPtUXFy2b1sGRPsLFMghhS
1. Lexical
2 . Synatx
3 both
4 Either 1 or 2
compiler-design
Both lexical and syntax anlysis. In lexical, symbol table entries are created for tokens. In later phase (syntax analysis)
most of attribute information of those tokens are entered.
compiler-design
treat it like
S->iESeS
E->(E)
A -> d
Here , it is not LL1 as A -> bAc and S -> bda both need to placed in the same cell.
Also , should I say that S -> Aa and A -> d are also SR conflicts as they both derive d ?
compiler-design
If 20% of bolts produced by machine are defective determine probability that out of 4 bolts choosen number of defective
bolts is less than 2
1)27/64
2)81/256
3)27/256
4)512/625
compiler-design
"For every grammar G, the GOTO function of the canonical collection of sets of items defines a DFA that recognizes viable
prefixes of G"
Which of the following symbol table implementations is best suited if access time is to minimum?
compiler-design
compiler-design
Selected Answer
We do not consider I1 state because that production has been added by us to show accept state, it is not a part of given
production
(a) linear list (b) search tree (c) hash table (d) none of the above
compiler-design
As the question did not seem to be complete , I am trying to guess the question from the answer ( shame on these test
series guys , can't even proof-read question ).
compiler-design
int main()
int gate,exam,rank;
gate=exam=rank=10.3;
printf("%c",gate);
a)lexical error
b)syntax error
c)semantic error
d)none of these
compiler-design
It won't print anything as ASCII character for 10.3/10 is newline; so it won't print anything , but go to the next line. I
don't think any error is present. So, D
S → BbA ∣ bA ∣ bBA
B → b ∣ c
A → a
Which of the following precedence relation is correct from above grammar? Assume x < y is used to represent y has highest
precedence than x and in expression y appears first then x appears next.
a). a < − b
b). c < a
if a grammar is regular then it will be Context free also [as per chomsky hierarchy] it may be or may be not ambiguous
depending on grammar.
as
S->bS|aX
X->bS|aY
Y->aY|bY|^
is regular having regular expression (a+b)*aa(a+b)* and unambiguous
but grammar
S->aS|bS|aX
X->aY
Y->aY|bY|^
is also regular having regular expression (a+b)*aa(a+b)* and ambiguous.[check aaa]
But it is sure any ambiguous regular grammar can be converted into unambiguous regular grammar.
compiler-design
Selected Answer
50..
q.26 : I do not understand the output . Why are real , integer and to coming?
Sum would be real value as well, and what you int to real is explicit casting.
Answer : D
compiler-design
R.in = f(Q.s) // R gets its value from Left sibling i.e. L attributed
Nonterminal a b e i t $
S S->a S->iEtSS'
By looking the parse table we found multiple entries in M [S',e] hence Grammar is not LL(1).
Now suppose I have to make a LL(1) parser but here I found grammar is ambiguous so I have to remove this ambiguity
otherwise we are not able to make LL(1) parser for this grammar .In order to remove ambiguity from grammar we always
choose the production S' ->eS to be present in parse table and remove S' ->epsilon and make it LL(1). So my question is
WHY we always choose S' ->eS production to remain in this parse table why not S' -> epsilon? Answer this..???
E--> b
But apart from that the LL1 table that you constructed is wrong
On top you have terminals along with $ . You have an entire coloumn for epsilon which is wrong
In LL 1 when ever we have NT --->∈ so in such case we find follow( NT ) , and what ever value we get ( say we get a and
b ) under a and b which are terminals we will put the NT --->∈ .
And i dont undersatnd your last statement can you elaborate it more :)
whereas For epsilon thing it has nothing to do with ambiguity . In ll1 we are looking 1 look ahead symbol then accordingly
we will use production ( in top down manner ) . So according to looakahead symbol we have to use which production is
summarized here :)
Selected Answer
S→A∣B
A→a∣ϵ
B→b∣ϵ
Now if I want to generate empty string (ϵ) from above grammar, I have more than one option to generate it. Obviously
grammar is ambiguous. No parser will work.
In each activation of a procedure , the local variables names in that procedure is bound to ----------- storage location ?
1) Diff
2) same
3) None
compiler-design
Selected Answer
2}same
S SS | a | ∈
Ans 3
http://gateoverflow.in/?qa=blob&qa_blobid=11048084677475811705
Option C is correct . You can derive all the required string of teh form a^n b^m c ^ (m+n) where n ,m >= 0
I dont understand the term left context here ? . I think it should make use of lookahead for reduction , if it then statement
1 is correct too
Statement 2 is correct .
Pépère après l'effort... Composition : dessus simili cuir - intérieur laine 100% - semelle feutre avec patin caoutchouc anti-dérapant. Mule avec l'intérieur de la charentaise procurant chaleur et
confort. Livrée avec une trousse cadeau. 2 articles ou plus : livraison gratuite http://www.paysdesgeants.fr/air-jordan-12-c-2_6.html
normal
4.91 Among LR(0), SLR(1) and LALR(1) which parser is going to detect error
faster and why?? top gateoverflow.in/351
Among LR(0), SLR(1) and LALR(1) which parser is going to detect error faster and why??
The basic difference between the parser tables generated with SLR vs LR, is that reduce actions are based on the Follows
set for SLR tables. This can be overly restrictive, ultimately causing a shift-reduce conflict.
An LR parser, on the other hand, bases reduce decisions only on the set of terminals which can actually follow the non-
terminal being reduced. This set of terminals is often a proper subset of the Follows set of such a non-terminal, and
therefore has less chance of conflicting with shift actions.
Selected Answer
and rest all the symbols used has to come down to id for satisfying the BNF grammar.so,
<expression>
<term>
<factor>
<expr>
4.93 Consider the following grammar. How many back tracks are required to
generate the string aab from the above grammar? top gateoverflow.in/43709
Consider the following grammar. How many back tracks are required to generate the string aab from the above grammar?
S → aB | aAb
A → bAb | a
B → aB | ε
No of Backtrack=3
S->aB->aaB->aa unsuccessful
backtrack 1 time
S->aAb->abAbb->ababb unsuccessful
backtrak
In each activation of a procedure , the local variables names in that procedure is bound to ----------- storage location ?
1) Diff
2) same
3) None
compiler-design
I guess Option 1)
After the assignment pi=3.14 if the storage address 200 associated with varaible pi is used , then the assignment changes
1) Enviorment
2) state
c) binding
d) none
As far as i know Binding happen at run time . Now whenever we declare a variable we are binding name to storage
allocation . so this is is nothing but an Enviorment . Now assigning the value to this variable is a state .
compiler-design
Selected Answer
And you are absolutely right. Answer will be (2) i.e. State, Here is I am putting some snapshot of the Compiler books,
written by legendary Jeffrey Ullman, Alfred Aho, Monica S. Lam, Ravi Sethi.
Selected Answer
You write a C program to add two input numbers. Compile it and run - get the sum.
We are writing C code as per C syntax in English language. But the computer has a processor inside it where it takes
instructions in machine language and the instructions should be of the form prescribed by the processor maker (Intel for
example). These will be like
"MOV A, B;
ADD A,B;"
So, the compiler does this job. It converts the source program written by a programmer in a high level language like C to
the language the processor can understand- often called object file.
In the above example I used A and B which can be registers- which are memory locations fixed inside CPU. But these
registers are limited and when we need more memory (say finding the sum of 100 elements) we use main memory (RAM)
and then the address is used in then instruction - like 0x40000321 (of course converted to binary) instead of A. Then the
CPU will call its address handler - in a VM system this will be converted to a physical address, and that returns/stores the
content from/to that address. For this reason we study CO&A.
compiler-design
Constants can b evaluated at compile time only so compiler removes this headache of run time by identifying the
subexpressions whose value dont change even if program runs,,ie the constants
eg:int a=5+b;
b=7;
a=12
4.97 How do we find out whether a given grammer is SLR(1) or LR(0). top
gateoverflow.in/40932
Consider the following grammer:
S-> aAb | Sc
A-> d | Sd | S
a) SLR(1)
b) LL(1)
c) LR(0)
compiler-design
Selected Answer
==>as the given grammar is left recursive (S->Sc),so it is not LL(1) grammar.
==>as the given grammar has SR conflict,it is not LR(0) grammar(A->S.d and A->S.)
so answer is A) SLR(1)
It is useless grammar. It doesnot generate any terminals. May be ambiguois might be the answer. I dont know what they
meant
compiler-design
Ans B
c) Portability is encahnced
compiler-design
1) Recursive
2) Serially usable
3) Non reusable
4) Reenterable
compiler-design
In computing, a computer program or subroutine is called reentrant if it can be interrupted in the middle of its
execution and then safely called again ("re-entered") before its previous invocations complete execution. The
interruption could be caused by an internal action such as a jump or call, or by an external action such as a
hardware interrupt or signal. Once the reentered invocation completes, the previous invocations will resume
correct execution.
This definition originates from single-threaded programming environments where the flow of control could be
interrupted by a hardware interrupt and transferred to an interrupt service routine (ISR). Any subroutine used
by the ISR that could potentially have been executing when the interrupt was triggered should be reentrant.
Often, subroutines accessible via the operating system kernel are not reentrant. Hence, interrupt service
routines are limited in the actions they can perform; for instance, they are usually restricted from accessing the
file system and sometimes even from allocating memory.
A subroutine that is directly or indirectly recursive should be reentrant. This policy is partially enforced by
structured programming languages. However a subroutine can fail to be reentrant if it relies on a global variable
to remain unchanged but that variable is modified when the subroutine is recursively invoked.
This definition of reentrancy differs from that of thread-safety in multi-threaded environments. A reentrant
subroutine can achieve thread-safety, but being reentrant alone might not be sufficient to be thread-safe in all
situations. Conversely, thread-safe code does not necessarily have to be reentrant.
Other terms used for reentrant programs include "pure procedure" or "sharable code"
2) Dynamiic dictonary
4) Range search
compiler-design
Hashtables cannot contribute to the problems like Given values a and b, find all the records whose key value is in the
given range.
1) Counting distinct values - can be easily done if we know the allowed range of numbers, say n and using the hashing
function :-
x mod n
2) and 3) are common applications of hashing..
In backpatching , what does the N mean in semantic rule for syntax rule ?
1.E1 or NE2
3.Not E1
compiler-design
Here N is a marker nonterminal in the grammar causes a semantic action to pick up, at appropriate times, the index of
the
next instruction to be generated.
If E1 is false, however, we must next test E2 .This target is obtained using the marker nonterminal N. That nonterminal
produces, as a synthesized attribute N , the index of the next instruction, just before E2 code starts being generated.
compiler-design
Selected Answer
1) Static Allocation: It occurs before run-time and does not change during run-time
(A) a + a + (a + a + a)
(B) a + a + (a + a + a + (a + a + a + a))
(C) a + a + (a + a + a + (a + a + a))
(D) None
compiler-design
operator + is left associative.the expression has to be left asssociative. but the resulting grammar may be left of right
recursive.
compiler-design
Selected Answer
here the grammar is LL1. there is no intersect between any of them.and for first of S they written first of B.but here first
of B not contain a..First(B)=(b,c)
First(S)=a,b,c
The main aim of Lexical is to identify token . each lexeme in source language , it will be categorized into token class .
The following are well known token class 1. Opening braces 2. Closing braces 3. Identifier 4.Keywords 5.Digits 6.Other (
including punctuation marks and all )
now each lexeme is taken and it is matched using a pattern specified for a token class
Remember that white spaces tab etc are used as a seperator . Just like in English lang , these spaces help us to identify
words from sentences . The same thing is applied here
a--- identifier
= ---- operator
a--- identifier
now space is there it mean it was end of one token and begining of other token '
so 10 --- digit
And we shouldnt talk about semantic , we will get error at syntax phase only
In this one I am unable to follow in the above node marked as "-" ,it has two edges one upward and one downward for "+"
node so then how to proceed with this ?
Selected Answer
In mathematics and computer science, a directed acyclic graph (DAG) is a directed graph with no directed cycles.
Ref ->
https://en.wikipedia.org/wiki/Directed_acyclic_graph
This is some weird test series question, I think you should not, & Nobody should spent time on this !
4.110 what is the difference between lookahead symbol and follow of a non-
compiler-design
E->E*F|F+E|F
F->F-|id
Selected Answer
F->F-E
Operator at lower level in tree has higher precedence than operator at upper levels
4.112 Is there any difference between derivation tree and parse tree ? gateoverflow.in/29720
top
I have gone through this link and found that both are synonyms to each other but I am not getting that when we have more
than one parse tree for a string so do we say that the grammar is ambiguous since in the parse tree we haven't mentioned
whether it is a left-most-derivation tree or right-most-derivation tree and we say that for a grammar to be unambiguous we
should have a unique left-most derivation tree and unique right-most derivation tree .
http://stackoverflow.com/questions/5729961/any-differences-between-terms-parse-trees-and-derivation-trees
The tree made for each derivation (right most or left most) would be the same. So, for an unambiguous grammar be have
a single parse/derivation tree.
Top down parsers parse LL(K) grammar ,Now if we talk about recursive descent parsers they just scan each input symbol
and then perform their respective function calls ,or even LL(1) parsers also see the input symbol and accordingly chose the
production and then push the symbols onto stack so then where do they see the look-ahead symbols, I am not getting this .
compiler-design
The input symbol is the look ahead. We would have constructed the parsing table to behave according to the current input
symbol. In recursive descent parsers we don't have parsing table hence we need backtracking. Also note that recursive
descent parsers also will accept all LL(1) languages.
Lexical error: Error while identifying lexemes. Like inz a; instead of int a;.
Syntax error: Error in the syntax of some construct. Like printf 30; instead of printf("30");
Semantic error: Error in the meaning of the statement. Like, you have evaluated area of triangle as 2L*B. They are not detected by
compilers.
2){A→a.b,B→b. }
3) {A→∊. , B→.a}
4)All of these
1.A->b.c here 1 more shift is needed then final product and B->b. is final product(no more shift is need needed)
similarly 2
1) { A→ b.c ,B→b. } - Yes, chances of SR conflict. If we have shift move from this state. Here, B->b is reduced and
shift on c.
2) {A→a.b,B→b. } - Yes, chances of SR conflict. If we have shift move from this state. Here, B->b is reduced and
shift on b.
3) {A→∊. , B→.a} - Yes, chances of SR conflict. If we have shift move from this state. Here, A->∊. is reduced and
shift on a.
S→ bAd /bBe
A→a
B→a
1) SLR(1)
d) Not LR(1)
Selected Answer
Caption
check it.
so option 1 matches.
S'→S
S→A/B
A→fAi/n
B→fBii/d
For the above augmented grammer , the number of states in LR(1) parser are_______________
Selected Answer
20 states i guess..
S → Aa ∣ B
B → a ∣ BC
C → a ∣∈
compiler-design
S->Aa|B
B->a|B|BC
C->a
S->a|BC
B->a|BC
C->a
so total 5 production in simplified CFG.
1.Compiler produce executable binary object file whereas an interpreter produce code , both executable can run many times.
2. Before translation , compiler and interpreter reads all of the input file.
compiler-design
Selected Answer
1. Compiler creates executable file and after that no need of compiler for running the program again and again while in case of
interpreter, it reads your program instruction by instruction and executes it that means you need interpreter each time you need to
run the program.
2. Before translation only compiler reads the complete input file while interpreter reads instruction by instruction as I mentioned
above.
gate2007 compiler-design
The maximum number of reduce moves that can be taken by a bottom-up parser with no epsilon and unit productions to
parse a string of length 3 tokens is ____ ?
compiler-design
if grammar is CNF then total reduce move are 2n-1. put n=3 here .
Selected Answer
There is no general procedure or algorithm to tell whether any grammar is ambiguous or not.
To prove any grammar is ambiguous you just need one string that can be derived in more than one ways from the
grammar and has more than one, different Parse Trees/Left Most Derivations/Right Most Derivations.
To prove any grammar is not ambiguous you have to ensure for each and every string that can be derived from the
grammar that there is only a unique way to derive the string.This checking process might never end if infinite number of
strings can be generated from the grammar.
If you have a specific grammar, & if the grammar is simple enough that you can analyse its productions & tell what each
production is doing then perhaps you can say whether it is ambiguous or not.
Some tricks might be helpful in deciding ambiguity, like no LL(k), LR(k) etc. grammar can be ambiguous.
So if you can prove that your given grammar belongs to any of these classes then you can say that you grammar is
unambiguous.
But unfortunately there exists a class of grammars that is not in LL(k), LR(k) etc. classes & still is unambiguous.
compiler-design fortran
Caption
Given answer: C
But I believe that syntax analyzer is just for checking the form of the source code. The meaning of the program is
interpreted in semantic analyzer phase of the compiler. Please correct me if I am wrong.
compiler-design
The dangling else problem in the construct If (E) sales S | is (E) S | a can be resolved IN SDTS by
(A) Using the associative & precedence of operating & the 'exe' munch principle
(B) By change the grammar to an unambiguous one
(C) Cannot be removed as It Is undecidable
(D) None of the above
compiler-design
Read the dangling else problem from here and it is an ambiguous case and it can be removed only if u convert the
ambiguous grammar to unambiguous one , so I guess answer is option B , it has nothing to do with precedence or
associativity.
https://en.wikipedia.org/wiki/Dangling_else
The most appropriate answer is (A) [It can also be B, if its possible to reduce into unambiguous].
Let me explain...
'Dangling Else' problem is like deciding with WHICH 'if' some 'else' can go with. Say for following...
ex1) X --> S | b
S --> if E X else a | if E X
Both of the above cases suffers through Dangling Else problems. Why? Both can derive, " if E if E b else a" . (E stand for
some expression in Code.) Now, with which 'if' should we configure our 'else'. Compilers (LALR(1) in our day to day life)
uses the approach of choosing 'nearest if' . But this is just ONE of the way to resolve this so called ambiguity. Some other
methods are...
2) By using something like 'endif' for marking the end of of conditional structure.
4) By using different precedence rules to associate the dangling else with nearest if. (By using lower
precedence for THEN and higher precedence for ELSE. Try it.) And by doing this and other techniques you are
HANDLING ambiguity in grammer.
Selected Answer
It is not done during compilation- rather just before it. This is done as by macro processor which is before any of the
compilation phase. You can see the output of macro expansion by using "-E" option in gcc.
gcc -E file.c
Choose the correct statement with respect to the syntax analysis of a compiler
(A) it can not always be modeled by a BNF grammar, but by a cfg
(B) it can be modeled by push down automata which is What a parser is all about
(C) it checks both the form & meaning of the program in a HLL
(D) none of the above
Given ans: C
compiler-design
Precedence of '*' = Precedence of '+' < precedence of '-' < Precedence of 'id'
4.129 When LALR(1) is constructed form CLR(1) does not contain any shift
reduce conflicts? top gateoverflow.in/29365
1)LALR can have shift reduce conflicts only if CLR has shift reduce conflict
2)LALR may have reduce reduce conflict even if CLR dont have any conflict(conflict arises due to merging of states where
lookaheads are same)
s->Aa | a | bC | b
B->a | bC | b
C -> a
clarify plz.....
Selected Answer
S->B
B->a|bC|b
C->a
S-> a|bC|b
C->a
in top down parsing while constructing parse tree , semantic actions are considered as child of Variable (ie part of production
on RHS)
how we can decide this as the right child or left child in parse tree ?
See SDT simple meaning is that while traversing the parse tree only we perform the semantic actions and a semantic
action is performed when we actually reduce the symbols to a particular production , and as far as ur query is concerned
that whether semantic actions are left child or right child of the non-terminal that depends on whether u are having S-
attributed SDT or L-attributed , since in first one semantic actions are placed at right end of production while in the later
case semantic actions are placed anywhere in RHS ,Now just see that if u want to convert any infix expression to post-fix
expression , so obviously u will place the semantic actions as the right child so that after u traversed all the child nodes
,now u perform the semantic action ,See book u will get examples of SDT u will observe then when to make sematic
actions as right child or left child of the non-terminal.
Viable prefix : The prefixes of right sentential forms that can appear on the stack
of a shift-reduce parser are called viable prefixes.
simple design lr(1) dfa. then u get the ans.
follow this
First one not LL1 as it is ambigous,option c is left recursive,cant decide about option b.... plss help..
compiler-design
Selected Answer
a) A→ a.b, {b}
B→ a. , {a}
b) A→ a.a , {a}
B→ a. , {b}
c) A→ b.a , {b}
B→ b.,{a}
d) A→ b.b , {a}
B→ b. , {a}
Selected Answer
So SR conflict is possible.
Can anybody enumerate the similarities and dissimilarities between LL, SLR, LALR and LR parsers.
http://stackoverflow.com/questions/2676144/what-is-the-difference-between-lr-slr-and-lalr-parsers
Could any one explain Register Allocation using graph coloring..with example!!!!!
Relative to the program translated by a compiler, the same program when interpreted runs
A) Faster
B) Slower
isro compiler-design
A compiled language like C is usually compiled directly into machine code. When you run the code, it is executed directly by the CPU.
while in interpreted mode When you execute your code, the CPU executes the interpreter, and the interpreter reads and executes your source code
this makes it slower than compiler i guess!
printf("i=%d,&i=%x",i&i);
a)13
b)6
c)10
d)11
Selected Answer
the same question came in gate 2001 printf("i=%d,&i=%x",i,&i); with this statement it has 10 token
1.printf
2.(
3."i=%d,&i=%x"
4.,
5.i
6.,
7.&
8.i
9.)
10.;
S->aAb/aBc/bAd/bBe
A->g
B->g
Lexical
Semantic
Both
None of these
compiler-design
Symbol table is modified in both of the given phases. So, none of these is the correct option.
It is true or false
If it is false explain
compiler-design
Selected Answer
It is true.
Because once we construct CLR table and it has no conflict then we go for merging the
states(LALR) and still there are chances for Reduce-Reduce Conflict in LALR table.
- But question says LALR has no conflict, then surely CLR has no conflict.
Selected Answer
when machine code is generated then the computer does not where the code will be placed at ram till run time . so
numbers all the line from 0-1-2.. so on. now suppose your program loaded at 230 address then this address on run time
will be converted to 230+0,230+1,230+2 means every line will just adjust acordingly . this type of address is call
relocatable address as we have to relocate the address it is a part of run time binding. whereas if i came to know at
compile time hat at what frame my program will be loading like i came to know my program will load at 530. i will make
all my line to start with 530. so that no address change will be required . so that is called absolute machine code . also
know as compile time binding.
refer to this:http://stackoverflow.com/questions/4202181/explanation-about-viable-prefix
E -> a printf("a")
for a + a + a is
compiler-design
sorry your question is very tough to understand but as much as i could understand input =a+a+a
Given answer: 1
I am able to get 2 rightmost derivation of 'a+a'
First:
S -> E + E -> E + a -> a + a
Second:
S -> E + E -> E + a -> a + a
compiler-design
in /* declare variable */ x;
Selected Answer
http://dragonbook.stanford.edu/lecture-notes/Stanford-CS143/03-Lexical-Analysis.pdf
4.147 What is the number of steps required to derive the string ((() ()) ())
for the following grammar. top gateoverflow.in/17222
S → SS
S → (S)
S → ε
ans -10
s -> (s)
-->(ss)
-->(s(s))
-->(s())
-->((s)())
-->((ss)())
-->(((s)s)())
-->((()s)())
-->((()(s))())
-->((()())())
compiler-design
Selected Answer
A ---> AB / epsilon
Here, A--->AB is useless production. So only production that matters is A---> epsilon. First of A is epsilon .
The minimum number of temporary variables that can be used in equivalent 3-address code of above code is
Approach:
t = t+e, g = g+a, t = t*g, g = g+g,t = t+g. Hence 4 temporary variables are needed. Is this right?
compiler-design
t1=e+t
t2=g+a
t1=t1+t2
t2=t2+t2
t1=t1+t2
compiler-design
1). Drawback with static allocation is that it does not support recursion.
2). Drawback with stack allocation is that, when function completes its execution it will be popped out from stack..
4).None of above
compiler-design
Selected Answer
2. is a bit ambiguous. But assuming a functional language feature, this is also true. In order to return a function, its
activation record must be alive even after function run. So, activation record is created on heap and not on stack for these
languages.
4.152 If an LL(1) parser carries out the SDT for a string output will be ?? top
gateoverflow.in/31762
E -> E * E
-> E ↑ E * E
-> id ↑ E * E
-> id ↑ id * E
-> id ↑ id * id
Should be c..
Selected Answer
main
int
fl
10
20
I4 contains 2 productions and I7 contains only one production,so we cannot merge these two state.
Can a grammar which is not LL(1) can be SLR(0)? Yes, can be!
4.156 Pankaj and Mythili were both asked to write the code to evaluate the
following expression top gateoverflow.in/239
Pankaj and Mythili were both asked to write the code to evaluate the following expression:
a − b + c/(a − b) + (a − b)2
d = (a-b)
print d + c/d + d*d
If the time taken to load a value in a variable, for addition, multiplication or division between two operands is same, which of
the following is true?
compiler-design normal
Selected Answer
In code A, three variables are used a, b and c to store values. The computation of a-b is repetitive and is performed 4
times in print statement requires more time compared to the computation of print statement of code B, because of the use
of additional variable d, to store the computed value of a-b. The print statement of code B replaces d with the already
computed value of a-b.
Selected Answer
D) none
S -> aS'
S'' -> c | d
compiler-design
I got option b as answer...Is this the ryt answer and ryt method of solving this pbm?
compiler-design
test-series
Selected Answer
Its a CFG because its of type V --> (V+T) * where V is variable and T is terminal.
this grammer is ambiguous since there exist two parse tree for a string.
id - id * id
compiler-design
My solution is
access-time
Where,
H1 = hit ratio in level 1 i.e. cache memory ( 0.9 ) , T1 = Average Access time in level 1 ( 20 ns )
H2 = hit ratio in level 2 i.e. main memory( 0.6 ) , T2 = Average Access time in level 2 (60 ns)
H3 = hit ratio in level 2 i.e. hard disk ( 1 ), T3 = Average Access time in level 3 = ( 12 ms i.e 12000000 ns )
= 480026 ns
Given answer is A. I am doubtful between A and B why not B is faster than A. Please explain
co&architecture ace-test-series
Selected Answer
Think what would take more time, a register access or a memory access? Register Addressing Mode will have the operand
in the specified Register, while in Absolute Addressing mode, the operand will be in the memory, the location of memory
cell is in the instruction.
(c) and (d) option cannot be answer becoz if they are compared with above two option than both c and d option are slow
(i,e take more time ) so they can be neglected now come to (a) option as register addressing in register addressing all
operand are present in register itself and after computation we store result in register itself also accessing of register is
much faster than than accessing the memory location ..one such common example is RISC processor which consists of
lots of register in which we can store the operands and because of this need of addressing mode is less, RISC proceesor
is costlier because of these registers only, where as CISC processor it is not fast becoz less use of register and more
addressing mode .
in (b) option absolute addressing there we have address in the instruction so with the helo of address we can fetch
operand from memormy which take time as compared to register accessing.. so (a) option true
What will be the size of Address Translation Table, for 32b addresses if there is an entry for: a) each byte; b) each word ,
word size is 32b; c) each 256B unit ?
ok. i think what they are trying to say is right. if there is a 32 bit address so it can interface 2^32 rows uniquely and now
they are saying every row should also be capable of identifying byte uniquely. size of each row will be 32 bit =4 bytes now
to represent 4 bytes uniquely i need 2 bits
for first byte i will use 00, for second 01, 10 and 11 , i can't get how they multiplied it by 4.
secondly for the second pat it should be 2^32 as every row can represent one word. i
can't get how they just did it. what i have read till now i will go with this . this is how we represent page in the page table
and map .
5.5 Addressing Modes: which addressing modes in this question top gateoverflow.in/25028
addressing-modes
Selected Answer
530=Pc + value
the instruction length is not give so how can i determine the addr loaded in pc hen instructtion at 630 is executing because if
instruction length is 4 bytes it should be 634
thanks in advance
co&architecture addressing-modes
Since the address part of the instruction is 10 bits, I assume instruction length is 16 bits = 2 bytes.
So, PC value during execution of branch instruction = 630 + 2 = 632 (PC always contains the next instruction address)
Now, branch is PC relative and the address to jump is 530, the operand will be 530 - 632 = -102 = (10011010) 2 (2's
complement representation. )
co&architecture addressing-modes
Selected Answer
" We have defined the Index mode by using general-purpose processor registers. Some computers have a version of this mode in which
the program counter, PC, is used instead of a general-purpose register. Then, X(PC) can be used to address a memory location that is X
bytes away from the location presently pointed to by the program counter. Since the addressed location is identified relative to the
program counter, which always identifies the current execution point in a program, the name Relative mode is associated with this
typeof addressing.
Relative mode—The effective address is determined by the Index mode using the program
counter in place of the general-purpose register Ri. "
-[Computeranization And Embedded Systems, Hamacher, Vranesic, Zaky, Manjikian, 6Ed, Mgh, 2012]
Consider 1GHz clock frequency processor, uses different operand access modes shown below:
Assume that 8 cycle consumed for memory reference, 4 cycles consumed for arithmetic computation and 0 cycles consumed when the operand is in register instruction
itself. What is the average operand fetch rate (in million words/sec) of the processor?
a. 117.45 M words/sec
b. 113.63 M words/sec
c. 217.45 M words/sec
d. 316.45 M words/sec
addressing-modes co&architecture
Selected Answer
Cpu time=8.8x10-9sec
Consider 1GHz clock frequency processor,uses different operand accessing models shown below:
Assume that 2 memory cycles consumed for memory reference ,3 cycles consumed for arithmetic computation and 1 cycle
consumed when the operand is in register(s) instruction itself . The average operand fetch rate (in millions words/sec) of
processor is __________ (upto 2 to decimal places).
addressing-modes
operand
frequency cycles
addressing mode
register 10% 1
immediate 20% 1
direct 30% 2 (2 memory read cycles)
4 (2 times 2 memory read
memory indirect 20%
cycles)
5 (2 memory read cycles +
indexed 20%
3 for index add)
1 ∗ .1 +1 ∗ .2 +2 ∗ .3 +4 ∗ .2 +5 ∗ .2
.1 +.2 +.3 +.2 +.2
Total number of cycle = = 2.7
Given an array A[100] of which each element size is 4 words. Processor uses a Cache Memory which is divided into 4 lines
each of size 8 words to execute the following code
for(i=0; i<100; ++i)
{
A[i] = A[i] + 10;
}
point I needed to extract from this question is : for calculation of hit ratio do we count a write operation as Hit or only Read
operations are counted
Selected Answer
a[0] a[1] stored in one block.for first time a[0] for first reference(read) it is miss.for write it is not miss.for a[1] both read
and write are hit
5.11 Associative Memory: Which of the following are true about associative
memory. top gateoverflow.in/6308
associative-memory
Selected Answer
d).
S2 is true and searching by content requires comparison and hence slower than accessing my address.
Both are Correct. Associative Memory is also called as Content addressable Memory..
http://gateoverflow.in/?qa=blob&qa_blobid=3717160066093697882
associative-memory
design 1
main mem address is 32 bit which includes 11 bits as word offset and remaining 21 bits as TAG
design 2
therefore TAG memory size =no of sets * No OF BLOCKS PER SET *NO OF TAG BITS
=256*8*17
= 34816 bits
http://gateoverflow.in/?qa=blob&qa_blobid=3717160066093697882
associative-memory
Tag Memory Size = #Cache lines * tag size = 2K * 18 bits = 4.5 KBytes
Assume that 16 bit cache address memory with cache size 1024 bytes. Block size of cache memory is 8 bytes and tag size is
9 bits. What is the associativity of cache memory?
Tag + (Cache size i.e. Block size + Number of Cache lines) - Associativity = 16 bit
9 + (10 - x) = 16
x = 3 bit
so Associativity is 2 3 = 8 way .
5.15 Average Stall Cycle Per Ins: Q26 ch-5 M_E workbook top gateoverflow.in/21135
suppose that in 1000 memory reference there are 40 misses in the first level cache and 20 misses in the second level cache.
Assume miss penalty from the L2 cache to memory is 100 cycles the hit time of the L2 cache is 10 clock cycles.the hit time
of the L1 cache is 1 clock cycle.
Ques. if there are 1.5 memory references per instruction. What is the average stall cycles per instruction
My work-
for average stall cycles per instruction = (memory reference per instruction) x (miss rate) x (miss penalty)
right??
=40*10+20*100
=2400
=3.6
Q31). Consider a pipeline "x" consist of 5 stages names as IF,ID,OF,EX and WB with the respective stage delays of 2ns ,5ns,
6ns and 1ns .The alternative pipeline "y" contains the same number of stages but EX stage is divided into 4 sub stages,
(EX1, EX2, EX3 and EX4) with equal delay i.e. (8ns/4) and ID stage is divided into 2 substages (ID1 and ID2) with equal delays of
(5ns/2). In the pipeline 'x' and 'y' memory reference instructions are not overlapped so the penalty of memory reference
instructions in the pipeline'x' is 4 cycles and in the pipeline 'y' is 8 cycles.If the program contains 30% of the instructions which
are memory based instructions, the speedup ratio of 'x' is speedup ratio of 'y' is _______
please elaborate on it ?
top
An instruction pipeline has 5 stages where each stage takes 2 ns and all instructions use all 5 stages. Branch instructions are
not overlapped i.e. the instruction after branch is not fetched till the branch instruction is completed consider ideal
conditions.
If a branch instruction is a conditional branch instruction, the branch need not be taken, if the branch is not taken, the
following instruction can be overlapped. When 80% of the branch instructions are conditional branch instruction and 50% of
the conditional branch instruction are such that the branch is taken calculate average instruction execution time.
5.18 Branch Conditional Instructions: pipelining - branch delay slot top gateoverflow.in/32276
For machine 70% of the delay slots are utilized so only 30% actually causes stalls. So taking stalls caused in machine 1 as
0.30*.20*.35≐0.021
therefore cpi≐1.021
For machine 2
therefor cpi≐1.14
Hope it helps..:)
Among the branch instructions 30% conditional and 70% of them does not satisfy the condition ( branch not taken). If there
is no stall due to them. What is average instruction execution time.
A. 28.96ns b. 30.2 ns
c. 32.27 ns d. 38.96ns
What is Byte Addressable and Word Addressable means in computer Architecture ? Difference between them with examples?
I also find some sources like stack overflow and wikipedia ? But still i couln't able to understand
http://stackoverflow.com/questions/2724449/different-between-word-addressable-and-byte-addressable
co&architecture byteaddressable
Byte addressable - To represent word in memory computer uses Bytes of code. i.e. called Byte Addressable
co&architecture cache
Selected Answer
no of blocks = 2^14
(all options are wrong,basically they wanted to know the tag memory size)
how many comparator and multiplexer are required in set assosiative maping technique . ?? what i know till now is if it is p
way set assosiative then p comparator will be required.. how many multiplexer will be required. ?
Based on the set bits appropriate set circuitry is activated and the tag bits are fed into their respective 4bits-comparators
in parallel along with the TAG bits from the address; The result from all comparators goes through a multi-input OR gate
to denote hit/miss.
5.23 Cache: Which blocksize is considered for transfering words from mem
to cache incase miss if blocksize of memory & cache differ? top gateoverflow.in/17985
Case1) cache block size is 4 Words and memory block size is 8 Words
Case2) cache block size is 8 Words and memory block size is 4 Words
PS: I don't think "block size" is used for main memory. It is page size for memory and it is usually much bigger than cache
block size.
a 4-way set - associative cache memory unit with a capacity of 16kb is built using a block size of 8 words. the word length is
32 bits. the size of the physical address space is 4gb.the number of bits for the tag field is
but answer is 22
cache
Remaining bits are to represent TAG, so remaining bits are 30-(7+3) = 20 bits.
5.25 Cache: Finding Hit Ratio when memory references are given in Hex top
gateoverflow.in/32998
A byte addressable computer has a small data cache capable of holding eight 32 bit words. Each cache block consist of two
32 bit words. For the following sequence of addresses (in hexa decimal ). Find the hit ratio if two way set associative LRU
cache is used.
200, 204, 208, 20C, 2F4, 2F0, 2F4, 2F0, 21C, 218, 24C
Also find the number of... i) Misses ii) Compulsory Misses iii) Conflict iv) Capacity Misses.
--------------------------------------------------------------------------------------------------------------------------------
What bothers me is the answer given in Madeeasy Test Series. Here is my try.
A block consists of two 4B words. So, a block consists of 8B and as memory is byte addressable, 3 bits are used for offset.
As well as 4 blocks are possible with above scenario and 2 sets, as a result, 1 bit is used for set.
[P.S. - There is same qstn asked by someone previously, but I guess, that explaination is conflicting. You can check it here -
http://gateoverflow.in/29182/cache-miss-in-two-way-set-associative ]
the ans is precisely 0.18..your aproach is right but in your xplanation you have done one mistake,the bit u choosed for set
determines in which set the address will go,that is either 0 or 1.that's it,but instead of determinning only that,u also
considered hit,miss by the set bit,there is only 2 hit .
these 2,
set bit only determines in which set the address will go,
hit,miss will be decided by total address..
these 2 are hit cause set no 1 is already contain 2F4 and 2F0...
i think now you will understand your mstk..
other than u r aproach is very good,and this approach will help you determine capacity and conflict misses.
consider single level cache woth access time 5ns line size of 128 bytes and hit ratio is 0.97.Main memory uses block
transfer capability that has first 8 bytes access time 50 ns and for remaining words 10ns What is access time when there is
cache miss(Assume cache waits until line is fetched from memory and then reexecutes for hit)
cache-memory
Selected Answer
Access Time on miss = Cache access + Memory fetch + Cache access (re-access cache as mentioned in question)
cache-memory
Selected Answer
true
The first access to a block is never in the cache. Also called cold start misses or first reference misses. and this type of
misses is called Compulsory misses . (Misses in even an Infinite Cache)
But here we increasing the block size then more adjacent words will be fetched on each miss, so references to these words
will not cause compulsory misses ( which can be reduced to 1 ) .
REF : http://courses.cs.washington.edu/courses/cse378/02sp/sections/section9-2.html
Consider a computer with the following characteristics: total of 1Mbyte of main memory; word size of 1 byte; block size of 16
bytes; and cache size of 64 Kbytes.
(a). For the main memory address CABBE, give the corresponding tag and offset values for a fully-associative cache and
tag,set and word offset for a two-way set-associative cache.
cache-memory
Selected Answer
no of sets=2 11
ie 2048
tag: 25
A system has cache main memory and disk for virtual memory...if referenced word in cache 30 ns to access it..if it is not in
cache 80 ns to load it in cache and reference is started again ..if word not in memory 22ms to bring from disk to memory
and 80 ns from memory to disk and start again cache hit ratio is 0.8 memory hit ratio is 0.9
cache-memory
cache-memory
5.31 Cache Memory: 64 word cache and Main memory is divided into 16
words block. top gateoverflow.in/10668
64 word cache and main memory is divided into 16 words block.The access time of cache is 10ns/word and for main memory
is 50ns/word. The hit ratio for read operation is .8 and write operation is.9. Whenever there is a miss in cache, associated
block must be brought from main memory to cache for read and write operation. 40% reference is for write operation. Avg
access time if write through is used.
cache-memory
Selected Answer
Whenever cache is missed, data (entire cache block) must come from main memory for write as per question. So, for hit,
we have to assume hierarchical access.
TavgW = hw*(tm + tc ) + (1-hw) (tc + 800)
Consider a single-level cache with an access time of 2.5 ns, a line size of 64 bytes, and a hit ratio of H 0.95. Main memory
uses a block transfer capability that has a first word (4 bytes) access time of 50 ns and an access time of 5 ns for each word
thereafter.
a. What is the access time when there is a cache miss? Assume that the cache waits until the line has been fetched from
main memory and then re-executes for a hit.
b. Suppose that increasing the line size to 128 bytes increases the H to 0.97. Does this reduce the average memory access
time?
cache-memory
Selected Answer
(
Tavg = timecache + 1 − hitcache )[timememory ]
= 2.5 + (1 − .95)[65]
as line size is 64 bytes and first word is of four bytes having acces time 50 and remaining three have access time 15(i.e.,
65)
= 2.5 + 3.25
= 5.75
(b)
now line size increases ie 128 bytes as now there are 32 words .
= 50 + 155
= 2.5 + 6.15
= 8.65
A computer has a cache, main memory, and a disk used for virtual memory. If a referenced word is in the cache, 20 ns are
required to access it. If it is in main memory but not in the cache, 60 ns are needed to load it into the cache, and then the
reference is started again. If the word is not in main memory, 12 ms are required to fetch the word from disk, followed by
60 ns to copy it to the cache, and then the reference is started again.The cache hit ratio is 0.9 and the main memory hit ratio
is 0.6.What is the average time in nanoseconds required to access a referenced word on this system
ans
tavg=Hit_cache*time_cache+(1-Hitcache)(hit_main)[60+20]+(1-hit_cache)(1-hit_mainmmry)[60+12+20]
cache-memory
Selected Answer
(
Tavg = hitcache × timecache + 1 − hitcache )(hitmemory )[timecache + timememory ] + (1 − hitcache )(1 − hitmemory )[timecache + timememory + timedisk ]
= 0.9 × 20 + 0.1 × 0.6 × 80 + 0.1 × .4 × 12000080
(
Tavg = timecache + 1 − hitcache )[timememory ] + (1 − hitcache )(1 − hitmemory )[timedisk ]
= 20 + 0.1 × 60 + 0.1 × 0.4 × 12000000
5.34 Cache Memory: Given the following specifications for an external cache
memory top gateoverflow.in/11117
Given the following specifications for an external cache memory: four-way set associative; line size of two 16-bit words; able
to accommodate a total of 4K 32-bit words from main memory; used with a 16-bit processor that issues 24-bit addresses.
Design the cache structure with all pertinent information and show how it interprets the processor’s addresses.
cache-memory
Selected Answer
Line size = 2 *16 = 32 bits = 1 word, for byte addressing (which is default) we need 2 offset bits to address 4 bytes.
So, we need lg 1024 = 10 set/index bits and 2 offset bits. Remaining 12 (24-10-2) bits must be tag bits.
S1: If compulsory misses are most common then the designers should consider to increase the cache line size to take better
advantage of locality.
S2: If capacity misses are most common then the designer should increase the cache associativity, in order to provide more
flexibility when collision occurs.
A. S1 is true, S2 is false
B. S2 is true, S1 is false
C. Both are false
D. Both are true
cache-memory
Selected Answer
A) is the answer
1st one
Compulsory misses means first time access to a cache block. By increasing the block size, this can be reduced as this
location might be fetched as part of a previous cache miss.
http://gateoverflow.in/11950/compulsory-problem-designer-increase-advantage-locality#c12032
2nd one is false. By increasing associativity we can only reduce "conflict" misses.
A byte addressable system with 16-bit address lines with a 2-way set associative, write back cache with perfect LRU
replacement. Assume 1 valid bit and 1 dirty bit maintains for each block. The tag store requires a total of 4352 bits of
storage. What is the block size of the cache? [in bytes]
cache-memory co&architecture
16 KB, 4-way set-associative cache, 32-bit address, byte addressable memory, 32-byte cache blocks/lines
co&architecture cache-memory
Selected Answer
No of sets = 4 = 2 bit
. = 32 - 7 - 5 = 20 bit
0x200356A4 = (<0010 0000 0000 0011 0101> <0110 101> <0 0100>)
A computer system contains a main memory of 32K 16-bit words. It also has a 4Kword cache divided into four-line sets with
64 words per line. Assume that the cache is initially empty. The processor fetches words from locations 0, 1, 2, . . ., 4351 in
that order. It then repeats this fetch sequence nine more times.The cache is 10 times faster than main memory. Estimate
the improvement resulting from the use of the cache. Assume an LRU policy for block replacement.
cache-memory
Selected Answer
Memory access time without cache = 4352 × 10x = 43520x, where x is the time for one access.
In cache we have 64 words per line and 4 lines per set (4 way associativity) and total size is 4096 words. So,
4096
64×4
number of sets = = 16
So after accessing 16 × 64 = 1024 words (0-1023) all the sets will be filled with one entry each. But with 4-way associativity
each set has space for 3 more. So filling can go like this for 4096 words (0-4095). After this next entry (cache line from
4096-4159) will go to first set and will replace the cache line 0-63 due to LRU policy. Like wise total no. of cache
replacements = (4351-4096)/64 = 256/64 = 4.
Now for the second iteration the first four cache line accesses will be cache misses as they got replaced. But these cache
lines will be replacing the oldest used one in the set. For example cache line 0-63 will be replacing 1024-1095. Now the
cache line 1024-1095 will in turn be replacing 2048-2111 and likewise all new cache line accesses will be cache misses
(LRU works badly). This will trigger 16 cache line misses - 4 each from the first four sets. For 5th set to 16th set, there
won't be any cache miss. Now, for the cache lines 4096-4351, there will be 4 more cache misses which are again
coming from the first 4 sets. So, totally 16+4 = 20 cache misses. (Shown in figure at end)
Thus,
So,
43520x
cache-memory
Selected Answer
= 128 * 2 * 16 = 4K words
= 16K.
Now, cache must also need space for tag entries. So, we need to find the number of tag bits for each entry.
Memory is word addressable and a cache block size is 16 words meaning 4 offset bits.
We are given physical address size and not virtual address size. So, we can assume a physically indexed, physically tagged
cache. So, out of 21 physical address bits we used 4 + 7 = 11 bits for offset and tag. Remaining 10 bits are tag ones.
Total tag size
= 10 * 128 * 2 bits
= 2560 bits
= 320 bytes.
So, option B.
Consider an L1 cache with an access time of 1 ns and a hit ratio of H 0.95. Suppose that we can change the cache design
(size of cache, cache organization) such that we increase H to 0.97, but increase access time to 1.5 ns. What conditions
must be met for this change to result in improved performance?
plzz add more in this answer and correct the answer if wrong......
when we increase the hit ratio than the acces time is increased as given in the question..
i think we should use direct mapped cache...and we should increase the size of the cache as.. in direct cache we need
address...to identify the particular word.....so it easy to get word in less time due to avalibility of address...
but if we use associative cache than there is no need of address and so we have to search throught the cache which wiill
increase the cache accees time ..and performance will decreases.....
cache-memory
Selected Answer
The question says that increasing the cache size results in better hit rate and more access time. So, we need not think
about how this is achieved (direct or associative) but just give the equation for access time. Assuming simultaneous
access: (by default take hierarchical)
Tnew
avg = 0.97 × 1.5 + 0.03 × Tmem
0.505
Tnew
avg < Tavg 0.97 × 1.5 + 0.03 × Tmem < 0.95 + 0.05 × TmemTmem >
0.02
= 25.25ns
Tnew
avg = 1.5 + 0.03 × Tmem
0.5
Tnew
avg < Tavg 1.5 + 0.03 × Tmem < 1 + 0.05 × TmemTmem >
0.02
= 25ns
Suppose that a cache is 20 times faster than main memory and cache memory can be used 80% of the time. The speed-up
factor that can be achieved by using the cache is _________.
co&architecture cache-memory
Selected Answer
so tc=tm/20
=4.8/20 tm
=tm/(4.8tm/20)
=20/4.8
=4.16
Suppose that a direct mapping cache has 2 9 lines, with 2 4 bytes per cache line. If cache items of a byte addressable
memory space of 229 bytes. How many bits of space will be required for storing tags( do not include bits for validity or other
tags; only consider the cost of tags themselves) [in bits].
A. 2 8 b. 2 13 C. 2 11
D. none of these
co&architecture cache-memory
Selected Answer
A tag is used to identify which of the memory block is currently present in a cache block. So, here you have to fin the no.
of distinct memory block (a block is the size of cache line- 16 bytes in this question) which can be mapped to a given
cache line. Say, this is x- now we need lgx tag bits as we store tag in binary. Now, this tag is needed for each cache line-
so multiply by the total no. of cache lines to get the total tag storage needed in bits.
2 29
4
No. of memory blocks = 2 = 225.
No. of memory blocks which can be mapped to a given cache line = Total no. of blocks/No. of cache lines (As direct
mapping is used)
2 25
9
= 2 = 216.
5.43 Cache Memory: find number of replacements and cache utilization top
gateoverflow.in/17204
SUM: 0
For j: 0 to 9 do
SUM: SUM + A(0,j)
End for
AVE: SUM/10
For k: 0 to 9 do
A(0,k): A(0, k)/AVE
End for
co&architecture cache-memory
5.44 Cache Memory: CO: Main Memory Hit Ratio top gateoverflow.in/34108
Consider an array of 4 elements and each element occupies 4-words. A 16 word cache is used and divided into a
block of 8 words. If the following code is executed what is the hit ratio?
x = A[i, j] + A[j, i]
co&architecture cache-memory
Selected Answer
number of blocks=2;
now given that each element occupies 4 words that means two elements of array can accomodate in 1 block.
coming to program
i=0;j=0
i=0 j=1
x=ar[0][1]+ar[1][0]//hit for ar[0][1] as it will be loaded when ar[0][0] was read and miss for ar[1][0]
i=1,j=0
i=1 j=1
total hit=6
so hit ratio=6/8=0.75
A 2-way set associative cache consists of four sets. Main memory contains 2K blocks of eight words each.
a) Show the main memory address format that allows us to map addresses from main memory to cache. Be sure to include
the fields as well as their sizes.
b) Compute the hit ratio for a program that loops 3 times from locations 8 to 51 in main memory. You may leave the hit ratio
in terms of a fraction.
Hello Sir, I am write now solving sums from "The essentials of Computer architecture " I got this sum . and there is no
solution provided i just wanna ask you to check this
Solution :
No of lines in a set=2
No of set in Cache = 4
Block size=8 words
So, Size of each cache= No of set* No of line in set * Block Size= 8*4*2=64 Words
Size of MM= no of block in main memory * size of each block=(2^11)*(2^3)= 2^14 words
We have a cache size/ capacity = 64 words and Size of Main Memory as( 2 ^ 14 words )
And since the loop says it starts from location 8 to 51 then . No of elements that will be encountered = (51-8+1)= 44 which
is equivalent for running i from 0 to 43 times (for 44 words )
Out of these 44 words there would be 22 words which would be mapped to set 0 and 22 words which would be mapped to
Set 1
Now in each Set , we have 2 lines and Each block has a size of 8 words ,
And so in reamining in (22-16) words we would have 6 words . to accomodate these 6 words again 1 block need to replaced
While in second iteration there would be again need of replacing 1 block to (first 8 words ) rest would be hit till and then
again 1 miss for (last 6 words ) this is just for 1 set
Is this correct ? Please help . i am sorry to write such a big content . But this question need and to show my way of
approaching towards sums :)
co&architecture cache-memory
Selected Answer
Actually in first part we got 9 tag bits, 2 index bits and 3 offset bits. So, these bits are like these:
tag bits | index bits | offset bits
That is, the lower bits are offset bits followed by index bits and then tag bits.
Our memory access starts from address 8. With 3 offset bits, this cache line reference will be from address 8 to address
15 (1000 - 1111 in binary). Say this cache line goes to cache set A during the memory access for address 8. Next 7
accesses are cache hits. When address 16 is accessed, its cache line goes to set B and not set A because after offset
comes the index/set bits so the set changes (this is made so that spacial locality won't reduce cache hits). Now, all
accesses till 23 are hits and 24 will be a miss and cache line for 24 goes to set C. Similarly, cache line for 32 goes to set
D. Now, for cache line of 40, it should go to set A. But it won't replace the cache line at set A, as each set has space for 2
cache lines (2-way associative). Similarly cache line of address 48 goes to set B. And that is the last cache miss in
iteration 1. So, we have 6 cache misses and 38 cache misses in iteration 1. For iterations 2 and 3, all are cache hits. So,
= 126/132
Consider a 64 KB cache with 256 sets. Addresses are 32 bits. Tags are 19 bits.
A. 4
B. 16
C. 2
D. 8
cache-memory
Selected Answer
I think its 8.
Given a virtual memory system with a TLB, a cache, and a page table, assume the following:
A disk reference requires 200ms (this includes updating the page table, cache, and TLB). •
The TLB hit ratio is 90%. • The cache hit rate is 98%. • The page fault rate is .001%. •
On a TLB or cache miss, the time required for access includes a TLB and/or cache update, but the access is not restarted. •
On a page fault, the page is fetched from disk, all updates are performed, but the access is restarted. • All references are
sequential (no overlap, nothing done in parallel).
For each of the following, indicate whether or not it is possible. If it is possible, speciify the time required for accessing the
requested data. a) TLB hit, cache hit b) TLB miss, page table hit, cache hit c) TLB miss, page table hit, cache miss d) TLB
miss, page table miss, cache hit e) TLB miss, page table miss Write down the equation to calculate the effective access time.
cache-memory
It is not directly mentioned, but it is clear that we are talking about a physically indexed cache (cache after address
translation)
5 + 12 = 17 ns
5 + 25 + 12 + 25 = 67 ns
When page table misses, cache hit cannot happen. Because when a page fault happens, we shouldn't check the cache as
it won't be having the requested data. At this point page fault service routine must be instantiated.
5 + 25 + 200 + 5 + 12 = 247 ns
It is mentioned in question that access is restarted on a page fault. So, once page is fetched, there will be another page
request which will hit in TLB and also in cache.
( ) ( ( )) ( (
0.98 × 12 0.02(12 + 25) 0.98 × 12 0.02(12 + 25) 5 + 12
EAT = 0.9 5 + cache hit + cache miss (TLB hit) + 0.1 5 + 0.999 25 + cache hit + cache miss (TLB miss, page hit) + 0.1 5 + 0.001 25 + 200 + access restarted
A byte addressable system with 16-bit address lines with a 2-way set associative, write back cache with perfect LRU
replacement. Assume 1 valid bit and 1 dirt bit maintains for each block. The tag store requires a total of 4352 bits of storage.
what is the block size of the cache?[in bytes].
ans________
co&architecture cache-memory
2 16
No. of memory blocks that can go to a cache set = x×#sets and we need to identify each of them with tag bits. So, no. of
2 16
#sets×2 x
tag bits, t = lg = 16 − x − lg(#sets).
Now, tag store size = No. of sets * (2 * t + 2 * dirty bits + 2 * valid bits + 1 * LRU bit).
(Each set is having 2 blocks and to identify the least recent use between 2 we need just 1 LRU bit)
How much speed do we gain by using the cache, when cache is used 80% of the time? Assume cache is faster than main
memory.
A. 5.27
B. 2.00
C. 4.16
D. 6.09
Selected Answer
We can assume memory is accessed only on a cache miss (hierarchical memory access by default) and hence on cache
miss we first access cache and then only main memory (both times are added here)
1
Tmemory T cache
Consider a 8 million word main memory and 256 block cache.Both partitioned into 64 words block.What is the size of
additional memory for tags? Size of the cache? consider direct mapping is used and word size 1 byte.
cache-memory co&architecture
Selected Answer
TAG = 23 - 8 - 6 = 9
Additional memory for TAGs = #CacheLines × Size of one TAG = 256 × 9 bits = 288 Bytes
Cache Memory Size = #CacheLines × Size of Each Line = 256 × 64 words = 2 14 words = 2 14 × 1 Byte = 214 Bytes
5.51 Car: Control address reg. And control data reg. top gateoverflow.in/34246
If no. Of mircrooperations r 1200 and processor h/w supports 64 Cs and 16 flags.8 different branch condition are used to
control the branch logic. Then what is the size of CAR and CDR when one address address field in microinstruction to control
the branch logic??
what should be the length of address register = number of bits to uniquely identify each row.
what is the length of instruction or data register. = the size of one word. if it. similarly
here the data register will be of the length of microprogramed control unit control word.
= log ( branch condition) + log ( flags ) + control signal + log ( control world memory)
= 3+4+64+11= 82
while address register will be 11 bit . as t need to only store address which should be able to identify uniquely one of the
1200 entries .
5.52 Cisc: Q-20 (control unit design) madeEasy workBook 2015 top gateoverflow.in/18875
Show below are sements of a code run on a CISC and RISC archy separately
CISC RISC
If the MUL instruction takes 40 clock cycles,Which of the following statement is true?
RISC will take 15 cycles( 3 for move statements and 12 for loop)
so speed up=42/15
=2.8
Q).We have two dsigns D1 and D2 for a synchronous pipeline processor, D1 has 5 pipeline stages with execution times of
3nsec 2nsec ,4nsec ,2nsec and 3nsec , while the design D2 has a 8 pipeline stages each with 2nsec execution time. How much time
can be saved using design D2 over design D1 for executing 100 instructions ? 196 nsec (integer value only) .The correct
answer is 202
co&architecture clock-time
Selected Answer
Td1-Td2= 416-214=202ns
The first word of the memory block (each block contains 4 words of 4 bytes each) takes 5 clock cycles and remaining 3
words are transferred in consecutive cycles. Given the clock rate is 100 MHz. The data rate (in MBps) of memory for
transferring one block of memory is ______.
------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------
Just wondering what is best way to answer this kind of questions.As far as I know , those 10 6 powers are only used in case
of Network Data Bandwidth not in Memory Transfer speed topic of CO ! If you think otherwise , that this question should
have been answered as 200 MB please give reference. If you think otherwise it should be 190.73 MB, Please give me
reference for that ! (So I can be happy :D )
Q 61
computer-organization clockcycle
5.55 Clockcycle: Drd0 2008 q-11 ch-3 i/o interface top gateoverflow.in/21304
In an n- CPU shared bus system, if z is the probability that any CPU requests the bus in a given cycle, the probability that
only one CPU uses the bus is given by-
A. Nz(1-z) n-1
B. Z(1-z) n-1
C. N(1-z) n
D. (N-1)z(1-z) n
co&architecture clockcycle
OPTION A.
There are N - CPUs , and exactly one of them uses the bus.
probability that only one CPU uses the bus = NC1 * z1 * (1-z) N-1 = A(Ans)
{Here z is probability of CPU using bus & we want exactly one Cpu to use the bus
A hierarical cache memory subsystem has a cache access time of 50ns and the main storage access time is of 500ns . with the read hit ratio of 0.9,
what is the average access time of the system considering only memory read cycle in the write through scheme?
A 5-stage pipeline is used to overlap all the instructions except the branch instructions. The target of the branch can't be
fetched till the current instruction is completed. What is the throughout of the system if 20% of instructions are branch
instructions ignore the overhead of buffer register. Each stage is having same amount of delay. The pipeline clock is 10ns
Branch penality if of 4 cycles.
A.55 MIPS
B.45 MIPS
C. 65 MIPS
D. None of these.
5.58 Coa: How many one address instructions are required to evaluate?
ISRO_2015_29 top gateoverflow.in/37956
In X= (M + N x O)/(P x Q), how many one address instructions are required to evaluate it?
Selected Answer
In Acc. CPU first alu operand is always required in the accumulator but second alu operand can be in the register or memory because of the
the availability of the one address along with the opcode.
X= (M + N x O)/(P x Q)
I2: Mul Q: ACC<--ACC*M[Q] //Second alu operand is in memory and destination is Register
A memory system has got the latency of 35 ns with 2 byte per operation. The system is pipelined so that 6 operations can
overlap during execution. The bandwidth of the system is
(A)
For one instruction time taken 35 ns . In 35 ns --- > 12 byte ... Bandwidth = 12 * 10^9 / 35 byte/sec = 3.42 * 10^8
byte/sec
Q.58
Consider 5 stage pipeline which allow all instructions except branch instruction. Program contain 30% conditional instructions
out of which 75% are branch instruction. Processor stop fetching the following instruction after the branch instruction untill
target address is available. Target address is available at the end of the pipeline stage.
All the stages are perfectly balanced with 20 GHz clock time. The processor is running with rate of ____________ (in MIPS).
made-easy computer-organization
Q.42
Three 4 bit shift registers are connected in cascade as shown in figure below. Each register is applied with
A 4 bit data 1011 is applied to the shift register 1. What is the minimum number of clock pulses required to get same input
data at output are with same clock?
11
12
13
14
Please answer !
made-easy computer-organization
I have used the above approach according to this after 12 clock pulses, 1011 will be at output.
my doubt is while finding no of blocks we need to have cache size and here cache is 4K with each word size is 16 bits so we
should take cache size as 4K or 4k*16 bits.??
computer-organization
Suppose there is unpipelined processor with a cycle time 30 ns which is evenly divided into 5 pipeline stages. The total latch
latency of the pipeline will be _______________ ns.
computer-organization co&architecture
Program consists of 16 instructions (I 1, I 2, I 3, ...., I 16 ). In which I 6 is a unconditional branch instruction transfer the controls
of I12 . In the pipeline, branch target address will be available at the end of execute state. Each instruction spends the same
amount of time in all the pipeline stages. The cycle time of the pipeline is 10 nsec.
What is the time (in nsec) required to execute the above program without using branch prediction?
computer-organization
Using (K+n-1)tp
1. I1 to I6 execute first
2. I7 & I8 will also be executed at this point I6 will reach to execute stage so it sends the control to I12
3.I12 to 116 will execute
so total 13 instruction
(13-1+4)10 = 160ns
The explaination is given assuming pipelined system having 1 cycle for each stage. My doubt is why to assume that? Is it
taken by default?? Explaination plz..
In an enhancement of a design of a CPU, the speed of a floating point unit has been increased by 30% and the speed of a fixed
point unit has been increased by 20%. The overall speedup achieved if the ratio of the number of fixed point operation to floating
point operations is 4 : 6 and the floating point operation used to take twice the time taken by fixed point operation in the
original design (upto 2 decimal places) is_________.
computer-organization
A non-pipeline processor has a clock rate 3 GHz and an average CPI of 4. An upgrade to the processor introduce 5 stage pipeline. How ever due to internal delay the clock
rate of the new processor has to be reduces to 2 GHz. What is the speed-up of pipeline over non-pipeline?
a. 3.1
b. 3.3
c. 3.5
d. 3.8
computer-organization pipeline
Selected Answer
=100*4*1/3*10^9=133.33 ns
=1*5*1/2*10^9+99*1/2*10^9=52 ns
=133.33/52=2.56
A two way set associative cache has lines of 16 byte and a total cache size of 8 K bytes. The 256 M byte main
memory is byte addressable. Which one of the following main memory block is mapped on to the set ‘0’ of the
cache memory?
A) (CFED09B)16
B) (FCED90C)16
C) (CFED00B)16
D) (FECD10C)16
cache-memory computer-organization
Selected Answer
so 28 bit
no of block = 2^9
so no of set 2^8.
now in 28 bit,
tag(16) | set(8) |
word offset (4)
so total 28 bits.
for determinning set we have to look on the two digits before the last digit.
for set 0
option C.
Consider a pipeline ‘x’ consist of 5 stages named as IF, ID, OF, EX and WB with the respective stage delays of 2 ns, 5 ns, 6
ns, 8 ns and 1 ns. The alternative pipeline ‘y’ contain the same number of stages but EX stage is divided into 4 sub stages,
(EX1, EX2, EX3 and EX4) with equal delay i.e. (8 ns/4) and ID stage is divided into 2 substages (ID1 and ID2) with equal
delays of (5 ns/2). In the pipeline x and y memory reference instructions are not overlapped so the penalty of memory
reference instructions in the pipeline ‘x’ is 4 cycles and in the pipeline ‘ y’ is 8 cycles. If the program contain 30% of the
instructions which are memory based instructions, the speedup ratio of x to speedup ratio of y is _______.
=> 2.27
=> 2.64
Consider the addition of the two numbers 10001110 and 10000000 in an 8-bit ALU. Which of the following best summarizes
the result and the status of the Z(zero), S(sign), C(carry) and O(overflow) flags? Assume that the numbers are represented
in 2's Complement format and that S=1 if the result is negative.
a) Sum = 100001110, Z = 0, C = 1, O = 0, S = 1
b) Sum = 00001110, Z = 0, C = 0, O = 1, S = 0
Selected Answer
A 10001110
B 10000000
SUM : 100001110
Z = 0 C = 1 S = 0
Array A contains 256 elements of 4 bytes each. Its first element is stored at physical address 4,096. Array B contains 512
elements of 4 bytes each. Its first element is stored at physical address 8,192. Assume that only arrays A and B can be
cached in an initially empty, physically addressed, physically tagged, direct-mapped, 2K-byte cache with an 8-byte block
size. The following loop is then executed.
for (i = 0; i < 256; i++)
A[i] = A[i] + B[2 ∗ i];
During the execution of the loop, how many bytes will be written to memory if the cache has a write-through policy?
a) 0
b) 256
c) 1,024
d) 2,048
The answer is D) 2048 , as the cache block is eight bytes long , so whenever an element of A is updated you have to
write the entire block which contains the element to memory , as 256 elements are updated there will be that many cache
block writes to memory so in all 8*256 = 2048 bytes are written.
Selected Answer
3010
a) Only S 1
b) Only S 2
c) Both S 1 and S 2
d) Neither S 1 nor S 2
made-easy computer-organization
Selected Answer
So remaining bits will be for memory operand i.e., 32 bits - (8 + 6) bits = 18 bits.
[GATE 1987]
Selected Answer
(a) is wrong. Microprogrammed CU can never be faster than hardwired CU. Microprogrammed CU it has an extra layer on
top of hardwired CU and hence can only be slower than hardwired CU.
(b) is a suitable answer as we can add new instruction by changing the content of control memory.
(c) is not correct as when only small programs are there, hardwired control makes more sense.
(d) control unit can also be hardwired, so this is also not correct.
Reference: http://www2.mta.ac.il/~carmi/Teaching/Architecture/SlidesOriginal/ch07%20-
%20Microprogrammed%20Control.pdf
for direct = 0.30*2 =0.60 cycles (becz 1 mem ref and for 1 mem ref 2 cycles are required)
index = 0.20*6=1.2cycles
so Tavg =2.7 ns
so in 1 sec=1/2.7 ns
pipeline data-dependencies
Selected Answer
In the same CPU cycle is not possible. Operand forwarding happens in the next cycle after the operation producing the
operand is finished.
If the operand forwarding happens from EX stage to EX stage, EX of the second instruction can proceed only in the next
clock cycle.
I1 : R1 = 100
I4 : R4 = R 1 + R 3
I5 : R1 = R 1 + 30
co&architecture data-dependencies
Inst1 2 3 4 5 6 7 8 9 10 11 12 13 14
I1 IF ID DF EX WB
I2 IF ID DF EX WB
I3 IF ID DF STALL EX WB
I4 IF ID STALL DF STALL EX WB
I5 IF STALL ID STALL DF STALL EX WB
I6 STALL IF STALL ID STALL DF STALL EX WB
All I3 I4 I5 I6 dependent.
ADD R 1 , R 2, R 2;
ADD R 3, R 2, R 1;
SUB R 4, R 1 , R 5;
ADD R 3, R 3, R 4;
FIND THE NUMBER OF READ AFTER WRITE(RAW) DEPENDENCIES IN THE ABOVE CODE.
data-dependencies
Selected Answer
RAW dependency are those in which one instruction tries to read before its write operation and also they are occured only
in adjacent instruction:
1.
ADD
R1
,
R2,
R2;
ADD
R3,
R2,
R1;
2.
SUB
R4,
R1
,
R5;
ADD
R3,
R3,
R4;
data-dependencies
5 RAW
3 WAR
1 WAW
co&architecture data-dependencies
RAW is true dependency,so RAW can only be found between two adjacent instructions.Here no two adjacent instructions
having RAW.
so,RAW =0
2)I3,I4
3)I4,I5
total 3 WAR
2)I1,I5
3)I2,I5
total 3 WAW
A pipelined processor uses a 4- stages instruction pipeline with the following stages. Instructions fetch (IF) , instruction
decode (ID), execute (EX) and write back (WB). The arithmetic operations as well as the load and store operations arr
carried out in the Ex stage. the sequence of instructions corresponding to the statement
The values of variables p,q,r,s and t are available in rhe resisters ro, r1, r2 and r4 respectively; before the execution of the
instruction sequence.
A.2,2,4
b.3,2,3
c.4,2,2
d. 3,3,2
Q-31 the if,id and wb stages take 1-clock cycle each. The ex stage takes 1- clock cycle each for the add,sub and store
operations and 3-clock cycles each for mul nd div operations. Operand forwarding from the ex stage to the id stage is used.
The number of clock cycle required to complete the sequence of instructions is
A.10
b.12
C. 14
D. 16
WB 1 2 3 4 5
EX 1 2 2 2 3 4 4 4 5
ID 1 2 3 4 5
IF 1 2 3 4 5
WAR-2 (MUL,SUB),(SUB,DIV)
data-hazards
Indicate the type of data hazards (RAW, WAR, and WAW) that exist between the following instructions:
I1:ADD R1, R2, R3 ; R1 = R2 + R3
I2:ADD R4, R1, R4 ; R4 = R1 + R4
I3:ADD R3, R1, R2 ; R3 = R1 + R2
I4:ADD R1, R1, R4 ; R1 = R1 + R4
data-hazards pipeline
According to me ,no hazards can not exists in single instruction. As we can change the sequence the of instructions but we
can not change sequence of instruction cycle (e.g you can not perform execute before fetch )
data-path co&architecture
5.87 Data Path: The ALU, the bus and all the register are identical in size. the
instruction "memory write" top gateoverflow.in/27358
The ALU, the bus and all the register are identical in size. The instruction "memory write" has the register transfer
interpretation M[(R1)] ← R2. The minimum number of clock cycles needed for execution cycle of this instruction if memory
write completion takes 1 cycle is
a) 2 b)3
c)4 d)5
co&architecture data-path
1.R2out,MDRin
2.R1out,MARin
Ref: https://en.wikipedia.org/wiki/Datapath
If we are given direct mapped cache, we have to add Multiplexer delay to the comparator delay ?
5.89 Direct Mapping: COA Adv practice test 27 q-22 top gateoverflow.in/37058
Consider the direct mapped cache organization which consists of m-lines with a line size of 2 w words/ bytes. Main memory
address can be viewed as consisting of three fields. The least significant w-bits identify a unique word within the block of
main memory. The remaining ‘S’ bits specify one of the 2 S block of main memory. Assume that cache is initially empty. Main
memory blocks are referenced by the CPU in a sequential order. Which one of the following sequence of the blocks are
mapped on the cache lines in sequential order from the initial line respectively.
2m + 1, 2m + 2,..., 3m – 1
2S – m, 2 S – m+1,..., 2 S – 1
1, 2, 3,..., m – 1
0, 2, 4,..., (m – 1)
Offset bits = w and 2w is the cache line size. So, this much size is exactly fitting on cache line.
Now, cache is always organized such that consecutive memory blocks go to consecutive cache sets (to make use of
spacial locality) and this is the reason tag bits are the left most.
Now, answer is easy here but options are not. Answer must be option B. In option A, it should start from 2m and not 2m + 1
and similarly in C, it must start from 0.
I have got
[MADEEASY]
- Direct Mapped - 16 words total cache size - 4 words cache block size
A) 7
B) 4
C) 8
D) 6
----------- MY TRY---------------------------------
the seek time of a disk is 30ms.it rotates at the rate of 30 rotations/second.the capacity of each track is 300 words.the
access time is (approximately)
disk
So, avg access time= 30 ms(seek time)+ 1/60 sec (avg rotational latency) + 1/ 9000 sec (transfer time)
= 30+16.6667+.1111 ms
= 46.78 ms(approx)
A certain device dumps data into its interface register every 200 ns. The main memory access time is 50 ns. If the CPU were interfaced to his device in cycle stealing mode,
what percentage of time does the CPU be in hold state?
A. 20
B. 25
C. 50
D. None of these
co&architecture dma
answer = option A
A processor is fetching instructions at the rate of 1 MIPS. A DMA module is used to transfer characters to RAM from a device
transmitting at 9600 bps. How much time will the processor be slowed down due to DMA activity?
A. 9.6ms
B. 4.8ms
C. 2.4ms
D. 1.2ms
isro2013 dma
Assuming Data Width of the System bus is Byte,DMA Will run every Cycle for every
Byte.which has arrived.
So,
Option D)
An 8-bit DMA device is operating is cycle stealing mode (single transfer mode). Each DMA cycle is of 6 clock states and DMA
clock is 2MHz. Intermediate CPU machine cycle takes 2 microsecond, determine the DMA data transfer rate.
co&architecture dma
2MHz = 2 x 10^6 cycles/s DMA cycle = 6/(2 x 10^6) = 3 mic s (10^-6 s) Intermediate CPU cycle is 2 mic s So, every 5
mic s, we have a 8 bit transfer - 1Byte In 1s => 10^6/5 = 200 x 1000 B
A DMA controller transfers 16-bit word to memory using cycle stealing. The words assembled from a device that transmits
characters at a rate of 2400 characters per second. The CPU is fetching and executing instructions at an average rate of 1
million instructions per second.
By how much will the CPU be slow down because of DMA transfer when the
characters are represented with 8 bit ASCII?
(A) 0.0833% (B) 83% C) 17% (D) 17.33%
How much more percent the CPU slows down when 32 –bits words are
transferred to memory using cycle stealing?
(A) 83% (B) 23% (C) 0.0833% (D) 17.33%
dma
all options are wrong. what i think they have missed the number of instruction required to transfer the word . so
considering one instruction will be required.
time due to dma wasted = time taken when cpu address bus was taken / total time *100
time wasted when cpu address bus was taken = transfer time. ( dma concept)
preparation time =
so one bit will be taken from the device to dma in 1/(2400*8) sec.
suppose one instruction is required to transfer 16 bit . ( which i think is missed in question).
second option . i am transfering 32 bit word which means preparation time is going to double . and now cpu will also take
2 instruction to transfer as i assumed 16 bit in one instruction . actually solving this u will see there is no effect on the
time of wastage . because wastage is time is due to the cpu was blocked. during preparation cpu never get blocked. so no
effect.
dma
for initialization and termination cpu need 400 and 500 clock cycle so for 900 clock cycle we need (900*3.3)=2970 ns
where 3.3ns is clock time derived from 300 MHZ.
hence the cpu time consumed is 2970/40000 =0.07425 =7.4% (is this correct?)
A hard disk with transfer rate of 20 kbps is constantly transferring data to memory using DMA cycle stealing mode. The size
of data transfer is 32 bytes. The processor runs at 800 kHz clock frequency. The DMA controller requires 12 cycles for
initialization of operation and transfer takes 4 cycles to transfer 2 byte of data from device to the memory. Then the transfer
time for transfer time ______(μs)
My question is : as it is cycle stealing mode and 2 Byte of data transferred at every 4 cycles. So , after every 2 Byte data
sent , DMA will give the control back to processor , is it correct ? So , will it not take 32/2 = 16 times to transfer the 32 B
co&architecture dma
A DMA controller transfers 16 bytes to memory using cycle stealing with frequency 1.2GHz. The number of clock cycles used
for transfer of 16 bytes is 20 Clock cycles. Find the throughout?
dma
throughput of dma is the data rate of dma. or number of words it can transffer to memory in one seconds.
1
1.2∗ 109
1 clock time = seconds
20
20
so time taken to transffer one byte will be ( 16 cycles.* 1 cycle time) seconds
dma
15 cycles for initialization +200 cycles for 100 bytes transfer=215 cycles
consists of 5 instruction each inst takes 1 cycle after they say program will be executed for each byte transfer
so for 100 BYTES TRANSFER PROGRAM SHOULD RUN 100 TIMES as now PROGRAM CONSISTS of 5 instruction
therefore require total of 500 cycles to transfer 100 BYTES.
SPEED UP=500/215=2.32
A progarm drive Data Transfer results overhead of 6 instruction per byte.System uses 100MHZ clock and need 4 clock on an
average for any instruction . what is maximum data transfer rate (Apprx) ?
dma
overhead=240 ns
data rate=1/240ns
=4.16Mbps
A) consider 1mbps hard-disk is interfaced to the processor in a cycle stealing mode of DMA whenever 64 bytes of data is
available in the buffer,then it is transferred to main memory (word=64bits)...machine cycle time is 2 micro sec..percentage
of CPU time consumed for DMA operation is ???
B) P ercentage of CPU time consumed for DMA operation if burst mode is used ???
dma co&architecture
Consider the disk drive with the following specification 16 surface. 1024 tracks per surface. 1024 sectors/track, 1 KB /sector
rotation speed is 3000 rpm.The disk is operated in Burst Mode.The processor runs at 600 MHZ and takes 300 & 900 clock cycle
to initiate & complete DMA transfer respectively. If the size of transfer is 20KB
What is the percentage of processor time consumed for the transfer operation?
dma
total cycle which dma need to initiate and then complete the total cycles that will be required will be 1200 cycles. Total
time by dma will be ( initiate + transfer + complete ) out of which only transfer time will be useful time.
now we have to calculate the time for transfer which can be easily calculated using the disk parameters given . assuming
a movable read write head is available . if it is movable in one round i will be able to read one track only else if it is fixed .
every surface will have a read write head and 16 tracks can be read in one rotation.
1 round = 50
cpu will be involved in the transfer time only . so percentage will be 392
5.105 Dram Refreshing: Find the refresh overhead in terms of percentage top
gateoverflow.in/28984
All dynamic memories have to be refreshed. A typical DRAM takes 64 ms to refresh. Suppose there are 8 K rows and it takes
four clock cycles to access each row. If the clock rate is 133 MHz, find the refresh overhead in terms of percentage (upto 2
decimal places).
Q 27
computer-organization dram-refreshing
Selected Answer
5.106 Effective Memory Access: Effective access time vs average access time
top gateoverflow.in/36416
OR
2. [ (H)(TLB access time + mem access time) + (1-H)(TLB access + PT access + mem access)]
When u get a hit in the TLB,it generates the physical address or the frame address that maps onto the appropriate frame
in the main memory...so TLB access time + main memory time..
But when its a miss, that means u have searched the entire TLB for the page number but u didnt get so TLB access is
there.. Now u have to access the page table to search the appropriate page number so the page table access time is
included. Now comes the mapping to the appropriate frame.. Once u do that main memory time wud be included.. Hence
the equation.. Remember that If u don't find the page in the page table it will generate a page fault then u have to fetch it
from the disk...
Actually there is solution also but not able to take screen shot.
My solution is :
TA1 = 0.95*30+0.05*300
TA2=0.95*30+0.05*270
TA1-TA2=3ns
Am I correct?
Selected Answer
TA1 = 0.95 * 30(HIT) + 0.05 * 330( CACHE ACCESS TIME + MEMORY ACCESS)
TA2 = 0.95 * 30(HIT) + 0.05 * 300(MAIN MEMORY ACCESS as searching is done simultaneously)
Consider a Processor with two Caches which it can access directly in parallel L1 (80% hit rate) and L2 (90% hit rate) with
access times as 100ns and 200ns respectively. In case of miss in any of those it fetches the data from hard disk L3 (100% hit
rate) which has a latency of 500ns. What is the average access time(Tavg ) of the organization?
(H1+H2)T2+(1-H1)(1-H2)(T3+T2)
http://gateoverflow.in/?qa=blob&qa_blobid=677596019370884012
floating-point-representation
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
floating-point-representation co&architecture
to get exponent in decimal we subtract bias that is 64 from exponent part f floating point no.
so, 84-64=20
1.What are global miss rate and local miss rates in two level cache.
L1 is closed to cpu then l2 and then main memory. So l1 is lower level and l2 is higher level. 6 mem. Ref. Are found in l1 and
for remaining 4 mem. Ref. L2 is accessed. and only 2 mem. Ref. Are found in l2.
I want to know how much important topic is microprogramming for gate? And what and from where I should prepare for this
topic?
Selected Answer
https://www.youtube.com/watch?v=Ru6YeppPA0U
https://www.youtube.com/watch?v=zKCr6uDlq1o
A hypothetical processor supports 256 instructions.Each instruction takes 12 cycles to complete the execution.
Processor supports horizontal control unit design. It has 24 control signals and 16 flags. What is the size of
microinstruction??
No of control words=256*12=3072
5.114 Ieee Representation: 16 Bit IEEE floating point format top gateoverflow.in/37652
Q: The decimal number -0.329 x 2^15 is to be represented using a 16 bit floating point format without normalization as
shown above. mantissa is pure fraction in sign magnitude form. Answer using rounding off is..
My Try: As it is 16 bit IEEE , so we should use [Exponent - 63 = 15] (coz, without normalization) which gives E = 78.
I dont know why they grouped 3-3 bits, so even if we group them by three.. So, 4th digit should br 1 and not 5.
Suppose there is unpipelined processor with a cycle time 30 ns which is evenly divided into 5 pipeline stages. The total latch
latency of the pipeline will be _______________ ns (integer value only)
5.116 Instruction Format: Max number of one address instruction, when two
address instruction is given is? top gateoverflow.in/16361
A computer uses expanding opcode. It has 16 bit instructions 6 bit addresses, it supports one address, two address
instructions only. If there are n two address instructions, the maximum number of one address instructions are?
Since, 6 bit addresses are used, and we have n two address instructions it would take 26 × 26 × n encoding.
Given, only one address and two address instructions are present. So, all remaining encoding can be used for one address
( )
instructions which will be 216 − 212 × n which will correspond to 216 − 212 × n /26 = 210 − n × 26 one address instructions as
address field needs 26 bits.
http://www.personal.kent.edu/~aguercio/CS35101Slides/Tanenbaum/CA_Ch05_PartII.pdf
16 bit instruction
6 bit address
Until user close the application, it keeps looping itself. So the address on the stack should be 1024 and not 1028.
Consider a system employing interrupt driven input/output for a particular device that transfers data at an average of 16
KB/s on a continuous basis. Assume that interrupt processing takes 50 μsec (i.e., the jump to the interrupt service routine
(ISR), execute it and return to main program). The fraction of processor time is consumed by this input/output device if it
interrupt for every byte is ______ (upto 3 decimal places).
Selected Answer
Device interrupts for every byte and it can send 16KB/sec at a time, so time taken to send 1 byte= 1/(16*10 3)=
0.0625msec
So, fraction of time consumed by I/O device if it interrupts for every byte= time taken to process interrupt / time taken by
device to send data= 50 * 10-6 / (0.0625 * 10 -3) = 0.8
P.S as per hint in question (upto 3 decimal places).. so they are considering 1KB= 2 10 bytes. Hence, answer might vary
accordingly i.e 16*210 * 50*10 -6 = 0.819
MOV R1,5000
MOV R2,2000
ADD R2,R2,R3 //Interrupt raised here, Mem Add of this instruction is 1008
Now when ISR is served and program resumes from ADD instruction(1008), R1 and R2 will have different values then
intended. How is it taken care of?
case 1: All register values are stored before interuptt and replaced.
case 2: Program begins execution from MOV R1,5000 after interuptt is served.
interrupts stack
the answer is in how interrupts are handled in cpu. after every instruction the interrupt flag are checked. if there is a
interrupt then all the values of register and as well as program counter are stored in special registers. and the interrupt
vector address is pushed onto the stack. and after the service . all the pc and the registers are again set to the earlier
position ,and no need to restart the program.
Can someone explain that will Interrupt Service routine will also follow that time sharing environment like other normal
processes in system.?
I think not. But i want to know difference in execution of normal process and Interrupt subroutine.
@Arjun Sir
interrupts
interrupts follow time sharing approach ? the answer depend on the situation.
basically interrupts are of two types hardware and software. the hardware interrupts like cpu overheating will never follow
time sharing. they have to services as they can cause the failure of the cpu. but if a interrupt is generated by a process
definitely it will be context switched as the process will be pre empted. what matter here is the priority of interrupt. a flag
is used to do so.
Higher-priority interrupts can preempt interrupts that have lower priority. To allow you to control preemption, use the preemption flags to specify whether an interrupt can be
preempted.
how interrupt handled is simple. interrupt is just a piece of code which is present at a special address. whenever an
interrupt occur cpu just go to that address, and execute that code. so a process generated an interrupt the cpu has to
execute that code first it goes to that address which i think is called "vector address". if it is a software interrupt it can be
preempted if the process can be preempted by the cpu and on the return the cpu will start servicing the interrupt where it
has left it.
5.121 Io: Direct memory access is used for high-speed I/O devices. top gateoverflow.in/27032
Why this happens.what is co relation between speed of I/O and DMA transfer becoz anyway DMA is more efficient than other
modes such as interrupt driven, so why its not efficient for slower I/O devices?
co&architecture io dma
Memory Mapped IO
IO Mapped IO
io-organization
5.123 Lockup Free Cache: Which of the following is true in case of lock up
free cache? top gateoverflow.in/21222
1. A cache structure allows a Cpu to access a cache while a hit is being serviced
2. A cache structure allows a Cpu to access a cache while a miss is being serviced.
And why?
cache-memory lockup-free-cache
5.124 Look Aside: Write Back and Write Through top gateoverflow.in/35154
A 64 word cache and main memory are divided into 16 word blocks. The main memory access time is 50 ns/word and the
cache access time is 10 ns/word. Hit ratio for read operation is 80% and for the write operation is 90%. Whenever a cache
miss happens, associated block must be brought from main memory to cache for both read and write operation. Let there be
40% references for write operations.
1) What is the throughput of the memory system for write through policy?
2) In the above problem if write back updation is used and at any point of time 30% cache blocks are modified, What is
Tavg in write back policy?
Ans for :
2) is 176.4 ns
Selected Answer
For write-back:
In write back, only when a block is being replaced from cache it will be written back to memory. And this write-back is
needed only if the block is dirty. So, for both read as well as write miss, 30% of time the block must be written back to
memory.
Tavg = hr × tc + (1 − hr) × (tm + tc + 0.3 × tm) = 0.8 × 10 + 0.2 × (800 + 10 + 240) = 218ns
R
5.125 Look Aside: Computer Org- write trhough and write back top gateoverflow.in/34061
co&architecture look-aside
top gateoverflow.in/28620
machine-instructions
Consider a hypothetical processor which support both 1 address and zero address instruction. It contain 6 bit instruction and
four bit address if there exists 2 one address instruction than how many zero address instruction can be formulated?
co&architecture machine-instructions
Selected Answer
There are 2 one address instructions, which would take 2 × 24 = 32 encodings as an address is of 4 bits. The remaining 32
encodings can be used for zero address ones and since they don't need any address part, each of them can be a separate
instruction. So, answer should be 32.
top
Assume that execution of 200 instructions on a 6 staged pipeline where the target address is available at 4th stage.Let X be
the probability of an instruction not being branch. The value of X such that speedup is atleast 5 is ________ ?
----------------------------------------------------
Doubt:
=> I know the normal method i.e. K stages / (1 + Branch freq * Stall cycles) = Speedup which yields near to
exact answer.
=> But I am unable to get the answer by : ( K stages * N instructions ) / [ (K + N - 1) + (freq * stalls) ]
Selected Answer
Got it! Actually in second method I was directly considering the probability. But, its a percentage of number of instructions
which have taken the branch.
Hence, (200 * 6) / [205 + (Y/100 * 200 * 3)] Which gives Y around 6% and so our required X would be 94% which is
Speed up is at least 5.
(Nonpipelinedtime)
Pipelinetime
So , 5 ⩽
Here , target address is available at the 4th clock cycle. So , if we execute any instruction at the 1st clock cycle , we would
need to wait till 4th clock cycle to get the output. So, this is stall. So , stall cycle = (4-1) =3
So ,
(6 )
5 ⩽ (1 +stallfrequency∗ stallpenalty)
(6 )
5 ⩽ (1 + (1 −stallfrequency) ∗ stallpenalty)
(6 )
5 ⩽ (1 + (1 −X) ∗ 3 )
Suppose that in 250 memory references there are 30 misses in first level cache and 10 misses in second level cache. Assume
that miss penalty from the L2 cache memory 50 cycles. The hit time of L2 cache is 10 cycles. The hit time of the L1 cache is 5
cycles. If there are 1.25 memory references per instruction, then the average stall cycles per instruction is ________.
answer given-4
madeeasy-testseries co&architecture
= ( 30/200)*10 +(10/200)*50 =4
first 1.25 memory references per instruction means total no. of instruction is 250/1.25 =200 instructions
Now total cycle required to execute all instruction
220*L1{Hit time} + 20*L2{Hit time} + 10*l2{penalty time}
220*5+20*10+10*50=1800 cycles
How many 512k x 8 static RAM chips are needed to design the 2M x 32 memory module.
a. 32 b. 8 c.16 d.64
No of chips=2M*32/512K*8
=2^26/2^22
=2^4
=16
If there is k-set associative cache, with total x cache blocks, and 2^n main memory locations, how is the mapping
calculated?
Selected Answer
Calculate no of sets(p)=x/k
In this way consecutive memory blocks will be going to different sets in cache there by making use of spatial locality.
Assume that a 16 bit cpu is trying to access a double word starting at an odd address.how many memory operations are
required to access the data?
a) 1 b ) 2 c) 3 d) 4
memory-interfacing
Selected Answer
Consider a direct mapped cache of size 16 KB and block size is 4 words. The word length is 16 bits. Find the number of bits needed for cache indexing if CPU
generates 32 bit address
memory-management
Selected Answer
no of blocks =16kB/8=2048
but as i searched over google it's says that index meas only (block offset)...so 11 bits should be the ans...
http://cs.stackexchange.com/questions/13356/how-to-calculate-the-tag-index-and-offset-fields-of-different-caches
Let cache of 0.7 hit having average access time 9 times faster than that of memory. if average access time increases 40%
from 80ns. What would be new hit ratio.
My answer is 0.74
Am i correct?
800
80 = x + 0.3 × 9x x = 37
800 7200
1.4 × 80 = 37 + (1 − h) 37 h = 0.53
Consider two cache organization: the first one is 32 kB 2-way set associative with 32 B block size. The second one is of the
same size but direct mapped. The size of an address is 32 bit in both cases. A 2 to 1 multiplexer has latency of 0.6 ns while a
k-bit comparator has a latency of k/10 ns the hit latency of set associative organization is h1 while that of the direct
mapped one h2
Q.12 th value of h1 is
A. 2.4ns b. 2.3 ns
c. 1.8 ns d. 1.7 ns
12. Op-a
= 2.4 ns
=17/10 = 1.7 ns
co&architecture memory-management
A micro instruction is to be designed to specify none/one of the three micro operations of one kind and none or upto 6 micro
operation of another kind. The minimum number of bits in the micro instruction is -
co&architecture microprogramming
Selected Answer
a micro programmed control memory supports 256 instructions .Every instruction on average consume 8 micro operations
.The system supports 16 flag conditions and 48 control signals.If the horizontal micro programming is used,what is the size
of each control word let 1 address control instruction is used.
co&architecture microprogramming
Selected Answer
No of control words=256*8=2048
microprogramming
Option C : 7 Bits
If we use only Vertical micro programming here then we have to use atleast 2 decoders => Min number of bits required will be 7.
log 2x + log 2y = 25
If we take x = 2 and y = 5, it's minimum, will generate atmax 2 parallel signals and also we can represent all 25 control signals.
Ques:-
Control field of microinstruction contain two groups of control signal group 1 supports none or one of 64 control signals and
group 2 supports at most 6 from remaining. What is size of micro operation?
co&architecture microprogramming
It means that there are total 64 control signals available in the Control Unit, and there are two groups considered here.
One group will have either none or one control signal from the given 64 signals. The other group can have at most 6
control signals from the remaining 63 signals, if the previous group used one signal, or from 64 signals, if the previous
group didn't use any signal.
5.140 Microprogramming: Q-13 (ch-2) Made easy workbook 2015 top gateoverflow.in/18870
The control field of 1-address control word has to support 2 groups of control signals.In the group-1 it is requires to generate
either 1 or none of the 63 control signals.In the group-2 at most 4 from the remaining.What will be the minimum no. bits
needed for control field.
option (A) 6
option (B) 10
option (c) 67
microprogramming co&architecture
Selected Answer
ONE
log2 N
microprogramming
Selected Answer
if no data is said , micro programming also takes same number of instruction per clock cycle
here it will be ONE
5.142 Microprogramming: How many and what size of field exits in micro
operation field? top gateoverflow.in/16485
If a micro program supports 46 micro operations with parallelism of 2, how many and what size of field exits in micro
operation field?
co&architecture microprogramming
Selected Answer
parallelism is 2
so we divide operations into two sets of 16 and 30 so that requires 4 and 5 bits so total 9 bits
consider a micro programmed control unit each of which takes 16 micro operations.The system supports 16 flag conditions and
54 control signals .If horizontal microprogramming control is used then what is the length of control word(bits/word)?
microprogramming
Selected Answer
the no. of bits in control word = no. of bits for flag + no. of bits for control signal + no.of bits for control memory
bits for control memory = log2(no. of instruction * no. of micro operation per instruction) = log2(total micro operations)=
log2(16)= 4
Direct mapped
8 words total cache data size
2 words block size
A sequence of eight memory read is performed in the order shown from the following addresses:
0 , 11 , 4 , 14 , 9 , 1 , 8 , 0
Calculate
1. No. of misses
2. No of compulsory misses
3. No. of conflict misses
4. No. of capacity misses
So, the corresponding block numbers will be: 0, 5, 2, 7, 4, 0, 4, 0 (000, 101, 010, 111, 100, 000, 100, 000)
Next 0 is a conflict miss as 4 has replaced the previously accessed 0. It is also a capacity miss as after the previous
access to 0, we have 4 unique block accesses and we have capacity only for 4 − 1 = 3 more.
No. of misses = 8
Will conflict misses increase if k-way set associative cache is used and we increase the cache capacity?
multiplexer
Z1=(ab+a'b')'c' +(ab+a'b')c
=a XOR b XOR c
Z2=(ab+a'b') 'b+(ab+a'b')c
=a'b+a'c+bc
5.147 Number: Which of the following result overflow with 2's complement
arithmetic ? top gateoverflow.in/28431
1. 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1
2. 0 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1
3. 0 1 0 0 0 0 0 0 + 0 1 1 0 0 0 0 0
Please justify your answer. I'm not getting a clue whether the given number is in 2's complement . Should I have to find
2's complenet of the given number or not
number-representation number
Ref.http://sandbox.mc.edu/~bennet/cs110/tc/add.html
a. 81 b. 51 c. 121 d. A1
number-representation
Selected Answer
it will be 9^2=81
In
X=(M+N*O)/(p*Q)
How many one address instructions are required ?
What the asnwer would be if we use 2 address instrction , 3 address instruction and ZERO address instruction
one add
1. PUSH P
2. PUSH Q
3. MUL
4. PUSH O
5. PUSH N
6. MUL
7. PUSH M
8. ADD
9. DIV
10. POP X
One Address
1. LOAD P
2. MUL Q
3. STORE T
4. LOAD O
5. MUL N
6. ADD M
7. DIV T
8. STORE X
Two Address
1. MOV R1,N
2. MUL R1,0
3. ADD R1 ,M
4. MOV R2,Q
5. MUL R2,P
6. DIV R1,R2
7. MOC X,R1
Three Address
1. ADD R1,P,Q
2. MUL R2,N,O
3. ADD R2,R2,M
4. DIV X,R2,R1
Case:-1
When all the pipeline stages are perfectly balanced(uniform delay) then one task execution time in pipelining equal to one
task execution time of nonpipelining.
Ques1:-
If K=No. Of stages =4
Tp=2ns and
N= no. Of instruction =1
Case:-2
When all the pipeline stages are not perfectly balanced(non uniform delay) then one task execution time in pipelining greater
than one task execution time in nonpipelining.
Ques 2:-
Then What are the performance gain and efficiency in both ques?
The following sequence of instruction is executed in a basic 5 stage pipelined processor ( S1, S2, S3, S4 , S5). Assume that
data dependency present in the program is resolved by operand forwarding techniques. Load instruction output present in 4th
stage ALU instruction output is available in 3rd stage. Assume each stage take 1 cycle.
What is the number of instructions must be inserted to achieve CPI = 1 by using operand forwarding.
Selected Answer
You are getting 216, because you are confusing it with LRU. In FIFO you have to take out 8, not 216.
5.153 Pipeline: Please any body know how to prepare all the types of
numerical in cache and pipeline. top gateoverflow.in/198
pipeline
Please read all the topics. If you have any doubt in question you can post here. We shall be posting questions in this topic
by November and we shall try to cover all types of problems.
Assume that each stage takes 1 clock cycle for all the instructions. How many cycles are required to execute the code,
without operand forwarding over a bypass network?
1. 9
2. 10
3. 11
4. 14
pipeline co&architecture
Selected Answer
1 2 3 4 5 6 7 8 9 10 11 12
I1 IF ID EX MA WB
I2 IF ID EX MA WB
I3 IF X X ID EX MA WB
I4 X X IF X X ID EX MA WB
WB and ID can go together in 1 cycle- WB writes to register file in first half of a cycle and ID reads it from the second half.
This is a common technique and need not be explicitly given in question. So, answer is 12 cycles without operand
forwarding. (Suppose this answer is not there in choice for GATE, we can do WB and ID in separate cycles and get the
answer in choice. But for previous GATE questions this was never the case).
1 2 3 4 5 6 7 8 9
I1 IF ID EX MA WB
I2 IF ID EX MA WB
I3 IF ID X EX MA WB
I4 IF X ID EX MA WB
A program executes on a non-pipelined processor in time t. The same program is executed on a m-stage pipelined
processor, with each stage delay d. Then, how it is that the execution time of the program on the pipelined processor is
given in terms of t, m and d as follows
I understand the term "d * m" but how can we have this term " t / m". I can't understand the logic behind this term. Please
explain.
pipeline co&architecture
Selected Answer
A program executes on a non-pipelined processor in time t. {means all instruction is executed in t time}
single instruction take time in execution is m*d {number of stage m, each stage delay is d}
So number of instruction is t/(m*d)
So [t/(m*d) -1 + m]*d
open bracket (t/m-d+m*d) {this is execution time on pipeline}
I think they calculated whole things wrong.. with operand forwarding answer is 9,but they drew wrong diagram..and without
answer will be 14.as we can use id stage under wb stage. so answer shoyld be 5. @arjun sir.
pipeline co&architecture
Overflow only
pipeline co&architecture
Selected Answer
total 9 cycles.
https://courses.cs.washington.edu/courses/cse410/05sp/lectures/cse410-10-pipelining-a.pdf
pipeline
Selected Answer
With pipelining we can have an instruction completed every cycle assuming we handle pipeline hazards. I assume the 2ns
overhead given takes care of it. So, we can have CPI = 1.
pipeline
Selected Answer
We cannot design a pipeline without the buffer registers . Therefore in between every pipeline stage there will be a
register buffer taking 20ns each . Therefore the time taken to complete first instruction is 100 + 20 + 100 + 20 + 100
+20 = 360 ns .
5.160 Pipeline: How will the compiler reorder the below statements so that it
doesn't have any stall cycle ? top gateoverflow.in/15588
How will the compiler reorder the below statements so that it doesn't have any stall cycle ?
pipeline
can we shift the sub instruction down to branch so that store will not be fetched since ID stage of Branch and If of sub will
overlap
and in ID satge Branch change the pc value and will transfer the control to loop if true .
5.161 Pipeline: Assume that 20 of the dynamic count of the total 100
instructions executed for a program are branch instructions. top gateoverflow.in/15589
Assume that 20 of the dynamic count of the total 100 instructions executed for a program are branch instructions. Delayed
branching is used, with one delay slot. Assume that there are no stalls caused by other factors. First, derive an expression
for the execution time in cycles if all delay slots are filled with NOP instructions. Then, derive another expression that reflects
the execution time with 70 percent of delay slots filled with useful instructions by the optimizing compiler.
pipeline
Selected Answer
If 70%stall filled with useful instructions i.e. no stalls due to these 70% instructions, for rest 30%instructionder will be 1
Stall cycle,
add $so,$to,$t1
sub $t2,$S0,$t3
2.Write to register file in first half and read from second half in clock cycle my timing dig goes like this
add IF ID EX MEM WB
NOP
NOP
IF ID EXE .....
pipeline
This will be the timing diagram. Three stall cycles are needed to ensure WB is completed before the ID stage of the SUB instruction. This assumes Register File
read is performed during the ID stage of the pipeline.
5.163 Pipeline: how many stall cycles in this system on cache miss ? top gateoverflow.in/18602
A pipelined processor with separate instruction and data cache has 5 stages with a cycle time of 30 ns. It is used with copy-
back data cache with block size of 1 word. T(cache)=30ns ans T(RAM)=80ns. Hit ratio for cache is 90%. In this cache, if
missed word is not passed to the processor until entire block is received from ram.
Q.1. How many stall cycles occur when memory access instruction misses in cache?
A) 1. B) 2. C) 3. D) 4.
What I thought was if a normal hit takes 30ns of IF then on miss it should take (block movement + IF from cache) i.e.,
({80+30} + 30) ... which will inturn give extra time of 110 ns resulting in 4 stall cycles. But the answer given is different.
And based on 1st qstn only you are able to solve second one.
We are asked the no. of stall cycles when MA misses in cache. So, lets find the time on a cache miss:
Time on cache miss = Time to access cache + Time to access RAM for a cache block (block size = word size given in
question) = 30ns + 80ns = 110ns.
"word is not passed to the processor until entire block is received from ram"
So this should mean we have to add one more cache access time - 30ns, and total time on cache miss = 140ns.
So, there will be stall for (140 - 30)ns which will be 4 clock cycles as CPU is operating at 30ns and each stage can use
30ns without causing a stall.
2. We have hit ratio for cache- but without knowing the average no. of memory access per instruction we can't calculate
the throughput.
Consider an instruction pipeline which has speed up factor IO. While operation with 80% efficiency. what could be the no. Of
stages in the pipeline?
a. 8 b. 10 c. 11 d. 13
co&architecture pipeline
On getting some instructions and stages How can one construct pipeline cycle
Eg:
I1 : LOAD R0,loc
I2 : ADD r0,r0
I3 : Add r2 , r0
Stages
Instruction Fectch
Instruction Decode
Execute
Memory Access
Write Back
pipeline
Selected Answer
That's the simplest way to take care of dependency. For pipeline to run without any problem for any instruction, it should
not have any dependency with 'k' neighboring instructions where 'k' is the number of pipeline stages. If there is a
dependency from ith stage to jth stage (i < j), j-i-1 delay slots (pipeline stalls during these) are introduced so that ith
stage eventually gets the required data from jth one.
For the given code, I2 depends on I1 for R0. More specifically ID stage (during which register is read) of I1 depends on
WB stage of I0. So, (5 - 2 -1) = 2 delay slots are needed.
I3 also depends on I2. More specifically ID stage depends on WB stage (when registers are updated) of I2. So, again 2
delay slots are needed.
If we can do operand forwarding- where the required data is directly passed from a stage to a stage of new instruction, we
can avoid stalls in many cases. For this example, we can pass data from Memory Access Stage to EX stage for I1-I2 (this
still requires 1 delay) and from the output of EX stage of I2 to EX stage of I3 (no more stalls required).
Consider 2 pipelines A and B where pipeline A having 8 stages of uniform delay of 2 ns. the pipeline B is having 5 stages
with respective stage delays 2 ns, 3 ns, 1 ns, 2 ns ,2 ns. How much time ia saved if 100 instructions are pipelined using A
instead of B.
a. 90 ns b. 98 ns c. 88 ns d. 0 ns
co&architecture pipeline
Selected Answer
N=Number of instructions
K=Number of stages
tp =time period for the clock cycle in pipeline ={ MAX(t i) from i=1 to k + Buffer delay }
For A
=214 ns
For B
=312 ns
5.167 Pipeline: Risc Pipelining, CPI (cycles per instruction) top gateoverflow.in/30006
In a pipelined RISC computer where all arithmetic instructions have the same CPI (cycles per instruction), which of the
following actions would improve the execution time of a typical program?
III. Doubling the sizes of the instruction cache and the data cache without changing the clock cycle time
(A) I only (B) II only (C) III only (D) I and II (E) I and III
pipeline
Correct me if wrong...
1. True
3. True, bcz larger cache size will hold more data..leads to low cache miss.
A pipeline P operating at 400 MHz has a speedup factor of 6 and operating at 70% efficiency. How many stages are there in
the pipeline?
A. 5
B. 6
C. 8
D. 9
Number of Stages = 9
1 A k single port
0 B k dual port
The pipeline allows all instructions except memory based instructions. If 2 memory operations can not be done in same
clock. The penalty is 1 clock. Let there are 20% memory instructions obtain S a/Sb
co&architecture pipeline
A 4-stage pipeline has the stage delays as 150,120,160 and 140 nanoseconds respectively . Registers that are used between
the stages have a delay of 5 nanoseconds each .Assuming constant clocking rate,the total time taken to process 1000 data
items on this pipeline will be
a)120.4 microseconds
b)160.5 microseconds
c)165.5 microseconds
d)590.0 microseconds
co&architecture pipeline
Maximum stage delay will be 160 ns and 5 ns uniform delay register are being used . so total time for each stage should
be 165ns so that every stage can work well.
tp = 165ns
option c
pipeline
http://gateoverflow.in/8560/gate2015-3_51
5.172 Preparation: Can Anyone tell me to what depth should I cover the book
Computer Organization and Embedded systems(6th edition)? top gateoverflow.in/42173
I am reading Computer Organization and Embedded systems(6th edition).Do I have to read Ch 1-3,5,6,8,9 completely?
Specifically do I have to read Chapter 9( Arithmetic) completely?
preparation
Don't read blindly . check previous year quetion then u have idea about what u have to cover from book or what not .
Hard Disk
DVD Disk
Keyboard
Printer
CPU Temperature Sensors
priority io-organization
Selected Answer
CPU Temperature Sensors > Hard Disk > DVD disk > Printer >Keyboard
5.174 Ram: How many 2K x 8 RAM chips are needed? top gateoverflow.in/4755
memory-interfacing ram
Selected Answer
(3) A RAM chip has 2K rows of cells to select (each row has 8 cells of 1 bit each which will always be selected together).
So, we need 11 bits to select any of these 2K rows.
(4) 16-11 = 5 address lines will be used to select the appropriate RAM chip(s)- 5 address lines to select 128 chips doesn't
seem logical but this is how multi-byte words can be fetched from memory in parallel. At any time 4 RAM chips will be
selected together and a byte can be fetched in parallel from all these, resulting in 4 bytes being fetched in 1 memory
cycle. (See (s) in the question)
(5) We use 5 address lines to select the RAM chips. So, decoder needs to be 5 to 32.
(A) choice.
5.175 Ram: how many address lines are needed to access RAM chips gateoverflow.in/15027
top
if each address space represents one byte of storage space , how many address lines are needed to access RAM chips
arranged in a 4 X 6 array ,where each chip is 8K X 4 bits ?
ram
Selected Answer
see in the array there are 6*4 =24 chip so to address them we need 5 bit .
and this is bye addressable "each address space represents one byte of storage space" .
5.175 Ram: How many 256 X 4 RAM chips are needed to organize a memory
of capacity of 32KB? top gateoverflow.in/14672
Selected Answer
256 x 4 bits is the capacity of a chip. So, to get 32 KB = 32 * 8 kbits = 218 bits we need
2 18 2 18
256 ×4 10
= 2 = 28 = 256
nd we have ram chips of 256*4. which means there are 256 rows in the ram with 4 bits in each row that is one nibble of
data.
so answer is divide and remember always divide the * part separately which means don't involve the in division 4 with
2^15. use it in dividing 8 so here we go
2^(15-8)*2
which is 128*2
this actually means we will be needing 128 rows and 2 columns of 256*4 chips
in case they ask the rows and columns there it will be needed
5.176 Ram: full syllabus test-10 adv. level MADEEASY top gateoverflow.in/38332
A RAM chip has 32 rows and 16 columns each with a single bit. The number of address line input required to gain unique
addressing to every location is __________ .
FOR UNIQUE ADDRESSING WE HAVE TO GIVE ONE INPUT TO EACH AND EVERY CHIP
What are some of the user friendly books for "computer organisation and architechture" which are best for self study. Such a
text that one can grasps the big picture, and understandhow various things are fitting with each other.
Topics include: machine instructions and addressing modes, ALU and data path , cpu control design, memory interface, I/o
interface (interrupt and DMA mode), instruction pipelining, cache and main memory.
Thanks
top
Consider a magnetic disk drive with 8 surfaces, 512 tracks per surface, and 64 sectors per track. Sector size is 1 KB.The
average seek time is 8 ms, the track-to-track access time is 1.5 ms, and the drive rotates at 3600 rpm. Successive tracks in
a cylinder can be read without head movement.
Estimate the time required to transfer a 5-MB file.
secondary-storage
Selected Answer
MB means we need 10 cylinder, so 9 times tack to track access time needed in order to access 10 cylinder. i.e. transfer
time + 9*track to track access time 1 track transfer time = 8*60/3.6 ms = 133.33 ms
Total time = seek time + 10*(per Tack transfer time + Rotational latency) + 9*(track to track access time)
The time delays of 4 segments are 60 ns, 70 ns, 100 ns and 80 ns respectively. Interface registers are have the delay of 10
ns. what is the speed up?
Selected Answer
= 310/110=2.818
≃2.9 option A
A nonpipeline system takes 50 ns to process a task. The same task can be processed in a six segment pipeline with a clock
cycle of 10 ns. determine the speed up ratio of the pipeline for 100 tasks.
Selected Answer
speedup
5.182 Stack: Is stack pointer affected by conditional branch? If no, why? top
gateoverflow.in/16358
A computer uses expanding opcode. It has 16 bit instructions 6 bit addresses, it supports one address, two address
instructions only. If there are n two address instructions, the maximum number of one address instructions are?
stack co&architecture
Selected Answer
No for conditional/unconditional JMP but Yes for conditional/unconditional CALL. Stack is used for current activation record
and this is per function. i.e., in each function memory for local variables are assigned with respect to SP and so whenever
there is a CALL, SP must be updated and not otherwise.
stall pipeline
1 RAW hazard present btwn last two instruction --> DATA HAZARD
PLZ check!!
I1 IF ID OF PO WB
I2 IF ID OF PO WB
I3 IF ID ---- OF PO WB
I4 IF ID OF PO WB
1 2 3 4 5 6 7 9 10 11 12
8
I1 F D OF PO WB
I2 F D OF PO WB
I3 - - F D OF PO WB
I4 F D OF PO WB
stall in pipeline at clock cycle 3 and 4 due to structural dependency (due to shared Instruction and data caches, OF and IF
of two instructions cannot happen in same clock cycle) and in 8 and 9 due to data dependency
so ans is d
lw R2, 100(R5)
sw R2, 200(R6)............ with out any bypass paths how many cycles does the sw instruction.. need to stall for? 5 stage
pipeline
pipeline stall
IF ID EX PO WB
IF - - - ID PO WB
http://gateoverflow.in/3547/gate2006-it_8
cycle stealing
Consider a machine with 10 ns clock and it takes 4 clock cycle per ALU instruction, 5 clock cycle per branch instruction, 6
clock cycle memory instruction. There exists 40% ALU instruction, 20% branch instruction, and 40% memory instruction.
What is throughput of pipeline system if overhead is 2 ns? ______________ MIPS (integer value only).
Selected Answer
10 − 6
50×10 − 9
So, MIPS = = 20.
The no. of cycles are different for ALU, branch and memory instructions. But do they affect pipeline throughput? - depends
on data and structural hazards.
Do branch instruction affect pipeline- yes and depends on branch prediction and how much delay each branch causes. I'm
not able to calculate this based on information in question (where is the question from?)
Assuming everything is neglected or included in overhead, with pipeline we complete 1 instruction every clock cycle. i.e.,
10 − 6
−9
MIPS = 12×10 = 83.33.
83 MIPS
Avg time for 1 instruction non pipeline= (40% * 4 + 20% * 5 + 40%*6)10 ns =5* 10 ns =50 ns
Avg time for 1inst in pipeline would be just 10 +2 = 12 ns
12 ns --> 1 inst
x= 12 ∗ 109 = 83MIPS
@Arjun sir, I solved it by using the same concept of gate 2003 78,79 ..but techtud marked it as wrong..this qs has only one
confusion which is how to use page table walk and tlb update...I used it in the part of L3 ache miss of Tlb miss.. and used
this formula ...
Tavg = Tlb hit( Tlb time +L1 hit (cache time) + L1 miss(L2 hit(cache time) + L2 miss( L3 hit (cache time) + L3 miss(cache time+memory time ))))
+ Tlb miss(Tlb time + Memory time + L1 hit (cache time) + L1 miss(L2 hit(cache time) + L2 miss( L3 hit (cache time) + L3 miss(cache time+ page table walk and Tlb update ))))
Selected Answer
Problem of using formula- we must know what's the use of a page table. It is to get actual physical address. TLB is a quick
look-up for page table.
Regarding question- it's a really well framed question like in GATE. Only issue is for me to read the small font.
So, memory access works like this - First look in cache and then go to RAM. But before looking in cache we need physical
address- because cache uses physical address as given in question. (it can use virtual addressing or virtually index and
physical tag also but this question is clear- physical index, physical tag).
Now what happens when a TLB miss happens? We look in page table which is in main memory. Can this page table be
cached? Yes, quite often. So, determining the time becomes complex. But see the question- it directly gives the time
during a TLB miss- so we are saved. Page walk just means looking up in page table.
If you haven't understood so far I suggest to better skip this portion for GATE. There is no use other than
getting negative if you read below without understanding above.
Average memory access time = Avg. address translation time + Avg. data access time
= (0.95 × 1 + 0.05 × (1 + 200)) + 0.95 × 1 + 0.05 × 0.80 × (1 + 8) + 0.05 × 0.2 × 0.5 × (1 + 8 + 50) + 0.05 × 0.2 × 0.5 × (1 + 8 + 50 + 100) = 11 + 0.95 + 0.36 + 0.295
Time = TLB access time + Miss rate TLB * TLB update time + L1 access time + Miss Rate L1 * L2 Access Time + Miss Rate of
L1 * Miss Rate L2 * L3 Access Time + Miss rate L3 * Memory Access time
Suppose TLB used in one level paging system with each look-up time of TLB 40 msec. Memory reference takes 120 msec. If
the effective memory reference time is 180 msec then page table references are found in TLB is ______
co&architecture tlb
Selected Answer
x = 0.8333
A disk has 16 equidistant tracks. The diameters of the outermost and innermost tracks are 16 cm and 1 cm respectively. The
innermost track has got the capacity of 20 MB. The total amount of data which can be stored on the disk if the drive rotates
at constant speed is ______________ MB (integer value only).
{capacity of each track is equal or outermost track has capacity greater than innermost track?? }
track co&architecture
why this qs has no effect of two level paging??i dont know if the answer given by madeeasy is right..
virtual-memory co&architecture
= 64 MB
For D1
1st instruction will take 3+2+4+2+3 = 16ns
rest 99 instruction will take 99*4=396
Hence total: 16+396=412
For D2
1st instruction will take 2+2+2+2+2+2+2+2 = 16ns
rest 99 instruction will take 99*2=198
Hence total: 16+198=214
Hence, 412-214=198 according to me
Where am I going wrong?
Selected Answer
u have taken everything right . But u missed that in a pipeline . the clock is set such that the maaximum stage can
complete . so in the starting 1st instruction everything will be 4ns . = 20ns .
20+396 = 416ns
416-216= 202 ns .
D1:
k = 100 , 5 stages , Stage Latency = 4ns
Total Time = (k+n-1)*t = (100+5-1)*4 = 104*4 = 416 ns
D2 :
k = 100 , 8 stages , Stage Latency = 2ns
Total Time = (k+n-1)*t = (100+8-1)*2 = 107*2 = 214 ns
An unpipelined processor has got the cycle time of 15 ns. Now the processor is pipelined into three stages and 15 ns is
divided among three stages as
Stage 1: 6 ns
Stage 2: 5 ns
Stage 3: 4 ns
The latch latency is 2 ns. Now the cycle time of new processor will be _______________ ns (integer value only).
write_through
Consider a two level memory hierarchy. L 1 (cache) has an accessing time of 10 ns and main memory has an accessing time
of 20 ns. Writing or updating contents into their memory takes 20 ns and 30 ns for L 1 and main memory respectively.
Assume L1 gives misses 80% of the time.
The average writing time for system (in ns) if it uses WRITE-THROUGH technique is ______.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------
Here I think answer should be 30, as in write Through Main Memory is updated no matter what !
Answer should be 30, as in write Through Main Memory is updated no matter what !
Array A contains 256 elements of 4 bytes each. Its first element is stored at physical address 4,096. Array B contains 512
elements of 4 bytes each. Its first element is stored at physical address 8,192. Assume that only arrays A and B can be
cached in an initially empty, physically addressed, physically tagged, direct-mapped, 2K-byte cache with an 8-byte block
size. The following loop is then executed.
for (i = 0; i < 256; i++)
A[i] = A[i] + B[2 ∗ i];
During the execution of the loop, how many bytes will be written to memory if the cache has a write-through policy?
a. 0
b 256
c 1024
d 2048
co&architecture
Halt instruction when executed change the program counter to it's own address.
I couldn't understand why to add average rotational latency. I think that transfer time of sector should be just 6 microsec. If
the same question comes in GATE what should I write?
co&architecture
10000 = 60 seconds
1 round = \fraction6010000seconds
confusing.
Consider an instruction pipeline with five stages without any branch prediction: Fetch Instruction (FI), Decode Instruction (DI), Fetch Operand (FO), Execute
Instruction (EI) and Write Operand (WO). The stage delays for FI, DI, FO, EI and WO are 5 ns, 7 ns, 10 ns, 8 ns and 6 ns, respectively. There are intermediate
storage buffers after each stage and the delay of each buffer is 1 ns. A program consisting of 12 instructions I1, I2, I3, …, I12 is executed in this pipelined
processor. Instruction I4 is the only branch instruction and its branch target is I9. If the branch is taken during the execution of this program, the time (in ns) needed
to complete the program is :
1. 165
2. 190
3. 215
4.328
All instructions before I4 will be pipelined & then I9-I12 will be pipelined so . Tp = maxt + delay = 11
T = (n1-1+n2-1+2*k)*Tp , n1 is first 3 instruction and n2 is 4 instructions from 9-12 , k is total stages in pipeline
Selected Answer
total = 11..
A byte-addressable memory organized in 32-bit words according to big-endian. A program reads ASCII characters and stores
them in successive byte locations, starting at location 1000. Show the contents of memory words at locations 1000,1004 for
name “ Johnson ” .
Each word has a unique address and we have 32-bit word. So why cant we take 8-bits for each letter and store 4 letters per
word.Thus we need only 2 addresses..
What is correct?
3 RAW dependencies
or
co&architecture
visit :
http://cs.stackexchange.com/questions/47622/read-after-writeraw-hazard
Consider the following set of instructions executed by 8085 microprocessor MOV H,20 MOV L,10 MOV E,00 XCHG After the
execution, the contents of E register will be ______________ (integer value only).
co&architecture
There are two processor M1 and M2. M1 uses four pipeline stages with the delay of respectively stage as 6 ns, 4 ns, 7 ns, 5
ns. M2 has got 7 pipeline stages with the delay of cache stage 4 ns. Then pick the correct option for executing 200
instructions on M1 and M2.
co&architecture
Selected Answer
none
During fetch phase, the PC is incremented by one. The incremented value is available after Fetch phase.
consider a case where 4-segment pipeline with a clock cycle time 20 ns in each sub operation to execute 100 tasks .Assume
that a non pipeline unit that can perform the same operation .Pipeline system will take how much time to complete task?
Selected Answer
Additional :
Time taken by Non Pipelined System = Number_of_Task * (Cycle_Time*Number_of_Stages)
Time = 100 * 20*4 ns = 8000 ns
A computer has a cache, main memory and a hard disk used for virtual memory. If referenced word is in cache, 20 ns are required to access it. If it is in main
memory but not in cache 60 ns are needed to load it into cache and then reference is started again. If word is not in main memory, 12 ms are required to fetch the
word from disk followed by 60 ns to copy into cache, the reference is started again. The cache hit ratio is 0.9 and main memory hit ratio is 0.6. The average time in
nano seconds required to access a referenced word on this system is ___________.
Solution: 480026
Selected Answer
Caption
now, avg stall/instruction = (misses in L1/instruction )* hit time in L2 + (misses in L2/instruction) * miss penalty in L2
= (150/250)*50 + (100/250)*120
= 78 cycles/instruction
= xy+xy'z'+zy'
= x(y+y'z')+zy'
=x(y+z')+zy'
= xy+xz'+y'z
Suppose a processor does not have any stack pointer registers, which of the following statements is true ? (A) It cannot have
subroutine call instruction. (B) It cannot have nested subroutine calls. (C) Interrupts are not possible. (D) All subroutine calls
and interrupts are possible.
5.213 The bus which is used to transfer data from main memory to
peripheral device is top gateoverflow.in/42602
The bus which is used to transfer data from main memory to peripheral device is
a) data bus
b) input bus
c) DMA bus
d) output bus
c)DMA bus contains both . data bus and address bus. Here CPU collect memory address via address bus
Option D
A 5 stage pipelined processor has instruction fetch (IF), operand fetch (OF). Instruction decode (ID), perform operation (PO)
and Write operand (WO) stages. The IF, ID, OF and WO stages takes 1 clock cycle each for any instruction. The PO stage
takes 1 clock cycle for ADD and SUB instruction, 2 clock cycles for MUL instruction and 4 clock cycles for DIV instructions
respectively. The number of clock cycles needed to execute the following sequence of instruction is ________.
Now , my question is , Here I 1 and I 2 are dependent , so how can they start without any stall , no operand forwarding is also
mentioned.
co&architecture
Yes for I 2 5,6,7 should be a stall.It should have been - or a implicit NOP[no operation] .
if there is one to many relationship from entity set A to B; B has simple primary key and a multivalued attribute, then min
no. of tables satisfying 3NF?
4 tables 2 for entity one for relation one additional for multivalueed attribute
5.218 What will be the size of memory address space for a 16 bit data and 20
bit address bus? top gateoverflow.in/42603
What will be the size of memory address space for a 16 bit data and 20 bit address bus?
a) 1 MB
b) 64 KB
c) 2 MB
d) None of these
A computer system has a main memory consisting of 1 M 16 bit words. It also has a 4 way set associative cache of size 4 K
words and 64 words per block. The number of tag bits are _______.
co&architecture
log((2^20)/(2^12/2^2))
co&architecture
Short version : virtually indexed means that you are determining the set number using the virtual address, and physically
tagged means that the TAG bits are used for determining the hit.
No of sets=128
No of bits in words=32bits
Advanced Pipeline topics Like, collision vector,Forbidden Latency etc to be covered totally from which book??
what I know is the question which has been asked in previous gate as well as this year
is from the basic Pipelining concepts such as Speedup,throughput,Number of cycles ,
frequency etc....
A virtual memory system is able to support virtual address space of 256 GB. An entry
in the page table is 4 bytes long.
(i) Calculate the minimum page size required for a three-level paging scheme.
(ii) Draw a diagram indicating how the bits of a virtual address will be interpreted by
the address translation mechanism. Indicate which bits (and how many) are used to
index the page tables at each level, and which bits form the page offset for the case
above.
co&architecture
Selected Answer
(238 /23P
)*43 <= 2P
244 <= 24P
P >= 11 bit
Consider the hypothetical processor which has 256 words memory. A 19 bits instruction is placed in 1 memory cell. It supports
2-address, 1-address and 0-address instructions. It uses expanding opcode technique. If there exist five 2-address instructions
and 760 1-address instructions, then number of 0- address instructions are _______.
co&architecture
Selected Answer
No. of encoding for 2 address instructions = 5 × 28 × 28 ∵ two 8-bit address fields = 5 × 216.
No. of encoding for 1 address instructions = 760 × 28 ∵ one 8-bit address field.
( )
= 219 − 5 × 216 − 760 × 28 = 28 211 − 5 × 28 − 760 = 28 (2048 − 1280 − 760) = 28 × 8 = 211 = 2048.
There 256 words in memory and implicitly given one word is 19 bit and memory is word addressable.
So, to address memory there require 8bits.
3bit- 8bits- II
opcode 8bits- I address address
Type 2 address=5
Type 1 address=(23-5)*28 =3*256=768-8(this remain 8 addresses can used for type 0 instruction)= 760
co&architecture
Consider a 32 bit microprocessor that has an on chip 16 Kbyte four way set associative cache. Assume that cache has a size
of four 32 bit words. The set number in the cache to which the word from memory location FFFAE8FA is mapped is
_________.
Selected Answer
Consecutive memory blocks will be mapped to consecutive cache sets (from left end, after offset bits we have index bits).
Here we have word addressing as question asks for "word at location". So, number of offset bits = 2. So, next 8 bits are
index bits. i.e., 8FA (top part of address won't affect the set) = 1000 1111 10 | 10
Consider a pipelined processor with the stages IF, ID, EX and WB. IF, ID and WB. Stages takes one clock cycle each to
complete the operation and EX stage depends on the instruction. ADD and SUB need 1 clock cycle. MUL and DIV need 3
clock cycles each. What is the number of cycles needed to execute the following sequence of instructions?
10
11
12
13
ya answer should be 11
Consider a fully associative cache with 6 cache blocks (0 to 5) and the following sequence of memory block requests:
5, 4, 29, 18, 21, 7, 25, 18, 16, 35, 45, 22, 7, 16
If LRU replacement policy is used, which cache block is used for memory block 16? Assume initially 6 blocks are placed in a
cache according to lexicographic order of cache index.
explain in detail...
16 ll be in Block 1
1-4-16
2-29-35
3-18-7
4-21-45
5-7-22
For an unpipelined multicycle CPU clock cycle time = 10 ns. Memory operation, branch operation and ALU operations with
instruction frequencies 40%, 20% and 40% respectively. If pipelining adds 2ns to the CPU cycle time then what is speed up
in instruction executing from pipeline (assume each operation take 5 cycles)
Selected Answer
speed up=50/12
=4.16
5.232 What can I deduce if its given that the processor is 32 or 64-bit
processor? top gateoverflow.in/36040
co&architecture
For 64 bit processor, I think the processor can deal with 64 bits simultaneously or perform operations on 64 bits
simultaneously. This speaks mostly about ALU.
5.232 Which devices should get higher priority in assigning interrupts? top
gateoverflow.in/36211
A main memory has 4096 blocks each consisting of 128 word of 32 bit. memory is word addressable.The number of bits
require for main memory adress is_____________
My Answer is
Given is Word addressable then why to convert it into bytes its just 2 12 * 27 = 219
if its byte addressable and given in words then we convert word to byte
Ans: given as 4K word/(64 x 2 byte) word = 32 number of blocks and then continued.....
my question is if 64 word is multiplied with 2 byte then why not 4K word also??
co&architecture
Selected Answer
for operand fetching (i.e. instruction is present in IR) in indexed mode Effective address= [BaseRegister]+ [Index Register]
Consider the addition of the two numbers 10001110 and 10000000 in an 8-bit ALU. Which of the following best summarizes
the result and the status of the Z(zero), S(sign), C(carry) and O(overflow) flags? Assume that the numbers are represented
in 2's Complement format and that
when you will add the given two numbers , the status of the flag will be ZERO FLAG-: 0, bcoz after addition the ALU
output(acc) is not zero so flag will be reset
SIGN flag-: 0, bcoz MSB bit is not 1 after addition so it will reset
CARRY flag-: 1, bcoz there is an extra bit out of the MSB so flag will be set.
OVERFLOW flag-: 1, bcoz their is a carry out of the MSB ,but not in the MSB so flag will be set
10001110
10000000
........................
the three outputs x1x2x3 from the 8x3 priority encoder are used to provide a vector address of the form 101x1x2x300. what
is the second highest priority vector address in hexadecimal if the vector addresses are starting from the one with the
highest priority
1 0 1 X1 1 0 0 0
The cache memory hit ratios for read and write operations are 80% and 90% respectively.
If there is a miss then 2 word block is to be through from main memory to cache.
Consider 30% updations and the cache access time is 20ns/word and memory access time 100 ns/word. Then calculate the
efficiency of write back and write through scheme
hi all! i am not able to understand why one extra stall is used after WB and EX of second and third instruction..plllzzzz
help..above is the question and its solution.
yes ; you are right .. it has 12 cycles without bypassing and 9 with bypassing...
see this....
http://gateoverflow.in/34735/pipelining-without-operand-forwarding
Given explanation:
I read somewhere that PC value is not incremented when HALT instruction is executed so I guessed the answer to be 1024.
Please check whether my understanding is correct?
co&architecture
The format of a double operand instruction of a CPU consist of 4 bit op-code and 4 bits for source and destination. 12 double
operand instructions and 24 single operand instructions must be implemented. Op-code field must identify the three groups
of n-operand instructions. Calculate the total number of zero operand instructions that can be implemented?
There are total 2^4 = 16 starting nibble value for all instructions, Out of these there are 12 reserved for 2 operand
instructions , for 1 operand instruction we can use 8 bit opcode and 4 bit operand so 24 instructions can be made by 2
values in first nibble and 2^4 bits in second which 2^5 > 24 . So you can only assign 2 values in first nibble for zero
operand instructions and 2^8 values for remaining bits so that total number zero operand instuctions are 2^9 = 512
a byte addressable computer has a small data cache capable of holding eight 32 bit words.Each cache block consists of two
32 bit words.For the following sequence of addresses( in hex), the hit ratio if the two way set associative LRU cache is used
is....
200,204,208, 20C,2F4,2F0,2F4,2F0,21C,218,21C
3/11
5.245 What is hit ratio? (including read and write) top gateoverflow.in/37588
In a system, integer has size of 4 bytes. The system have 1024 KB set associative cache with associativity equal to 2 and
block size of 32 bytes. Consider the program below. Assuming that initially A was not present in cache, cache hit ratio is ____
A[i] = A[i]+2;
A[i + 1] = A[i]+3;
Selected Answer
Consider a tape of length 4m containing 80 parallel tracks and moving with a linear velocity
of 32cm/sec and it employs the recording density of
512 KB/cm-track. If the tape is divided into records of size 8cm and length of the gap
between the records is 2cm, then calculate effective data transfer time.
To calculate effective data transfer rate,do we need to consider the entire length(i.e 32cm) or only recording length? i.e ( for
every 10 cm,recording length is 8cm,hence for 32 cms recording length will be 26cm)
my ans 2.64
Selected Answer
speed up = ET nonpipe/ETpipe
= (4 */3G) / (1/2G)
= 8/3
= 2.66
IF ID EX MA WB LOAD
IF ID EX MA WB LOAD
IF ID - - EX MA WB ADD
IF ID - - - - EX MA WB SUB
IS THIS CORRECT ?
a 8 bit DMA is operating in cycle stealing mode.each DMA cycle is of 6 clock states and DMA clock is 2MHz if the cpu cycle
takes 2microsecond what would be DMA data transfer rate?
co&architecture
they have not given the number of cycles taken by ADD/LOAD..i have taken as 1..correct if i am wrong
The following sequence of instruction is executed in a basic 5 stage pipelined processor ( S1, S 2, S 3, S 4, S 5). Assume that
data dependency present in the program is resolved by operand forwarding techniques. Load instruction output present in 4th
stage ALU instruction output is available in 3rd stage. Assume each stage take 1 cycle.
made-easy test-series
Selected Answer
i can't upload my answer here due to maximum answer lenght. plz check here and comment here only if u find anything
wrong
https://docs.google.com/document/d/1KQVugaIWSz_OIPUFeEFkH6uQlRzSJOIWwqx5r8Tccqg/edit?usp=sharing
Consider 1 GHz clock frequency processor, uses different operand accessing models shown below:
Assume that 2 memory cycles consumed for memory reference, 3 cycles consumed for arithmetic computation and 1 cycle
consumed when the operand is in register(s) instruction itself. The average operand fetch rate (in million words/sec) of
processor is __________ (upto 2 to decimal places).(ANSWER-344.82)
made-easy test-series
Selected Answer
Immediate-1Cycle
Time req for 1 instruction= 2.9*10^9 (Since CPU is 1 GHZ) ==2.9 nano sec
consider a system employing interrupt driven input /output for a particular device..that transfers at avg of 16Kb/s on
continuous basis.assume interrupt pricessing takes 50us(jump to interrupt processing routine execute it and return to main
program ) . Find the fraction of processor time is consumed by this input output device if it is interrupted for every byte
Selected Answer
(1,2)
(1,3)
(2,3)
(2,4)
(3,4)
so as per me too 5
Given a 32 bit processor with 16 MB main memory, 32 KB 4 way set associative on chip cache and block size of 16 words,
The number of tag bits in memory address format are : ?
co&architecture
block size of 16 words = 2^4 (here i have a doubt ,in this qs word size is not given,should i take standard word size 4 B..then block size will be 64 B,then 2^6)
no of blocks = 2^9
so tag bits = 24 - 6- 7 =11 (considering word size as 4 B...dont know i am right or wrong)
I2 MOV r1, r0 1
I3 ADD ro, r1 1
I4 INC r0 1
I5 INC r1 1
I6 ADD r0, r1 1
I7 Store r1, 2
I8 Halt Stop 1
Assume that memory is word addressable with word size 32 bits. Program is loaded into memory location (3000) 10 onwards.
The value of PC at the end of execution of above program is _____
ref : https://en.wikipedia.org/wiki/Memory_refresh
in average read time why hasn't the cache time been added to the main memory time in case of miss?
Assume a simple 5 stage pipeline (IF, ID, DF, EXE, WB) each stage takes a single cycle. How many cycles the following code
takes to execute. If there is no special hardware to improve the performance in presence of hazards?
I1 MOV A, C ; A ← C
I2 MOV B, C ; B ← C
I3 ADD A, B ; A ← A+B
I4 MOV C, A ; C ← A
I5 MOV D, C ; D ← C
I6 MOV A, D ; A ← D
5.264 Calculating average number of cycles per operand fetch top gateoverflow.in/36808
Solution:
co&architecture
A) First 12 bits (0 – 11) specify register operation, last 4 bits (12 – 15) are always 1111
B) First 11 bits (0 – 10) specify register operation, last 5 bits (11 – 15) are always 01111
C) First 12 bits (0 – 11) specify register operation, last 4 bits (12 – 15) are always 0111
D) First 4 bits (0 – 3) are always 0111, last 12 bits (4 – 15) specify register operation
Hit ratio of the cache memory read request is 85% and the cache memory is 5 times faster than main memory. Block size in
memory organization is 4 words. The access time of the main memory is 72 ns per word. Write through protocol
(simultaneous memory organization) is used in the system. CPU generates 60% of the read requests to read the data and
the remaining for write operation. What is the average access time (in ns) of the memory when considering both read and
write operations?
Average time to read is = 0.6 *(0.85*57.6 + 0.15*(288)) since an entire block is transferred so 72*4=288..
So average access time is = Average time to read+ avg time to write.. (U calculate )..
Consider 5 stage pipeline which allow all instructions except branch instruction. Program contain 30% conditional instructions
out of which 75% are branch instruction. Processor stop fetching the following instruction after the branch instruction untill
target address is available. Target address is available at the end of the pipeline stage.
All the stages are perfectly balanced with 20 GHz clock time. The processor is running with rate of ____________ (in MIPS).
Ideal CPI = 1
20∗ 109
1 +0.9
= 10526.31 * 10^6 hence 10526 MIPS
During a program execution out of 1000 memory references there are 250 and 120 misses in L1 (Level1) and L2(Level2)
caches respectively. Hit times for L1 and L2 cache are 24 and 40 cycles respectively. If there are 2.5 memory references per
instruction, how many average stall cycles per instruction? (Assume L2 to memory miss penalty is 250 cycles)?
a)50
b)100
c)150
d)200
Selected Answer
option B is answer.
buffer delay is called as interface delay .if in the question they have mention the buffer delay than we have to consider it.
and usually it is used between two stages to hold the intermediate result..
Consider a system in which cycle takes 500 ns. Transfer of bus control
in either direction, from processor to I/O device or vice versa, takes 250
ns. One of the I/O device has a data transfer rate of 50 kB/s and
employees DMA. Data are transferred one byte at a time. For how long
(in ms) would the device tieup
the bus when transferring block of 128
bytes.??
Selected Answer
Transfer time (in milli second) >>> Setup time (in nano second) // ignore setup time
a computer system that uses memory mapped IO configuration ,has 32 bit address space Address with 1's in the two MSB
refer to devices.WHAT is the MAximum amount of memory IO device and port address that can be referenced in such a
system respectively
means
00
01
10
11
now they say 11 bits refer to devices option C AND D cannot be the answer ,so answer should be in between A and B
now port address is that which is connected to devices and that bits is 11 so 1* 2 30 and rest left as 00 ,01, 10 means 3*230
co&architecture
Here is (R1 in ADD + R1 in SUB ) + (R2 in SUB and same R2 in MUL). So two DATA dependencies.
Hit ratio of the cache memory read request is 85% and the cache memory is 5 times faster than main memory. Block size in memory
organization is 4 words. The access time of the main memory is 72 ns per word. Write through protocol (simultaneous memory
organization) is used in the system. CPU generates 60% of the read requests to read the data and the remaining for write operation.
What is the average access time (in ns) of the memory when considering both read and write operations?
co&architecture
Average Memory Access Time = 0.6 * Avg. time for read + 0.4 * Average Time for write
Cache access time = Main memory access time/5 (Given in question) = 14.4 ns
Avg. time for read = 0.85 * 14.4 + 0.15(14.4+ * 72 * 4) (On a cache miss entire cache block is taken from main
memory)
= 57.6 ns
(simultaneous memory organization is given in question for writing as all writes are going to memory irrespective of
cache hit/miss. So, we can assume read is hierarchical access though it won't change the answer much)
Avg. time for write = 72 ns (No need to update the whole cache block- we are given main memory access time per word
meaning a word can be directly accessed and there is no point updating the whole block in write through cache)
5.272 Give me the formula for write back and write through ( avg access
time ) in both parallel and serial top gateoverflow.in/14480
WRITE THROUGH
On a write, memory and cache are often updated simultaneously (usually this will be specified in question) and so write
time will be memory access time for a word. On a cache miss, usually only memory is updated (no write allocate policy).
On a read, a cache block is retrieved from memory and hence the read time on cache miss will be the time to bring a block
from memory plus cache access time on hierarchical access and just the memory access time for a block, if both memory
and cache can be accessed in parallel.
So,
Due to hit rates being larger and cache being much faster, the above 2 times are almost the same.
Hierarchical access and write-though case for memory write is actually not present in practical as since memory
is always accessed in case of write through, it makes sense to provide simultaneous write to cache and memory.
Twrite = Tmemory_word
Notice that on write, a word is being updated and on read a block is retrieved from memory.
WRITE BACK
In a write-back cache whenever a cache block is replaced, if it is dirty, then that block is written back to memory. So, this
is an overhead on all cache misses. Write Back, policy usually follows write-allocate- i.e., on a cache miss during write, the
corresponding memory block is brought from memory to cache.
Tread = Twrite = H × Tcache + (1 − H) × (Tcache + Tmemory_block + Twrite_back) = Tcache + (1 − H) × (Tmemory_block + Twrite_back), where Twrite_back = x × Tmemory
Tread = Twrite = H × Tcache + (1 − H) × (Tmemory_block + Twrite_back), where Twrite_back = x × Tmemory_block, where x is the fraction of dirty blocks
Ref: http://web.cs.iastate.edu/~prabhu/Tutorial/CACHE/interac.html
5.272 I1 : Load R0,3(R1) I2:Sub R3,R0,R4 I3: Mul R5,R0,R6 I4: Div R7,R0,R8
.How many cycles are needed to complete above instruction using RISC
pipeline, where all stages take 1 cycle top gateoverflow.in/14253
IF :instruction fetch
ID :instruction decode
EX : execution
I1:Load R0,3(R1)
I2:Sub R3,R0,R4
1 2 3 4 5 6 7 8 9 10 (cycle)
I1 IF ID EX MA WB
I2 IF ID ----------- EX MA WB
I3 IF ID EX MA Wb
I4 IF ID EX MA WB
so 10 cycles required..
5.273 Consider a system such that the number of clock cycles for a polling
operation (including transferring to the polling routine, accessing the device
and restarting the user program) is 400 cycles, and that the processor
executes with a 500 MHz clock. Determine the fraction of CPU consumed
when the mouse must be polled 30 times per second. •0.002 % •0.02 %
•0.2 % •None of these top gateoverflow.in/13606
Consider a system such that the number of clock cycles for a polling operation (including transferring to the polling routine,
accessing the device and restarting the user program) is 400 cycles,
and that the processor executes with a 500 MHz clock. Determine the fraction of CPU consumed when the mouse must be
polled 30 times per second.
•0.002 %
•0.02 %
•0.2 %
•None of these
co&architecture
Number of cycles per second required=30 times per second *400 cycles per polling operation =12000 cycles per sec
=0.0024
5.273 difference between external interrupt and i/o interrupt top gateoverflow.in/12043
assume that memory is BYTE addressable with word size of 32 bits.the program has been loaded in memory 300(decimal)
onwards. if an interrupt occured during the execution of HALT instruction which is stored at 328.what will be the return
address pushed on to the stack
1 332
2 328
3 324
4 none
It is mentioned during the execution of Halt instruction, so the instruction execution must be restarted and the return
address must be 328 for the interrupt.
For completed HALT instruction, the return address must be 328 + 4 assuming size of HALT instruction is one word- 4
bytes.
Ref: http://x86.renejeschke.de/html/file_module_x86_id_134.html
ques..
A CPU has a 32 KB direct mapped cache with 128 byte-block size. Suppose A is two dimensional array of size 512×512 with
elements that occupy 8-bytes each. Consider the following C code segment initially the array is not in cache and i ,j ,x are
in registers than calculate the hits_____________?
cache size is 32 kb
=28
=256
no of rows are 512..and no of elements in each row are 512 therefore no blocks needed to store 1 row elements is 32
blocks...
now these 32 blocks are going to be direct mapped from main to cache memory as there are 16 elements in one block, first
element in the block will be miss and rest 15 elements will be hits.means when one block is mapped to cache then there will
be 1 miss and 15 hits..
for 32 block there will be 32*15 hits i.e 480 hits and there are 512 rows therefore no fo hits will be 512*480=245760 hits
http://gateoverflow.in/1854/gate2006_80-81
question
A microprocessor provides an instruction capable of moving a string of bytes from one area of memory to another. The
fetching and initial decoding of the instruction takes 10 clock cycles.Thereafter, it takes 15 clock cycles to transfer each
byte.The microprocessor is clocked at a rate of 10 GHz.
a. Determine the length of the instruction cycle for the case of a string of 64 bytes.
b.What is the worst-case delay for acknowledging an interrupt if the instruction is non interruptible?
c. Repeat part (b) assuming the instruction can be interrupted at the beginning of each byte transfer.
solution.
correct me ...
(b) as in b part they say instruction is non interruptable ...means whenever the interupt will occur during the execution oh
this instruction than it will not service it..bcoz due to non interruptable..so it will return control to interrupt when the current
instrunction will finish and it will be finished after 970 cycles
(c)
in this part also it wiil be delayed for 970 clock cycle becoz control to interrupt will be given when the current instrunction
will over and i will over after 970 clock cyle
INSTRUCTION cyle =FETCH cycle +execution cycle =10+15*64(as in ques they said 15 for each byte)
(b) as in b part they say instruction is non interruptable ...means whenever the interupt will occur during the execution it
will not service it..bcoz due to non interruptable..so it will return control to interrupt when the current instrunction will
finish and it will be finished after 970 cycles so delay wiil be of 970 clock cycle..
(c) in this part max delay should be 15 cycle only.. because transfer can be interrupted at beginning of each cycle..
Frequency = 5GHz
Assume a processor having a memory cycle time of 300 ns and an instruction processing rate of 1 MIPS. On average, each
instruction requires one bus memory cycle for instruction fetch and one for the operand it involves.
1
106
Clock Cycle per Instruction = = 1μs
600
1600
Bus utilization time = = 37.5%
b. Since not given, we can take instruction cache access time as negligible. Now, the memory cycle needed for an
instruction on average is 1.5 (instruction cache cannot help in operand fetch) as hit rate is 0.5. So,
450
Should be option D.
Q> How much speed do we gain by using the cache,when cache is used 80% of the time? assume cache is faster than main
memory.
a)5.27
b)2.00
c)4.16
d)6.09
Soverall=[(1-F)+F/S]-1
as F=0.8
Selected Answer
In the pipelined implementation, the clock must run at the speed of the slowest stage plus overhead, which
Speed up = avg time in pipe/ avg time in non pipe = 44/11 = 4 times
options (c)
co&architecture
5.283 consider a 33MHz cpu based system.what is the number of wait states
required top gateoverflow.in/16309
consider a 33MHz cpu based system.what is the number of wait states required if it is interfaced with a 60ns memory?
Assume a maximum of 10ns delay for additional circuitry like buffering and decoding.
a) 0 b) 1 c) 2 d) 3
co&architecture
Selected Answer
https://en.wikipedia.org/wiki/Wait_state
5.284 How much speed do we gain by using the cache top gateoverflow.in/17674
How much speed do we gain by using the cache,when cache is used 80% of the time ?Assume cache is faster than main
memory.
a)5.27
b)2.00
c)4.16
d)6.09
Selected Answer
Probably the assumption : "Cache is faster than main memory" is not sufficient to answer this question precisely.It should
be given that "Cache is how many times faster than the main memory".
However with the given information we can guarantee that speed up has to be strictly less than 5.
In general cache memory access is around ~100 times faster than the main memory access so,
ASSUMING : Cache access time is 1 ns & main memory access time is 100 ns.
1) Time Required Without Cache - P main memory accesses & 0 cache accesses = ( P * 100 ) + (0 * 1) = 100P
nanoseconds.
2) Time Required With Cache - (2/10) * P main memory accesses & (8/10) * P cache accesses
Speed gain = Time Without Cache / Time With Cache = 100P/{(208/100)P} = 1000 / 208 = 4.8
Thus speed up will be around 4.8(less than 5 but near 5), assuming the cache is 100 times faster than main memory.
_______________________________________________________________________________
& all of the cache accesses(= 80 out of 100) takes total x units of time.
Now since generally cache is very fast than main memory (around 100 times), value of x would not be too much, so
answer should be 4 point “something”.
5.285 How much time will the processor be slowed down due to DMA
activity? top gateoverflow.in/17666
A processor is fetching instructions at the rate of 1 MIPS.A DMA module is used to transfer characters to RAM from a device
transmitting at 9600 bps.How much time will the processor be slowed down due to DMA activity?
a)9.6 ms
b)4.8 ms
c)2.4 ms
d)1.2 ms
The
DMA
combines
(assembles)
one
word
from
one
consecutive
character
(byte)
so
we
get
I
am
assuming
1word=1
Byte
9600
chars/s
=
9600
bytes/s
=
1200
words/s
=
1200
W/s
If
we
assume
that
one
CPU
instruction
is
one
word
wide
then
1
million
instructions/s
=
1
million
words/s
=
10^6
W/s
So
we
have
1200
words
received
during
one
second
and
(10^6-1200)
words
processed
by
the
CPU
(while
DMA
is
transferring
a
word,
the
CPU
cannot
fetch
the
instruction
so
we
have
to
subtract
the
number
of
words
transferred
by
DMA)
and
we
get
(1200
w/s)
/
(10^6
w/s
-
1200
w/s)
=
1200
/
(10^6
-
1200)
=
1200
/
998800
=
0.0012014417...
So
Convert
0.0012
this
in
ms.
it
will
come
1.2
ms
5.286 what are the values of overflow,carry and zero flag . cpu uses 2's
compliment top gateoverflow.in/17594
two 8 bit 1100 0011 and 0100 1100 are added. what are the values of overflow,carry and zero flag . cpu uses 2's compliment
1 1
11000011
01001100
1 00001111
Swap space is some space in virtual memory. but why it called as swap space?
Swap space is the space on the disk reserved for the full virtual memory space of a process.
When Operating System creates a process, it also creates (or reserves) a space on disk for all the pages of that process.
It is called swap space because it is the space(or place) in the disk from where the pages are exchanged(swapped) with
main memory, for any process.
I know function call is like subroutine call. But why it is differentiate from function call?
and if a processor calls a subroutine is any interrupt is possible?means what is the relationship of subroutine call and
interrupt?
Selected Answer
The interrupt service routine is just like a subroutine. The difference is that when you call a
subroutine, you call it when you decide, and you understand completely what will be changed by the subroutine,
5.289 Easy one but I'm not getting Approach. top gateoverflow.in/18369
A DMA controller transfers 16Bytes to memory using cycle stealing with frequency 1.2GHz. The Number of clock cycles used
for transfer of 16Bytes is 20 clock cycles. Find the throughput?
1.04 GBps
a)Parallel search
b)Sequential search
c)Binary search
d)Selection search
Selected Answer
Search in associative memory is parallel. For k-way associativity we can have k comparators which compares the tag bits
of 'k' blocks in parallel. We can't increase 'k' beyond a limit due to hardware limitation.
If a microcomputer operates at 5 MHz with an 8-bit bus and a newer version operates at 20 MHz with a 32-bit bus,the
maximum speed-up possible approximately will be
a)2
b)4
c)8
d)16
It should be max(20/5, 32/8) = 4. Increasing the bandwidth aids in achieving the maximum speed up. Suppose we had a
memory intensive program then increase in bandwidth becomes critical whereas for a CPU intensive process, increase in
clock speed becomes critical.
Consider the following pseudo code. What is the total number of multiplications to be performed?
efficiency =S/K
70/100=6/K
Selected Answer
Consider a cache with 64 blocks and block size 16 bits block number of byte address 1600 is
http://gateoverflow.in/?qa=blob&qa_blobid=256200031073543854
i assume here 1 instruction is there with two 15 bit address and one three bit register
30 *23 =2 33
so 1*2
= 1073741824
i assume here 64 instruction having with one 15 bit address and one with 3 bit registers
*218 =224
so 64
=16777216
5.296 The number of logical CPUs in a computer having two physical quad-
core chips with hyper threading enabled is top gateoverflow.in/16310
The number of logical CPUs in a computer having two physical quad-core chips with hyper threading enabled is-----------.
a) 1 b) 2 c) 8 d) 16
co&architecture
Selected Answer
2 * 4 physical cores * 2 = 16 logical cores. I'm not sure if we can call this logical CPU. But Hyper Threading is vendor
specific and hence out of GATE scope.
https://en.wikipedia.org/wiki/Hyper-threading
5.297 How to calculate the address of the sector in below question ? gateoverflow.in/16737
top
A hard disk has 63 sectors/track ,10 platters each with 2 recording surfaces and 1000 cylinders ,the address
of each sector is given as
where C is cylinder no , H is surface no and S is sector no , thus the 0 th sector is addressed
as <0,0,0> , 1st sector is address as <0,0,1> and so on , so then the address <400 , 16, 29 > corresponds to
which sector no ?
<400,16,29> , sector number = 400th cylinder + 16th surface of 400th cylinder + 29th sector of 16th surface of 400th
cylinder
5.298 how many number of times the instruction sequence below will loop
before coming out of the loop? top gateoverflow.in/17044
how many number of times the instruction sequence below will loop before coming out of the loop?
MOV AL,00H
A1: INC AL
JNZ A1
a)1
b)256
c)255
MOV AL,00H--- means 0000 0000(binary) is loaded into the register AL. Register AL is of 8 bits (Intel x86 architecture).
Now in each loop the value of AL is incremented by one.....this will go on till AL value becomes 1111 1111(binary) i.e
255(decimal).
After this when it is incremented i.e 1111 1111 + 0000 0001= 10000 0000. Now this is an overflow as AL is of 8 bits. The
MSB is discarded(the carry out) and hence AL becomes 0000 0000 again. Therefore, it comes out of the loop.
5.299 Need of TLB lookup before Cache Look up? top gateoverflow.in/17532
Why do we need to look in the TLB for a virtual address without looking into cache first?
Why we do not look for a given data directly into the cache?
TLB look up could increase hit time even if the data is in cache.
Suppose there is a TLB miss, then we have to look up in the Page Table. If data is in the page table then we are checking it
in Cache, so after all we are accessing main memory (before cache access).Is not the time required in this process
equivalent to time required in a cache miss? So how it is going to speed up the memory access?
tlb hold recent entries of page table . while cache contain recently used blocks. u should note that without getting the
frame number it is very hard to search whether a page is in cache or not. so for the same reason we have to first get the
frame number. (if u have studied cache mapping u should be knowing that frame number is required to map the block to
cache). so to get the frame number u have to o to the page table but like cache . tlb is teh cache of page table so before
visting page table i visit tlb.
yes it seems that there is a time penality but as the numerical we solve we are not given the data to be transferred, in
real scenario the data also has to transferred . so time is conversion of address + transfer time. directly access the main
memory for address takes verl less amount of time as compared to transferring a whole block. so if using the above
procedure we are spending more time in translation still it is very very less than transferr time so overall system become
more efficient . worst case can be costly .
5.300 More than one word are put in one cache block to top gateoverflow.in/17264
d)none of these
Selected Answer
When a word is accessed, we take a block of word and put in cache expecting words in that block to be accessed in nearby
time- which is spatial locality.
RAW {I1, I2} {I1, I3} {I2, I5} {I3, I4} {I4, I5}
5.302 Consider the following code: for (i=0; i <20; i++) for ( j= 0; j< 10;
j++) a[i] a[i]* j a. Give one example of the spatial locality in the code. b.
Give one example of the temporal locality in the code. top gateoverflow.in/11127
a. a[1] is accessed after a[0] both are near memory locations and hence example of spatial locality.
b. a[0] is accessed for j = 0 and for j = 1; same memory location accessed in nearby time and hence example of temporal
locality.
A computer system supports 1-address instructions and 2-address instructions and word size is 16 bits. Main memory is 64
words. If there are eight 2 -address instructions then how many 1-address instructions are used?
Total one addr instructions(after combining 6 address bits to instruction opcode-expand technique ) =8*2^6=512
instructions
5.303 plez tell me the correct approach and meaning of question top gateoverflow.in/5133
http://gateoverflow.in/3692/gate2004-it_49?show=3983#a3983
5.303 what are average read cycle time and write cycle time in write through
and write back cache?Elaborate the concept please. top gateoverflow.in/4775
A 5 stage pipeline with the stages taking 1, 1, 3, 1, 1 units of time has throughput of
(A) 1/3 (B) 1/7 (C) 1/5 (D) 1/6
throughput=1/7 instruction per unit time (assuming total instruction execution time is the sum of the individual delays of
the stages)
So answer should be D.
A hard disk with a transfer rate of 10 M bytes/second is constantly transferring data to memory using DMA. The processor
runs at 600 MHz. and takes 300 and 900 clock cycles to initiate and complete DMA transfer respectively. If the size of the
transfer is 20 Kbytes, what is the percentage of processor time consumed for the transfer operation?
(A) 5.0%
(B) 1.0%
(C) 0.5%
(D) 0.1%
Selected Answer
Solution : D
20×2 10
20
Duration of transfer = 10×2 = 2 × 2 −10
1200
600 ×106
Time for 1200 clocks = = 2 × 10 −6 and processor is used only for this much of time. So,
2 ×10 − 6 2 ×10 − 4
8 - miss [8 - - -]
9 - miss [8 9 --]
11 - miss [8 9 - 11]
16 - miss [16 9 - 11]
8 - miss [8 9 - 11]
9 - hit [8 9 - 11]
17 - miss [8 17 - 11]
8 - hit [8 17 - 11]
9 - miss [8 9 - 11]
11 -hit [8 9 - 11]
co&architecture
In Pc relative addressing
Pc will contain 302 in this case coz its a 2 byte instruction so effective address =302+500=802
If we see, 11 bits(0-10) are used to address in the instruction. So, main memory can be up to 2 11 bytes.
If word addressing is used, we get 2 11 words = 2 * 2 11 = 2 12 bytes as each word here is 16 bits = 2 bytes.
http://www.cs.ucla.edu/classes/winter04/csM151B/l2/examples/ByteVSWordAddr.pdf
5.309 How many stall cycles are needed with the best bypassing possible for
each of the following instruction sequences in a 5-stage DLXpipeline ? ADD
R3,R6,R8 ORI R7,R3,0x67 top gateoverflow.in/3541
Clcok frequency becomes low means time period of clock becomes high. When this time period increses beyond the time
period in which the non-volatile memory contents must be refreshed, we loose those contents. So, clock frequence can't
go below this value.
The cache, register etc. inside CPU and RAM for primary memory are all examples of non-volatile memory and needs
refresh within the specified time period or else will loose their contents.
Non-volatile memory are being developed and computers in future should be tailor made for that.
Selected Answer
Because microprocessor can also have hardwired control unit. Microprogrammed control unit is just a design option for
control unit in a microprocessor. This "micro" is not related to the "micro" in microprocessor.
Selected Answer
A cache as everyone knows, stores a copy of data from memory in a fast storage near to CPU. Now, in a system with
virtual memory, CPU will be working on logical address and this logical address will be translated to physical address by
the memory unit before data is fetched from the main memory. So, if we use the cache before this translation, it will be
virtually addressed and if we use cache after this translation, it will be physically addressed.
TLB (which is like a cache for page table) is looked up on to perform virtual-physical address translation. So, in a virtually
addressed cache, TLB comes after cache and in a physically addressed cache, TLB comes before the cache.
in microprogrammed cu every computer instruction has its own microprogammed routine in control memory (mano )
Does this mean than every m/c instruction would have its own implementation of fetch routine loaded ?
http://gateoverflow.in/1922/gate2014-1_44?show=3336#a3336
0 address means, during execution of the instruction, we just need to fetch the instruction- instruction fetch but no data
fetch. So, for an m-bit instruction
Number of memory reference for p = m/n
For 1-address instruction, a part of m-bit instruction will have a memory address and that memory needs to be fetched
during execution. So,
Number of memory reference for q = m/n + 1
(May be the question meant p is the number of 0 address instruction, it is not clear)
Plz xplain
co&architecture
This happens when all significant (mantissa) bits are 1, and the exponent bits are all 1.
= (b)p −1 − 1 × (b)X−q
This happens when the LSB of mantissa is 1 and the exponent bits are 0 so that subtracting the bias gives the largest
negative value possible for exponent
= 1 × (b) −q
co&architecture
You should practice a few. It is one of the few areas where practice is an absolute necessity.
http://gateoverflow.in/tag/cache-memory
They have explained the concept of 3 state gate which can be used as a multiplexer which have output 1, 0 and high
Impedance. what is used of it (I am not getting )
digital-logic
This is useful for the operation of bus (shared by many components) and hence very important in computers.
http://en.wikipedia.org/wiki/Three-state_logic
What will be the minimum size of ROM which maintains truth table of square of 3 bit numbers(in bits) ?
Selected Answer
so it will have 3 address line mean 8 address [000 to 111] and 6 bits [B0 to B5] at each address = 8 X 6 = 48 bits
Can you explain why the offset in addressing modes need to be a signed integer ?
co&architecture
Consider a hypothetical 32 bit microprocessor having 32 bit instructions composed of two fields: The first 4 bits contains the opcode and the
remainder an immediate operand, an operand address, or register references.
Selected Answer
a. Out of 32 bit instruction, 4 bit is opcode. So, remaining 28 bits can be used as an operand address and hence up to 228
bytes can be addressed assuming byte addressing.
b.
1. 32 bit address bit means full capability of 228 addresses can be used. But 16 bit data width means each instruction
requires two memory reads.
2. With 16 bit address field we can address only 216 words of memory. So, two memory reads are required for each
address using address latching which slows down the microprocessor. Here also, two memory reads are required for
each instruction as we have only 16 bit data bus.
5.317 Assume an instruction set that uses a fixed 16-bit instruction length.
Selected Answer
But all these encodings are not distinct instructions as even if operands are different, we consider them as same
instruction. So, we have to find the number of each types of instructions.
We have L 0 operand instructions. Number of encodings taken by these = L as they don't have any operand part.
We have K 2 operand instructions. Number of encodings taken by these = K × 26 × 26 = K × 212 as there are 2 operands and
each being 6 bits.
All the remaining encodings can be used for 1 operand instructions, which will be equal to 216 − L − 212 × K
216 − L − 212K
26
16 Kb cache size.
no of sets=no of lines/p(way)
no of lines=2 7
no fo sets= 27/22
therefore no of sets=32.
its binary from is :1010 1011 1100 1101 1110 1000 1111 1000
Selected Answer
Yes. You are correct. But how cache hit/miss is detected is not answered :)
Option C
5.319 What is the Associativity, if we have 128 KByte cache, with 512 sets
and a block size of 64-bytes? top gateoverflow.in/11047
Selected Answer
No of sets = 128kB/512*64
= 4
5.319 what is the average access time for a drum rotating at 4000
revolutions per minute top gateoverflow.in/9485
Selected Answer
average access time is time to complete 1/2 revolution i.e. . 7.5 milli second..
= 7943.936 or 7944.935 ?
digital-logic
the bias value is a number which will be added to actual exponent to make the n-bit exponent to lie in the range (0 to 2 n
- 1).
Since the actual range of 8 bit signed integers is -128 to +127, we need to add +128 to exponent to bring the range to 0
to +255. So +128 is the bias value for 8 bit exponent.
In similar way,
1) for 6 bits, the actual range is -32 to +31. so bias value is +32.
2) for 7 bits, the actual range is -64 to +63. so bias value is +64. in base-8, 080.
a. Consider a fixed-point representation using decimal digits, in which the implied radix point can be in any position (e.g. to
the right of the least significant digit, to the right of the most significant digit, and so on). How many decimal digits are
needed to represent the approximations of both Planck’s constant and Avogadro’s number the implied radix point must be in
the same position for both numbers?
b. Now consider a decimal floating-point format with the exponent stored in a biased representation with a bias of 50. A
normalized representation is assumed. How many decimal digits are needed to represent these constants in this floating-
point format?
Then Planck Constant which is 6.63*10 -27 for this Biased Exponent Field= -27+50= 23
Now, they asked us to find number of digit in decimal only to represent this number
0 23 63
02
0 73
Is it right?
co&architecture
a. Scaling factor needed is 10 -29 to represent Plank constant. Now Plank constant is 663 and Avogadro number is 602..0
(50 0'2). So, we need 50 + 3 = 53 decimal digits.
b. "6 is a hidden bit in both cases" Because of normalization? In binary normalized representation 1 on the left of decimal
point is taken as implied. But in decimal this "digit" can be any from 1-9. So, we can't just imply it.
Normalization just means that the leading significant digit is non-zero. 1 being taken implicitly in binary is something done
in addition to normalized representation because '1' is the only possibility there.
Under computer integer arithmetic, the quotient J/K of two integers J and K is less than or equal to the usual quotient.True
or false?
co&architecture
false..
Binary Arithmatic follow truncation rule.. that ll result greater(+ve no) equal (well normalised without truncation) or
smaller( negative no) value ..
a) s1
b) s2
c)both
d) none of these
S1: Booth algorithm reduces the spaces for fixed point signed multiplication
S2: Booth algorithm increases time for fixed point signed Multiplication
a) s1 is true
b) s2 is true
c) cant say
d)None of these
co&architecture
Selected Answer
S2 is wrong as booth algorithm was invented to decrease the time of multiplication. It does mutiplication by using shift
operation which is much faster then a normal multipier where m*n multiplier cells is used.
S1 is correct as in booth algorithm we just need to keep track of bits which is flipping nd booth algorithm just uses a
shiftregister where the multiplier reside ,calcullated result is stored in the same register so it uses very few space than
any other algorithm.
I just google first about negaBinary (-2 ) , The procedure says divide number by -2 , to get positive remainder and then read
from bottom to top
-20 = (-2)*(10) + 0
(10)= (-2)*(5) + 0
(5) = (-2)*(-2) +1
(-2)= (-2)*(1) +0
1 = (-2)*(0) + 1 (MSB)
co&architecture
The base expansion of a number can be found by repeated division by , recording the non-negative remainders of , and concatenating those
remainders, starting with the last. Note that if , remainder , then .
-5/-2 = 3, remainder 1
-1/-2 = 1, remainder 1
1/-2 = 0, remainder 1
The overflow condition for unsigned 8 bit integer would be if c= a+b if c<a Or c< b
The overflow condition for signed 8 bit integer would be if c= a+b if c<a and c< b
right ??
co&architecture
For c = a + b, UNSIGNED
The overflow condition for unsigned 8 bit integer would be c < a or c < b
For c = a + b, SIGNED
We can't say anything like that. We need to say only with respect to the sign of the input numbers. If the sign of a and b
are same but the sign of c is different, there's overflow. If a and b are of different sign, overflow cannot happen.
(When a = -3 and b = -5, c = -8 but there is no overflow and c < a and c < b)
5.328 The process of organizing the memory into two banks to allow 8 and
16 bit data operation is called top gateoverflow.in/18567
The process of organizing the memory into two banks to allow 8 and 16 bit data operation is called
a)Bank switching
b)Indexed mapping
d)Memory segmentation
Selected Answer
https://en.wikipedia.org/wiki/Interleaved_memory
Selected Answer
is 2ns?(in MIPS)
Selected Answer
CPI(non-pipeline)=40%( no of cycles ALU required)+20%( no of cycles branch instruction required )+ 40% (no of cycles
memory instruction required)=0.40(4)+0.20(5)+0.40(6)=5cycles=5*10=50ns
suppose there is unpipelined processor with a cycle time of 30ns which is evenly divided into 5 pipeline stages.The total latch
latency of the pipeline will be
the maximum clock frequency at which the data path can operate is ??
Selected Answer
Dirty Bit : In a write back scheme, when a write occurs, the new value is written ONLY to the block in the cache.The
modified block is written to the lower level of the hierarchy when the block is replaced.
To avoid unnecessary writes of unmodified pages, we would like to know whether a block need to be write back or not
when we choose to replace it.
So Dirty bit tells us, whether the block has been modified(dirtied) or not from the time since it was brought into the cache.
Valid Bit : Valid bit indicates that whether the associated block in the cache contains valid data or not.
For example, when processor starts up, the cache may contain junk or invalid data & the tag fields will be meaningless.At
that time Valid bit will be 0.
cpu fetches words from 0-4351 so no of blocks required is: 4352/64= 68 blocks
1st time 68 miss operation occured. but after this step i got stuck.
Assume that memory is byte addressable with word size of 32 bits. the program has
been loaded in memory 300 (decimal) address onwards.if an interrupt is occurred
during the execution of HALT which is stored at 328. what will be return address
pushed on the stack?
Given ans is 326. but i am not getting how this ans is coming. please explain.
1) No, compulsory miss can be reduced. It is like all places in cache is empty and No block yet came. So to reduce
compulsory miss take some block in cache
2)No, Conflict miss is there , when there is no place empty in cache. Associativity cannot say there is no conflict misses
http://courses.cs.washington.edu/courses/cse378/02sp/sections/section9-2.html
5.339 An instruction pipeline has five stages where each stage takes 2 nano
seconds.. top gateoverflow.in/29187
An instruction pipeline has five stages where each stage takes 2 nano seconds and all instructions uses all 5 stages .There
are 20% instructions. Branch instruction are not overlapped, i.e., the instruction after the branch is not fetched till the
branch is completed under ideal conditions. If a branch instruction is a condition branch instruction , the branch is need not
be taken . If the branch is not taken the following instructions can be overlapped when 80% of all branch instruction are
conditional branch instruction , and 50% of branch conditional instruction are such that the branch is taken . What is the
average instruction execution time ?
Selected Answer
=(1+0.48)*2 =2.96
Assume that RISC processor contains 10 global registers, 10 local registers, 6 In register and 6 Out register. It contain 4
register windows what is the size of window and register file of the processor?
a) 30 and 74
b) 32 and 74
c) 22 and 64
d) 22 and 70
Selected Answer
B should be answer.
5.341 "TLB with physically addressed cache" plz write expression for avg
mem access time??? top gateoverflow.in/28454
The average memory access latencies when the cache is physically addressed (in cycles) (up to 2 decimal places)
is__________.
co&architecture
answer = 2.105
consider the system in which cycle time is 500 ns. transfer of bus control in either direction, from processor to I/O device or
vice versa, takes 250 ns.one of the I/O device has a data transfer rate of 50 kB/s and employees DMA. data are transferred
one byte at a time. The time(in ms) would the device tie-up the bus when transferring block of 128 bytes is _______
The MegaGiga hard disk rotates at 10000 rpm (6 ms/rot) with a seek time given by = 1 + 0.001tmsec, where t is the number of
tracks the arm seeks. Assume a block size of 512 bytes, 1024 sector/track, 8192 tracks, and 4 platters. The disk has a 16MB
track buffer. The disk controller can DMA read or write data between memory and the disk device at a rate of 100MB/sec.
Estimate the worst case delay to read 512 bytes from this disk.
a. 25ms
b. 15.2ms
c. 14.9ms
d. 26.3ms
Selected Answer
best match is b . 15.2 we have to calculate the worst case time delay and worst case will happen when everything will be
maximum,.
transfer time here include both preparation time and then dma transfer time .
maximum seek time will be when i have to cross all the tracks = 1+0.001*8192= 9.192ms
maximum rotational latency = total time to take one round only. as in gneral case we divide with 2 . that is because on an
average the disk has to move half. 2 is for the average, but here we have not to consider the average case . so it will be
time to take one round . which will be equal to 6 ms.
now the transfer will be like. first the data will be buffered in the buffer and when 512 bytes wll be ready dma will be
called to transfer it to the memory .
one round = 6 ms
now the data is available in the buffer now time taken by the dma
in this question as said block size contains two 32 bit word, and byte addressable, so each time fetching a block from main
mem will fetch 8 byte, so my doubt is, BCD address 200 and 204 in decimal 512 and 516, fetching block at address 200 also
contains bytes at address 204 so for 200 miss and 204 will next time, bcz 204 already fetched during fetching of 200
The size of the instruction in a single accumulator is 16 bits. In order to evaluate the expression Y = A-B+C / E+F , how
much memory space is required to store the program?
a) 18 bytes
b)24 bytes
c)22 bytes
d)20 bytes
Load C
Div E
Add F
Add A
Sub B
Store Y
Consider a 32 bit processor that has an on chip 16Kbyte 4 way set associative cache. assume that cache has a size of four
32 bit words. the set no in the cache to which the word from memory location FFFAE8FA is mapped_________
Selected Answer
= 16KB / (16 * 4 )
= 256 sets
5.348 made easy test flt advance pipeline plz expliain.. top gateoverflow.in/30167
Selected Answer
5.349 adv flt test madeeasy pipeline, no of cycle required?? top gateoverflow.in/30196
1 . R1 =100
2. R1 = R2 + R4
3. R2 = R4 + 25
4 . R4 = R1 + R3
5. R1 = R1 + 30 .
I think compulsory miss could be reduced by putting the data initially in the cache.
Consider a system in which DMA technique is used to transfer 16 MB of data from an I/O device into memory. The bandwidth
of I/O device is 128 KB/s. What percentage of time is the CPU in busy mode (approximately)?
Suppose there are 100 instructions ad we have a 6-stage pipeline, then if 25% of the instructions have 2 stall cycles, what is
the time taken by the pipeline?
Will it be 25*3+75=150 , or
6+25*3+74=155.
Why?
This is actually related to 2014 question, where we have to compute speedup; I did this way, for 150 i get 4, for 155 i get
3.8
Speed up =4
Selected Answer
When we are asked to find access time for a cache having write through or write back policy.....which cache access method
to apply(hierarchial or simultaneous).
nd also
I1 : R1 = 100
I2 : R1 = R2 + R4
I3 : R2 = R4 + 25
I4 : R4 = R1 + R3
I5 : R1 = R1 + 30
Calculate sum of (WAR, RAW and WAW) dependencies the above instructions. (a) 10 (b) 12 (c) 6 (d) 8
Q. When we are asked to find access time for a cache having write through or write back policy.....which cache access
method to apply(hierarchial or simultaneous) ?
Ans: In all such question, you will be given directly or indirectly which method to use either hierarchical or simultaneous.
For example : take this question for reference http://gateoverflow.in/11137/coa., in this they have clearly mentioned
what to do once miss occur at cache, then it will access from main memory and load it into cache then refer it, so this is
an example of hierarchical access.
Same way if it is simultaneous it will directly access it from the memory level it has found the word.it will not load it into
the first level and then access it.
I1 : R1 = 100
I2 : R1 = R2 + R4
I3 : R2 = R4 + 25
I4 : R4 = R1 + R3
I5 : R1 = R1 + 30
Total = 4 + 4 + 3 = 11
co&architecture
To put it simply, Privileged instructions required hardware support from the system, and so they are executed by OS.
Example, reading the output from the disk buffer.
digital-logic
Selected Answer
Ans : 1000
After rising edge of clock t1,output of register A = 0110.Hence input of ROM = 0110.Now since enable E = 1,so ROM is
enabled and output of ROM = data present in ROM at address 0110 i.e DATA[6] = 1010 (from the table given).
Next after rising edge of t2, this input 1010 will appear as output of register A.Hence it will become input for ROM.
Again since E = 1,output of ROM = data at 1010 = data at address at 10 = data[10] = 1000
Consider a 5 stage pipeline with IF, ID, EX, MEM and WB latencies 8, 6, 4, 6 and 4 respectively (in ns). If IF stage is made
50% faster, the percentage it will improve the performance CPU is __________.
Ans: 25%
DMA interface unit eliminates the need to use CPU registers to transfers data from
A four-way associative writeback cache has a 211 ∗ 89-bit tag store. The cache uses a custom replacement policy that requires
9 bits per set. The cache block size is 64 bytes. The cache is virtually -indexed and physically tagged. Data from a given
physical address can be present in up to eight different sets in the cache. The system uses hierarchical page tables with two
levels. Each level of the page table contains 1024 entries.A page table may be larger or smaller than one page. The TLB
contains 64 entries.
Q50).How many bits of the virtual address are sued to choose a set in the cache?
(a). 11bits
(b). 12bits
(c). 13bits
(d). 14bits
(a). 512KB
(b). 256KB
(c). 128KB
(d). 1024KB
let s is no of bits for representing sets and given no of entries in each level page table is 1024 therefore no of tag bits is
20
50)A 51)A
5.361 How to calculate total size of meta data for cache ? top gateoverflow.in/30346
An 16KB 4-way set associative write-back cache is organized as multiple blocks, each of size 64-bytes. The processor
generates 32-bit addresses. The cache controller maintains the tag information for each cache block comprising with 1 Valid
bit and 1 Modified bit. As many bits as the minimum needed to identify the memory block mapped in the cache. What is the
total size of memory needed at the cache controller to store meta-data (tags) for the cache?
co&architecture
data dependencies can happen anywhere for any order of instructions.Plz clarify
5.363 Which of the following is most relevant addressing mode used to write
code in which reallocation done at run time? top gateoverflow.in/31559
Q.14
Which of the following is most relevant addressing mode used to write code in which reallocation done at run time?
Indexed mode
Indirect mode
Direct mode
Relative mode
Related to
http://gateoverflow.in/3578/gate2006-it_39
http://gateoverflow.in/1656/gate1998_1-19
Q.27
Consider a CPU where 150 instructions take 8 clock cycles each to complete the execution. A horizontal microprogrammed
control unit has to generate 125 control signals. What is the minimum size of control word? _______
Answer given is 136 (multiple of 8 bit)
Actual No of bits required is 133. Do we always need multiple of 8 ? Here issue is that they have not specified unit (Bit or
byte) , Neither they have given that answer should be multiple of 8 , if it is in bit !
Control field indicates the control signal which is 125 Control Signal.Since Horizontal control Word uses decode binary
format to represent control signal i.e. 1 bit per control signal.
In Control Unit 1 micro operation require 1 cycle so total number of micro operation = 1200 micro operation
number of bits required to represent Control Memory Address = Ceil( log 2 1200 ) = 11 bits
** Control Word Size is not always mandatory to be multiple of 8. Actually there is no need of specifying bit or bytes in
this question.
Consider a pipeline ‘x’ consist of 5 stages named as IF, ID, OF, EX and WB with the respective stage delays of 2 ns, 5 ns, 6
ns, 8 ns and 1 ns. The alternative pipeline ‘y’ contain the same number of stages but EX stage is divided into 4 sub stages,
(EX1, EX2, EX3 and EX4) with equal delay i.e. (8 ns/4) and ID stage is divided into 2 substages (ID1 and ID2) with equal
delays of (5 ns/2). In the pipeline x and y memory reference instructions are not overlapped so the penalty of memory
reference instructions in the pipeline ‘x’ is 4 cycles and in the pipeline ‘y’ is 8 cycles. If the program contains 30% of the
instructions which are memory based instructions, the speedup ratio of x is speedup ratio of y is ___________.
Y = [IF] [ID1] [ID2] [OF] [EX1] [EX2] [EX3] [EX4] [WB]; Clock = 8ns
For X:
For Y:
Consider two cache organizations. The first one if 64 KB way associative with 64 byte block size. The second one is of the 64
KB direct mapped cache. The size of an address is 32 bits in both organizations. A 4 to 1 multiplexer has latency of 0.8 ns
which k bit comparator has latency of k/5 nsec. The difference between the hit latencies of both cache organizations (i.e.
associative hit latency – direct mapped hit latency) (in nsec) is ___________.
Selected Answer
as per given 4:1 mux,if we consider it is 4 way associative then answer is 1.2 ns.
There will be something n way set associative,else we can't determine set offset.The qs seems wrong..
Suppose that in 1000 memory references there are 150 misses in first level and 100 misses in second level cache. Assume
that miss penalty from L2 cache to memory is 120 cycles. The hit time of L 2 cache is 50 cycles.
If there are 4 memory references per instruction, the average stall per instruction is
Selected Answer
Tavg stall/ints = Miss in L1/int * Hit in L2 + Miss in L2/int * Miss Penality in L2(memory access )
150 100
250
therefore Tavg stall/ints = *50 + 250 *120 = 78
Suppose that a cache is 20 times faster than main memory and cache memory can be used 80% of the time. The speed up
factor that can be achieved by using the cache is
Selected Answer
Let Cache access time is X, then main memory access time will be 20X .
Speed up factor = (Time taken to get data W/O Cache)/ (Time taken to get data with Cache)
Speed up = 4
= ((1-.8) + ( 20 ) -1
= 4.166
A weather forecasting computation requires 250 billion floating point operations. The problem is processed in a super
computer that can perform 100 mega flops. How long will it take to do these calculations?(in mins)
co&architecture
With reference to the return instruction. Which of the following statement is / are true?
1. The instruction can be used only to take the flow of control back to the program from which it initially jumped.
2.The instruction retrieves the address using the current stack pointer from the stack and alters the control to the program
pointed to by it.
3. The instruction works only if the registers used in the main program have been pushed and later popped before its
execution.
4.The instruction can be used only in conjunction with the call instruction.
B. 2nd only
co&architecture
In the NONIX operating system, the time required for various file read operations are given below:
A. 45 msec B. 47 msec
C. 90 msec D. 94 msec
co&architecture operating-system
8 + 2 + 2 + 10 + 25 = 47 ms.
5.372 Find out the content of the register pair top gateoverflow.in/21082
1006 POP H
a) SP=27FF, HL=1003
b) SP=27FD, HL=1003
c) SP=27FF,HL=1006
d) SP=27FD,HL=1006
co&architecture
5.373 Q34- The above circuit represents __________ stages. top gateoverflow.in/21300
A. n states
B. (n-1) states
C. 2n states
D. 2n-1 states
co&architecture
5.374 consider the floating point representation, for each part provide ans as
true or false... top gateoverflow.in/20849
TRUE/FALSE
biased
id sign mantissa
expo
1 0 00000001 00000000000000000000000 is first smallest no in IEEE 754 representationid
11111111111111111111111 is largest no represented through IEEE
2 0 11111110
754
3 0 00000000 00000000000000000000001 is smallest de-normalized no
4 0 00000000 11111111111111111111111 largest unnormalized no
11111111111111111111111111 largest no represented through
5 0 11111111
IEEE 754
6 0 00000000 10000000000000000000000000 smallest normalized no
For each id(row i.e exponent and mantissa) there is a corresponding red statement you hv to tell that it is true or false.
All 0 exponent and non-zero mantissa means a number is denormalized in IEEE 754 - no implied 1 before ".". Also, bias
for denormalized numbers is "-126" and that for normalized is "-127".
00000000 0 ( )
111...111 1 − 2 −23 × 2 −126 Largest de-normalized number
Ref: http://steve.hollasch.net/cgindex/coding/ieeefloat.html
5.375 Minimum and maximum (-ve) mantisa range in IEEE 754 32 bit gateoverflow.in/20841
top
Minimum and maximum (-ve) mantisa range in IEEE 754 32 bit floating point number representation with 1bit for sign, 8 bit
for exponent and 23 bit for mantisa.
co&architecture
Selected Answer
i think the range will be from all zeros to all once. so mantissa can be from 1.0000000....00 to 1.11111111...111 = 1 to
2 − 2 −23
5.376 The number of bits (in binary) required to represent 25-digit decimal
number top gateoverflow.in/20746
The number of bits (in binary) required to represent 25-digit decimal number
digital-logic
Selected Answer
The concept is the maximum number of 10 digit number by 10 digit should be equal to x digit number in base 2.
so 1025-1 = 2x-1
taking log both side . take log of base 2 so that RHS can become x
25log10 base 2 = x.
An 8 byte, 2-way set associative (using LRU replacement) with 2 byte blocks receives requests for the following addresses
(represented in binary): 0110, 0000, 0010, 0001, 0011, 0100, 1001, 0000, 1010, 1111, 0111 .
How page replacement is done?What are the types of misses occured in this case?
Selected Answer
Compulsory miss: Miss occur by the first reference to a location. (Will happen even in an infinite size cache but may be
reduced if we use a larger block size)
Conflict miss : Misses which happen due to collision. In a set associative cache of set size say 2, 2 blocks can live together
and on 3rd entry, we have a collision and one block is removed. If a miss happens due to this removal, it is counted as
conflict miss.
Capacity miss : A capacity miss occurs when a memory location is accessed once, but later because the cache fills up, that
data is discarded. And this is assuming the cache is fully associative (no conflict miss).
Word
Tag set
1bit
2bit 1bit
All the given address will use this instruction set to identify there set and line.
To get the capacity miss we can count the no. of unique block accesses before the access causing the miss and after that
particular block was last accessed. For example, in above case 011 is causing capacity miss as after its last access we
have unique block accesses to 000, 001, 010, 100, 101, 111 − 6 unique accesses and we have only space for 4 − 1 = 3 more unique
accesses. Thus this miss becomes a capacity miss. 000 is not a capacity miss because after the previous access to 000, we
only have 3 unique block accesses - 001, 010, 100, which means in a fully associative cache (of the given size) this would not
be causing a miss.
the first approach to this type of question involve conversion of binary to decimal and apply the property of set assosiative
cache.
which is surely wrong. because they have not said anywhere that binary number are page refrences they are saying these
are the address refrences. Reading the question with a little bit of patience is the key and is not as simple as it seems. i
lost one year for the same. plz practice for this a lot. otherwise u are surely going to loose a lot of marks.
coming to question. as they are addresses we have to consider as computer sees them . 8 bytes of memory with 2 per
block .
now every set will contain 2 cache lines 00,01 . as it is 2 way set asso.
now consider the address as cache controller handles it. every address refrence is compared with the the format the cache
controlled is programmed for . for ex here for set associative it will see it as . TAG SET OFFSET AND WORD OFFSET.
word offset will be one bit because the size of block is 2 bytes.
so the first address which is 0110. the last bit is representing the byte which we want to get. second last the set it will go
in and remaining the tag line they will go in .
NOTE: 0110 and 0111 are refrences for same page but different bytes. so no miss .
2 votes -- Ravi Singh ( 7303 points)
5.378 How many zero address instructions are there? top gateoverflow.in/19850
PUSH P
PUSH Q
MUL
PUSH N
PUSH O
MUL
PUSH M
ADD
DIV
POP X
No of instructions required will be dependent on architecture set...Say if there is no Mul instruction then we need to mul
instruction by using add instruction...so to ans que we need to know architecture or instruction set
A computer has 24-bits instructions.A program has been loaded into main memory with starting address of
300.Which of the following is the valid value for the PC(Program counter)?
1.400
2.500
3.600
4.700
co&architecture
Here, size of instruction = 24/8 = 3 bytes. Program Counter can shift 3 bytes at a time to jump to next instruction. So the
given options must be divisible by 3. only 600 is satisfied.
5.380 capacity of disc pack and the number of bits required to specify a
particular sector in the disc are respectively top gateoverflow.in/18599
Consider a disk pack with 16 surfaces , 128 tracks per surface and 256 sectors per track.512 bytes of data are stores in a bit
serial manner in a sector.The capacity of the disc pack and the number of bits required to specify a particular sector in the
disc are respectively
Selected Answer
b)Branches off to the interrupt service routine after completion of the current instruction
d)Hands over control of address bus and data bus to the interrupting device
Selected Answer
CPU checks the status bit of interrupt at the completion of each current instruction running when there is a interrupt it
service the interrupt using ISR.
so OPTION B)Branches off to the interrupt service routine after completion of the current instruction
for(i=1;i<=100;i++)
S1 S2 S3 S4
I1 1 2 1 2
I2 2 1 2 1
I3 1 1 2 1
I4 2 1 2 1
Selected Answer
if we use without loop level parallelism than it will take 1100 clock cyles becoz loop is from i=1 to 100
as also for first i=1. it will take 11 cycles similalry for next 100 it will take 1100 cycles...
b) immediate
c) register indirect
d) register relative
isro co&architecture
MOV [BX],AL
say [BX]=200
Number of track=500
Number of sectors/track=100
Number of bytes/sector=500
Time taken by the head to move from one track to adjacent track=1 ms
What is the average time taken for transferring 250 bytes from the disc?
a)300.5 ms
b)255.5 ms
c)255 ms
d)300 ms
Refer to this.:http://gateoverflow.in/3479/gate2007-it_44
The minimum time delay between the initiation of two independent memory operations is called
a)Access time
b)Cycle time
c)Rotational time
d)Latency time
(b) option..
Consider the following program segment: What types of dependencies were included in the above program?
I1 : MOV R3 , R7 ; R3 (R7 )
I3 : Add R3 , R3 , 4 ; R3 (R3 ) + 4
D). Write after write,read after write, and write after read
Ans will be D
Q. the access time of cache is 100 microsec, the access time of main memory is 900 microsec. and hit ratio is 95%, then
what is the access efficiency related to cache?
Effective memory access time with cache = .95 * 100 + 0.05 * 1000 = 145 microsec.
r: Rotational speed.
Which of the following expression gives the total avg access time?
a. Ts+(r/2)+(rb/N)
b. Ts+(1/2r)+(rb/N)
c. Ts+(1/2r)+(N/rb)
d. Ts+(1/2r)+(b/rN)
Selected Answer
=1/2r
So ans is d
a computer system contain a main memory of 32k 16 bit words. it also has 4k word cache divided into 4 slot sets with 64
word per slot. assume that the cache is initially empty.
given data: | tag 3 bit | set 4 bit | word 6 bit | and no of cache line 2^6
The processor fetches word from locations 0,1,2,.............4531 in that order. it then repeats this fetch sequence 9 more
times. Assume a LRU policy for block replacement . how many miss operation occur in total??
5.391 no of clock cycle required for bellow figure "in case of no operand
forwarding used" ?? top gateoverflow.in/27741
Nothing given, am considering risc pipelining. Data Mem accessed during MA stage only. It will take 11 cycles
no advantage in having too many pipeline stages, Objective of Classic RISC pipeline is to make CPI = 1, with the purpose of reducing
average instruction execution time. Achieve that no matter how many stages.
increase in the number of pipeline stages will involve more buffer registers between stages, thereby reducing speed of overall pipeline.
frequency of what? system? if of system then it depends on the processor's clock not stages.
B) How many bits are required to represent the nth Fibonacci number in binary?
http://gateoverflow.in/20746/number-bits-binary-required-represent-digit-decimal-number
using a sequential implementation, it takes a total of 320 ns for each instruction, 300ns for combinational logic to complete
and 20 ns to store result. This means that a throughput will be 3.12 millions instructions/second. assuming you switch to a 3
stage pipeline by splitting the combinational logic into 3 equal parts and all reg. take 20ns to store results.Assuming pipeline
never starts, what will be the improvement in throughput?
Time in pipeline=100+20+20=140
Throughput=1/140ns=7.14
So improvement=7.14-3.12=4.02
consider unpipelined machine with 12 ns clock cycles. It uses 4 cycles for alu operation and branches, whereas 5 cycles for
memory operations. Assume that the relative frequencies of these operations are 30% 20% 20%.Pipelining overhead is 1 ns.
The speedup of the pipeline is:
2.0 3.1 2.8 3.5
Selected Answer
.3 ∗ 4 +.2 ∗ 4 +.2 ∗ 5
.3 +.2 +.2
CPI = = 4.2
clock cycle timenon-pipeline = CPI*Clock cycle = 4.2*12 = 50.4
CPI pipeline = 1
Clock cycle time = 1*(12+1) = 13
50.4
S = 13 = 3.87
5.398 clash of cache block replacement and page replacement top gateoverflow.in/25673
can cache block replacement and page replacement activities clash with each other?
No.
They may/may not occur at different levels for same instruction, but their event will not affect the result of the
instruction.
The doubt is, Will there be definitely a cache miss for something in instruction if there was a page fault for the same
instruction?
What will be the average cost per bit for a system with main memory of 1024 cost, 100 units and secondary memory of 4096
cost, 10 units?
Consider c code:
for(i=0;i<=100;i++)
A[i]=B[i]+C;
A & B are 64 bit arrays and C & i are 64 bit integers. Assume instruction size to be 4 bytes. A, B, C and i are at addresses
0,5000,1500 and 2000.Assume that the values in registers are also between iterations of the loop. Write the assembly code
for the c code fragment.
5.401 percentage of time of cpu blockage during dma transfer top gateoverflow.in/26367
Consider a disk drive with following specifications: 16 surfaces, 512 tracks/surface, 512 sectors/sector, 1KB/sector, rot.
speed 3000rpm. The disk is operated in cycle stealing mode whereby whenever one byte word is ready it is sent to memory;
similarly for writing the disk surface reads a 4 byte word from the memory in each dma cycle. Memory cycle time is 40ns.
The max. percentage of time that cpu gets blocked during dma operation:
y
Then % of time CPU Blocked = x + y ∗ 100
= 195ns(approx)
y 200
Therefore x + y ∗ 100 = 200 + 195 ∗ 100 = 50%
the mapping function is implemented using the address. For purpose of cache access each main memory address can be
viewed as containing three fields: the least significant w bits identify a unique word or byte within a block of main memory.
the remaining s bits specify one of the 2^s blocks of main memory. The cache logic interprets these s bits as a tag of s-r bits
and a line field of r bits.The number of lines in cache equal to?
2^r 2^(r+w)
There can be 2s−r distinct memory blocks going to each cache line and that is why we need s − r tag bits to identify which
memory block is currently present.
A CPU has cache with block size 64 bytes. The main memory has k blocks, each being c bytes wide. Consecutive c byte
chunks are mapped on consecutive blocks with warp around. All the k blocks may be accessed in parallel, but two accesses
to the same block need to be serialized. A cahe block access may involve multiple iterations of parallel block accesses
depending on the amount of data obtained by accessing all k blocks in parallel. Each iteration requires decoding the block
numbers to be accessed in parallel which takes k/2 ns. The latency of one block access is 80ns. If c=2 and k=24 then latency
of retrieving a cache block starting at address zero from main memory is
5.404 Question on constructing larger RAM from smaller RAM top gateoverflow.in/33630
Given explanation:
Please explain me the given explanation of this question (if possible with a dig),
co&architecture
ans is 4
For a computer address,if we reduce the no of bits by 2 and if we double the addressability then
total address space will be
3)Remain same
6.3 Bitmap: Calculate Number Of Disk Block using bitmap method top gateoverflow.in/30585
For a Hard disk of Capacity 20 MB . Disk block address of 16 bits and disk block size of 1 KB . The number of disk blocks
required to store all the Free Blocks using Bitmap method is
1
2
3
None
Selected Answer
1 block=1kB=2^10*8 bits
no of blocks=20*2^20/2^10=20*2^10 blocks
=ceil(2.5)=3
so 3 blocks required
please clear the confusion between both these processes, whether they occur simultaneously or not and how?
cache-memory
Selected Answer
In the discussion
https://docs.google.com/document/d/1yOhA-OFenops6oqmdAw6yBGCpLpzLxF_eSl1tOyzF6w
It has been mentioned that virtual/main memory is divided into pages/frames and cache block is a smaller division of the
same.
# 0f tracks=1024
#of sectors/track=512
a)What is the percentage of improvement(approx) in average access time ,if disk speed is doubled?
Bernstein's conditions are not satisfied but statements are executed concurrently.
Bernstein's conditions are not satisfied, so statements are not executed concurrently.
None of these.
operating-system concurrency
Selected Answer
1)R(S1)∩W(S2)=∅
2)W(S1)∩R(S2)=∅
3)W(S1)∩W(S2)=∅
two statements dont have any dependency and can be executed parallely
6.6 Concurrency: Given a code snippet as question,are there any fast tricks
to Test the three neccesary conditions for the process synchonization. gateoverflow.in/3771
top
First do check for mutual exclusiveness. Then do for bounded waiting and progress. Its not difficult to do- in coming week
we will take on all previous questions given below and the same technique should work in almost all of them.
http://gateoverflow.in/tag/process-synchronization
Consider the following sequential code which is executed in a multiprogramming mode by assuming that each statement can
execute independently to achieve the concurrency. If any statement dependent on other statements then those statements
will be executed in the order.
S1: a = b + c;
S2: x = y + z;
S3: y = a + c
S4: q = y + z
Which of the above statements can execute concurrently at the beginning of execution?
a)S3 and S 4
b)S2 and S 3
c)S 1 and S 2
d)S2 and S 4
operating-system concurrency
I think the answer is d. S1 executes first then S3(which uses value of a to calculate y) and then any of S2 or S4
executes(which use value of y). What is your opinion?
context-switch
http://stackoverflow.com/questions/7439608/steps-in-context-switching
b. Memory speed also matters- because process state is saved on stack and it is in memory.
d. process size also matters as say for example, for a smaller process we require small amount of page tables (assuming
multilevel paging).
e. Matters as long as register copying doesn't work in parallel, anyway this is not in options.
Type 1 Type 2
Process
Used Max Used Max
P1 1 2 1 3
P2 1 3 1 2
P3 2 4 1 4
Predict the state of this system ,assuming that there are a total of 5 instances of resource type 1 and 4 instances of resource
type 2.
b)Safe state
c)Unsafe state
d)Deadlock state
deadlock
The system is in an unsafe state. In order to be sure a process can complete, it will need its request of all resource types
to be satisfied, so you need to look at the need for each process for all resource types and see if what is available can
satisfy any process’s needs. In this example we have the following needs: Process Type 1 Type 2 P1 1 2 P2 2 1 P3 2 3 As
we have only 1 unit of each resource type available, and no process has a need that can be satisfied, so the system is
unsafe.
but in bankers algorithm if system found in unsafe state how to check further for deadlock. explain with example
deadlock
http://www.cs.jhu.edu/~yairamir/cs418/os4/sld025.htm
If I have 10 processes and each process wants 3 resources so now usually we first calculate the maximum no of resources so
that there is deadlock by assigning one resource less than the maximum need of the resource and then add 1 to it , to find
the minimum no of resources to remove deadlock ,I agree to that logic too so by using that I get the answer as 21 ,Now
what if I assign 1 resource initially to 9 processes and then assign 3 resource to 10th process or assign 2 resource to any
one of the process and 1 resource to the remaining this would account to 11 which will lead to deadlock and then add 1 to it
=12 ,this would remove deadlock , what is the mistake in this logic ?
deadlock
Total number of just enough free resources needed in a system such that Deadlock never happens is given by :
So, if there are 21 resources in our system then it is just the enough number that deadlock can never happen, no matter
how the distribution of resources among processes takes place.
Mistake in your logic is that you are Not considering that there is a chance of free resources(which in your
case =12) getting uniformly distributed among the requesting processes, which is sufficient to bring the
Deadlock.
Which of the following is not a necessary condition for a deadlock among processes?
deadlock operating-system
it is necessary condition for deadlock.since if resources are not shared then every process will get its private resources and
always executes.
(b) No Preemption
so answer is maybe C or D
True/False
(1) Mutual Exclusion is guaranteed?
(2) Deadlock free Algorithm?
(3) Progress is guaranteed?
Selected Answer
The mutual exclusion not guaranteed as it can context switch at else statement of entry section and both process can
enter the CS
Progress is satisfied because entry of the process is only decided by the processes willing to enter critical section. because
occupied can be made 0. as soon as process completes
In order to prevent deadlock we try to disable any one of the necessary conditions of deadlock .Now my point of confusion is
that while we have to disable Hold and wait we say that either a process must make request initially only or if before it can
request for additional resources it must be able to release all the resources that are currently allocated to it .
Now in case of disabling No Preemption also we do similar things like if a process is holding some resource and requests
another resource that cannot be immediately allocated to it ,then all the resources currently being held are preempted , so
then what is the basic difference between the two when in both of these scenarios we are trying to release the resources
from the process if it is trying to ask for some additional resources ?
deadlock
Hold and wait: 1] Allocate the resource before the start of the process
2] The process should release the existing resources before making new request
e.g. P1 request for 100 instance of R1 but allocated only 75
then P1 should release all the pre allocated resource before making another new 100 request
and keep on doing requesting and releasing untill it gets all 100 instances .
OR
deadlock
Does Deadlock imply no Bounded waiting Or no Progress or BOTH of These?Also provide explanation in support
deadlock process-synchronization
Starvation is long waiting. While deadlock is infinite waiting. Deadlock surely implies no bounded waiting.
Consider the following situations for three process P1, P2 and P3. [Assume R1, R2 and R3 are resources]
S1: P1 is holding R1 but it is tied up in a busy wait loop repeatedly trying to access R2, which it never gets because R2 is
held by P2. P2 is also stuck in a busy wait loop repeatedly trying to access R3, which it never gets because R3 is held by P3.
P3 is also in a busy wait loop repeatedly trying to access R1.
S2: P1 is holding R1 and issued a blocking call for R2, which is held by P2. P2 issued a blocking call for R3, which is held by
P3, P3 issued a blocking call for R1. Find which of the following is correct for above situations.
A) S1 is deadlock S2 is starvation
B) S1 is livelock S2 is starvation
C) S1 is starvation S2 is deadlock
D) S1 is livelock S2 is deadlock
Here it is very easy to see that S2 is deadlock. For S1 I am not sure why it should be livelock. It is starvation for sure, but
every livelock is special case of starvation. Answer given is D)
Defination of Livelock :- A livelock is similar to a deadlock, except that the states of the processes involved in the livelock
constantly change with regard to one another, none progressing.
Here can we say S1 is livelock because Processes P1,P2 , P3 are constantly changing between running & Ready states ?
"states of the processes involved in the livelock constantly change with regard to one another, none progressing" is
Processes switching between ready & Running state.
Selected Answer
D is correct. S1 is livelock and S2 is deadlock. In S1, the processes are executing instructions to get out of the lock (busy
checking) which makes it a livelock.
Ref: http://www.dcs.warwick.ac.uk/~sgm/cs237/lec/busy/
Selected Answer
Some times deadlock free.Lets assume process i started executing, and executed until flag1=true and preempted, now
process j is executing flag2=true and as flag1=true it will busy wait , again if its preempted process i will busy wait thus
deadlock will occur. If process i or j executes without preemption, assuming flags values are initially false then mutual
exclusion is there.
6.19 Deadlock: If the available no of resources are unable to meet the future
need of any of the processes then what is the state ? top gateoverflow.in/19708
Just wanted to know that if none of the needs of a process is met so can we directly say that it is unsafe state as well as will
lead to deadlock since none of the needs can be satisfied .Even if one need was satisfied and not other then we will declare it
to be unsafe but since it can't meet further the requirement of any process so then what can we say about it ?
deadlock
the question straties implies that it belongs to "deadlock detection and recovery"
2.the process which satisfies the availability is safe..and the rest will lead to unsafe hence deadlock go for recovey
A computer has six tape drivers, with n processes competing for them. Each process may need two drivers. What is the
maximum value of n for the system to be deadlock free?
a] 6
b] 5
c] 4
d] 3
Selected Answer
Give each process 1 less than it requires . and then add 1 resource
So , n*1 + 1 <= 6
so , n <=5
Without any deadlock we can have 5 processes bcz we can allocate resources(2,1,1,1,1) for processes so that one process
gets finished followed by other
1.Mutual Exclusion
2.Hold and wait
3.No pre-emption
4.Re-entrancy
operating-system deadlock
deadlock process-synchronization
initially FLAG is FALSE when PROCESS P1 tries to enter in CRTITICAL SECTION If condition is TURE after that making
FLAg value false... now PRREMPT the process P1 when it is present in CS . after that try the above code for P2 process
hence now FLAG value is TRUE here for p2 process If condition falis .therfore p2 will not enter the CS hencew mutual
exclusion will be satisfied.. r
therefore starvation occur For EXACTLY ONE PROCESS EITHER U FIRST START FROM process P1 or FROM P2.. HENCE NO
DEADLOCK!
Selected Answer
now suppose if we have only 2 available resource than we can satisfy the need of process p 1 or p 2 if we first satisfy the
need of process p 1 than according to resource allocation policy all the allocated resource will be given back hence now we
have 3 available resource , now we can we can satisfy the need of process p 2 and after that we have now 4 available
resource ,
if we look in need column than process p 3 and p 5 can't be satisfed its, therefore whole system is not safe hence,
deadlock occur option ( b) cannot be the answer.
now again repeat the above whole procedure with three(3) available resource,
6.24 Deadlock: 'm' processes share 'n' resources of same type. The
maximum need of each process does not exceed 'n' and the sum all their
maximum needs is always less than m+n. In this setup deadlock can occur
or not? top gateoverflow.in/12228
This is a question from Operating System concepts by Silberschatz, Gagne and Galvin. On very first go I could make that in
such a situation deadlock can never occur. But doing guess work is a really bad habit and risky to.
So I did some paper work using Banker's Algorithm and somehow concluded that deadlock can never occur.But I need some
systematic approach on such question and proper explanation of the answer.
I'm curious to know how you guys would have solved this question.
Thanks in advance.
deadlock
Selected Answer
Consider the worst case- all processes acquire maximum resources but still not able to finish. So, the resources available
must be 1 less than than the maximum need, for each of the processes (this ensures none of them can finish).
We are given maximum need is always less than m + n. As per our condition for deadlock, resources available must be 1
less than maximum need for each of 'm' processes => totally the resources available must be less than m + n - m = n.
But 'n' is the available number of resources and hence no deadlock can occur.
deadlock
p : 1| Q: 1| R:1|S:1(Block)|P:2(Block)| Q:2(block)|R: 2(block) here 1,2 are line no of process which is executed and
P,Q,R execute line no 1 . but s is block becoz it request for the A which is hold by P , then if P execute lin2 req for B which
hold by R,so it will be blocked , Q executed line no 2 it block bcoz it request for the A . which not released .similar R req
for C which is hold byQ. so there is hold and wait or cycle . so there is deadlock .
there is not always deadlock . in these seq there no deadlock P:1 2 3| Q: 1 2 3| P: 4 | R 1 2| S 1 | R 3 4| S 2 3 4 .. you
can do also for other sequence .
a)Mutual exclusion
b)Reentrancy
d)No pre-emption
deadlock
what is mean by sufficient but not necessary condition for deadlock and what are their names?
A computer system has 6 tape drives with n processes competing for them. Each process may need 3 tape drives. The
maximum value of n for which the system is guaranteed to be deadlock free is
a) 1 b) 2 c) 3 d)4
Ans given is 2....But for 4 processes also there will be no deadlock ....If we initially allocate 1 to each process 2 will be
available...and we can allocate those 2 to the first process...after its execution 3 tape drives will be free..and 2 could be
allocated to next process...so continuing in this way we can allocate resources to each process without any deadlock......
operating-system deadlock
We have to guarantee that the system will be deadlock free in every condition. So first of all we can't invent easy ways to
allocate resources to the process, we have to see that even in worst condition, there is no deadlock (as per given
question). So in case of 2 processes there may never be possibility of deadlock. In case of 4 processes, not with your
scheme of allocation but with some other allocation- for ex, give 2 resource to P, 1 to Q, 2 to R and 1 to S-- results in
deadlock-- so it is not guaranteeing no-deadlock in 4 processes,, while in case of 2 processes , system is guaranteed to be
deadlock free.
P1 P2 P3
2 2 2 This is a deadlock state.as each of the process is waiting for one resource at
the same time, the system has reached max of its available
resources and there are no resources available which can be taken by any process and can run to completion,.
If there are 0,1,2 processes then there would be no deadlock.As in the maximum scenario of 2 processes running ,both
utilizing 4 resources we still have 2 more resources left which can be taken by either of P1 or p2,and can run to
completion,.
Ans is 2.
6.28 Deadlock: what is the difference between livelock and deadlock top gateoverflow.in/3996
what is the difference between livelock and deadlock?how will you explain livelock to layman?asked at an interview @iitb
operating-system deadlock
Selected Answer
Deadlock means two or more processes are waiting for a lock without doing anything (inactive).
Livelock means processes are active but not able to progress due to interdependence. Its like two people trying to cross a
one man bridge, both backing off together and then both trying to move at the same time and doing this indefinitely.
http://www.cs.sfu.ca/CourseCentral/300/oneill/Resources/Segment7.pdf
deadlock
Selected Answer
6.30 Deadlock: How many safe sequences possible for the given processes?
top gateoverflow.in/33348
operating-system deadlock
Selected Answer
If we took A as a starting ,then we can take C or D,for each we can make 6 sequences(let A,C, then (B,D,E) in 3! Way..)so
total 12 seq...
And same for if we start by taking D,then we can also get 4! Seq..
operating-system demandpaging
Selected Answer
so total fragmentation=(5-3)+(10-2)+(30-12)=28
so total fragmentation=(5-3)+(12-2)+(30-12)=20
ans is c
Consider a disk pack with following specifications - 16 surfaces, 128 tracks/surface, 256 sector/track and 512Bytes/sector.
Now, the disk is rotating at 3600RPM, what is the data transfer rate.
Please be as elaborative and simplified in your approach of explaining! Thank you, all the nerds on this site!
disk
Selected Answer
There are 16 surfaces -> The following operation will be carried simultaneously on by 16 read/write heads.
We will find the number of tracks one read write head will cover in one second.
Also 16 surfaces are simultaneously operated => 16 x 60 x 256 x 512 Bytes => 125829120 Bytes => 120 MBps
A Program of size 64MB is stored on disk which supports an average seek time of 30ms and rotation time of 20ms.Page size
is 4MB and track size is 32MB. if the pages of program are contiguosly placed on disk then what would be the total time
required to load the program from disk?
operating-system disk
Seek time = 30 ms
Rotation Time = 20 ms
20
Rotation Latency = 2
= 20 = 1.6MB/ms
For one page 1ms ------------------1.6MB
? 4MB
= 1.6 = 2.5ms
Total Time for one page = 30 + 10 + 2.5 = 42.5ms
64
How much space will be required to store the bit map of a 1.3 GB disk with 512 bytes block size ?
operating-system disk
We need a bit for each block. Number of blocks = disk size/ block size
= 1.3 GB / 512 B
This will give the size of bit map in bits. To get the byte size divide by 8 and we get 332.8 KB. For disk size, GB is taken as
1024*1024*1024 bytes and for KB it is 1024 bytes.
Ref: https://en.wikipedia.org/wiki/Gigabyte
In my book prescribed under our university i found in many solution they had done
not only here another sum had 128 * 100kbps = 13mbps but it should be 12.5 mbps
operating-system disk
first of all post the question otherwise we can't understand what u are talking about.
my approach
seek time 30
rotationn latency=10
tranfer time :
64 kb prog page size is 4kb so in 16 pages this prog wiil be accesed through memory since track size is given 32 kb
so in 32kb is read in one rtotaion in 20msec
so 4kb --------------------------------(20/32)*4
=2.5
for 1 page it take transfer time as 2.5msec as program is spread in pages so total acces 16 pages we need totoal time as :
(30+10+2.5)*16=680 msec
correct me !! if wrogn thanks..given ans by them is 120.
operating-system disk
Selected Answer
Seek time : time require to move the R/W Header to desired track
Now Total time taken for the first track = Seek Time + Rotation latency+ Transfer time
= 30 ms + 10 ms+ 20 ms
= 60 ms
After reading the complete one track again, there will a need to place R/W header at the track in which next 32MB data present. So for this,it will again perform seek operation and find the location from
where the next data is present.
Total time taken to transfer the second track = Seek Time + Rotation latency + Transfer time
= 30 ms + 10 ms + 20 ms
= 60 ms
Given explanation:
operating-system disk
Selected Answer
A program of size 64MB is stored on disk which supports an average seek time of 30ms and rotation time of 20ms. Page size
is 4MB and track size is 32MB. If the pages of the program are contiguously placed on disk, then the total time required to
load the program from disk in ms is _____
operating-system disk
Selected Answer
where:
(A) Track
(B) Geometrical sector
(C) Track sector
(D) Cluster
64MB
Program has to be loaded from the disk, it will happen in the following way:
on an average takes up 2 × Rotation Time. Then it will read the track and simultaneously transfer data which will take up 1 Rotation
Time(in one rotation a head can read a single track)
1
so, till now 1 Seek Time+ 2 × Rotation Time + 1 Rotation Time has passed.
2. After reading 1st track it will move to the second track and to do that same process will be followed which will take exactly the same
time as in first case.
Hence,
1
(
Time taken to load = 2 × 1 Seek Time +
2
× Rotation Time + 1 Rotation Time )
1
(
= 2 × 30ms +
2
× 20ms + 20ms )
= 120ms
seek time 30 ms
32 MB covers in 20 ms
6.40 Disk: Estimate the average time to read a random sector from disk top
gateoverflow.in/34338
Consider a disk with a rotational rate of 10,000 RPM, an average seek time of 8 ms, and on average of 500 sectors per track.
Estimate the average time to read a random sector from disk.
(A) 7.012 ms
(B) 11.012 ms
(C) 14.012 ms
(D) 10.012 ms
operating-system disk
Selected Answer
= 60/20000 sec
=0.012 msec
11.012 ans
pls xplain the last line of the qs,"records cannot span 2 records" and what effect does it bring to the problem
disk
Cannot span means,1 record cannot be split into two sectors.So in the above example a sector can hold 4000B and hence
it can hold only 14 records of 280B [14*280=3920] and 8 bytes will be wasted.So here the 15th record cannot be split.
plz explain scan cscan ,i have 2 books which gives 2 different implementation
operating-system disk-scheduling
SCAN: In SCAN algorithm the disk arm moves into a particular direction and services the requests coming in its path and
after reaching the end of disk, it reverses its direction and again services the request arriving in its path. So, this
algorithm works like an elevator and hence also known as elevator algorithm. As a result, the requests at the midrange
are serviced more and those arriving behind the disk arm will have to wait.
Advantages:
High throughput
Low variance of response time
Average response time
Disadvantages:
Long waiting time for requests for locations just visited by disk arm
CSCAN: In SCAN algorithm, the disk arm again scans the path that has been scanned, after reversing its direction. So, it
may be possible that too many requests are waiting at the other end or there may be zero or few requests pending at the
scanned area.
These situations are avoided in CSAN algorithm in which the disk arm instead of reversing its direction goes to the other
end of the disk and starts servicing the requests from there. So, the disk arm moves in a circular fashion and this
algorithm is also similar to SCAN algorithm and hence it is known as C-SCAN (Circular SCAN).
Advantages:
Provides more uniform wait time compared to SCAN
Reference : http://geeksquiz.com/disk-scheduling-algorithms/
** I don't know what kind of different implementation you have found. Can you please mention that also?
Any way the above explanation for both the algorithms are good and its same as in Galvin so you can follow this.
6.43 Disk Scheduling: Find the number of head movements in cylinders using
SSTF scheduling. top gateoverflow.in/41420
Consider the following disk request sequence for a disk with 100 tracks.
Head pointer starting at 53 (current position of R/W heads).Find the number of head movements in cylinders using SSTF
scheduling.
Selected Answer
it follows :53--65--67--37--14--98--122--124--183
Which of the following disk scheduling policies results in the minimum amount of head movement?
(A) FCFS
(B) Circular scan
(C) Elevator
disk-scheduling
6.45 Disk Scheduling: Find the number of head movements in cylinders using
SCAN scheduling. top gateoverflow.in/41419
Consider the following disk request sequence for a disk with 100 tracks.
Head pointer starting at 53 (current position of R/W heads) and moving in left direction.Find the number of head movements
in cylinders using SCAN scheduling.
disk-scheduling made-easy
In SCAN Scheduling,the disk arm starts at one end of the disk,and moves towards the other end,servicing requests until it
gets to the other end of the disk,where the head movement is reversed and servicing continues.
Here in this question,R/W head is at 53 position and moving in left direction so it will serve all the requests till 14.
Take a look.
53-->37
37-->14
Now it will reach the end of the disk 0 so this will also be a track movement.
14-->0
0-->65
65-->67
67-->98
98-->122
122-->124
124-->183.
6.46 Disk Scheduling: which disc access scheduling policy is used? top gateoverflow.in/16939
There are 200 tracks on a disc platter and the pending requests have come in the order - 36,69,167,76,42,51,126,12 and
199.Assume the arm is located at the 100th track and moving towards track 200.if sequence of disc access is
126,167,199,12,36,42,51,69 and 76 then which disc access scheduling policy is used?
a)Elevator
c)C-SCAN
disk-scheduling
Selected Answer
It should be C-SCAN il as the disc access has continued towards the nearest end from initial from 100 and
and then jumped to the other end and serviced 12,36,42,51,69,76 in similar manner .
Disk requests come to a disk driver for cylinders in the order 10, 22, 20, 2, 40, 6 and 38 at a given time when the given disk
drive is reading from cylinder 20. The seek time is 6ms per cylinder.
1.What is the total seek time, if the disk arm scheduling algorithm FCFS is used?
2.What is the total seek time, if the closest cylinder next scheduling is used?
operating-system disk-scheduling
Selected Answer
1. FCFS
Total seek time
= 10*6 + 12*6 + 2*6 + 18*6+ 38 * 6 + 34*6 + 32*6
= 146*6
= 876 ms
operating-system dram-refreshing
top
Let the page fault service time be 10ms in a computer with average memory access time being 20ns. If one
page fault is generated for every 10^6 memory accesses, what is the effective access time for the memory?
Effective memory access time = hit rate(main memory access time) + page fault rate(main memory access time +
page fault service time).
Suppose the time to service a page fault is on the average 10 milliseconds, while a memory access takes 1
microsecond. Then a 99.99% hit ratio results in average memory access time of (GATE CS 2000)
Average memory access time = hit rate(main memory access time) + page fault rate( page fault service time).
These two questions are asked in gate, both uses different formulae, pls explain in detail what is the difference among them,
I found them as similar.
memory-management effective-memory-access
ANS. 30 ns.
Calculate the exponential averaging for the SJF with τ 1=10, α=0.5 and previous runs as 8,7,4,16(give the answer correct to
one decimal place)
6.51 File System: Can someone help me to find out neumericals on File
Directory Structure . top gateoverflow.in/30450
file-system operating-system
Selected Answer
http://www.cs.utexas.edu/~lorenzo/corsi/cs372/06F/hw/11sol.html
This helped me :)
a computer system uses a single level directory structure.The directory occupies 2 disk blocks.The disk block size is 2KB.
Directory entry size is 4 bytes. What is the maximum number of files in the file system?
a 512
b 256
c 1k
d 786
operating-system file-system
Selected Answer
Since single level directory structure, so the directory will have the file location information stored. Maximum number of
file supported will be
Given the disk Capacity of 30 MB has block size 512 bytes and block/cluster is 4, the number of entries require in the FAT
table is?
a) 30*2^11
b) 30*2^20
c) 30*2^31
d) 30*2^9
Selected Answer
So ans is D
Selected Answer
Each block is address with 16 bit,means there are total 2^16 blocks,
How many times Hi printed and how many child process will created?
include<stdio.h>
int main()
{
printf("hi");
fork();
fork();
}
fork non-gate
"Hi" will be printed only once because fork() calls are after pintf("hi").
operating-system fork
After first fork there will be one child. After second fork, 2 new child processes (as now 2 processes are executing fork)
In the given code we have 4 levels and thus 1 + 2 + 4 + 8 = 15 child processes plus 1 parent process.
In general it will form complete binary tree when fork is executed in a loop without any further condition.
for(i=0; i<n; i++)
6.57 Fork: Fork query what will be the effect of t3= -1 here? top gateoverflow.in/34920
fork operating-system
answer is 4. dont count c1 c2 c3 c4..the childrens are at t1=0,t2 = 0,at t3 =0 for both t2 != 0 and t2 = 0. so
total 4
main()
{
int t1=0,t2=0,t3=0;
t1=fork();
t2=fork();
if(t1!=0)
{
t3=fork();
printf("0");
}
}
Find the total number of processes that will be created by the above program execution.
operating-system fork
Selected Answer
At the call of fork, a child process is created which executes the same code of the parent from that point. The return value
of fork is 0 for the child and is child pid (not 0) for the parent and this value is used to distinguish between child-parent
while writing code using fork.
Thus 5 child processes are created. Since the question asks for "total number of processes created" we must include
parent also making this 6 processes in total,
6.59 Fork: How many process are created by the program? top gateoverflow.in/19324
int main(){
int i;
for(i=0;i<4;i++)
fork();
return 0;
}
in my calculation i think 14 processes will be created including the the parent process. am i right ? Is there any easier
method to solve this kind of question ?? please provide the right approach to solve these kind of problems
operating-system fork
Selected Answer
If the program have n Fork() call then it will have 2 n-1 child processes
operating-system fork
child process gets 0 as process id and parent gets child's process id as its process id. so t1 's child process won't execute
3rd fork(). therefore 4 times 0 will be printed and total process = 6.
fork operating-system
The given answer is wrong. The output may be "HiHi" or "Hi". At the time of fork, printf might not have been executed and
hence the code of printing might be copied to child as well. (printf is a non-blocking call). To avoid this behaviour, either
we have to use fflush or use the return value of printf before calling fork.
What is the output and how many child(what is the code of all other child .what they copied from parent give tree diagram)
t1=0;t2=0;
Fork();
Printf("hi");
t1=Fork();
Printf("hi");
t2=fork();
printf("hi);
fork();
printf("hi);
fork
what if the program like this(t1 is copied to all or printf will copied to all child)
main()
t1=0,t2=0;
t2=fork();
Fork();
Printf("Hi");
Fork();
t1=Fork();
Printf("hi");
Arjun sir , I don't know the buffer concept.please explain with tree method. How many child and how many time Hi printed.
fork
Selected Answer
20 "hi" will be printed and 15 child process will be created , here is an image how to visualize it. The best way is to write
value on branches, the parent is which have all the values of fork! =0;
sorry the right hand side will be the parent. i just misplaced it. well the concept is right.
So 16 times "hi"
Total 20 times....
#include <stdio.h>
#include <unistd.h>
int main()
{
fork();
fork() && fork() || fork();
fork();
printf("forked\n");
return 0;
}
operating-system fork
In The diagram PLZ REPLACE PARENT WITH CHILD, AND CHILD WITH PARENT. the concept is right and i have edited the
theory just the diagram. as no answer is available. kindly cooperate.
what i think is answer will be 16 including the parent process. Go with the tree method other wise you will get lost in this
Ok just keep in mind that the "and" operator is fully calculated only when first will result in one .
as if it is one then only seeing second one matters, if first is zero then definitely it will be zero, similarly for or . if first
result in one no need to calculate further.
so here we go , one more point- fork return non zero to parent i.e process id to the newly created child , and child will
have value zero
so in this image at point a first fork is called. then we got two nodes b and c. suppose c is the parent
now the line 2 . with and condition will be executed, so first fork will be executed by b , which will create two process i.e d
and e,
now we know one will be parent and one will be child. suppose d is the child then it get return value as zero and hence
condition for it will become 0 and something. as mentioned earlier it will stop execution and wait to execute line number 3,
now the point e will execute further. and will produce L and I, now here also one will be parent and one will be child . for
child the LHS for the OR will become 1 and zero which will be zero , and this will go further while for the another one it will
become 1, so it will terminate and wait to execute line number 3. and only one process will call the fork again, and then all
will execute line number 3. total it will be 16 and 1 parent will be there so 15.
fork() system call spawn processes as leaves of growing binary tree. If we call fork() twice, it will spawn 2
2 = 4 processes. All these 4
processes forms the leaf children of binary tree. In general if we are level l, and fork() called unconditionally, we will have 2l processes at
level (l+1). It is equivalent to number of maximum child nodes in a binary tree at level l(+1).
As another example, assume that we have invoked fork() call 3 times unconditionally. We can represent the spawned process using a full
binary tree with 3 levels. At level 3, we will have 23 = 8 child nodes, which corresponds to number of processes running.
The logical operator && has more precedence than ||, and have left to right associativity. After executing left operand, the final result will be
estimated and execution of right operand depends on outcome of left operand as well as type of operation.
In case of AND (&&), after evaluation of left operand, right operand will be evaluated only if left operand evaluates tonon-zero. In case of
OR (||), after evaluation of left operand, right operand will be evaluated only if left operand evaluates to zero.
The man pages of fork() cites the following excerpt on return value,
“On success, the PID of the child process is returned in the parent, and0 is returned in the child. On failure, -1 is returned in the parent,no
child process is created, and errno is set appropriately.”
A PID is like handle of process and represented as unsigned int. We can conclude, the fork() will return a non-zero in parent and zero in
child. Let us analyse the program. For easy notation, label each fork() as shown below,
#include <stdio.h>
int main()
{
fork(); /* A */
( fork() /* B */ &&
fork() /* C */ ) || /* B and C are grouped according to precedence */
fork(); /* D */
fork(); /* E */
printf("forked\n");
return 0;
}
The following diagram provides pictorial representation of fork-ing new processes. All newly created processes are propagated on right side
of tree, and parents are propagated on left side of tree, in consecutive levels.
At level 1, we have m and C1 running, and ready to execute fork() – B. (Note that B, C and D named as operands of && and || operators).
The initial expression B will be executed in every children and parent process running at this level.
At level 2, due to fork() – B executed by m and C1, we have m and C1 as parents and, C2 and C3 as children.
The return value of fork() – B is non-zero in parent, and zero in child. Since the first operator is &&, because of zero return value, the
children C2 and C3 will not execute next expression (fork()- C). Parents processes m and C1 will continue with fork() – C. The children C2
and C3 will directly execute fork() – D, to evaluate value of logical OR operation.
At level 3, we have m, C1, C2, C3 as running processes and C4, C5 as children. The expression is now simplified to ((B && C) || D), and at
this point the value of (B && C) is obvious. In parents it is non-zero and in children it is zero. Hence, the parents aware of outcome of overall
B && C || D, will skip execution of fork() – D. Since, in the children (B && C) evaluated to zero, they will execute fork() – D. We should note
that children C2 and C3 created at level 2, will also run fork() – D as mentioned above.
At level 4, we will have m, C1, C2, C3, C4, C5 as running processes and C6, C7, C8 and C9 as child processes. All these processes
unconditionally execute fork() – E, and spawns one child.
At level 5, we will have 20 processes running. The program (on Ubuntu Maverick, GCC 4.4.5) printed “forked” 20 times. Once by root parent
(main) and rest by children. Overall there will be 19 processes spawned.
The evaluation order of expressions in binary operators is unspecified. For details read the postEvaluation order of operands. However, the
logical operators are an exception. They are guaranteed to evaluate from left to right.
Source: http://www.geeksforgeeks.org/fork-and-binary-tree/
Consider a file system that uses UNIX like inodes to keep track of the sectors allocated to files. Assume that disk blocks are
1 KB in size, disk block addresses are 32 bits and the inode has space for 8 direct blocks, 1 singly indirect blocks, 1 doubly
indirect block and 1 triply indirect block. What is the largest disk drive that could be fully utilized by this system?
Consider a file system implemented using unix inode. The system consist of n0 direct disk block addresses, n1 single indirect
disk block addresses, n2 doubly indirect DBAs and n3 triple indirect DBAs.
What is the total size of file system? Explain how the formula for it holds good.
What is the largest file size possible? Explain how the formula for it holds good.
What is the Maximum possible size of file system? Explain how the formula for it holds good.
In a Unix-style file system, the inode is a data structure used to represent a file-system object; which can be one of various
things including a file or a directory .
this def. from Wikipedia; the part underlined above seems obscure.
to calculate Maximum File Size in the above given question I will use only the triple indirect and obtain
.
This is so because using one particular Triple Indirect Pointer I can point to this much data at Maximum; A Triple indirect
pointer can ultimately point to maximum number of Disk Blocks in comparison to direct/single/double.
and the Total Size of the file system (i.e. how much data we can point to + it excludes file system metadata)
saying this holds good to me coz in this formula all pointers, which INODE has been representing are taken into account.
But I investigated this, asked the GATEOverflow community and found that
If I consider this good then it is making me assume that all other metadata of inode is vanished and only a single disk block
is being used completely(something like that) to hold up pointers to other disk blocks. What about single/double/triple
indirect pointing phenomenon?
and for the Maximum possible Size of file system = total size of disk on which the file system is implemented. this
includes data we can point to + all of metadata together.
Q.1) Consider the Unix inode with 12 Direct Disk Block Addresses(DBA), 1 single indirect DBA, 1 Doubly Indirect DBA and 1
triple indirect DBA. The DBA requires 32 bits and the Disk block size is 1KB. Then what is the maximum file size possible?
Vs
Q.2) A file system with 300 GByte disk uses a file descriptor with 8 direct block addresses, 1 indirect block address and 1
doubly indirect block address. The size of each disk block is 128 KBytes and the size of each disk block address is 8 Bytes.
What is the maximum possible file size in this file system?
Vs
210
22
So, number of address in one block = = 28
(
Maximum possible file size = 12 + 256 + 2562 + 2563 × 1KB = 16.0627GB )
27
23
Q2) Number of address in one block = = 16
(
Max possible file size = 8 + 16 + 162 × 128KB = 35MB )
0 votes -- Pooja ( 22773 points)
I think, 2 times synchronization is needed. One for connection establishment and other for connection release(If it is what
you're asking,actually i'm not getting what you mean by "synchronization points")
producer's code
do { *
// produce an item in nextproduced
wait(empty) ;
wait(mutex) ;
buffer[in] = nextProduced;
in = (in + 1) % BUFFER-SIZE;
signal(mutex) ;
signal(full) ;
}
while (TRUE) ,-
consumer's code
do {
wait(full);
wait(mutex);
nextConsumed = buffer[out] ;
out = (out + 1) % BUFFEFLSIZE;
signal(mutex) ;
signal(empty) ;
}
while (TRUE) ;
My question is why do we use same mutex for both producer and consumer. Since producer does not affect 'out' and
consumer does not affect 'in', so we could have used mutex1 and mutex2.
the problem are independent they are interrelated. the mutax is the variable which tells the consumer is whether a item is
present to consume . or how many item are pressent. if it is not the case. if i use mutax 1. and mutax 2. suppose mutax
one for producer. it will go on producing while mutax1 is full. then the consumer will not be able to start as mutax 2 will
be zero ( if initally taken as false.) its value has not been changed. else if u start with max value of mutax 2 cnsumer will
consume all the data of mutax 2 and the sytem will go in live lock. neither producer will produce anything nor the
consumer will be able to consume because it will not be knowing that item is present.
simple exaple. u are playing counter strike . u took another server and another team took another server. even i start
with 5 -5 player initally . suppose u killed their one player now how will second team will come to know that their one
player is dead. it is not possible till a common interface is used.
The available main memory for loading processes is 128 MB which is divided into fixed number of partitions each of size 16
MB. If the processes of size 12 MB, and 6 MB are loaded into memory. The percentage of the internal fragmentation is
____________ (upto two decimal places)
so 4+10/32=43.75%
say it there was process of 18MB then it would cause external fragmentation..it that case we consider non allocated
blocks
what is bit rate of video terminal unit with 80 character/line , 8 bits/character and horizontal sweep time of 100 micro sec?
operating-system io-handling
80
character/line
,
8
bits/character
so
total
we
have
80*8
bits=640
bits
these
are
swappd
in
horizontal
means
we
have
to
access
in
100
micro
sec,so
100
microsec---------------------640
bits
100*10-6---------------------------640
bits
1
sec---------------------------(640)/(100*10-6)
=6.4mbps
(rate)
A program has just read the 12th disk block using linked allocation. If it next want to read the 5th disk block, then the number
of disk blocks must the program already read to reach the 5th disk block ________.
linked-lists
A process spends 20% of its execution time waiting for completion of I/O operation. If there are 4 such processes in memory
at once, then the probability of CPU time wasted is _. (Assuming all I/O operations are overlapped)
My answer is : 0.200
We can assume that each process takes 10ms to complete, so time waiting for I/O is 2ms. For 4 processes, we will have
total wasted time as 8ms. This is divided by total execution time 40ms.
In solution, they gave a formula, if there are 'n' processes competing with waiting time 't', then probability of CPU time
utilization is tn . How is this formula coming?
n +1 C (n −2 ) +n +1 C (n −1 ) ≤ 90
getting n= 1 to 9
so answer should be 9
maths
Fragmentation is
a. dividing the secondary memory into equal sized fragments
b. dividing the main memory into equal size fragments
c. fragments of memory world used in a page
d. fragments of memory words unused in a page.
Please explain.
operating-system memory-allocation
http://en.wikipedia.org/wiki/Fragmentation_(computing)
If i have a Reference string with S and page fault as N . then what is number of page fault when we take reverse of string
sr ?
1)FIFO
2)LRU
3)MRU
4)OPTIMAL
// i was given this question for 1 algorithm , but the i tried to find for all page replacement algorithm .
memory-management
// i can be wrong . i just tried it . it may happen that all relation ,ay be wrong and depends upon reference string only
so according to me
Am i right sir ?
operating-system memory-management
Selected Answer
fixed partition suffers from external and internal fragmentation both if memory is not continous and variable partition
suffers from only external fragmentation
Is it always true that FIFO will suffer from Belady Anamoly when i increase the frame number allocate from k to k + 1 .or it
depends upon the reference string also ?
memory-management
Selected Answer
it's not always true. it depends on the string. all cases does not follow belendy anamoly.
On a system using fixed partition with sizes 2^8, 2^16, 2^24, 2^32 and 2 ^ 64. How many bits must the limit register
have ?
a) 16 bits
b)24 bits
c)32 bits
d) 64 bits
memory-management
yes . limit register tell us that we always access under the limits of the process. whenever a request is made of data or
instruction in a process. the base address is added with limit register. every request must be less than this address. here i
have the largest segment of 2^64 bits so 64 bit will be required. because in worst case i have to check whether the
request is crossing the 2^64 segment.
If page fault service time is 50 milli second and memory access time is 100 ns, then what will be EMAT, if the probability of
page fault is p ?
a) 500000 + 100p ns
b) 100 + 500000p ns
c) 10 −7 − 5p × 10 −2 seconds
d) 10 −7 + 49.9p × 10 −3 seconds
operating-system memory-management
Selected Answer
= p(50000000)ns +100ns−100pns
Page fault service time includes memory access time too. So need to add it in case of page fault.
Consider a system in demand paged enviorment supporting a virtual address of 32bits with a page size of 4KB, physical
adddress is 29 bits . Page fault rate is 2% page fault service time is 20 ms and main memory access time is 2micro second .
Page table contain 1 valid/inavlid bit , 1 dirty bit , 1 ref bit and 3 bit for protection apart from other information .
If Page Table entry size is a multiple of 3 byte What is approx page table size of process in bytes and what is effective
memory acess time ?
a)6MB,42O MICROSEC
d)3MB , 42microsec
memory-management
In this context why don't we calculate memory access twice when there is no page fault. Because in case of paging system
to read a page from memory we need two memory read, one for page table access and another for reading actual page-
frame.
What is the maximum process size that we can have in a 32 bit operating system?How is that limit calculated.
memory-management
A 32 bit computer can address 2^32 memory so . the maximum process size will be 4GB.
The size of the virtual memory is the maximum size of the maximum size your computer can address using pointers. so a 32 bit os will have
a 32 bit address bus. so by 32 bit address bus we can address 2^32 bytes.
while 64 bit computer or os means it uses 64 bit address bus. so it can address 2^64 bytes of memory.
A certain computer system has the physical address space as 2 16 bytes . And consists of 2byte page table entries . Assume
that each page table entry contain (beside other information ) 1 bit for valid , 3 bit for protection and 1 bit for dirty . How
many bits are available in page table entry for storing the aging information for the page ?
a) 3 b) 4 c) 5 d) 6
memory-management
Selected Answer
so now page table entry bit = no of bit used for farme number + 1 valid + 3 bit for protection + 1 dirty bit + Required
Aging information
so 16 = 7+1+3+1+x
x=4
is it right ?
Assume 140K, 260K, 60K memory is free. What is the total external fragmentation that arises for the following requests
110K, 30K, 210K, 50K using Best-fit policy, assume no compaction
A) 120K
B) 110K
C) 60K
D)30K
My ans:
Please explain.
memory-management test-series
Selected Answer
50k request also der which occupy 260kth slot. so total external fragmentation is 30k + 30k = 60k only.
operating-system memory-management
Selected Answer
http://gateoverflow.in/26223/external-fragmentation-best-fit-memory-allocation-policy
A Computer system implements 8 kilobyte pages and a 32-bit physical address space. Each page table entry contains a valid bit, and the translation. If the maximum size
of the page table of a process is 20 megabytes, then what will the length of the virtual address supported by the system (in bits)?
a. 26
b. 30
c. 36
d. 20
http://gateoverflow.in/8247/gate2015-2_47 The above question related to this gate question.But when I tried i got 33 bit
but i choose 30 bits
operating-system memory-management
Selected Answer
I will use the answer by Arjun given on the link you gave, with the relevant values modified.
operating-system memory-management
Total number of addressable block are 2^16 , Total number of blocks needed for directory = 4 , so maximum file size in
blocks is 2^16 = 65536 . Total memory for storing 2k file records of 32 bits each = 2048*32/8 = 8192 bytes. Total
number of blocks need to store directory is 4 , so 4 * BlockSize = 8192 , BlockSize = 2048 bytes. Total size of largest
file in blocks(MB) = 65536*2048/2^20 = 128 MB
10bit ---8 bit ---6 bit --8 bit . We use a 3 level page such that first 10 bit are used for the first level and so on .
then what is size of a page table for a process that has a address 0 ?
a 4096 bytes
b 4274 bytes
c 4608 bytes
d 2148 bytes
memory-management
We have 3 levels of page tables. And address 0 is for start address? Where is the question taken from?
Consider a system using a sengmented paging architecture. The segment is divided into 8k pages each of size 2k words .
The segement table is divided into 256 k pages each of size 512 words. The page table entry size requires 64 bits . the frame
number requires 22 bits then calculate logical address (LA)
a) 51 bits
b) 61 bits
c) 33 bits
d) 64 bits
memory-management operating-system
Selected Answer
Since Segment is divided into 8K pages of 2K words each.It means Paging is done over D part of address .
Now D Part will be broken into P|D' Format.
Where P is PAge No
D'- Word No
So D=P+D'=log(8K)+log(2k)=13+11=24
Now Segment table is also divided.It means Paging is done on S part Of Logical address.
S=Log(256K)+Log(512)=18+9=27
I always get confused between internal and external fragmentation.Is there any relation between them?pls
explain in detail
memory-management
Fragementation:
Fragmentation occurs when memory is allocated and returned to the system. As this occurs, free memory is broken up
into small chunks, often too small to be useful.
Internal Fragmentation:
Internal fragmentation occurs when a process is assigned more memory than it has requested and the wasted memory
fragment is internal to a process.
Memory block assigned to process is bigger. Some portion of memory is left unused as it can not be used by another
process.
External
Fragmentation:
External fragmentation occurs when there is sufficient total free memory to satisfy a memory request, yet the memory is
not contiguous, so it cannot be assigned. Some contiguous allocation schemes may assign a process more memory than it
actually requested (i.e. they may assign memory in fixed-block sizes).
Total memory space is enough to satisfy a request or to reside a process in it, but it is not contiguous so it can not be
used.
http://stackoverflow.com/questions/1200694/internal-and-external-fragmentation
operating-system memory-management
Selected Answer
160000∗ 16
128
Number of pages needed = = 20000 = 20*10^3
6.91 Memory Management: No. of bits in physical and logical address space
top gateoverflow.in/14684
Is it possible to have different number of pages and frames or they need to be equal in number?
memory-management
Selected Answer
Given answer: 8
Please explain
operating-system memory-management
Disk block is 8 KB
Hit for 1-level PT only and search the TLB again for 2-level PT, or
Hit for 2-level PT too and are ready for searching the cache/memory for the physical address ?
But 2-level PT can be found in TLB and we search TLB again for 2-level PT, or
And so the 2-level PT will also be missing in TLB. Hence, we search the memory for 2-level PT ?
3. If there is a TLB miss i.e. the PT is not in TLB, thedata word will definitely be not in the cache and we directly search memory for this. Is this correct?
Please give your answer for all the 3 points. If possible, kindly provide a link so that I can refer it for more clarity.
memory-management
operating-system memory-management
Selected Answer
No of blocks 4
So, no of files 4K
Direct mapped
8 words total cache data size.
2 word cache block size.
A sequence of eight memory reads is performed in the order shown from the following addresses
0, 11, 4, 14, 9, 1, 8, 0
The (number of misses + Number of compulsory misses +Number of conflict misses ) value is ____.
so total miss = 8
compulsory miss = 4
conflict miss = 4
so ans = 16
Where am i wrong ?
http://gateoverflow.in/1488/gate1999_2-10
multitasking
Consider a uni-processor system executing four tasks T1, T2, T3, T4 each of which is composed of 10 sequence of jobs which
arrive periodically at interval of 2, 4, 8, 16 ms resp. The priority of each task is directly proportional to its period and
available tasks are scheduled based on priority, with highest priority task scheduled first. Each instance of T1, T2, T3,
T4 requires execution time of 1, 2, 4, 6 ms resp. Given all tasks initially arrive at t=0, the 2nd instance of T3 completes its
execution at the end of ______ ms.
||0 T4 6 || 6 T3 10 || 10 T3 14 ||
T4 has not yet arrived so giving chance to 2nd instance of T3 which is next high proirity process.
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S, T and U:
Process P: Process Q:
P(S) W:
P(T) X:
P(U) Y:
Print ‘a’ Print ‘a’;
Print ‘b’ Print ‘b’;
V(S) A:
V(T) B:
V(U) C:
1. with only W it is "Not possible to avoid deadlock". but yes W = P(S) , X = P(T), Y = P(U) results deadlock free system.
So W = P(S)
2. if W = P(S) then X = P(T), Y = P(U) works fine.
operating-system operating_system
operating_system
Trap has been set to access the kernel mode. kernel mode is required to handle the system critical signal. This mode
reside in the running mode. and require domain cross rather than context switch.
operating_system
Let's talk of segmentation . Cpu generates a logical address say of n bits. Out of n bits k bits is the segment number while
rest n-k is offset. After checking the segment from segment table of process the limit register is checked with the offset if
offset<limit then it's a valid request and request is granted else a trap to os is made incase of irrelevant address.
operating-system operating_system
operating_system
An invalid memory access exception will be generated and thrown to OS- segmentation fault in Linux.
6.101 Page: The total time reuired to load the program from Disk top gateoverflow.in/30488
A program of size 64 MB is stored on disk which supports an average seek time of 32ms and rotation time of 20ms . Page
size is 4MB and track size is 32MB . If the page of the program are countiguously placed on DIsk then the toatal time
required to load the program from Disk in msec is ______
=2*(32+20+10)=124ms
6.102 Page Fault: What is the average access time to service a page fault top
gateoverflow.in/10975
In a demand paging memory system, page table is held in registers. The time taken to service a page fault is 8
m.sec. if an empty frame is available or if the replaced page is not modified, and it takes 20 m.secs., if the replaced page is
modified. What is the average access time to service a page fault assuming that the page to be replaced is modified 70% of
the time ?
page-fault
6.103 Page Fault: Please help me in understanding how to solve the problem
top gateoverflow.in/14570
where A[0][0] is at location 200 in a paged memory system with pages of size 200. A small process that manipulates the
matrix resides in page 0 (locations 0 to 199). Thus, every instruction fetch will be from page 0. For three page frames, how
many page faults are generated by the following array-initialization loops, using LRU replacement and assuming that page
frame 1 contains the process and the other two are initially empty?
a.
for (int j = 0; j < 100; j++)
for (int i = 0; i < 100; i++)
A[i][j] = 0;
b.
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
A[i][j] = 0;
operating-system page-fault
Selected Answer
First of all I am assuming some of the facts because the question does not state them.
I assume array is stored in row major order and i is used for accessing row and j is used for accessing column. As page
size is specified in number I am assuming it is going to hold 200 elements of the array.
Now it is saying memory has 3 frames and as said earlier 1 frame will be always occupied by the process so we have left
with 2 frames.
(b)
(a)
You may guess that now blue element will be needed for which another page fault will occur and we will be accessing only
2 element per page fault. So number of page faults =10000/2=5000.
This concept can be extended if page size is given in kB and array element size is taken as 4B- just count number of array
elements in one page. I think now you have understood the concept.
6.104 Page Fault: what will be the average instruction time? top gateoverflow.in/25475
If a page fault occurs on an average every 1000 instructions and average instruction time is 100ns without page fault and
100ms with page fault. what is average instruction time?
operating-system page-fault
Selected Answer
1 1
6.105 Page Fault: Need explanation on page fault handling. top gateoverflow.in/12521
Suppose a process is suspended due a page fault(page is being written back to disk or required page is being read from
disk). Now after the page IO is completed, the process becomes runnable or resumes execution ? Also will the scenario be
different ,if the process itself requested for some IO(read , write , etc) ?
If it just becomes runnable, and if it is of low priority, isn't it possible that by the time it resumes execution the page for
which it had faulted has again swapped back to disk ?
page-fault
Selected Answer
Problem with low priority- I don't know how this is actually done, but after swapping in, the priority of the process can be
temporarily made quite high.
"isn't it possible that by the time it resumes execution the page for which it had faulted has again swapped back
to disk"
This is the reason for thrashing rt?
page-fault
3=p[(p(300)+(1-p)100)+1]+(1-p)(1);
200p2+100p-2=0;
p=0.0194
Demand paging uses a second chance page replacement policy (clock). It uses one use bit to give every page one more chance in FIFO replacement. Whenever a page is
referenced its use bit set to 0. Whenever it is need to replace by other page for the first time then its use bit is changed to 1 and next page will be searched for
replacement. If already given the chance then it will be replaced.
Assume that the system has 3 page frames. Consider the following page reference stream in the given order.
7, 0, 1, 2, 0, 3, 0, 4, 2, 3
The number of page faults occur using clock algorithm are ___________.
page-replacement operating-system
Considering, when new page read into a memory frame has the second chance bit set to ZERO (0) and Each time a
memory frame is referenced, set the "second chance" bit to ONE (1) - this will give the frame a second chance.
operating-system page-replacement
Selected Answer
A memory page containing a heavily used variable that was initialized very early and is in constant use is removed when
(a) LRU page replacement algorithm is used
(b) FIFO page replacement algorithm is used
(c) LFU page replacement algorithm is used
(d) None of the above
Selected Answer
LRU can't be used as the page is still is in use , so it will be in most high priority.
LFU can't be used as it has been accessed several time , it's frequency value will be larger.
FIFO can do it as it only considers the time the page came in RAM. So the page can be deleted by FIFO . also from that statement
we can assume FIFO wasn't in use till now.
suppose R=3,2,4,3,4,2,2,3,4,5,6,7,7,6,5,4,5,6,7,2,1 is a page reference stream.if the window size is 6 and assuming pure
demand paging.how may page faults will it cause under the working set algorithm
operating-system page-replacement
Working set here at any point contains the previous 6 page references (non-distinct).
Selected Answer
Size of PAGE TABLE = (No of Pages in LOGICAL ADDRESS SPACE) * (SIZE OF PAGE TABLE entry)
Size of PAGE TABLE = (224-k) *(16-k) bit = (2 24-k) *(16-k)/8 byte = (2 25-k - k*221-k)B
Consider a machine with 64 MB physical memory and 34 bit virtual address space.If the page size is 4 KB ,the approximate
size of conventional and inverted page table will be??
operating-system page-table
but for calculating inverted page table size there should be size page table entry size(PTE) as in conventinal page table we know that each entry
contains the corresponding frame no !!
If the no of pages in a 32 bit machine is 8kB then what is the size of the page table?
a. 8kb
b. 16kB
c. 4 KB
d. Cant say
Ans: a
operating-system page-table
6.114 Page Table: What is approximate size of page table top gateoverflow.in/33765
Selected Answer
no of frames =2^16/2^k=2^(16-k)
=2^(21-k)(16-k)
=2^(25-k)-k 2^(21-k)
answer is option a
Selected Answer
Since the virtual address is of 32 bits and page size is 1KB. Therefore, the total number of pages required would be 1M.
Means, these many page entries required in page table, so our page tables itself become an overhead.
Problem 3
In a 32-bit machine we subdivide the virtual address into 4 pieces as follows:
We use a 3-level page table, such that the first 8 bits are for the first level and so on. Physical addresses are 44 bits and there are 4 protection bits per page.
Answer the following questions, showing all the steps you take to reach the answer. A simple number will not receive any credit.
How much memory is consumed by the page table and wasted by internal fragmentation for a process that has a code segment of 48K starting at address
0x1000000, a data segment of 600K starting at address 0x80000000 and a stack segment of 64K starting at address 0xf0000000 and growing upward (towards
higher addresses)?
operating-system page-table
operating-system paging
Given answer is A.
I believe that B should be the answer because as the number of page tables are k. k memory access are required for each
table and finally, one for accessing the data from main memory. Please check.
operating-system paging
Selected Answer
if there is no page table then number of memory reference(s) to get date is ONE.
if K- PAGE TABLE are der (i.e. K-LEVEL PAGING) then number of memory references are (K+1)*m.
The question I answered was 4096 bytes and what the test answered is in KB and both the answers are correct . But in GATE
how do we come to know whether the answer should be given in bytes or Kb or MB or GB?
paging
In a two level paging environment a page table is divided in to 2^12 pages each of size 4KW. The memory is word
addressable. The physical address space is 128MW. Memory is divided into 2^14 frames.Length of the logical address is
_________
My approach:
pagesize = 4KW.
PAS = 128MW
#frames = 2^14
using the #pages and pagesize we can get VAS? how to approach.
operating-system paging
Represent the sentence "We are IT students" in physical memory if page size is 5 characters and the entries in page table
are-
0 6
1 5
2 7
3 10
memory-management paging
we need 18 characters and so 4 consecutive pages. Assuming we start from 0, in physical memory the locations will be 6,
5, 7 and 10. S, physical memory contents will be like (we have 11 frames for 55 characters):
e IT
We ar
stude
nts
Other frames can have any value. Actual memory content will be bits but here characters are used for representation
purpose. Say for ASCII code, we convert 'A' to 01000001 and so on.
suppose a paging system has 2^g+h virtual addresses & uses 2^h+k locations in primary memory for integers g,h & k.
what is the page size of the system that is implied by the virtual & physical address sizes? how many bits are required to
store a virtual address
paging
Thread is a light-weight sub-process. If so, what is executed by the processor? Process or thread? If it is thread, why do we
say that ready queue has processes? Should not we say that ready queue has threads? And if the answer is process, what is
the use of threads then? Is thread just another name of a process which is very small in size? What is actually the difference
between these two?
Thank you.
Threads are small processes which is part of a Big Program . You can compare like divide and conquer . Splitting the big
program into small small processes .
ready queue holds the processes . threads are actually a process which is part of big process . ready queue totally
unaware of that its a thread or a process so it will treat like a normal process . And its the duty of that program (big
program ) to manipulate each of its threads and how to execute them .
Let t be the time interval between two processes pi and pi +1 for any i and service time of pi is si.
If t > si for every i, then find the best strategy to schedule the processes.
(a) FCFS
(b) SJN
(c) RR
(d) SRTF
process-schedule
t>si for every i ,so before the next process enters the system first process surely completes its execution ,
and for this reason all srtf sjf and fcfs will act as same as fcfs (in case of RR it`ll be more because of context switch for
every time quantum, but order will be same if cs time is very less ) .
Consider the following preemptive priority-scheduling algorithm based on dynamically changing priorities. Larger priority
numbers imply higher priority. When a process is waiting for the CPU (in the ready queue but not running), its priority
changes at a rate X when it is running, its priority changes at a rate Y. All processes are given a priority of 0 when they
enter the ready queue. The parameters and can be set to give many different scheduling algorithms. What is the algorithm
that results from Y>X>0?
a. LIFO
b. FCFS
c. Round Robin
process-schedule operating-system
Selected Answer
It should be FCFS. Although I'[m ASSUMING that - when question says priority is changing, it implies the change is
positive - i.e. priority is increasing.
Consider that a process is running and its priority is increasing at rate of Y . Now another process arrives and waits in a
queue at time t0.
At time t1, priority of process which is running would be (t1-t0) * Y while the one which is waiting would be (t1-t0) * X.
Since Y > X, running process will always have a higher priority. SO the process in queue continues to wait .
A process in which of the following state is best suited for swapping into main memory?
I think both suspend ready and suspend wait is correct as both signifies that the process is in the secondary memory and
hence from this state only its best suited to swap it back into the main memory!
Consider the progarm to be run on a computer using Round robin scheduling . The program size is 100K . hard disk transfer
rate is 1mbps .Average latency is 8ms . assuming no head seek , what could be the acceptable time quantum for cpu
utlization
1) 11oms
2) 180ms
3)210ms
d)none
process-schedule operating-system
I think it should be 110ms .. 100K/1MBPS = 100ms for transferring the program and 8 ms of latency.
But frankly I think something is missing in the question. They should have given the rate of program processing, i.e. when
the program is in the main memory, then at what rate it can be processed..
2) memory unavailable
3) Parent termination
4) Child termination
process-schedule
In some operating systems, if a parent process dies, then all of its child processes die too.
When a process terminates—no matter why—all of its resources are cleaned up:
Answer to the above question is (C). I am unable to understand that how can a process in ready state can get blocked.
Please give an explanation.
process-schedule operating-system
there is a state called suspend ready, when system needs to free up resources, some processes are moved to that state
from ready state
Round robin scheduling or shortest job first scheduling,which one has better average turnaround time?
operating-system process-schedule
(1)SJF
(2)SRTF
(3)Priority(without preemption)
(4)Priority(with preemption)
a)1,2,3 b)1,2,4
c)1,3,4 d)1,2,3,4
e)1,3 f)1,4
process-schedule
Selected Answer
6.132 Process Schedule: Which scheduling algo has the second highest TAT?
top gateoverflow.in/16648
process-schedule
TAT(RR) =35
TAT(FIFO)=28
TAT(SJF)= 23
Consider four processes with a burst time of 10, 20, 30, 40 all process arrived at time 0. Each process spends first 10% of its
execution time doing i/0, next 40% time doing CPU operations, next 20% time doing I/0 and the last 30% time doing CPU
operations. The system uses shortest remaining time next algorithm for scheduling. Calculate the completion time of P3?
Selected Answer
p3 completes at 49
10%
ArrivalBurst 40%CPU 20%IO 30%CPU
IO
P1 0 10 1 4 2 3
P2 0 20 2 8 4 6
P3 0 30 3 12 6 9
P4 0 40 4 16 8 12
Gant chart
Suppose two jobs, each of which needs 10 minutes of CPU time, start simultaneously. Assume 50% I/O wait time.
How long will it take for both to complete, if they run sequentially?
a) 10
b) 20
c) 30
d) 40
process-schedule
CPU TIME = 10 min, IO Time = 50% i.e. 50% for CPU & 50% for IO. (it is not 50% of CPU time, read question again)
t=0 to 10ms,
A completes its CPU Burst.
t= 10 to 20,
B completes CPU & at same time A Complete its IO burst.
t=20 to 30,
B completes its IO.
Consider four processes all are arriving at time zero, with total execution time of 20, 10, 10 and 20 unit respectively. Each
process spends the first 20% of execution time doing CPU, the next 60% of doing I/O computation and the last 20% of time
doing CPU computation again. The operating system uses longest time first scheduling algorithm and schedules a new
process either when running process get blocked I/O or when the running process finishes its CPU burst.
Assume that are I/O operations can be overlapped as much as possible. The average TAT of the system given by ______
unit.
[Note: When same burst occurs for multiple process high priority given to lowest process id] (upto one decimal place)
Selected Answer
0---P1--4---P4---8----P2---10---P3---12----no process---16---P1---20---P4---24---P2---26---P3---28
At 16 P1 finishes it IO
At 20 P4 finishes it IO
At 16 P2 finishes it IO
At 18 P3 finishes it IO
When ever a process is going running to blocked state its get pre-empted right ??
process-schedule
Process moved to blocked state does not imply that it is preempted. Preemption is when a process is moved back to the
Ready Queue from the Running State against its will.
Among all the 5 state through which a process goes , BLOCK state is the only state where the process goes by its will .while in other it depends upon the Scheduler .. And The scheduler
we have seen are care about CPU bound process , and not for I/o bound process . So here the i/o process leave the cpu by its will . And in premptive CPu throws the process out and
take another process (Note the diff between between former and latter case ) hence its is non premptive
Between Round robin and shortest job first CPU scheduling algorithm which one has better average turnaround time?
process-schedule operating-system
SJF(Shortest Job First) or SRTF(Shortest Remaining Time First) has better turn around time
SJF which is smallest job end first. So, finishing time is less
http://perugini.cps.udayton.edu/teaching/courses/cps346/lecture_notes/scheduling.html
1. prefetching is a method of overlapping the I/o of a job with that jon own computation
2.With spooling scheme , where the CPU overlaps the input of one job with the computation and output of other jobs
4.Spooling is much more effective way of overlapping I/O and CPu operation
process-schedule operating-system
If the waiting time for a process is p and there are n processes in the memory then the CPU utilization is given by,
a. p/n
b. p^n (p raised to n)
c. 1-p^n
d. n-(p^n)
operating-system process-schedule
Answer is (C)
The IO wait percentage w of a process is the percentage of time the process wait for an IO to completion when executed in a
monoprogramming enviorment . on a system using round robin with n process ,all having same IO . what percentage of time
cpu will be idle in term of (w) ?
process-schedule operating-system
b) 2 only
c) 1 and 2 only
d) 1 and 3 only
process-schedule
Selected Answer
Multi level feedback queue favours IO bound process, because those process are idle for long time , their priority
increases.
remaining option
6.141 Process Schedule: why pcb's of the process have links in ready queue?
top gateoverflow.in/2973
operating-system process-schedule
Each PCB has a pointer field which stored the address of the next ready process. This is how ready queue is implemented.
http://www.just.edu.jo/~basel/os/os_slides/OS%20Chp4%20Processes.pdf
Consider the following set of processes, with arrival times and the required CPU-burst times given in milliseconds.
What is the sequence in which the processes are completed? Assume round robin scheduling with a time quantum of 2
milliseconds.
A. P1, P2, P3
B. P2, P1, P3
C. P3, P2, P1
D. P2, P3, P1
isro2013 process-schedule
Consider 4 processes sharing the CPU in a round robin fashion. Assuming that each process takes 5 seconds. What must be
the maximum quantum size P. Such that the overhead resulting from process switching is minimized but at same time each
process is guaranteed to gets its turn at CPU at-least every 40 seconds ________ (upto 2 decimal place).
process-schedule
Selected Answer
http://gateoverflow.in/1690/gate1998_2-17?show=1690#q1690
N*St + (N-1)*Q = 40
4*5 + 3*Q = 40
3Q = 20
Q = 6.333
We are given a computer system consisting of a CPU and a disk. We are told that, each user request has a compute time of 80 msec and an
average generates 10 disk requests. We are further told that, the service time at the disk is 10 msec. What is the maximum number of user
process-schedule operating-system
First process completes cpu at 80, cpu assigned to second and first process do io, second process completes cpu at 160,
first process completes io at 180
Coz only one disk multiple io request at same time to same disk not available, disk will have an io queue where
processes ll be lined up
Ans must be 9
Each User request requires 80 m sec of CPU Time and 10 disk request as IO Time.
= 180 ms
Suppose a system contain n processes and system use Round Robin Scheduling , then which data structure is best suited for
ready queue of this process ?
process-schedule
Since it is given that there are n processes in the ready queue, we do not have to worry about the overflow in the circular
queue also.
process-schedule
The highest waiting is for SJF and second highest is present in both SJF and RR and that is 12 for process B in both.
6.147 Process Schedule: Process executes systems call for top gateoverflow.in/36623
operating-system process-schedule
Selected Answer
C. if another Process Address space is shared with Existing process then no need of system call otherwise a TRAP
generated..
yes D obviously be correct answer bcoz that (Space Allocation) is responsibility of OPERATING SYSTEM MEMORY
MANAGEMENT component which always runs in Kernel mode..
#out of given four options D is correct bt it doesn't mean option D is ONLY reason for system call :)
operating-system process-schedule
Any process will get its turn after n-1 have finished running their quantum so and there are 100 processes to be scheduled
( including the concerned process) before the concerned process starts running.
T = (n-1)*Tq + n*Ts ,
T = 1 = 99*Tq + 100*0.001/1000
operating-system process-schedule
process-schedule operating-system
KINDLY SOMEONE POINT OUT MY MISTAKE. I FEEL PAREND ,PARBEGIN CONSTRUCTS CAN BE USED FOR S1 AND S2. BUT
ONE SOLUTION BOOK IS SHOWING DIFFERENT PRECEDENCE GRAPH.THERE IT IS EVEN SAID WE CANT USE PARBEG
,PAREND
I AM VERY CONFUSED OVER THIS.PLEASE HELP ME. I FEEL S1 AND S2 CAN BE CONCURRENT AS THEY DEAL WITH
DIFFERENT VARIABLE. THEN WE SHOULD BE ABLE TO USE PARBEG AND PAREND FOR THEM .PLZZ HELP AND RECTIFY ME
process-synchronization
i think this is the right answer . can u plz post a copy of the solution provided,. what they have told u about the answer. ??
a) x = 1, y = 2
b) x = 1, y = 3
c) x = 4, y = 6
process-synchronization
Selected Answer
B and C is possible .
For b : y=2 ;
x=x+3=3
y=y+x = 2+1 =3
for c :
x = 4, y = 6
this is possible run x=1 after that prrempt it now run code of y=2, x=x+3 here x=1
therefore y=4.now resume from where we prreempt ie statement x=x+y executed x=4+2
Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values
of shared boolean variables S1 and S2 are randomly assigned.
The above two processes are both deadlock free and starvation free . Is this statement right? Because both s1 and s2 are
taking different sets of values to enter the critical section and hence no way they are getting blocked out all at once from
their critical section.So no deadlock.
Also its starvation free .
operating-system process-synchronization
Selected Answer
Yes, This sequence of statements is both Deadlock free & Starvation free. Though as you can see, Progress is not
guranteed. (If P1 does not want to enter critical section it can block P2 & so on !)
operating-system process-synchronization
http://gateoverflow.in/?qa=blob&qa_blobid=10456887729102921117
process-synchronization
ohhh i was wrong basically wht i read was just a small example of spin lock . the exact definition is here .
a spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("
spin") while repeatedly checking if the lock is
available. Since the thread remains active but is not performing a useful task, the use of such a lock is a kind of busy waiting..
which of the following strategy is employed for overcoming the priority inversion problem?
process-synchronization
Its also called priority inheritance, it is used to solve the priority inversion problem.
https://en.wikipedia.org/wiki/Priority_inheritance
process-synchronization
Reason:-
satisfies mutual exclusion :-value of turn can be either i or j at the same time so any one process can be in cs.
satisfies progress-after execution of each process its flag is set to false (see in the exit section) .as this flag goes to f other
waiting process whose flag value is 1(process interested to enter cs) will enter the cs as while loop condition satisfies in
this sitiuation.
bounded waiting-after completing its execuion in cs its flag is set to false which allow other process to enter the cs .the
same process cant be executed again and again indefinetly if other process is ready and waiting.
process-synchronization operating-system
Selected Answer
1)Primary
a) Mutual Exclusion
b) Progress
2)Secondary
c)not progress(Other process has to enter into cs to enable the cs for other process)
b) Progress
c) BW
a) ME
b) Progress
c)BW
a) ME
b) Progress
Description of Peterson's Algorithm & also for which problem it is used to solve
(1) deadlock
(3) Thrashing
(4) Paging.
made-easy process-synchronization
Petersons Algorithm is a Programming Algo that allows two process to share a single -use
resource without conflict,using only shared memory for communication..
Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the
array. For the element stored at index i of the array (i ≤ n), the index of the parent is
(A) i − 1
(B) 2
i
2
(C)
(i +1 )
(D) 2
operating-system process-synchronization
NO.
and a lock X, may be semaphore_lock(X).(lock is required by only L and H but M does not require this lock)
Scenario:
1. L runs and acquires X
2. Then H tries to access X while L has it, because of semaphore, H sleeps.
3. M
arrives,
pre-empts
L
and
runs.
In
effect,
H
&
M
were
two
processes
waiting
to
run
but
M
ran
because
H
was
waiting
on
lock
and
couldn't
run.
4. M finishes, H can't enter because L has the lock, so L runs.
5. L finishes, relinquishes the lock. Now H gets the lock and executes.
H had the highest priority but ran after the lower priority processes had run. This is Priority Inversion.
http://research.microsoft.com/en-us/um/people/mbj/Mars_Pathfinder/Mars_Pathfinder.html
process-synchronization
Here in this question all processes will be blocked and no one can proceed ..so this cause deadlock...in first scenario its
busy wait, process is not blocked it's still executing but not doing any useful work so that creates livelock...
https://en.wikipedia.org/wiki/Deadlock
operating-system process-synchronization
Yes there is spin lock which is kind of deadlock .. it occur due to priority inversion problem .
2. cmp R ,#0
3 critical section
suppose there is 2 process p1 and p2 intial R =0 and for now line 1 is exected by process p1 and it enter into critical
section .now p2 comes which is high priority than p1 so p1 is preempted and go in ready queue and p2 execute the line 1
and 2 but lock R is not 0 . so it will be in busy waiting until it get critical section so we cant preempt it and p1 is in queue
so it could not release the lock . and fall in deadlock .
const int n = 5;
int count = 0;
void test(){
for i = 1 to n
count += 2;
}
main() {
Par begin
test();
test();
test();
Par end
}
What can be the maximum and minimum value of count after completion of the program?
process-synchronization operating-system
1. Read count
3. Store // Globally
All 3 test() inside par begin par end means these function executes concurrently.
Program execution for max value.of count : run serially all Test(). Count becomes 30..
Each test() increment count value to count +2 LOCALLY & still waiting for all test() to increment der local count by 2.
After incrementing local count let 1st test write count to 2 GLOBALLY.
Then 2nd test write count to 2 (because count +2 done locally so count value is still 2 for this test() ) . It overwrites count
value by 2.
6.164 Process Synchronization: What are the possible values of x and y after
completion of the program top gateoverflow.in/33245
int x=0,y=0;
par begin
begin
x=1;
y=y+x;
end
begin
y=2;
x=x+3;
end
par end
what are the possible values of x and y after completion of the program?
a. x=1 ,y=2
b.x=1,y=3
c.x=4,y=6
operating-system process-synchronization
There are total 6 orders possible for executing these 4 statements concurrently (like in DBMS transactions)
x=1; y=2;
y=y+x; x=x+3;
A) 4,2
B) 4,3
C) 1,3
D) 4,6
1. Peterson's Solution
2. SWAP instruction
3. Strict Alternation
4. Both 2 and 3
process-synchronization operating-system
Peterson satishfies ME, progress using interested array and bounded waiting using turn var.
Strict alteration satisfy ME, bounded waiting using turn var but not progress.
Swap instruction Doesnt satisfy bounded waiting, same instruction can get hold of cs without allowing others to use this
shared area/resource because its dependent on which instruction finds cs free at the time and no mechanism is involved
to ensure bounded waiting( such as turn var)
process-synchronization
option d
Explanation:
Semaphore X=0;
Process 1 Process 2
Repeat Repeat
1. V(X) 1. P(X)
2. Compute; 2. Compute;
3. P(X) 3. V(X)
Forever Forever
----------------------------------------------------------------------------------------------------------------------------------------------
--------------------------
The process 1 is performing up() operation in step 1, whereas process 2 is performing down() operation.
Semaphore is initialized to 0;
----------------------------------------------------------------------------------------------------------------------------------------------
---------------------------
S1. All synchronisation mechanisms that Do not Prevent Deadlock, guarantee mutual exclusion.
S2. All synchronisation mechanisms that guarantee mutual exclusion and prevent deadlock will prevent starvation.
d) none of these
process-synchronization
d.
1. Because for preventing deadlock one of the 4 conditions should not be satisfied. It should not be necessarily mutual
exclusion.
2. Because for preventing deadlock after mutual exclusion you need to have at least one of the three conditions not to be
satisfied for deadlock. But starvation is possible when that condition is not preemption. Meaning if we allow preemption
then there is the possibility of the starvation. so it doesnot necessarily prevent starvation.
Let I , K, L are three processes and binary semaphores are S =1 , T=0 , Z=0 initially ;
Process I
{
while(1)
{
P(S)
printf("*");
V(T)
}
}
Process K
{
P(T)
V(Z)
}
Process L
{
P(Z)
V(S)
}
process-synchronization
Selected Answer
Since the process I is waiting on S(initialized with 1), so it will print *. After some time when process K and L are done
running their code, S will gain have a value 1, process I having a while(1), it will again print *. Now there is no process
which can increment semaphor S again, so process I will keep waiting on S.
Thus answer is 2.
When a process is rolled back as a result of deadlock , the difficulty which arises is
a) Starvation
b)System Thoughput
d) Cycle stealing
process-synchronization
2. System throughput will be affected as the whole execution of the process till the rollback is going waste.
process-synchronization
It reads the contents of the memory word lock into register RX and then stores a nonzero value at the memory
address lock. The operations of reading the word and storing into it are guaranteed to be indivisible—no other processor
can access the memory word until the instruction is finished. The CPU executing the TSL instruction locks the memory bus
to prohibit other CPUs from accessing memory until it is done.
It is important to note that locking the memory bus is very different from disabling interrupts. Disabling interrupts then
performing a read on a memory word followed by a write does not prevent a second processor on the bus from
accessing the word between the read and the write. In fact, disabling interrupts on processor 1 has no effect at all on
processor 2. The only way to keep processor 2 out of the memory until processor 1 is finished is to lock the bus, which
requires a special hardware facility (basically, a bus line asserting that the bus is locked and not available to processors
other than the one that locked it).
In which of the following order indefinite blocking may occur if we add and remove process from the list associated with a
semaphore.
a)LIFO
b)FIFO
process-synchronization
Selected Answer
Indefinite blocking may occur if we add and remove processes from the list associated with a semaphore in LIFO order.
d) Both (a)&(b)
operating-system process-synchronization
Ans will be D
S=1,Q=1, if P0 takes both the value first then P(S) and P(Q) will make S=0,Q=0 and print Hello. Now V(Q),V(S) makes
S=1,Q=1 again
So when P0 takes the value of S,Q then P1 have to wait, when P1 takes the value of S and Q P0 have to wait.
Now if P0 takes S value but not Q value so for P0 S=1, Q=0, so P0 cannot proceed
and similarly P1 takes Q value but not S value , so S=0, Q=1, P1 cannot further proceed
There also have chance for starvation , as only P0 printing "Hello Hello Hello......" for a long period of time and P1 waiting
A
Pi :
flag[i]=True
turn=i
B
Pi :
flag[i]=True
turn=j
I have dry run the code and It satisfies all the three properties of Mutual Exclusion , Progress and Bounded waiting but the
issue is that I am not getting the essence of these two codes i.e. in A , the process gives chance to itself while in B the
process gives chance to another process by assigning turn =j so not getting the significance of how is actually in both of the
cases the code runs correctly
process-synchronization
6.174 Resource Allocation: why is the below state although being unsafe not
leading to deadlock ? top gateoverflow.in/19629
I got the state to be unsafe since Available is (1,1) which can't satisfy the need of any process so why is not deadlock ?
resource-allocation
it will be a deadlock as the execution of any process cannot complete in any possible way of execution. unsafe state
means the system may go to deadlock if not executed in a determined manner.
operating-system resource-allocation
Selected Answer
http://cis-linux1.temple.edu/~giorgio/old/cis307f95/readings/deadlock.html
6.176 Resource On: link for page table concept top gateoverflow.in/41936
Till now i have not got any exciting and detailed explanation of page tables and multi level page tables concept. if you have
any resource on this please post the link ..
resource-on page-table
Try
http://gatecse.in/wiki/Best_video_lectures_for_CSE
by P.K. Biswas
6.177 Secondary Storage: How long does it take to load a 64-KB program
from a disk top gateoverflow.in/38416
How long does it take to load a 64-KB program from a disk whose average seek time is 10 msec., whose rotation time is 20
msecs., and whose track holds 32-KB for a 2-KB page size?(How to solve this?)
64 KB program will be organized into 2 tracks because of each track capacity is 32KB.
To load entire track we require 20msec. To load 2KB we require 1.25 msec.
10msec+10msec+1.25msec=21.25msec
Since 64KB program is organized into 2 tracks then I/O time will be 2(21.25)=42.5 msec
option b and c are the reason i know are resolved by virtual memory concept.No idea of overlays..:p
for b-since in segmentation the memory is segmented so that there comes a complete function of a program in a segment.
That way there would by less chances of page faults because it is expected that the instructions in a function would be
most likely to be executed completely at a time.
for c-Since a function a segmented, no other process is allowed to use the segment block allocated to other. Thus it
provides security.
explain similarities and dismilarities between Segmented paging and paged segmentation
So,after vigorously searching on net for the difference or similarity between these two terms,I have come up on a final answer.First of all I would write
down the similarities:
They both (segmented paging and paged segmentation) are a type of paging/segmentation combined systems (Paging and Segmentation can be
combined by dividing each segment into pages).
In both the system the segments are divided into pages.
Now to describe the differences I will have to define and describe each term separately:
Segmented paging- Segments are divided into pages.Implementation requires STR(segment table register) and PMT(page map table).In this
scheme, each virtual address consists of asegment number, page number within that segment and an offset within that page.The segment
number indexes into segment table which yields the base address of the page table for that segment.The page number indexes into the page
table,each of which entry is a page frame.Adding the PFN(page frame number) and the offset results in the physical address.Hence addressing
can be described by the following function :
va = (s,p,w) where, va is the virtual address, |s| determines number of segments (size of ST), |p| determines number of pages per segment (size
of PT), |w| determines page size.
address_map(s, p, w)
{
pa = *(*(STR+s)+p)+w;
return pa;
}
Paged Segmentation- Sometimes segment table or page table may too large to keep in physical memory(they can even reach
MBs).Therefore,the segment table is divided into pages too and thus a page table of ST pages is created. The segment number is broken
into page no.(s1) and page offset(s2) of page table of ST pages.So,the virtual address can be described as :
va = (s1,s2,p,w)
address_map
(s1, s2, p, w)
{
pa = *(*(*(STR+s1)+s2)+p)+w;
return pa;
}
virtual-memory segmentation
Segment table is often too large to fit into one page. So segment table itself must have a page table in a paged segmented
scheme.
So, option (a) is correct.
Which page replacement policy sometimes leads to more page faults when size of memory is increased?
A] Optimal
B] LRU
C] FIFO
D] None of these.
Selected Answer
0 200 200
1 5000 1210
2 1527 498
3 2500 50
what happens if the logical address requested is -Segment Id 2 and offset 1000?
c)Deadlock
segmentation
an os trap signal will be generated. as offset tell how much deeper we have to go in the segment. as we have given 1000
as offset while the segment size is 498 . it will try to read another process memory which should not be allowed in any
case
virtual-memory segmentation
paging is applied on segment table, becoz due to increase in size of the segment table.and not on segment
Pair - 1
A. Virtual Memory
B. Shared Memory
C. Look-ahead buffer
D. Look-aside buffer
Pair - 2
P. Temporal locality
Q. Spatial locality
R. Address translation
S. Mutual exclusion
http://cs.stackexchange.com/questions/9612/look-ahead-buffer-vs-translation-look-aside-buffer
A-R,B-S,C-Q,D-P
A binary semaphore ensures mutual exclusion. Does a counting semaphore ensure mutual exclusion too?
Selected Answer
Yup improper use of semaphore not ensure the mutual exclusion . only proper use of semaphore ensure mutual exclusion.
ex: monitor.
semaphore
http://gateoverflow.in/19489/isro_a-2015-30
**repeat question
6.187 Semaphore: How to implement the given using only 2 semaphores? top
gateoverflow.in/14121
semaphore process-synchronization
P1: P2:
wait(R) USE R1
signal(R)
USE R1
USE R2
signal(S) wait(S)
USE R2
USE R3
wait(R) signal(R)
USE R3
USE R4
signal(S) wait(S)
USE R4
I. Race Condition
II. Process Synchronization
III. Mutual Exclusion
IV. None of the above
a) I and II
b) II and III
c) All of the above
d) IV.
semaphore
Race condition is achieved by making shared data area should not be accessed by two or more processes at the same
time which can be achieved using Semaphore. so, answer should be C(all of the above)
these are the codes for down and up operations in a binary semaphore. The down operation's code seems to be correct, but
I am having some doubt in the UP's code.
Suppose a process p1 arrives and executes down. the initial value of "value" is 1. now p1 will decrement it to 0 , and then
proceed to execute CS. Suppose, during this time another process p2 arrives and executes down. now it will be forced to
sleep as value==0. Lets assume the same for another arriving process p3.
Now if P1 finishes its CS, it will execute UP, and find that L is not empty, so it will select a process from it and wake it up.
BUT, p1 has not changed the value of "value". So even if p2 wakes up and executes down, it will be forced to sleep again..
Am I missing something, or is the above implementation incorrect ?
Whenever Binary Semaphores are used to synchronize the Critical Section by a Binary Semaphore Variable lets take it
"S".Generally the code structure will be like below
Critical Section
we do down operation to achieve mutual exclusion i.e once a process its entered into the critical section and executing it,
meanwhile no other process is allowed to execute the critical section and more on it will be suspended and it's PCB will be
kept into the suspended list of semaphore variable i.e. S.
After execution of critical section the process will perform up operation on S inside exit section and binary semaphore does
not always make S value to 1. It makes the S.value = 1 once the S.list is empty and it will simply wake up a process from
the S.list and allocate the critical section to it when S.list is not empty.
Now your confusion is, "Why UP() operation is not performing S.value = 1 when S.list is not empty ?"
Lets do it first, once we will make S.value =1 when S.list is not empty. There will be chance of process P2 may enter into
starvation.Because once the S.value is 1 any process can come and perform down operation and execute critical section.
This the process P2 may not get chance to execute the critical section.
6.190 Semaphore: Can anyone explain the below question in a detailed way?
top gateoverflow.in/37083
A Binary semaphore variable mutex is initialized to '1' and the various binary semaphore operations like 9P(), 14V(), 6P(),
8V(), 3P(), 2V() are performed, then what is the present(final) value of the binary semaphore mutex?
semaphore
semaphore
This question was asked in gate 2008 in a different way.Anyway it will clear ur doubt I hope otherwise I will try to explain
further.It is actually the implementation of a counting semaphore by 2 binary semaphores:
The P and V operations on counting semaphores, where s is a counting semaphore, are defined as follows:
P(s) : s = s - 1;
if (s < 0) then wait;
V(s) : s = s + 1;
if (s <= 0) then wakeup a process waiting on s;
Assume that Pb and Vb the wait and signal operations on binary semaphores are provided. Two binary
semaphores Xb and Yb are used to implement the semaphore operations P(s) and V(s) as follows:
P(s) : Pb(Xb);
s = s - 1;
if (s < 0) {
Vb(Xb) ;
Pb(Yb) ;
}
else Vb(Xb);
V(s) : Pb(Xb) ;
s = s + 1;
if (s <= 0) Vb(Yb) ;
Vb(Xb) ;
Answer (C)
Both P(s) and V(s) operations are perform Pb(xb) as first step. If Xb is 0, then all processes executing these operations
will be blocked. Therefore, Xb must be 1.
If Yb is 1, it may become possible that two processes can execute P(s) one after other (implying 2 processes in critical
section). Consider the case when s = 1, y = 1. So Yb must be 0.
Question 5.24
semaphore
This is how P and V operations will be made by procedures. Initially all semaphores are zero. Don't confuse that T5 will be
called twice. It will be called only once by any of T1 or T3 , whosoever runs V(b) first. Also this solution forces T6 to
complete before T4 , it will never be the case that T4 has completed and you need to block T6 forever.
6.193 Semaphore: How to implement the given using only 2 semaphores? top
gateoverflow.in/14120
semaphore process-synchronization
P1: P2
wait(P) wait(S)
use R1 use R1
use R2 signal(P)
signal(S) wait(S)
wait(P) use R2
use R3 use R3
use R4 signal(P)
signal(S) wait(S)
Use R4
top
In this empty must be 0 since producer will first produce only then it will empty
process-synchronization semaphore
Answer is C. empty and full can be initialized any way depending on how we are going to use it. Here, empty is initialized
to n-meaning n empty slots are there. So, producer must wait on this. Similarly, consumer must wait on full as it is
initialized to 0.
A similar question:
http://gateoverflow.in/3708/gate2004-it_65
semaphore
i think there is no such drawback instead it uses a diffrent mechanism which was made to overcome the problem of busy
wait and spin lock . which is sleep procedure till someone is inside the critical section don't knock at the door just go to
sleep when there will be a space the process will wake u up . the process of busy waiting is a charterstic of lock variable
not of semaphonre
6.196 Semaphore: What is the meaning of wake up() operation in the up()
binary operation, Definition is mentioned below. top gateoverflow.in/37088
Up(Semaphore S)
{
if (Suspended list() is empty)
S.value=1;
else
{
Select a process from the suspended list and WakeUp()
}
}
semaphore
PLEASE DON"T Downvote on this as My concept of Semaphoe is not good ....I will take up an example to explain wake up
and sleep calls..suppose there are 2 friends and one of them tells the other to wake him up now the other can do it only
once so he went to wake him up by knocking on his door and he didn't check whtr the other person was in the room or
not ..suppose he was not in the room and after that the person went to sleep and now the other person who went to wake
his friend want to sleep and he will think that his friend will wake him up but his friend also went to sleep at the same time
..now there is a DEADLOCK ..both people will think that the other would wake them up ..so there was a need of
Semaphore that is one of the reason it was invented(I think maybe I am wrong do correct me) ..so when the semaphore
value is 1 that means one process will use the value and enter into critical section ..
top
semaphore
if its counting then mutual exclusion is not guarntee (multiple process be at a time in CS )
the following five concurrent processes operating on counting semaphore variable (s) which is initialized to 0
A) 1 B) 2 C) 3 D) 0
Selected Answer
P4 and P5 can do signal operation without any intermediate wait and thus s can go up to value 2.
getting 7/11
The test suite (set of test input) used to perform unit testing on a module could cover 70 % of the code. What is the
reliability of the module if the probability of success is 0.95 during above testing
software-testing
6.200 Testbook Test Series: Length of logical address in 2 level paging gateoverflow.in/36515
top
In a 2-level paging environment a page table is divided into 2^12 pages each of size 4 KW. The memory is word
addressable. The physical address space is 128 MW. Memory is divided into 2^14 frames. Length of logical address is
________ ?
Here p1=12bits p2=12bits and d=12 bits. Therefore logical adress size=36 bits
Given answer: A
Please explain.
answer = option A
in array only the total number of processes are fixed which are available to be executed in the main memory; But in other
data structures many more elements can be added without any restriction.
I think answer should be TLB as we need it for address translation to get frame no. and then access cache
Is my approach right?
Yes you are right but only in case the Cache is Physically Addressed.
If Cache is Physically Addressed then TLB will reside between CPU and Cache because CPU does a TLB lookup on every
memory operation and the resulting physical address is sent to the cache.
But in case Cache is virtually Addressed then CPU generated addresses i.e. Virtual Address will directly looked up in Cache
and In case of cache miss, we need the address translation then only TLB will be accessed.
In multi level Cache organization,TLB may reside even between two cache.
6.203 Virtual Memory: Page tables are stored in memory , which has access
time of 100 ns. top gateoverflow.in/779
Page tables are stored in memory , which has access time of 100 ns. The TLB holding 8 page table entries, has an access
time of 10 ns. Using execution of process , it is found that 85 % of the time, a required page table entry exist in TLB and
only 2 % of the total references causes page fault. Page replacement time is 2 ms . Calculate the effective memory access
time , assuming page memory access requires 2 memory accesses and TLB requires one memory access.
0.85(10+110)+0.15(13/15(10+100+100)+2/15(10+100+2000000+100)=40125
85% time there will be a TLB hit so it will take (10+100) ns.
X% of the time page fault will occur that is it will take (10+100+2000000+100) ns.
(1-X)% of the time no page fault so it will take (10+100+100) ns.
6.204 Virtual Memory: Calculate the number of levels of outer page required
top gateoverflow.in/30487
In a paged virtual memory organization with 32 bit virtual address and 1 KB page size PTE is 32 bits. The number of levels of
paging required to limit the outer page table fit in one page frame is ________
operating-system virtual-memory
Selected Answer
2 32
10
So, no. of pages = 2 = 222.
Now, the outer page table must fit in a page frame - its size must be ≤ 1KB.
2 10
2
So, no. of entries in outer page table ≤ 2 = 256.
It is not mentioned in question if the second level page table must also fit in a page frame, but assuming this, we need
another 8 bits maximum for second level and only 32 - 10 - 8 - 8 = 6 bits remain for third level meaning it can easily fit in
a page frame.
page size 2 10 B
So, -ve factor i.e. 1st level page will be 2 bit less than page size
6.205 Virtual Memory: Please explain this question on paging top gateoverflow.in/29409
http://www.cs.utexas.edu/~lorenzo/corsi/cs372/06F/hw/3sol.html
1. What is the size of a page table for a process that has a code segment of 48K starting at address 0x1000000, a data segment of 600K starting at address
0x80000000 and a stack segment of 64K starting at address 0xf0000000 and growing upward (like in the PA-RISC of HP)?
First, the stack, data and code segments are at addresses that require having 3 page tables entries active in the first level page table.
operating-system virtual-memory
virtual-memory
consider a system using 2 level paging applicable page table is divided into 2K pages each of size 4 KB. if pas is 64 MB which
is divided into 16K frames memory is byte addressable . page tabke entry size is 2 bytes in both the levels calculate the
length of
operating-system virtual-memory
PAS=64MB =2^26 B
so PS=26bit
Page Size=2^12 B so Page offset=12 bit
so the PS is divided as 14|12
This step does not require any paging info
-------------------------------------------------------------
inner most PT size =Number of pages * Size of each page =2^11 * 2*12 = 2^23 B
PTE size =2B
so No of PTE = 2^23/2=2^22 = Number of pages in the process
So the Virtual adress is divided as 22|12
Now outer page table size =2^23 B and page size = 2^12 B so inner page table cant fit in one page
hence paging of inner page table is required , so the number of pages possible of the inner page table each of 4K size is
2^23/2^12 =2^11 pages = number of entries for the outer page table
PTE size = 2B
so outer page table size= 2^11*2 = 2^12 B
So outer page table size is 2^12B and page size is 2^12 B so now the page table can fit in one page of the main memory
. Hence no longer paging of outer page table is required
So answer is : 14|12
22|12
2^11 entries or 2K entries
Hope this helps!
6.208 Virtual Memory: Maximum size of Main Memory supported with 2 Level
Paging top gateoverflow.in/28969
Consider a 32-bit virtual address is used for paging with page size of 1024 bytes. Two-level paging is implemented with
equal number of entries in every page table of the system. If page table entry size is 2 bytes. The maximum size (in MB) of
main memory supported by the above system is ______.
-----------------------------------------------------------------------------------------------------------
Maximum size of Main Memory in 2 Level Paging => 2 18 * 1024 B = 2 28 Bytes = 256 MBytes.
virtual-memory operating-system
Selected Answer
VA = 22 +10
operating-system virtualgate
virtualgate operating-system
Selected Answer
--> Safety Algorithm requires O(m x n^2) time complexity where m is work vector and n is the finish vector
. So, option (D) is correct .
Suppose that a process spends a fraction of time P performing CPU activity.With n processes in memory at once, the
probability that all n processes are perforimng I/O operation.
A P n
B 1-Pn
C (1-P) n
D 1-(1-P)n
virtualgate operating-system
virtualgate operating-system
Consider a 256k 4- way set associative cache with block size 64 Bytes. Main memory is 2Gb. The number of bits used for
tag,set and word will be respectively?
A 10,15,6
B 9,16,6
C 8,17,6
D 7,18,6
Consider following disk request sequence for a disk with 100 tracks.
44, 20,95,4,50,52,47,61,87,25
Head pointer starting at 50. Find the no. of head movements in cylinders using SCAN scheduling. Assume head moving
towards cylinder 99.
SCAN Algorithm:
When a new request arrives while the drive is idle, the initial arm/head movement will be in the direction of the cylinder where the data is stored, either in or out.
As additional requests arrive, requests are serviced only in the current direction of arm movement until the arm reaches the edge of the disk. When this
happens, the direction of the arm reverses, and the requests that were remaining in the opposite direction are serviced, and so on.
50->52 = 2
52->61 = 9
61->87 = 26
87->95 = 8
95->99 = 4
99->47 = 52
47->44 = 3
44->25 = 19
25->20 = 5
20->4 = 16
Total = 144 head movements.
Alternate:
50->99 = 49
99->4 = 95
Total = 144 head movements
Answer) 144
In SCAN Algorithm, the disk arm(head) starts at one end of the disk and moves toward the other end servicing requests
as it reaches each cylinder it gets to the other end of the disk. At the other end direction of the head movement is
reversed and servicing continues.
For the given problem, first the arm will move towards 99 and reverses back to Zero(0) as follows:
50->52->61->87>95->99->47->44->25->20->4.
Consider an operating system capable of loading and executing a single sequential user process at a time. The disk head
scheduling algorithm used is First Come First Served (FCFS). If FCFS is replaced by shortest seek Time Fist (SSTF), claimed
by the vendor to given 50% better beachmark results, what is the expected improvement in the I/O performance of user
programs?
(A) 50%
(B) 40%
(C) 25%
(D) 0%
D) 0%
In a single-user environment, the I/O queue usually is empty. Requests generally arrive from a single process for one
block or for a sequence of consecutive blocks. In these cases, FCFS is an economical method of disk scheduling since OS
can execute a single sequential user process at a time, the disk is accessed in FCFS manner always. The OS never has a
choice to pick an IO from multiple IOs as there is always one IO at a time.
6.216 what is the relation between bounded waiting ,Progress and starvation
? top gateoverflow.in/33930
If any synchronization mechanism does not gurantee any of the conditions either progress or bounded waiting then will it
always lead to starvation ,and if both are satisfied then can deadlock occur still ?
A process spends 25% of its waiting time waiting for i/o to complete.If 3 processes in memory at a same time then
probability of cpu time wasted(Assume that all i/o operatio is overlapped)
.25*.25*.25= 0.015625
Consider a system with a two-level paging scheme in which a regular memory access takes 150 nanoseconds, and servicing
a page fault takes 8 milliseconds. An average instruction takes 100 nanoseconds of CPU time, and two memory accesses.
The TLB hit ratio is 90%, and the page fault rate is one in every 10,000 instructions. What is the effective average instruction
execution time?
A
645 nanoseconds
B
1050 nanoseconds
C
1215 nanoseconds
D
1230 nanoseconds
Consider a file system that uses UNIX like inodes to keep track of the sectors allocated to files. Assume that disk blocks are 1 KB in size,
disk block addresses are 32 bits and the inode has space for 8 direct blocks, 1 singly indirect blocks, 1 doubly indirect block and 1 triply
indirect block. What is the largest disk drive that could be fully utilized by this system?
Only triple indirect block will be considered because maximum file size is possible only in Triple Indirect
---->> (2^10/2^2)^3*2^10
---->> (2^30/2^6)*2^10
---->> 2^34
#of Disk Block Pointer that can fit in one block pointer = 1024/4 = 256
Due to Single Indirect Pointer maximum file size = 256 * 1KB = 256KB
Due to Double Indirect Pointer maximum file size = 256 * 256 * 1KB
Due to Triple Indirect Pointer maximum file size = 256 * 256 * 256 * 1KB
Consider the following snapshot of a system running n processes. Process i is holding xi instances of a resource R, for 1≤i≤n.
Currently, all instances of R are occupied. Further, for all i, process i has placed a request for an additional y, instances while
holding the xi instances it already has, There are exactly two processes p and q such that yp = yq = 0: Which one of the
following can serve as a necessary condition to guarantee that the system is not approaching a deadlock?
(A) min(xp,xq) < maxk≠p,q yk (B) xp+xq ≤ maxk≠p,q yk (C) min(xp,xq) < 1 (D) min(xp,xq)>1
Consider three processes (process id 0,1,2, respectively) with compute time bursts 2,4, and 8 time units. All processes
arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving
priority to the process with the lowest process id. The average turn around time is
(A) 13 units (B) 14 units (C) 15 units (D) 16 units
Caption
A set of processors P1, P2, ……, Pk can execute in parallel if Bernstein’s conditions are satisfied on a pairwise basis; that is P1
|| P2 || P3 || ….. || Pk if and only if : (A) Pi || Pj for all i ≠ j (B) Pi || Pj for all i = j+1 (C) Pi || Pj for all i < j (D) Pi || Pj for
all i > j
(A) Pi || Pj ∀ i≠j
Singly Indirect block addressing will point to 1 disk block which has 256/2 disc block addresses
=128*256B
=128*128*256B
=4131KB
Max File size in File System=[#of Direct DBA +(DB Size/DBA)+(DB Size/DBA)^2+(DB Size/DBA)^3+........]*DB Size
=4131KB
or 4MB(apx)
No option is true.
http://superuser.com/questions/414290/when-a-non-vectored-interrupt-occurs-does-the-processor-ever-look-up-the-vector
In a non-vectored interrupt, the peripheral itself provides the address of the interrupt service routine directly to the processor. This requires more time for
an interrupt to be serviced, since the address must be retrieved from the interrupting device every time the interrupt is triggered.
S ans is B??
operating-system test-series
In non-vectored interrupt, it is responsibility of CPU to find the address of ISR and to find the device which caused
interrupt.Actually once CPU gets interrupt from a device, it completes its current execution phase and start servicing the
interrupt. To do so,CPU first runs a default ISR, address of it is already known to CPU. Now this default service routine is
stored somewhere in fixed memory location which CPU knows. So CPU refers to it and find the address of actual ISR from
it & also address of the device which caused the interrupt. Actually CPU uses POLLING technique to find address of
interrupt causing device.So once CPU gets address of ISR,it starts executing it and after completion it resumes its own
execution.
6.228 Find maximum number of files possible in this file system top gateoverflow.in/32832
test-series
Selected Answer
No of files=2^13/2^2=2K files
there is 6 processes required for 99% utilization , each process utilize 250 KB , so total memory needed = 6*250
=1500KB.
now we have already 750KB(1000-250 as os occupied ) so required memory will be 1500-750 = 750 KB
6.231 Calculation of context switch overhead - ISI KOL -2014 Qstn 6(a) top
gateoverflow.in/43781
Consider three processes, P1, P2, and P3. Their start times and execution
times are given below
operating-system
In case of SJF
P.No AT BT CT TAT WT
1 0 100 100 100 0
2 25 50 170 145 45
3 50 20 120 70 50
p2 p3 p2
In case of SRTF
P no AT BT CT TAT WT
1 0 100 170 170 70
2 25 50 95 70 20
3 50 20 70 20 0
0 25 50 70 95 170
p1 p2 p3 p2 p1
turnaround time for P1, P2, P3 be reduced by choosing a SRTF over SJF But here it is already less so we can consider x=0.
(See both TAT ( SRTF TAT<SJF TAT))
Consider three processes, all arriving at time zero, with total execution time of l0,20and 30
units, respectively. Each process spends the first 20% of the execution time doing VO, the next
70% of the execution time doing computation and the last 10% of the time doing I/O again. The
operating system uses shortest remaining time first algorithm and schedules a new process either
when the running process gets blocked on I/O or when the running process finishes its compute
burst. Assume that all I/O operations can be overlapped as much as possible. For what
percentage of the time does the CPU remain idle?
operating-system
The answer is given as 11. can anybody explain probably with a diagram?
say for loop is executing k<=3, then picture will be this. isnot it?
6.233 Why are user level threads faster than kernel level threads? top gateoverflow.in/41646
Kernel-level threads require a context switch, which involves changing a large set of processor registers that define the current memory map and
permissions. It also evicts some or all of the processor cache.
User-level threads just require a small amount of bookkeeping within one kernel thread or process.
However, the difference isn't big if your threads are predominantly doing I/O operations, as those have to go through the kernel in any case. It's most
important if you're trying to implement some kind of simulation with a very large number of independant processes. In that case you need to pay
careful attention to what thread synchronisation mechanisms you use, as some of them also go up to the kernel and trigger a context switch.
http://www.cs.rochester.edu/u/cli/research/switch.pdf "In general, the indirect cost of context switch ranges from several microseconds to more than
one thousand microseconds for our workload."
Edit: user-level threads maintain a stack per-thread, and may or may not save the general-purpose registers depending on the architecture and the
clobber rules of its calling convention. It can be as simple as dumping the registers to the stack, jumping to a new address, and popping a few
registers, which may be in your cache if that thread was run recently.
Kernel-level context switches also change the memory map by writing to the TLB, and changing the security level (privilege level or "ring") of the
processor. See "Performance Considerations"
User level threads are managed by a user level library however, they still require a kernel system call to operate. It
does not mean that the kernel knows anything about thread management. Not at all, It only takes care of the execution
part. The lack of cooperation between user level threads and the kernel is a known disadvantage. In this case, the kernel
may not favour a process that has many threads. User level threads are typically fast. Creating threads, switching
between threads and synchronizing threads only needs a procedure call. They are a good choice for non blocking tasks
otherwise the entire process will block if any of the threads blocks.
Kernel level threads are managed by the OS, therefore, thread operations (ex. Scheduling) are implemented in the
kernel code. This means kernel level threads may favour thread heavy processes. Moreover, they can also utilize
multiprocessor systems by splitting threads on different processors or cores. They are a good choice for processes that
block frequently. If one thread blocks it does not cause the entire process to block. Kernel level threads have
disadvantages as well. They are slower than user level threads due to the management overhead. Kernel level context
switch involves more steps than just saving some registers. Finally, they are not portable because the implementation is
operating system dependent.
If the total number of available frames is 50, and there are 2 processes one of 10 pages and the other of 5 pages. Then how much of memory would be
proportionally allocated to each of these processes?
d. 5 and 10 respectively
A processor uses 36 bit physical addresses and 32 bit virtual addresses, with a page frame size of 4 Kbytes. Each page table
entry is of size 4 bytes. A three level page table is used for virtual-to-physical address translation, where the virtual address
is used as follows
bits 30-31 are used to index into the first level page table,
bits 21-29 are used to index into second level page table
bits 12-20 are used to index into third level page table
bits 0-11 are used as offset within the page
The number of bits required for addressing the next level page table(or page frame) in the page table entry of the first,
second and third level page table are respectively
(A) 20,20 and 20 (B)24,24 and 24 (C) 24,24 and 20 (D) 25,25 and 24
Suppose a process has only the following pages in its virtual address space; two contiguous code pages starting at virtual
address 0x0000000, two contiguous data pages starting at virtual address 0x00400000, and a stack page starting at virtual
address 0xFFFFF000. The amount of memory required for storing the page tables of this process is
(A)8 KB (B) 12KB (C) 16 KB (D) 20KB
Some part of the question is missing. Actually it is common data question in CS gate. Answer is 16 kB. Two code pages
are present in one page Two data pages are present in one page Stack takes one page Page table takes one page total
4*4K=16K
A computer system supports 32-bit virtual addresses as well as 32-bit physical addresses. Since the virtual address space is of the same size
as the physical address space, the operating system designers decide to get rid of the virtual memory entirely. Which one of the following is
true?
This question has made created doubt every time I see this question This is previous year gate question... According to
me Answer Should be Option A) but everywhere The answer is given is option C)
1)Operation is interruptable
ANSWER: 3
EXPLANATION
An indivisible or irreducable operation is an atomic operation that is performed entirely or not performed at all.
Any operation which is indivisible requires processor until it executes entirely. If processor decides to perform some other
operation or service some other request like interrupt, the operation will be left to the current state and might never be
executed entirely, ever. However, the state of operation might be or might not be consistent, but the operation is
anyways reduced and violates the property of indivisible operation.
Race condition is an undesirable situation where two or more process attempts to modify same data at almost same time,
which is a concept of multithreading.
In a 32-bit machine we subdivide the virtual address into 4 segments as follows: 10-bit 8-bit 6-bit 8 bit
We use a 3-level page table, such that the first 10-bit are for the first level and so on.
1. What is the size of a page table for a process that has 256K of memory starting at address 0?
2. What is the size of a page table for a process that has a code segment of 48K starting at address
0x10000000, a data segment of 600K starting at address 0x80000000 and a stack segment of 64K
starting at address 0xf00000000 and growing upward (like in the PA-RISC of HP)?
A process spends 20 of its execution time waiting for completion of I/O operation. If there are 4 processes in memory at
once, then the probability of CPU time wasted is ____ (Assume all I/O operations are overlapped, upto 3 decimal places).
Suppose a new process in a system arrives at an average of six processes per minute and each such process requires an
average of 8 seconds of service time. Estimate the fraction of time (in %) the CPU is busy in a system with a single
processor?
operating-system
Selected Answer
Consider a minute. 6 process arrives and each require 8 seconds service time - totally 6*8 = 48 seconds. So, out of 60
seconds, 48 seconds, CPU will be busy -
4
5
main()
printf(" * ");
for(i=0;i<n;i++)
fork();
printf(" * ");
2n +1
http://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/create.html
if multiple forks are given. then multiple processes will be created. Are all children created through first child are counted as
children only?
you can say they are grand child :) and this can go any depth. If on a unix shell try getting parent of a process, then its
parent and so on..
We use a 3-level page table, such that the first 8 bits are for the first level and so on. Physical addresses are44
bits and there are 4 protection bits per page. Answer the following questions
1. How much memory is consumed by the page table and wasted by internal fragmentation for a process that
has 64K of memory starting at address 0?
2. How much memory is consumed by the page table and wasted by internal fragmentation for a process that
has a code segment of 48K starting at address 0x1000000, a data segment of 600K starting at address
0x80000000 and a stack segment of 64K starting at address 0xf0000000 and growing upward (towards
higher addresses)?
operating-system
Consider a hard disk with 16 recording surfaces (0-15) having 16384 cylinders (0-16383) and each cylinder contains 64
sectors (0-63). Data
storage capacity in each sector is 512 bytes. Data are organized cylinder-wise and the addressing format is <cylinder no.,
surface no., sector
no.> . A file of size 42797 KB is stored in the disk and the starting disk location of the file is <1200, 9, 40>. What is the
cylinder number of the
last sector of the file, if it is stored in a contiguous manner?
(A) 1281 (B) 1282 (C) 1283 (D) 1284
1. Semaphore
2. Monitor
3. Bankers Algorithm
4. None
operating-system
Monitor bcoz bankers is deadlock avoidance technique and if semaphore is used in the wrong way it could violate mutual
exclusion condition so ans is monitor
Consider the 3 processes, P1, P2 and P3 shown in the table. Process Arrival time Time Units Required
P1 0 5
P2 1 7
P3 3 4
The completion order of the 3 processes under the policies FCFS and RR2 (round robin scheduling with CPU quantum of 2
time units) are
RR2 0-2 :p1 2-4:p2 4-6:p1 6-8:p3 8-10:p2 10-11:p1 11-13 :p3 13-15:p2 15-16:p2
can anyone give me proper explanation, i cant understand why in 4-6 part p1 is taking (not p3?).
not getting what you are asking but I hope the below work help you.
PIGEONHOLE Principle.
ans is c(3)
If the size of the page table>=Page Size we go for multilevel paging , Paging is
Applied on the Pages of page table until first level page table size<==Page size.
in the question there is a misprint, INSTEAD OF PTE{page table entry} size ptr size is given.
PTE=4B
2^16>>2^10
So
3 level page table is required ,so that outer page table fit in one page frame.
6.258 what is the logic to find max and min no. of resources that are requied
to avoid deadlock top gateoverflow.in/36055
operating-system test-series
32 MB - 20 ms
4MB - 2.5 ms
Total Access time = Seek + RotationalDelay + K*(transfer time for each block) [Blocks are stored sequentially, therefore
they would be in the same cylinder]
operating-system
A CPU generates 32 bit virtual address. The page size is 2KB. The translation look aside buffer (TLB) can hold 256 page table
entries and is 2 way set associative mapping. The number of bits in TLB tag is ____ and total bits in single TLB entry ____?
Ans for TLB tag: 14 bits ( not sure) for first part
SOL acc to me: 11 bits are offset , table address index will be 7 bits and therefore tag will be 32 - 11 - 7 = 14
Block Size=2KB=2^11B
#Line(N)=256
Total No of Sets=N/P-Way=256/2=128=2^7
<----------------------32--------------------->
If nothing is given in the question , then should we assume that all the page tables are page aligned ?
average process size is 128KB per page entry requires 8 bytes, then optimal page size?
(D) None.
My answer 2n +1 − 1 times ' * ' will be printed. Pls correct me if I'm wrong.
A processor uses 36 bit physical addresses and 32 bit virtual addresses, with a page frame size of 4 Kbytes. Each page table
entry is of size 4 bytes. A three level page table is used for virtual to physical address translation, where the virtual address
is used as follows
• Bits 30-31 are used to index into the first level page table
• Bits 21-29 are used to index into the second level page table
• Bits 12-20 are used to index into the third level page table, and
• Bits 0-11 are used as offset within the page
The number of bits required for addressing the next level page table (or page frame) in the page table entry of the first,
second and third level page tables are respectively
(A) 20, 20 and 20 (B) 24, 24 and 24 (C) 24, 24 and 20 (D) 25, 25 and 24
If a room have capacity of 20 persons...9 persons already inside the room....then what will be the value of semaphore
integer.
A. 20
b. 9
c. 11
d. 29
Selected Answer
Assuming a counting semaphore is used to indicate the availability of a space in the room we can do as follows:
So, initial value of semaphore here is 20 and when 9 person are inside, it becomes 20 − 9 = 11.
6.268 Which of the following is TRUE about the above construct ? top gateoverflow.in/41273
Two processes P 1 and P 2 need to access a critical section of code.Consider the following syncronization construct used by the
processes-
|*P1*|
while (true) {
wants1 = true;
while(wants2 == true);
[Critical Section]
wants1 = false;
}
|*P2*|
while(true) {
wants2 = true;
while(wants1 == true);
[Critical Section]
wants2 = false;
}
Here,wants1 and wants2 are shared variables which are initialized to false.Which one of the following statements is TRUE
about the above construct ?
(c) It requires that processes enter the critical section in strict alteration.
gate2006-cs
It ensures Mutual Exclusion as only one process can enter Critical section at a time
But it does not prevent deadlock as if both wants1 and wants2 becomes true it enters in deadlock
state...
The Answer is D)
i am unable to understand the concept of progress and bounded waiting after many reads of galvin.... i knw the basic but how to say looking at a code that progress
is satisfied?
6.270 Does compile time binding also indicate that the compiled code is
allocated in memory at compile time ? top gateoverflow.in/34396
I have just one confusion that when we talk about compile time binding then all the symbols are resolved at compile time so
does it necessarily imply that the code will also be allocated memory at that time only , since absolute address is known at
that time ?
any binding actually means when the code is binded with the actual address. if it is compile time then the actual address
will be available at compile time. if it is run time the address will be available at run time. and if link time then it means
the code be binded at link time. and we know linker is used at link time this means the linker will be converting your
relocatable address to absolute address. in run time loader will be doing it, and compile time compiler do it . refrence
:http://www.isical.ac.in/~mandar/os/memory.pdf
Compile-time binding
Location of program in physical memory must be known at
compile time
Compiler generates absolute code
compiler binds names to actual physical addresses
Loading copying executable file to appropriate location in
memory
If starting location changes, program will have to be recompiled
Example: .COM programs in MS-DOS
In a 32-bit machine we subdivide the virtual address into 4 segments as follows: 10-bit 8-bit 6-bit 8 bit
We use a 3-level page table, such that the first 10-bit are for the first level and so on.
1. What is the size of a page table for a process that has 256K of memory starting at address 0?
2. What is the size of a page table for a process that has a code segment of 48K starting at address
0x1000000, a data segment of 600K starting at address 0x80000000 and a stack segment of 64K
starting at address 0xf0000000 and growing upward (like in the PA-RISC of HP)?
If (Pid !=0)
fork2 ();
fork3 ();
The number of total process created when above code is executed is________(excluding parent).
Correct answer : 5
Please clarify the difference between the DIRTY BIT and the VALID BIT in virtual memory?
process
fork();
fork();
fork();
Selected Answer
7.
First fork() will generate 1 children. Total number of process = 1 child (C1) + 1 parent (P) = 2.
Second fork() will generate 1 more process in C1 (C2) and one more process in P (C3), Total number of child processes at
this stage = 3.
Similarly, 4 more child processes will be generated after calling third fork().
So, overall 8 processes will be there, 1 parent and 7 children. For more information, you can refer to the link provided to
you in response to your another similar question .
a). S1, S2
b). S2, S3
c). S1, S3
Since processes start at 0 any processes that have been in the system that is it is either running or waiting have higher priority. Therefore, new processes go
to the back of the queue. When a process runs its priority keeps increasing at the rate of beta which is more of an increase than for the processes in the
ready queue. Therefore, every time the process's timer runs out, it goes to the front of the ready queue and gets dispatched again which is equivalent of
FCFS.
Consider a 32 bit virtual address is used for paging with page size 1024 B.Two level paging is implemented with equal
number of entries in every page table of the system. If page table entry size is 2 B , the maximum size of main memory
supported by the above system _______________
As the page offset is 10 bits and page table entry is 2 bytes so not considering dirty , invalid bits , the total amount of
main memory supported is 10+2*8 = 26 bits.
Request:170,37,98,122,53,14,39,28
Selected Answer
The path followed is 60 - > 53 -> 39 -> 37 -> 28 -> 14 -> 98 -> 122 -> 170 .
We use a 3-level page table, such that the first 8 bits are for the first level and so on. Physical addresses are44 bits and
there are 4 protection bits per page. Answer the following questions
1. How much memory is consumed by the page table and wasted by internal fragmentation for a process that has 64K of
memory starting at address 0?
2. How much memory is consumed by the page table and wasted by internal fragmentation for a processthat has a code
segment of 48K starting at address 0x1000000, a data segment of 600K starting at address 0x80000000 and a stack
segment of 64K starting at address 0xf0000000 and growing upward (towards higher addresses)?
Consider a selective repeat sliding window protocol that uses frame size of 2 kb. The capacity of the link is 2 Mbps and whose
one-way latency is of 100 msec. To achieve a link utilization of 50%. What is the minimum number of bits required to
represent the sequence number field is__________.
Selected Answer
1
2 ×106
Time for ACK to reach back for a frame = TTframe + PD + PD + TTack = (2 × 106 × + 100 + 100 + 0)ms = 201ms.
Amount of data that could be transferred in 201ms = 201 × 10 −3 × 2Mbps = 402kb = 201packets.
201
Now, the window size in selective repeat protocol is half the sequence number space ( given in any text). So, we need
one more bit for sequence number field making it at least 8.
Q1)
Given a question with z Byte track size x Byte sector size and R rpm
Q2 )
if no method to calculate sector size , then how do I calculate transfer time ? Given D Data Transfer Rate
Q3 )
if no method to calculate sector size , then how do I calculate transfer time ? NO Data Transfer Rate rate also given
operating-system
A specific editor has 200 K of program text, 15 K of initial stack, 50 K of initialized data, and 70 K of bootstrap code. If five
editors are started simultaneously, how much physical memory is needed if shared text is used ?
(A) 1135 K (B) 335 K
(C) 1065 K (D) 320 K
But they could share initial stack, initialized data and bootstrap code
14. Consider three processes, all arriving at time zero, with total execution time of 10, 20 and 30 units, respectively. Each
process spends the first 20% of execution time doing I/O, the next 70% of time doing computation, and the last 10% of time
doing I/O again. The operating system uses a shortest remaining compute time first scheduling algorithm and schedules a
new process either when the running process get blocked on I/O or when the running process finishes its compute burst.
Assume that all I/O operations can be overlapped as much as possible. For what percentage of time does the CPU remain
idle?
(a) 0% (b) 10.6%
(c) 30.0% (d) 89.4%
grant chart
spooling is done here as it provide best overlapping . it is overlapping current job computation with other job input output
Every thread has its own Program counter,register set and stack pointers ....thread of process do share code and data
segment heap
repeat
flag[i]=true;
turn =j;
critical section;
flag[i]= false;
remainder section;
until false;
Above algorithm is the correct soln of the critical section problem which satisfies all the three codition-1.>mutual exclusion
2.>progress 3.>bounded waiting
my question is how this algorithm satisfies bounded waiting ??let say both the process pi and pj want to enter its critical
section then they will turn flag[i] and flag[j] to 1 then pi while change the value of turn to j and and pj to i but turn can
contain only one value so any one of the process will enter its cs let say it is pi.later the process pi on completion again want
to enter its cs then is it will be executed indefinetly and pj will never be executed if this phenomenon is repeated .so,please
tell me where i m wrong .
what u got wrong here is again when the p1 come after executing it will change the turn varaible to himself and then the
older process while condition will break so after one another will go in . so aftre every 1 step second is getting a change to
enter so .
tell me if im wrong
in oder to access a page first we look in TLB if present we in look in cache( if present no need to acces main memory) if not
we go directly and accses the page with out going to see page tabels if there is a page fault we service the page
cache can be virtual or physical .If its virtual one then it is placed between processor and MMU ..Mapping is done using
virtual address..In case of physical cache is placed between MMU and memory that is address translation is done first to
find location of page.. so depending on organisation we have proceed to fin date
https://en.wikipedia.org/wiki/CPU_cache
6.288 what is the difference between a job, task and a process ? top gateoverflow.in/16658
I have already gone through the stack-overflow posts but still could not clear with this concept , so plz clarify it with some
examples rather than explaining its definition .
The word job was used in earlier days in the batch systems. where we just collectively said that there is a job the job may
or may not be of one process suppose u have 10 process requiring to print 1 page each . u just collectively gave printer
command and may say it as a printing job. similarly we can say computation job e.t.c. task may be a job no specific
definition or boundary exist between a task and a job . u may think a task as a sub part of a job like printing a page of
process 1 is a task.
process. program under execution . u are running nfs most wanted which is of 4 gb . u have ram of 1gb still u can run this
.
suppose u r just playing stage one of that game so only that stage will be under execution and currently will be in
memory. that is called a process. process is the part of a program under execution .
When the partition size is very small then why do we say that it is sometimes profitable to allow internal fragmentation in the
partition ?
if the size of each segment of memory is small nd it is smaller than most of the processes then internel fragmentation will
never occur but some of the processes will never be able to complete its executuion because not a single segment is
large enough for that process.
but if we segment the memory in larger block then also it is nt a good idea as some memory will be wasted that why MVT
(multiprogramming with variable no of tasks) model is used.
6.290 what is the actual meaning of new state of the process ? top gateoverflow.in/16661
when I play a media file then what is actually the new state of the job since in case of a program being compiled, (hence the
executable code is actually the new state of the job) ,we say that now the program is compiled hence it is now ready for
execution and hence it is right now a new job in new state
but when we actually execute the command a.out , then it is actually executed and we say that it enters ready state and
according to the
time shared policy of CPU , the program is executed but in case of a media file or any other software start up what is the
new state of a job ?
operating-system
When you play a media file - you don't execute it. Instead you execute the "player" which is like a "a.out" executable.
Now, the media file is provided as an input file to the player and it does the playing. So, the player (which is usually
compiled and made as an executable) would be reading the input as a file similar to reading a binary file in a C code- each
byte or set of bytes have fixed meaning defined as per the media format and after interpreting that, it does the playing.
6.291 what is the searching technique used for selecting a job from ready
queue ? top gateoverflow.in/16660
If the ready queue is such that we have all the PCB's linked up together as a linked list then whenever the CPU needs to pick
up a process for execution then does it perform linear search on it , and if it does then it would be taking large time
since there a large no of processes executing simultaneously in the memory , so then which searching technique is generally
empolyed
to pick up a process from the linked list ?
operating-system
A queue can be implemented using a linkedlist, but always allows constant time deletion- and this is used to pick up a
process for execution. There is no need to do a search here. Whatever criteria is needed to pick up a process can be used
to design the "priority" of the queue and it can be made a priority queue.
6.292 Consider the relation R(A,B,C,D) with dependencies AB -> C, ABC -> D
and AC ->>- B. top gateoverflow.in/15062
R is not in 3NF
R is in 4NF
databases
Its in Bcnf .
Candidate keys are AB and AC .
Transfer time is the time taken to read the complete sector , so how does this formula comes ?
I am unable to get that how come no of sectors per track comes , since transfer time is the time taken to read one complete
sector and on a track many sectors are present , so how come it is taking into consideration all the sectors present on the
track ?
Well u are assuming the definition of transfer time. Its definition may vary according to context of the question . sometime
they also include the seek time, rotational latency and the actual time need to transfer it will be given in the question.
basically transfer time is included till stated by question
there will always be data present to find the number of sector present on the disk. u have not specified any of the
question so i am unable to provide the exact solution.
u can easily calculate it . i will suggest not to learn anything like the complicated formula . keep thing simple there are hell
lot of concepts to remember . u post a question instead . then i may help u more.
5 batch jobs A through E arrive at a computer center at almost same time. They have estimated running times of A:10, B:6,
C:2, D:4 and E:8 minutes. Their priorities are A:3,B:5,C:2,D:1 and E:8 min. Their(externally determined) priorities are
A:3,B:5,C:2,D:1 and E:4 respectively with 5 being highest priority.Ignore context switch overhead.
Q- What will be the mean process turnaround time under R-R scheduling algorithm(assuming time slice of 1 min)?
Selected Answer
Why complicate this one . first of all one tip. never panic seeing a question. whenever u see such a question the answer is
very easy just rewind the concept .
so here it is asking cpu efficincy . simply cpu efficency = usefull work done by cpu/ total time .
now there are n processes which will be running and after every process context switch willl occur.
A-
q is quantum time
now we have to calculate how many time processes are switched ,so no of switched = r/q
When parent process executes fork system call process moves into
a) created state
b)ready state
c)running state
d)zombie state
Parent process has already begun execution and hence can not be in created (new) state
Running state is the state of a process while running. But a process just forked can't start running until the child process is
created and its pid returned to it. Till then it'll be in READY state.
Zombie state is a state of a process when the process has terminated but it's id is still in the process table (for parent to
check its exit status)
Selected Answer
A. is true.
In N process round robin scheduling a process will be in running state after N context switch and (N-1) CPU burst. i.e. NC
+ (N-1)Q
B. True because preempted process id puts in queue which is FIFO. So W executes before P.
C. True.
= Q/(Q+C)
6.298 How the "caching disabled" bit in page table entry prevent caching of
I/O registers? top gateoverflow.in/11948
I mean, how is it possible? We cant access page table before looking into cache? I think I am missing some point.
Thanks in advance.
Selected Answer
I get it. Before moving a page into cache , its cache disabled bit is checked from page table entry. If it is 1, the page is not
moved into cache.
6.299 how much memory is needed to store each user's access data? gateoverflow.in/15029
top
consider a system where each file is associated with a 16 bit number.for each file ,each user should have the read and write
capability.how much memory is needed to store each user's access data?
I think answer is A .
Question is that how much memory is needed to store each user's access data so its only the memory reqd for read/write
information which is asked. For 2^16 files, there are 4 different combinations of read(R) write(W). Read, write, no read,
no write.
=16KB
6.299 ISRO 2011 There are 3 processes in the ready queue.,when the
currently running process requests for I/O how many process switches
takes place? a.1 b.2 c.3 d.4 top gateoverflow.in/14617
Selected Answer
One.
The currently running process will be sent in blocked state and a process from ready queue will come in.
According to me now , on learning and focussing the points of vivek the answer is one . one context switch takes.
saving one process context and then loading the another process context and then running it . its all in one context switch.
now if u can understand then i may define it in the way we have read till now.
in the grant chat how many context switch does we count if we switch one process and select another process. only one .
if this question is taking two context switch then we must have to take 2 context switch between p1 and p2 . one to push
it in the wait/ suspended . and second to put p1 in running state that is not happening . so answer is one.
I THINK
Consider a system with five processes P0 through P4 and three resource types R1, R2 and R3. Resource type R1 has 10
instances, R2 has 5 instances and R3 has 7 instances. Suppose that at time T0, the following snapshot of the system has
been taken : Allocation R1 R2 R3 P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 2 2 Max R1 R2 R3 7 5 3 3 2 2 9 0 2 2 2 2 4 3 3
Available R1 R2 R3 3 3 2 Assume that now the process P1 requests one additional instance of type R1 and two instances of
resource type R3. The state resulting after this allocation will be (A) Ready state (B) Safe state (C) Blocked state (D) Unsafe
state
option (b)
alocation max
process reaminig need (R1 available(R1
(R1 R2 need(R1
no R2 R3) R2 R3)
R3) R2 R3)
p0 010 753 743 332
p1 200 424 224
p2 302 902 600
P3 211 222 011
P4 022 433 411
initially need for process is 322 but process P1 requests one additional instance of type R1 and two instances of
resource type R3. with 332 we can satisfy p3 need therefore giving all its allocated resource back resulting 5 4 3 now
available resources. with 5 4 3 we can satisfy either p1 need or p4 need here we cant satisfy p0 or p2 need becauz
remaining need resouce are more than available resource so on ..... therefore there is safe state with safe sequence as P3,
P4, P1 , P2. P0
6.301 How to calculate the capacity of disk pack in the below question ? top
gateoverflow.in/16736
A disk pack has 19 surfaces and storage area on each surface has an outer diameter of 33cm and inner diameter of 22cm .The maximum recording storage density
on any track is 200 bits/cm and minimum spacing between tracks is 0.25 mm , then how to calculate the capacity of disk pack ?
Disk capacity = total number of surfaces * no. of tracks per surface * amount of data per track
Total number of tracks per surface = (outer radius - inner radius)/ inter track gap = (33cm/2 - 22cm/2 )/0.25mm = 220
amount of data present in single track = perimeter * density = 13829 bits (approximately)
6.302 how many entries will be there in the page table if it is inverted? top
gateoverflow.in/16972
In a 64 bit machine,with 2GB RAM and 8KB page size,how many entries will be there in the page table if it is inverted?
a)218
b)220
c)233
d)251
Selected Answer
The answer is 218 (option a) . The number of entries in page table of an inverted page table is equal to number of frames
in the main memory. which will be 2 ∗ 230 /23 ∗ 210 = 218
6.303 What will be the total page faults in the following ques ? top gateoverflow.in/19975
Selected Answer
answer is 9 just check once again. initally 3 page fault then on the sequence d,a,b,e,c,d = 9 page faults
In a system having a single processor,a new process arrives at the rate of six processes per minute and each such process
requires seven seconds of service time .what is the cpu utilization?
a)70%
b)30%
c)60%
d)64%
Selected Answer
6.305 The total time to prepare a disk drive mechanism for a block of data to
be read from it is top gateoverflow.in/17263
The total time to prepare a disk drive mechanism for a block of data to be read from it is
a)seek time
b)latency
d)transmission time
Selected Answer
option (c) .The total time to prepare a disk drive mechanism for a block of data to be read from it
is latency plus seek time.
In a LRU page replacement policy we just replace the least recently used page, without looking at its dirty bit.
However If we also look at the dirty bit of page table entries along with the LRU bits, and replace only the pages that has not
been modified(i.e. replace only pages that has dirty bit = 0) unless all the table entries have been modified ( I.e. all the
entries in the page table have their dirty bit = 1) then we can postpone the process of write back for some time.
That is we are going to apply LRU only on the pages that have not been modified untill all the pages gets modified.
co&architecture
Selected Answer
I suppose it will be advantageous. But having a separate list of modified pages would be tricky as any page can be
modified at any time and that should be moved to the modified list. Also, some frames might be just read from but
frequently and due to this policy such pages might get replaced by less actively accessed write pages. So, depends on the
accesses this can benefit or not but I guess it is a good technique. There should be such works already done for page
replacements.
Consider a system running 10 I/O bound task and one CPU bound task.Assume that I/O bound task issue I/O operation once
every millisecond of CPU computing and each I/O operation takes 10 msec to complete.Also assume that context switching
overhead is 0.1 ms and all process are long running tasks.What is CPU utilization for round robin scheduler when
1)time quantum is 1 ms
2)time quantum is 10 ms
all task are long running task so we cannot wait to complete as no limit is given so i take one cycle in consideration.
one cycle will be from the execution of P0 till it comes back again.
thsi will be one cycle .. not to forget the last context switch as we have not considered a context switch on before p0. so
we have to consider the last one .
now p1 will execute for 1 unit and then will go for i/o and will come back after 10 ms which is 11 ms.
well as no cpu time will be wasted as it will always have a job to execute and i/o will be overlapped like the normal day
practice it will work like normal and only wastage will be context switch time which will be 11 *0.1=1.1 ms
efficiency = (11-1.1)/11*100= 90%. well the process which is cpu bound will not have to go to i/o so he will just exit the
queue and again come in line. it will not have any effect here .
2 case.
so we know after every 1ms process goes to i/o. but a process will only be preempted when time quantum expires .
so now the cycle time will be 110 as every process is running for 10 ms. and all are long tasks not completing in one or 2
cycles
so the context switch will be the same and the wastage will also be same 1.1.
but in the time quantum every process will only do 1 ms of usefull time and all 9 ms will be wasted . except the process
which is cpu bound . he will work the whole time. so usefull time will be 1*10+10
20 unit will be only the usefull work .minus the context switch overhead = 20-1.1
18.9 is the actual useful work out of 110. so efficiency = 18.9/110*100= 17.18 %
When a process is rolled back as a result of deadlock the difficulty which arises is
a)Starvation
b)System throughput
d)Cycle stealing
We can see the example of bridge crossing, in which bridge has only one lane.
6.309 Find out the min and max no. of page faults. top gateoverflow.in/18459
Selected Answer
i think the max will be m . for every memory access if there is a page fault then it will be m. and minimum will be p as i
have to make memory access to p distinct pages.
We generally say that the scheduler picks a process from the ready queue and then brings it to CPU for execution but in
general ready queue is actually a linked list of PCB's and a process is actually a different section of memory so then how
come we are able to pick up a process for execution from a queue .
Also a process has a set of executable instructions so then when CPU fetches an instruction from it , so then is it that the size
of the process in the memory changes because I saw the task manager and saw that the memory occupied by the processes
was changing nearly increasing and decreasing as the process as allocated to CPU , so I couldn't get the logic for this that
how come the memory occupied by the process changing when CPU is allocated to it ?
operating-system
Selected Answer
Ready queue is a linked list of PCBs- so the scheduler gets a PCB. Now, PCB will have all information about a process.
https://en.wikipedia.org/wiki/Process_control_block
As part of this data will be the code location of the process. When a process is created, it is assigned memory for the code,
data, stack and heap section. Now, the CPU will start executing instructions from the code section from the PC pointed
value.
How process "memory usage" changes during execution? Because the process is using dynamic memory allocation. Write
a C code with no dynamic memory allocation- that is no function calls and simply running a nested loop a million or more
times. There won't be a change in memory usage. Memory usage changes during function calls- dynamic memory
allocation on stack (in languages like C) and on dynamic memory allocation on heap.
Now if here paging algorithm means page replacement algorithm then option a is incorrect.
for dynamic address translation we need MMU(Memory Management Unit) which itself is a hardware. so option c is correct.
Feedback queues
6.313 which of the following is correct,please explain every point top gateoverflow.in/17095
. address translation
.demand paging
Explaination :
a) We can make a system multi user and multi-programming even by not using Virtual memory. We can use static
partitions in Main memory to do our job. It's just that the degree of multi-programming will be less. But it is possible.
b) DMA has nothing to do with multi programming if we consider only processes to be CPU bound.
d) demand paging, Reason same as option a. Without VM we can make a system to ne multi programmed.
Why option c?
Because in case of multiuser system, one user will be root user for sure which will have access to privilaged instructions.
So to switch from normal user to root user you need hardware bit which is switched between two modes of uses. Also for
a system to be multi programming, we need to swap in and out the processes from memory which need hardware access
which can be only done in system mode.
6.314 how many possible different schedules are there? top gateoverflow.in/16985
A CPU scheduling algorithm determines an order for the execution of its scheduled processes.Given n processes to be
scheduled on one processor , how many possible different schedules are there?
a)n
b)n2
c)n!
d)2n
answer is n! as n process have the choice to run at any place 1,2,3,4,5...n places .
6.315 which of the following are the likely cause of thrashing? top gateoverflow.in/16983
ANSWER: A
if page size is very small , locality of reference will be reduced. which increases page faults.
reference:
http://www.nptel.ac.in/courses/106108101/4
Identify the schedular which involves only in the decision for selection of partially serviced jobs?
.S.T.S
.L.T.S
.M.T.S
.NONE
Assume that there are 2 independent processes which are in memory and each process spends a fraction 2 of its time
waiting for I/O to complete. Each process requires 4 minutes of CPU time. The utilization of CPU in percentage is _____.
operating-system
as 1/2 of the time is for IO for both process . then 0.5*0.5 = 0.25 is for IO
Thrashing
in which of the following four necessary conditions for deadlock processes claim exclusive control of the resources they
require?
a)no preemption
b)mutual exclusion
c)circular wait
b. Mutual Exclusion
in which of following scheduling algorithm. any short jobs arriving after long jobs will have a longer waiting time?
A) Round Robin
B)SJF
C)FCFS
D)SRTF
Selected Answer
FCFS Scheduling.
6.320 in which conditions,you will not allow a page to cached? top gateoverflow.in/10430
operating-system
When that page is shared with another process running on a different core of the machine. For example, in Intel 3rd
generation core architecture (Ivybridge) L1 and L2 cores are private for a core and L3 is shared. So, a shared page must
not go above L3 cache or otherwise explicit coherence mechanism must be done by the programmer.
If initially semaphore is 1, up to 3 processes can be executing in critical section at a time as each process from 0 to P n-
1 decrements the counter on enter and increments on exit while P n increments it twice when it leaves without
decrementing.
If initial value of semaphore is 0, then up to 2 processes can enter the critical section at a time.
Similarly, if the initial value of semaphore is n-2, then up to n processes can enter the critical section at a time.
The sequence …………… is an optimal non-preemptive scheduling sequence for the following jobs which leaves the CPU idle for ………………… unit(s) of time.
----------------------------
Job Arrival_Time Burst_Time
----------------------------
1 0.0 9
2 0.6 5
3 1.0 1
----------------------------
(a) {3,2,1),1 (b) (2,1,3},0
(c) {3,2,1),0 (d) {1,2,3},5
Assuming optimal is with respect to the total waiting time (a) is correct.
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/5_CPU_Scheduling.html
C needs to be checked only during a cache miss as then only there will be a main memory reference and we have to
decide whether to cache that particular page or not.
All others are not always required. If we are not caching a page, then there is no need to do virtual address to physical
address translation while looking in cache.
Also, a dirty page can be cached. Dirty bit in a page means, the page is modified and must be written back to secondary
memory during replacement. This has nothing to do with the page being cached or not.
http://6004.mit.edu/Fall13/tutprobs/vm.html
a) Program Counter
b) Stack Pointer
c) Execution Stack
Options
A) a),b),c) only
B) only a) and b)
c) only c)
d) All
Ans is b).. Is execution stack shared among the threads as only code,data and files are shared among the threads
If execution stack is shared, suppose one thread calls a function, (that function will push the activation record on to
stack), then the current activation record in the other threads gets corrupted.
Ans is B) ...but after z...y should not printed since b would become 0 then....so II should not be a possible output...
Plz explain......
When b becomes 1, the while loop in P2 breaks. Now the next instruction is printf("y"). But before this instruction gets
executed, the instructions
b=0;
printf("z");
CAN be executed by P1. (There is a possibility for that). So, B is the correct answer.
6.325 A certain moving arm disk storage, with one head, has the following
specifications. Number of tracks/recording surface = 200 Disk rotation
speed = 2400 rpm Track storage capacity = 62,500 bits The average latency
of this device is P msec and the data transfer rate is Q bits/sec. Write the
value of P and Q. top gateoverflow.in/5196
Disk rotation speed= 2400 rpm
Average Latency = p
Data transfer rate is nothing but how much data can be read in one second
x= 60 *10 3 / 2400
x= 60 *10 3 / 2400
therefore we get x = 25 ms
Hence P =12.5 ms
Consider a system consisting of n resources of same type being shared by 4 processes, 2 of which need at most 2 resources
each and other need at most 3 resources each.The min value of n so that the system is deadlock free is ___________?
Selected Answer
Now, assume the worst case. All processes are allotted all resources except 1. So, 2*1 + 2 * 2 = 6. Here, deadlock is
possible with n = 6.
When n = 7, at least one process must finish and we get 7 resources for 3 processes which require maximum 8 resources
between them. So, again at least one of them will finish and there won't be a deadlock.
Ans is (D)
bounded waiting is also guranteed. As per Operating System Concepts by Galvin, "There exists a bound on the number
of times that other processes are allowed to enter their critical sections after a process has made a request to enter its
critical section and before that request is granted."
in option B they said m/e and b/w are guranteed only. means they indirectly saying progress is not guranteed. so B is
wrong.
in D they said m/e and progress guranteed. Here they didnt mention anything negative about b/w so we can not think b/w
is not satisfying. therefore D is correct.
A cpu generates 32- bit virtual address .The page size is 4kb .The processor has a tlb which can hold 128 entries and is 4-
way set associative .The minimum size of tlb tag is ???
Selected Answer
Now, 32-5-12 = 15 bits are there and we need all of them to be used as tag bits as otherwise we cannot identify a page
from the tag. (215 possible page can come to a set and minimum 15 bits are needed to identify the page).
Suppose a process has only hte following pages in its virtual space : 2 contigous pages frm address 0x00000000 , 2
contiguous [ages frm 0x00400000, a stack page starting at virtual address 0xffff0000.The amount of memory for storing the
page tables is ???
8kb
12kb
16kb
20kb
http://gateoverflow.in/788/gate2003_78-79?show=788#q788
Please explain with a situation where bounded waiting is satisfied but progress is not.
A livelock would be an example. Here, all the processes might get a chance to execute thus making the waiting bounded
but due to live lock no one will be able to eventually complete resulting in no progress.
6.331 Consider two processors P1 and P2 executing the same instruction set.
top gateoverflow.in/367
Consider two processors P1 and P2 executing the same instruction set. Assume that under identical conditions, for the same
input, a program running on P2 takes 25% less time but incurs 20% more CPI (clock cycles per instruction) as compared to
the program running on P1. If the clock frequency of P1 is 1GHz, then the clock frequency of P2 (in GHz) is _________.
operating-system normal
Total execution time, E = No. of instructions executed( #I) × CPI / clock frequency (F)
EP2 = 0.75 × EP1
Given two processes how do I check for starvation condition?Given below is a program which when executed spawns two
concurrent processes:
Semaphore X:= 0;
operating-system
Selected Answer
Also, it can be the case that the Process P1 starves for ∞ long time on the semaphore S, after it has successfully executed
its critical section once, while P2 executes infinitely long.
answer = option A
A is the answer.
Case 1:Here P1 is performing signal operation so it is first one to start...Now it may happen that after executing CS it
makes X=0 again tries to enter CS my making X=1 so it is possible that P2 can starve(just a possibility)
Case 2:If P1 executes signal operation and its execution is suspended temporarily, P2 executes wait and enter CS and
then execute signal operation making X=1 now P2 can enter critical section by executing wait operation..this may happen
for infinite amount of time..so in this P1 may starve
6.333 Which of the following are equal things when there is only one CPU in
a system. top gateoverflow.in/2335
Which of the following are equal things when there is only one CPU in a system.
D) None of these
operating-system
D. None of these
In short:
Multiprogramming is number of processes that can be in ready queue at any given instance of time. Here they can be any
number, depending on the capacity of ready queue.
Multiprocessing is the number of tasks going on simultaneously in different cores of cpu. Here number of cpu is one so at
a time one task will be going on. Notice that I am using the term task rather than process or thread because task can be
generalised to both without creating a confusion about its size. Linux uses the concept of tasks only, no processes or
threads.
Multitasking is the number of tasks CPU seems to execute simultaneously. That means we can run web browser and songs
simultaneously. They seem to run at same time but truth is at the backend, they are given CPU in time shared manner.
Its just an illusion that they are running together. In this question's case, number of tasks can be any. Browser, songs,
etc.
So answer is D.
Multiprocessing- Happens when hardware can provide multiple processing resource- like multiple CPUs, cores etc. It is a
hardware feature.
Multi-programming- Happens, when the system has the capability to run multiple programs at the same time- when one
waits for say IO, context switch happens and next one is executed. It is to be supported by software.
Muti-tasking- Similar to multi-programming but here unit is a task which is a smaller unit than a process- a thread of
execution can be a task.
So, in a single CPU system we can say multi-processing is absent (assuming no multi-cores). Also, multi-programming and
multi-tasking don't make a difference if there is a single CPU or multiple. So, answer should be D- none of these.
R e f : http://www.8bitavenue.com/2012/10/difference-between-multiprogramming-multitasking-multithreading-and-
multiprocessing/
on a system using paging and segmentation references to swapped in locations accessible through an entry in
associative table take 200ns if the main memory page table must be used ,the reference takes 400ns.References that
results in page faults require 10ms .if the page to be replaced has been modified,5ms otherwise.if the page faults rate is 5%
the associative table hit rate is 65% and 40% of replaced pages are dirty,what is the effective access time?Assume the
system is running only a single process and cpu is idle during swaps.
Average Access time = 65% * 200 + 35% * 400 + 5% * (1- 40%) * 5,000,000 + 5% * 40% * 10,000,000
= 130 + 140 + 150, 000 + 125, 000
Q1)
An OS contains 10 identical processes that were initiated at the same time. Each process contains 15 identical requests, and each request consumes 20msec of
CPU time. A request is followed by an I/O operation that consumes 10 msec. The system consumes 2 msec in CPU scheduling. For time quantum of 20 msec , the
response times of the first request of the last process is
A) 26 msec B) 220 msec C) 200 msec D) none
Ans : A
Q 2)
In the above problem , the scheduler length is
A) 3300 msec B) 3600 msec C) 6300 msec D) 6600 msec
Ans : A
Please explain.
Selected Answer
Take the last process -> it will get its first request processed after 10 schedules. Because after the first time quantum, the
first process does an I/O operation (as it would have finished its request which also takes 20ms and hence CPU given to
next process) and hence the second process gets its chance. Thus, after 9 time quantum, the final process gets its request
served (assuming a previously given process is never given CPU time again until all other processes in wait are given). So,
this means we need 10 schedules (including one at the beginning) and given in question that each scheduling takes 2ms.
So, response time for the first request of the last process
= 9 × 20ms + 10 × 2
= 180 + 20 = 200ms.
P1 P2 P3 ... P10 P1 P2 P3 ... P10 .... P10 P1 P2 ... P10 (P1-P10 repeated 15 times)
After every time quantum and at the beginning we need 2ms for scheduling the next process. So, total scheduling length
= (20ms + 2ms) × 10 × 15
= 220 × 15 = 3300ms
6.335 what is the main difference between translation look aside buffer and
translation look ahead buffer . top gateoverflow.in/3304
operating-system
The below link says TLB- Translation Lookaside Buffer is used for address translation while Translation Look-ahead buffer
is used by disks to put pages in the disk cache ahead of its access (probably based on spatial locality), and that makes
sense. I have seen TLB being referred as Translation Look-ahead Buffer at some places, but that doesn't make any sense-
as looking is not done ahead here.
http://cs.stackexchange.com/questions/9612/look-ahead-buffer-vs-translation-look-aside-buffer
Now, the remaining needs of P0, P1 and P2 are 2, 2 and 2. With just 1 free tape, system is not in a safe state. Now,
deadlock may or may not occur in a non-safe state. If some process release a resource, then deadlock can be avoided.
6.336 Can anyone explain, how does Livelock occur in case of priority
inversion? top gateoverflow.in/5475
Selected Answer
Consider two processes A and B both needing an instance of X. Assume priority of A is greater than B. Initially X will be
assigned to A due to higher priority of A. But if before X completes execution, priority of B becomes greater than A, A can
be put on hold and B can start execution. Now, during execution of B, if priority of A becomes greater, the same cycle
continues- two processes trying to make progress but not able to do- livelock.
ref@ https://en.wikipedia.org/wiki/Deadlock#Livelock
where does page table resides in main memory.. os space or user space.. and i hope there is a page table in main memory
for every process.. am i right... please clarify me.thank you.. .
Page table is stored in main memory at the time of process creation and its base address is stored in process control block.
Page table is created for Each Process separately unless inverted Paging is used In which there is single Page table for all
the Processes.
6.338 which one of the following process in UNIX operating system does not
have a parent process ? (a) sh (b) dev (c) login (d) kernel top gateoverflow.in/8938
which one of the following process in UNIX operating system does not have a parent process ?
(a) sh
(b) dev
(c) login
(d) kernel
operating-system
sh does have a parent process and its parent is whoever has called sh.
arjun@armi:~$ ps -f 3985
UID PID PPID C STIME TTY STAT TIME CMD
arjun 3985 3887 0 13:17 pts/13 S+ 0:00 sh
login also has parent and its parent is the init process.
arjun@armi:~$ ps -f 498
UID PID PPID C STIME TTY STAT TIME CMD
root 498 1 0 13:11 ? Ss 0:00 /lib/systemd/systemd-logind
arjun@armi:~$ ps -f 419
UID PID PPID C STIME TTY STAT TIME CMD
root 419 1 0 13:11 ? Ss 0:00 /lib/systemd/systemd-udevd --daemon
So, the answer is "kernel" which has process id 0 and is the parent of the "init" process.
http://unix.stackexchange.com/questions/83322/which-process-has-pid-0
6.338 consider a machine with 64Mbyte physical memory and a 32 bit virtual
address. if the page size is 4 kByte, what is the approximate size of the
page table? a)16 Mbyte b)8 Mbyte c) 2 Mbyte d) 24 Mbyte top gateoverflow.in/7465
Selected Answer
And page table needs to store the address of all these 2 14 page frames. Therefore, each page table entry will contain 14
bits address of the page frame and 1 bit for valid-invalid bit. we suppose 16 bit require it means 2 bytes (approx.)
so Size of Page table = Total PTE (from eq 1) x Size of page table entry= 2 20 x 2 = 2MB
32 bit virtual address means 2 32 /4K = 2 20 entries in the page table as each entry points to a page (the lower 12 bits are
not used while looking up in the page table).
Each PTE must address a memory location of a page which ranges from 0 to 64M/4K = 16K. So, should need 14 bits.
Assume that current cpu burst of the lone process spans more than one time-slice of the round-robin algorithm.
My reasoning is as below
The steps that may take place when a timer interrupt occurs in a typical case are
1. Interrupt occurs.
2. Switch to kernel mode
3. OS saves current context into PCB(save registers, process state and memory-management info of current process)
4. Perform many architecture-specific operations, including flushing data and instruction caches and TLB's.
5. Put current process into the ready queue
6. Choose the new process to execute
7. Load context from the PCB of that process
8. Switch to user mode. Start executing the new process
I am now thinking that the OS might as well inspect the ready queue first and check if there are other processes. If there
aren't any there is no need for a context switch. Thus handling of the timer interrupt will entail switching between the user
mode and kernel mode, checking the ready Q, and switching back to the user mode to resume execution of the process.
Is this what happens? Or does a proper context switch of involving the unnecessary saving of the current state of the lone
process and the restoring the same take place?
Selected Answer
You should see the word "NECESSARILY" in question. We don't need to save TLB or cache the ensure correct program
resumption. They are just bonus for ensuring better performance. But PC, stack and registers MUST be saved as
otherwise program cannot resume.
Ref: http://www.linfo.org/context_switch.html
a) software interrupt
b) polling
c) An indirect jump
d) A previledged instruction
Privileged instruction cannot be the answer as system call is done from user mode and privileged instruction cannot be
done from user mode.
a) Internal fragmentation
b) External fragmentation
c) Both
d) None
Answer :B
Segmentation is similar to dynamic partitioning, only this time process can have several segments, while in dynamic
partitioning a partition is accommodating the entire process.
A different memory management approach known as dynamic partitions (also called variable partition) which creates
partitions dynamically to meet the requirements of each requesting process.
DYNAMIC PARTITIONING
6.342 consider the given sequence of scheduling then what will be the
number of context switch: p1p1p2p2p3p1p4p4p4. plzzzz rply some one top
gateoverflow.in/9492
Answer is 4
P1 to P2
P2 to P3
P3 to P1
P1 to P4
Whenever CPU starts execution with Process P1(initially) we wont consider as Context switch
Context switch is one occurs when CPU changes the execution from one process to other Process
6.343 A certain computer system has the segmented paging architecture for
virtual memory. top gateoverflow.in/7324
A certain computer system has the segmented paging architecture for virtual
memory. The memory is byte addressable. Both virtual and physical address
spaces contain 16 2 bytes each. The virtual address space is divi8ded into 8 nonoverlapping
equal size segments. The memory management unit (MMU) has a
hardware segment table, each entry of which contains the physical address of the
page table for the segment. Page table are stored in the main memory and
consists of 2 byte page table entries.
(a) What is the minimum page size in bytes so that the page table for a segment
requires at most one page to store it? Assume that the page size can only be
a power of 2
(b) Now suppose that the pages size is 512 bytes. It is proposed to provide a
TLB (Translation look-aside buffer) for speeding up address translation. The
proposed TLB will be capable of storing page table entries for 16 recently
referenced virtual pages, in a fast cache that will use the direct mapping
scheme. What is the number o tag bits that will need to be associated with
each cache entry
(c) Assume that each page table entry contains (besides other information) 1
valid bit, 3 bits for page protection and 1 dirty bit. How many bits are
available in page table entry for storing the aging information for the page?
Assume that the page size is 512 bytes.
Selected Answer
So 1 st Given Virtual Space = Physical Space = 16 bit and There are 8 Segment in the memory So for 8 segment there are 3 bit to
represent the 8 segment
SO
And Size of page table = Page Size (Due to Statement given in Que= page table for a segment requires at most one page to store it )
214-n = 2n so n = 7
So Answer is 4 Bit....
Which scheduling algorithm is optimum among the following disk scheduling algorithm in most of cases?
a)FCFS
b)SSTF
c)SCAN
d)LOOK
ans must be D)
LOOK behaves almost identically to SSTF, but avoids the starvation problem of SSTF
Also please explain how many times "PROCESS" will be printed when we don't use fflush()...?
Selected Answer
It must be fflush(stdout);
In C code by default stdout is buffered until a newline occurs. So, here if we don't use fflush, printf buffer will be active
during fork, and hence copied to the child process also. The two fork() calls create 3 child processes, and hence
"PROCESS" will be executed 4 times if we don't use fflush.
If we put a '\n' at end of printf or use fflush(stdout); only 1 printf will be done.
http://stackoverflow.com/questions/2530663/printf-anomaly-after-fork
operating-system
What I think, we can solve it by checking the flow of the execution. First, after S1 , fork is done and new process's address
S3. so two arrows from S1 (i.e S3;new process address , S2;normal execution) . Similarly proceed with other forks. At
DEF we can see S5,S4,S2 can reach. So, these processes are combined.
6.346 State True/False with explanation for the statement --> Multilevel
paging optimizes the program execution time. top gateoverflow.in/5721
True. But depends on the size of virtual address space. Multilevel paging can ensure all page tables needed for a process
can fit in physical memory and thus avoid swapping out of pages (pages of page tables) to hard disk. In this way it can
reduce execution time.
Now, if the page tables are initially itself fitting on main memory, then multi-level page table only decreases execution
time due to overhead of multi-level lookup.
6.346 State true or false with explanation.Larger time quantum gives more
efficiency than smaller time quantum used in RR scheduling top gateoverflow.in/6203
True.
Smaller time quantum leads to more context switch time and the time cpu spends actully executing the process is
reduced.
6.346 Can any one tell , how the formula works ? i mean why no. of process
is added ?? Sum of all process max need < No. of Process + Resource No. top
gateoverflow.in/6467
I suppose this is the formula for min. no. of processes required for deadlock. For this, we assume the worst case and this
happens when all but 1 required resources are taken by all the processes.
If we have one more resource, one process can be finished and this results in more processes getting finished and there
won't be a deadlock. So, for deadlock,
or
What is value of binary semaphore "S" after executing 10 P (Wait) operations and 14 V (Signal) operations if the initial value
of "S" is 1 ?
It will be 1
Next 9 p operations : semaphore value not 1 So block all the process and place in suspended list
Value 1.
Semaphore is shared between parent and child. Since, it is initialized to 1, one of either parent or child will succeed in
wait(sem) prints Gate and then signal(sem). Now, the other process also does the same. So, "Gate Gate" will be the
output.
4.LOCK=0
I am unable to get that this code belongs to which process in general since P1 and P2 both execute this code and also they must be having some other code also
in addition to this one so is it that both of the processes have this piece of code present in them and if it is so then how come the value of LOCK changed by one
process is seen by the other process since LOCK is present in the entry section and not in the critical section which implies that it is not a shared variable since if it
were a shared variable it would have been inside critical section, but it is not .Also each process would make changes in its own register contents only so then how come they are actually able
to see the actual values of LOCK variable
Hi , no the above code is right . this is because both process will use same code . I will explain you LOCK is a
synchronisation variable . Let us see how . you will have LOCK=0 as initial value to get into critical section. Suppose if i
have 2 process p1 p2 . And if anyone of the process P1 come then it , it will find lock value as 0 ryt ? Now while statement
(0!=0) . false right . so it will go out of while loop and enter into critical section by making LOCK variable =1 . Now
suppose this time if p2 come , it will grab lock varaible and check (lock!=0) -->(1!=0) ;which is true , so it will loop in
while loop only (see ; after whileloop ). Hence you can get this would be exceution if any 1 process come first and then
another one (while p1 is executing ) Now imagine a scenario when both process come together and grab a lock varaible
(inital lock value is 0 ) . both will compare (0!=0) which is wrong so both of them simulatenously will enter critical section
. And the thing that here Lock is used as one of door to critical section . Its not a critical section !
If a synchronization mechanism does not gurantee Progress then does it implicitly imply that it won't gurantee Bounded
waiting as well
Selected Answer
Not really. Because "Progress" is defined for the system and "Bounded wait" per process. Even if a process is starved and
violate bounded waiting, system can progress.
On the other hand if "progress" is not guaranteed, "bounded waiting" carries no meaning. So, no progress implies no
bounded waiting- your second statement is correct.
http://csit.udc.edu/~byu/UDC3529315/Lecture6.pdf
Suppose you have byte addressable computer system with a 44 bit logical address and the page size in 6.4kbytes and each page entry takes 4 bytes. you are
running a 4 Gbytes program in this system. How many page frames would you need in order to put your entire program (including its page tables) in memory?
is it 65540?
Total no. Of frame required = no of frame for storing the program + no. Of frame required to store the page table
=(2^32÷2^16) + (2^18÷2^16)
= 2^16 + 4
=65540
Correct me if i am wrong..Thanks..
Bounded waiting: there must exist a bound on the number of times that other processes are allowed to enter their critical sections
after a process has made a request to enter its critical section and before that request is granted.
so while p0 check for while condition and enter into 2nd while loop
at that time p1 check 2nd while loop condition since flag[0]=flase so not enter into while loop and go into critical section,
now p0 check 3rd while loop condition and enter into 3rd while loop since flag[1]=true
now here case arrise when p0 check 2nd while loop then flag[1]= true and when p1 check for 2nd and 3rd while loop then flag[0] =
false.
so by this p0 never getting the chance to enter in C.S. .. and p1 enter infinite number of times.
Formula will be like cache is physicaly addressed so. first go to TLB then in cache.
EMAT= TLB hit [ cache hit (TLB time + Cache time) + cache miss ( TLB + Cache + memory) ] + TLB miss [ cache hit (TLB
time + Cache time) + Cache miss ( page fault [TLB + Cache + Page table+ Memory + Hard disk] + no page fault[ TLB +
Cache + Page table+ Memory]]
it is the same implementation of peterson algorithm , just they have changed the turn = process , to turn = others
process, the primary purpose of semaphore is to provide mutual exclusion which is definitely guaranteed.
http://gateoverflow.in//1853/gate2006_78-79
A computer system implements a 8kilobytes pages and a 36 bit physical address space.each page table entry contains a valid
bit,and the translation.if the maximum size of the page table is 96megabytes,Then what will be the length of the virtual
address supported by the system(in bits)?
Selected Answer
page table entry = frame no bits + valid bit = 23+1=24 bits = 3B.
so, 96 MB = x * 3B , so , x= 32 M = 2^25
2x
2 13
Now, no. of page table entries = Virtual memory size/ Page size = = 2x−13
Each page table entry needs 23 + 1 = 24 bits (23 bits for addressing a frame and 1 valid bit). And the total size of the
page table is 96 MB. So, we get
consider a uniprocess system executing four tasks T1,T2,T3 and T4 each of which is composed of an 10 sequence of job(or
instances) which are arrives at periodically at interval of 2,4,8 and 16 ms respectively.the priority of each task is directly
proportional to its periods and the avaliable task are schedule in order of priority,with the highest priority task schedule
first.each instance of T1,T2,T3 and T4 requires an execution time 1,2,4 and 6 ms respectively.given that all task arrive at
beginning of the 2ms and task preempted allowed,the 2nd instance of T3 its execution at the end of_______ ms
Selected Answer
execution sequence....
1).............................
2)T4
3)T4
4)T4
5)T4
6)T4
7)T4
8)T3
9)T3
10)T3
11)T3
12)T2
13)T2
14)T1
15)................................
16)T4
17)T4
18)T4
19)T4
20)T4
21)T4
22)T3
23)T3
24)T3
25)T3....
Page 1 has least last reference time(260) so LRU will replace page 1
If it was asked for FIFO then page 2 will be replaced(least loaded time)
For most frequently used page 3 will be replaced(highest last ref time)
6.359 In particular unix OS each data block is of size 256 bytes top gateoverflow.in/27252
operating-system
Max possible size= ( Direct + Single indirect +Double indirect)* block size
so Answer is
= [20+4+(4) 2 ]*256B
= 40 *256B
= 10KB
Execution sequence
1)x=1 1 1 3 1 2 2
2)y=y+x 2 4 4 3 4 3
3)y=2 3 2 1 2 1 1
4)x=x+3 4 3 2 4 3 4
x=4 y=2 x=4 y= 6 x=1 y=3 x=4 y=3 x=4 y=6 x=4 y=3
So option D
6.361 CPU having a single interrupt request line and a single interrupt grant
line top gateoverflow.in/26448
Which one of the following is true for a CPU having a single interrupt request line and a single interrupt grant line?
A. Neither vectored interrupt nor multiple interrupting devices are possible
B. Vectored interrupts are not possible but multiple interrupting devices are not possible
C. Vectored interrupts and multiple interrupting devices are both possible
D. Vectored interrupts are possible but multiple interrupting devices are not possible
6.362 Using a larger block size in a fixed block size file system leads to top
gateoverflow.in/26445
Using a larger block size in a fixed block size file system leads to
If the block size is large then seek time is less (fewer blocks to seek) and disk performance is improved,
but larger block size also causes waste of disk space.
So option a is correct.
Calculate the exponential avg for the SJF when t1=10, alpha=0.5...previous run as 8,7,4,16
6.366 Can anyone please help (or provide some link stated clearly) in
Selected Answer
https://courses.cs.washington.edu/courses/cse451/08wi/os-paging.ppt
http://www.cs.columbia.edu/~junfeng/10sp-w4118/lectures/l21-page.pdf
Answer (C) As in First fit case Total is { (5-3) + (10-2) +(30-12) } = 28K
4KB bcz one data block used to store directory entries each of 4 Byte...So 1K max. No. Of files..
Now as mentioned 8-bit entry per data block means there are 2^8= 256 data blocks out of that first 2 datablocks are
overhead so 256-2=254 Blocks max file size in terms of blocks
operating-system
Let there are 4 process . P1, P2 ,P3, P4. Round Robin used for scheduling , Time quantum = q . each process burst time is
greater than q . all processs arrived at time t = 0.
_P1_P2_P3_P4_
to count context switched all dashes need to consider . or need to left first or last.
plz explain ?
as it is given Q> burst time so no one will end in once cycle. so again after all these q1 wil come. so definitely we have to
consider . till the last process. what i think there is no need to count the last one. whichever it is.
Explain why a and b must be true.I think it should be only b because block is .. process is in wait state ie not consuming cpu
cycles whereas in busy wait cpu cycles are consumed
So while process is in CS the the other process continuously check lock is available or not.
If lock available it gets chance to enter in CS and if not it will just wait and continuously check the LOCK variable is free or
not .
Assume memory access time is 10 μs and reading a page from disk takes 10 ms. If page fault occur in 0.5% of the memory
references then what is the average memory access time (in μsec)?
operating-system
Thus
EMAT= m+p(ps)
= 10 microsec + 5*10-3*10*10^-3
= 10 microsec + 5 * 10^-6
= 10 microsec + 5 microsec
= 15 microsec
operating-system
offset 10 bits
page 3 bits
page=101
so ans d
0--p1--1--p2---4----p3---7---p2---8---p3--11--p3---12
Execution
Process
Time
P1 3
P2 5
P3 2
P4 1
P5 3
P6 4
Assume that all process arrive at t=0 and cut off time (TQ=2 units).
One cycle includes the one occurrence of each and every remain process in system and provided that they may complete
their execution in one cycle only
Q) How many jobs will complete their execution by the end of second cycle of selection?
a) 2 c) 4
b) 3 d) 5
I am not getting from where we have to start first cycle or second cycle ?
A computer System has 4GB of physical addressable memory with 32 bit memory addresses. It uses virtual memory with
demand paging for memory management , with a page size of 4 KB . Each page entry contains a page ID, a frame ID, and
three additional bytes of information. Q. How many bits of the virtual address are replaced by the MMU when it translates
the address into a physical address A. 12 B. 16 C. 20 D. 32
operating-system
No of surface of cylinder 85594/ 64 =1337 (here remainder 26 is no of sectors filled of last cylinder)
So, from starting cylinder 1200+83+1=1284 for last sector of the file
in this question alpha =0.25. but how we can determine that alpha
Page tables are stored in memory , which has access time of 100 ns. The TLB holding 8 page table entries, has an access time of 10 ns. Using execution of process , it is found that 85 % of
the time, a required page table entry exist in TLB and only 2 % of the total references causes page fault. Page replacement time is 2 ms . Calculate the effective memory access time ,
assuming page memory access requires 2 memory accesses and TLB requires one memory access.
0.85*[100+10]+0.15[0.02{10+100+2000000+100}+0.98{10+100+100}]
= 6125.00 ns
If there's TLB miss ,refer memory if page fault occurs replace page and again refer memory.
. Two concurrent processes P1 and P2use four shared resources R1, R2, R3 and R4 as shown below:
Both processes are started at the same time, and each resource can be accessed by only one process at a time.
The following scheduling constraints exist between the accesses of resources by the processes:
P2 must complete use of R1 before P1 gets access to R1 P1 must complete use of R2 before P2 gets access to R2 P2 must
complete use of R3 before P1 gets access to R3 P1 must complete use of R4 before P2 gets access to R4 There are no other
scheduling constraints between the processes above scheduling constraints, what is the minimum no. of binary semaphores
needed?
Answer is B .
x= 0; y=0;
Cobegin
begin
x= 1; y= y + x;
end
begin
y= 2; x= x + 3;
end
Coend;
Which of the following indicates possible values for the variables when the segment finishes execution?
(1) x= 1, y= 2 (2) x= 1, y= 3 (3) x= 4, y= 6 (a) 1 only (b) 1 & 2 only (c) 1 & 3 only (d) 2 & 3 only (e) 1, 2, 3
Const int n= 10
int Count= 0
Void A( )
{ int i; for(i= 1 to n)
Count= Count + 1;
Main ( )
{ Par begin
A( );
A( );
A( );
A( ); Par end }
What is the minimum and maximum possible value of count after the completion of the program?
(a) 1, 40
(b) 2, 40
(c) 3, 40
(d) 4, 40
Option B --2,40
. Consider a concurrent program with two processes P & Q, where A, B, C, D & E are arbitrary atomic statements; assume
that main program does a Par begin of the two processes:
Void P( ) Void Q( )
D;
E;
{ A;
B;
C;
(b) The order of Execution of statements will be same independent of the process execution
(c) The relative order among the statements of P & Q is always maintained
(d) None
Which is true?
Option D: Page Table size = number of entry * page table entry size
LAS
test-series operating-system
I think answer is D.It is very nice qs.6 is running and its next pointer is poiniting to 0.which is poiniting to in 3 ready.In 3
ready next pointer is 12,which is pointing to 12 ready,in 12 ready next pointer 14,so pointing to 14 ready,then pointing to
6 ready,and lastly next pointer * pointing to free 8...
I think option B is the answer because in running header 6 is the current one and 0 is the pointer to next .In 0 ready,3 is
the next.In 3 ready 12 is the next.In 12 ready,14 is the next.In 14 ready 6 is the next.
6.390 What is the minimum and maximum possible value of count after the
completion of the program? top gateoverflow.in/19318
Constant n= 10
int Count= 0
Void A( )
{ int i;
for(i= 1 to n)
Count= Count + 1; }
Main ( )
{ Par begin
A( );
A( );
A( );
A( );
Par end }
Selected Answer
MIN = 2
MAX = 40
Maximum is obvious.
For Min -
step 2 INCR Ri
step 3 M[count] Ri
Where Ri is the local register allocated by each function called and used for temporary storage.
Now every function from A1() to A4() will execute concurrently and each function will execute all 3 micro instruction;
1> Now consider A1() call first, it increment COUNT from 0 to 1 in 3 micro instruction but after executing 2 micro
instruction and gets preempted so at this time the value of R1(temprrary register ) = 1 but the count value will be still 0.
2> Now let A2() and A3() complete the execution so count value will be 20.
3> A4() will start it execution and let it iterate for "9" times so the count value will be 29 and preempt the A4().
4> Let A1() will start it's execution and it will execute its 3 micro instruction and overwrite count value from 29 to 1 in it's
first iteration and again preempt.
5> lets A4() start it's execution now the count value is 1 so it will iterate its 10 'th iteration and execute 2 micro
instruction and then preempt A4(). at this time R4(temporary register = 2) and count = 1.
6> Now execute remaining iteration of A1 form i=2 to 10 so it will make count value as 10 and complete it's execution.
7>In final step A4() will start it's execution and will execute 3 micro instruction for 9'th iteration and overwrite count = 1
and in the 10 iteration it will increment count from 1 to 2 and finish the execution.
So Min = 2
Max = 40.
Semaphore is used to enforce Mutual Exclusion and Synchronization between processes interacting over shared data and
variables. Which of the following statements is true about semaphores in this regard?
c) ‘Busy-Wait’ solutions to the Critical Section are typically implemented using machine instructions that execute in the
Kernal mode
operating-system
Only 1 needs to be true always. But "typically" in option 3 means it is also true. Busy-Wait can be done using Though
there is no strict requirement to do a signal after CS, assuming it got a lock, the process has to release it. So, it also
becomes true. So, I think D is the best choice.
P0
wait(s); wait(q);
P1[
wait(q);wait(s);}
signal(q);signal(s);....
Progress is not guaranteed I think bcz P0 will do down operation on s and q,so when P0 is in critical section for a very long
time P1 have to wait for arbitrary time until P0 releases s and q.When a process is stopping other process from executing
then we say there is no progress.correct me if I'm wrong..
Consider the processes P1, P2, P3 arrived in the sequence P2, P3, P1 and the burst time of the processes are 3, 3, 24
respectively. What is the average TAT??
where TAT(Pi) is the Turn Around Time of process Pi & n is the total number of processes participating in the scheduling
algorithm.
6.394 why is bankers algorithm less efficient than resource allocation graph
algorithm ? top gateoverflow.in/19575
I am unable to get this logic since in both of these algorithms we need to have a record of future requirement of the
processes so then why is it that resource allocation graph algorithm is more efficient ?
i think so that in A resource allocation garph , to detect a cycle we need n^2 operation (where n is no of process )
Whereas in banker Algorithm take m*n*n operation to determine whether is safe or not where m = no of resources and
n is no of process
option a) 1 b ) 2 c) 3 d) 1,2,3
operating-system
Selected Answer
Paging divides memory in equal size pages.It suffers from internal fragmentation (on an average (page size)/2) at very
last level of page. Paging also implement virtual memory.
It is known that as we increase the degree of multiprogramming the CPU utilization tends to increase but it is not in a
uniform manner so is there any proper term which we can relate while talking about relationship between CPU utilization and
degree of multiprogramming.
Let say I have n processes and they spend p fraction of time in IO state so then CPU utilization would be 1-p^n , so then can
we derive relationship between utilization and n from this relation ?
hence if take a system which is capable for running 1 process only (say p1) and now if this process p1 goes for I/o
operation then CPU would be idle right ? so cpu utilization here is low
but if i now bring more process and if any of the process goes for I/o then scheduler can take another process so that CPU
can be kept busy .Hence if you see if we increase number of process then CPU utilization automatically increases
span
style="background:rgba(220,220,220,0.5);background-image:url(denied:
Yes the answer is unsafe . As far I know banker algorithm given us just the state of machine as safe and unsafe . That all . And the fact that unsafe may or may not be deadlock . So chose
unsafe as answer . They have even said state of the system . They didn't sate of system at that particular instant ( note the difference ) . It might happen that after some time with a new
request we can go to safe sate . So unsafe is safest answer yet
t we would choose deadlock as answer for state of system , then any further request won't help us to get out of situation . I hope you got it :)
operating-system
Selected Answer
3. Resource utilization is low. If we try to prevent deadlock we will be doing over conservative and thus resources might
get less used.
A address can be both . physical as well as logical. it depends whether your system has that much of ram. i.e suppose u
have a cpu of 32 bit it means it can accommodate 2^32 rows of memory . if u have that much of physical memory then
no need of any virtual or paging memory and the same address may be called as physical address. while if we don't have
such amount of memory we always reflect cpu that we have that much of memory but we manage it under virtual memory
or paging , so at that time the address generated by cpu is not the actually but need some modification after which it
becomes physical address.
Consider a file system where linked allocation strategy and contigous allocation strategy is used , The number of disk block
to be accessed if the k block of file to be accessed respectively is ?
a) 1,k
b)k,1,
c)klogk , k
d) k , klogk
operating-system
Contiguous allocation support direct access so 1 access required to access kth block(starting address known)
So ans is b
Which file is a sequence of bytes organized into blocks understandable by the system’s linker?
a) object file
b) source file
c) executable file
d) text file
operating-system
Selected Answer
A. object file.
A text file is a file where contents are text characters like English alphabets where each character is encoded as
bytes/multi-bytes based on some encoding like ASCII. So, supposing ASCII, to read a text file, we can read 8 bits, and
lookup the ASCII character corresponding to that 8 bits in decimal.
A source file is a text file, where the content represent some program in some programming language.
An executable file is produced by the linker after fixing all inter module dependencies thus making the object file
executable. For example, extern references, library linking etc are done by linker and these are absent in object file. Now,
executable file contains a sequence of bytes which will be organized into different sections (ELF format in linux) and the
code section will be composing of bytes of the form opcode-operand - or proper instructions as understood by the CPU.
If a synchronization mechanism satisfies Bounded Waiting but no Progress and also it is a busy waiting solution so will there
be any starvation ?
Yes, there can be. Busy waiting doesn't help for starvation freedom. Bounded waiting + progress ensures no starvation,
but just bounded waiting alone doesn't ensure no starvation.
Bounded Waiting: "After a process made a request to enter its critical section and before it is granted the permission to
enter, there exists a bound on the number of turns that other processes are allowed to enter"
So, bounded waiting condition is not violated during a deadlock, but progress is not made and starvation freedom may not
be there for some process.
http://www.csl.mtu.edu/cs3331.ck/common/05-Sync-Basics.pdf
A computer system uses a single level directory structure . The directory occupies 2 disk block . the disk block size is 2KB.
directory entry size is 4 bytes . Then what is maximum number of File in File system ?
operating-system
P:
while (1)
wait (mutex);
print '1';
signal (mutex);
Q:
wait (mutex);
print '0';
signal (mutex);
operating-system
In a nCPU shared system , if Z is the probability that any CPU request the bus in a given cycle , the probability that only 1
CPU use teh bus is given by :
a)nZ(1-n)(n-1) b)Z(1-Z)(n-1)
c)n(1-Z)n d)(n-1)(1-Z)n
operating-system
Selected Answer
6.406 Which one of the following is allowed only in kernel mode? top gateoverflow.in/19811
D) non of these
operating-system
context switching is done in kernel mode so acc to that b and c should occur in kernel mode
main( )
{ if (fork( ) == 0)
{ /* Child */
while (1)
} }
else { /* Parent */
while (1) {
operating-system
Parent will never execute printf in this case as child executes before parent and child has a infinite loop
When frame allocation strategies are employed , how can the architecture set a minimum criteria for allocating frames to a
particular process since every process may have different nature ?
operating-system
Selected Answer
Each process might have different needs and might require different no. of page frames- hence the no. of page frames
allocated can be different. Now, the minimum no. of page frames allocated is determined by the ISA- which restricts it to
the maximum no. of pages a single instruction can access. You can find more info in the below GATE question.
http://gateoverflow.in/1018/gate2004_21
Why is the overhead in paging equal to average overhead caused by page size which is P/2, P is the size of Page ?
operating-system
As the page may contain few lines of instruction so the last page of a process may not be able to completely full the page
or it may be half filled or completely filled.
So we consider avg. case so it becomes p/2 . on an average half full. This is in context to internal fragmentation. external
fragmentation is zero and if the context changes and then according to the context page table overhead may or may not
be included.
If I say that the multi-level paging reduces the size of page table needed to implement the virtual address space of a
process, then what is the meaning of last lines in the statement :"to implement the virtual address space of a process"
Page tables are used to translate the virtual addresses seen by the application into physical addresses ( in this way page
tables are used to implement the virtual address space of a process; though the entries may not be linearly available in
the page table as demand paging does not require all pages to be present in the physical memory at the same time ).
Multilevel paging reduces the size of the page table in physical memory.
6.411 How does relocation register differ in case of load time binding and
execution time binding ? top gateoverflow.in/20818
I have gone through this link but still I am unable to get what is it actually trying to convey , when binding is done at
execution time then obviously before it we must have loaded the process so then load time binding must have been
performed as well as after it is loaded then we in the entire life time of the process it may be swapped in and out accordingly
so relocation will be done in the entire execution of the process , so will the contents of relocation register remain same or
vary since before execution load time binding will surely occur so then how do the contents of relocation register vary ?
operating-system
The concept of binding says only that when the absolute address will be available for the process. if during run time it is
available then it is run time binding or if available at load time which is necessary if absolute address is not available at
any of the above points. relocation register is set to the absolute address at that time only according to the binding you
are using. otherwise any other address in the register will be only called relocatable address only because that is not
absolute address. what should know is only that . there are only two type address. relocatable address and absolute
address. absolute address is the address at which finally after all the linking and symbol resolution program will be loaded.
so any address in the intermediate stages will only be called relocation address.
6.412 How can we compare the logical address with the contents of the limit
register ? top gateoverflow.in/20819
when the limit register contains the maximum physical address of the process so then how can we compare directly the
logical address with the limit register contents ?
operating-system
here the comparison is only to make sure that the address is less than that of the limit register any of the digital
comparator can be used for the same. And it is done so that we cannot access the address space of any other process.
If i have a 32-bit virtual memory space with a page size of 4KB then i will have 2^20 entries in page table with let 4 byte
entry,so size=4 MB. Let it divided into <10,10,12> to implement the same using multilevel paging concept. So the upper
10-bit will be used to index page directory and number of entries in page directory = number of 2nd level page tables. My
doubt is :
2> How many entries does each second level page table has ?
3> What page directory entries holds ? (is it base address of each 2ndary page tables)
4> The <10,<em>10,12> marked 10-bit used to index 2nd level page table or it is added with base of each table i.e.
entries of page directory as a displacement to get exact entry ?
1. Easy to do, with 10 bits we get 210 = 1024 entries in page directory (first level page table).
2. This is also easy- another 1024 entries here due to 10 bits being used again.
4. Base address is got from page directory and the second 10 bits are used for indexing- that is why no of entries become
1024.
6.414 what is the meaning of virtually addressed physically tagged cache ? top
gateoverflow.in/20415
I am confused over one point that do we look up into cache before address translation or simultaneously , In the below link it
is mentioned that it " caches are typically indexed with the virtual address, allowing the indexing to begin before address translation is
completed. "
http://superuser.com/questions/745008/whats-the-difference-between-physical-and-virtual-cache
Now the point of confusion is that how come only page offset is used to index a cache , and if hit occurs then what will
happen to the physical address generated by MMU , since the cache is indexed before address translation only .
6.415 why is the large hole between the stack and the heap a part of virtual
address space ? top gateoverflow.in/20962
"The large blank space between stack and the heap is a part of virtual address space but will require actual physical pages
only if the heap or stack grows .Virtual address spaces that include holes are known as sparse address spaces.Using a sparse
address space is beneficial because the holes can be filled as the stack or heap segments grow or if we wish to dynamically
link libraries during program execution ".
My confusion is that this sparse address must be existing inside the main memory ,how come in becomes a part of virtual
address space since there may be a possibility that the stack and the heap segment are not allocated contiguously inside
the main memory then how can they simultaneously grow towards each other .
On a virtual memory system, we are accessing main memory in units of "page". So, suppose a page size is 4KB, and a
process needs 100 MB of main memory, we can allocate 25K page frames and these frames may be at any point in
physical memory- they need not be contiguous, only each 4KB needs to be contiguous.
Now, the compiler generates addresses (virtual) which are continuous. During run time memory for heap and stack are
also given and each of them is also continuous to facilitate variable addressing in programs. Now, the given paragraph
talks about the space allocated to stack and heap. We can say stack starts from memory address 0x2FFF and heap from
0x1000 and stack goes down and heap grows up. During program run both the stack and heap size can change (during
each function call, stack grows as new activation record gets created and during dynamic memory creation like malloc,
heap grows). So, in the above example, I gave after sometime stack and heap spaces might collide. To avoid this we must
leave enough gap between them and also limit the maximum memory space a process can take. In linux usually 8KB is
the default stack limit for a process.
6.416 How to calculate virtual address space in below question ? top gateoverflow.in/20176
If we are given PAGE SIZE=4KB, PAGE TABLE ENTRY SIZE=4B OUTER PAGE TABLE SIZE=4KB and levels of Paging=3 ,so
how to go about calculating the virtual address space .
Now these entries will point to pages in which the inner page table2 is actually divided therefore no of entries in outer
page table implies the no of pages in which we divide the inner page table2 and it is equal to K.
Now in each page of inner page table2 , we will have same 2^10 entries ,therefore in total we will have K*K entries
coming out from inner page table 2 and these many entries are actually the no of pages in which we have divided the
innermost page table 3, and therefore no of pages in which innermost page table 3 is paged is K*K , now in each page I
shall have again K entries therefore total K*K*K entries would be coming out from innermost page table 3 and it is
actually equal to no of pages in which my process would be divided therefore no of pages in virtual address space is
K*K*K and each page is of size 4KB therefore virtual address space =2^30*2^12 Bytes =2^42 Bytes hence no of bits in
virtual address =42 bits
6.417 How many entries will be present in one page of inner page table in
below question ? top gateoverflow.in/20139
In 2 level paging say I have an inner page table which is of size 2^22 Bytes ,Now page size is of 4KB , so no we will divide this page table into pages ,so no of
pages =2^10 ,Now in outer page table entries =2^10 , now my confusion is that how many entries will be present in 1 page out of the 2^10 pages in the inner page
table,assuming that each entry is of size 4Bytes.
Selected Answer
so no of entry is 2^20
6.418 what is the relation between internal and external fragmentation ? top
gateoverflow.in/19985
whenever we have internal fragmentation then we always have external fragmentation so but not vice-versa so is internal
fragmentation a sufficient condition for external fragmentation , I guess it won't be a necessary condition since if there is no
internal fragmentation then we can't say whether we have external fragmentation or not .
Here, It is not necessary that if there is internal fragmentation, then there is definitely external fragmentation. e.g Paging
where there is no external fragmentation but there is chance to have internal fragmentation.
Also this can be conversely also true that if there is external fragmentation then it is not necessary that there will be
internal fragmentation. Like in segmentation
6.419 What is counting method for free space management ? top gateoverflow.in/19978
In counting method each entry consit of first free block n then no of contiguous block which are free after it So we have 3
free blocks here(i m assuming address start from o) Address count 1. 4 2 2. 8 0 3. 9 2
If a process on the system could issue an I/O request then the process will be placed on which of the following ?
a)Ready State
b) Running state
c) ready queue
d) I/o queue
operating-system
Selected Answer
The process could issue an I/O request and then it would be placed in an I/O queue. after complete the request it will come in
ready queue ...
ref: http://www.tutorialspoint.com/operating_system/os_process_scheduling.htm
3) disabling interrupts
I think its a reading of clock and reading of status of process can be done un user mode address translation is done in
kernel mode and masking unmasking disabling interrupts is done in kernel mode
Consider a disk with the 100 tracks numbered from 0 to 99 rotating at 3000 rpm. The number of sectors per
track is 100 and the time to move the head between two successive tracks is 0.2 millisecond.
a. Consider a set of disk requests to read data from tracks 32, 7, 45, 5 and 10. Assuming that the elevator algorithm is
used to schedule disk requests, and the head is initially at track 25 moving up (towards larger track numbers), what is
the total seek time for servicing the requests?
b. Consider an initial set of 100 arbitrary disk requests and assume that no new disk requests arrive while servicing these
requests. If the head is initially at track 0 and the elevator algorithm is used to schedule disk requests, what is the
worse case time to complete all the requests?
Following are my answers after solving
a) I get the answer [161 ∗ .2] = 32.2ms
diskseeksusingelevator(25 → 32 → 45 → 99 → 10 → 7 → 5) = 161seeks .
(0 → 1 → 2 → 2 ⋅ ⋅ ⋅ ⋅ ⋅ → 98 → 99)
Please help
Selected Answer
a) 25-----32------45------99------10------7-------5
no of movements=168
so seek time=168*0.2=33.6 ms
B) worst case:
0--------99-------1--------98--------2.............. and so on
no of movements=99+98+97+.....1
=99*100/2
=4050
If the memory is such that it is divided into various allocation unit and each allocation unit is of 32 bit and for each allocation
bit we make a bit 0 or 1 in the bit map if that allocation unit is actually a hole or is occupied by a process , so in general
space taken by bit map is 1/33 , how ?
I applied the logic that let there be x allocation units so 32*x=Total Memory size(M) , so I got x=M/32 , so if I have these
many allocation units that implies these many bits in the bit map and therefore this is the total size of bit-map , but then
why arewe including the size of allocation units as well ?
now i am using 33 bits to represent one allocation as the in which one is the bit map bit.
a) true
b) false
Becoming easy. Also depends on the language. If you write in Java- it is easy as thread is supported in language itself. In
C/C++ it used to be supported with libraries but C++11 supports thread in language itself.
6.425 Suppose a system uses shortest job first scheduling and exponential
average of the top gateoverflow.in/31913
Suppose a system uses shortest job first scheduling and exponential average of the measured length of previous CPU burst
is 0.25. If the initial value of the predicted CPU burst time is 4 unit. The predicted time for 4 th CPU burst for a process with
burst time of 4 unit, 12 unit and 8 unit respectively (units) is ______.
Selected Answer
So, we have
P2 = 0.25 * 4 + 0.75 * 4 = 4
P3 = 0.25 * 12 + 0.75 * 4 = 6
7 Databases top
7.1 B: Minimum levels of B+ tree required for 5000 keys? top gateoverflow.in/39290
What is the minimum levels of B+ tree index required for 5000 keys and order of B+ tree node (P) is 10. (Assume P is the
max pointer possible to store in B+ tree node)
My answer was 3.
i.e., 10^3 * 9 = 9000 >= 5000 .. So 3 levels req. But given answer is 4.
Selected Answer
10(H+1) - 1 = 5000
10(H+1) = 5001
H + 1= 4
H = 3
if we consider root at level 1 than level =height +1
so Number of levels = 4
other way:
so Number of level = 4
7.2 B Tree: Why is there a need for Tree-based indexing mechanisms ? top
gateoverflow.in/17570
In DBMS, why is there a need for the use of tree based indexing algorithms, when we have multilevel indexes available for
use ?
databases b-tree
Selected Answer
Multilevel indexing are static . while b and b+ tree dynamic . the advantage is , databases are very much dynamic in
nature the data in the databases change a lot . so if we do multilevel indexing according to and instance and then the data
incresed the multilevel index will fail . so we need a dynamic thing like trees . they automatically grow and shrink as the
data varies.
7.3 B Tree: In a B tree, Suppose the search Key is 9 bytes long, the disk
block size is 512 bytes... top gateoverflow.in/17567
Here, the value of p should be 24, not 23 as taken...also no reason is given for this assumption by the author (Navathe ).
Can anyone explain this ?
databases b-tree
Selected Answer
yes i think ans should be 24 , if there is any fraction then we choose the floor value (eg: 23.9 then 23 )
but i`m curious that they give the reason why 23 not 24 ("p=24 is not chosen because of the reasons given next"). please
upload that page . though to me 24 is correct .
7.4 B Tree: Suppose for insertion in a b+ tree of order 3, the values are
inserted in order 73,108,100. top gateoverflow.in/17623
Suppose for insertion in a b+ tree of order 3, the values are inserted in order 73,108,100. What will be the structure of the
resulting tree? I have watched few lectures on b+ trees and in one of the lectures by a professor from IIT KGP , inserts in a
way that the resulting tree will be-
Then i watched some more lectures by some other professors and they recommended to insert in a way that will result in-
Which of the above methods should I use. I am confused as to me both seem right
b-tree databases
The basic concept is that leaf node should contain all the values . U can assign internal node to the left children or the
right children it's your choice the tranversal will be same . so such rule is there that u always have to assign it to left or
right. its like bst deletion , u may use the biggest child of left subtree or smallest child of right subtree
7.5 B Tree: Minimum number of insertions to add a new level to this tree top
gateoverflow.in/32130
b-tree
1.add between 42 to 51 it will split the leaf node and internal node at second level e.g.43
2.then add one more key which split leaf node only and inserted at second level . e.g 41
3.now insert one more which will split at all level e.g. 40
Calculate the order of leaf (Pleaf) and non leaf (P) nodes of a B + tree based on the information given below.
A. Pleaf = 51 & p = 46
B. Pleaf = 47 & p = 52
C. Pleaf = 46 & p = 51
D. Pleaf = 52 & p = 47
Answer c)
Pleaf
Pleaf<=46.18
Pnonleaf
Pnonleaf <=51.8
7.7 B Tree: Why does a B tree contain only unique values , whereas a B+
tree can contain repeated values ? top gateoverflow.in/17566
I was reading the chapter on multilevel indexes , given in the Elmasi Navathe book. The following points have been given for
key values in b and b+ trees-
B trees-
Why are values repeated in a B+ tree, but not in a B tree ? How is thing possible ? Can someone please explain this by
giving an example.
databases b-tree
Selected Answer
this is because we always maintain a copy of internal data in leafs in b+ tree. for further study. just take a book and read
first.
Maximum number of nodes in B+ tree possible with order 4 and height 6 is ___________.
b-tree databases
Selected Answer
Ans. 5461
Bp
minimum 2
maximun 4
For Getting maximum number of node, we need to utilize maximum possible block pointer as a node in next level.
The height of a node is the number of edges on the longest path from the node to a leaf.So i have taken upto 6th level, so this way
root to leaf number of edges will be 6.
** 1365 is the maximum number of nodes up to 5th level i.e. height 5 of this type and 5461 is the maximum number of nodes up to level 6th
i.e. height 6.So both are not the correct answer.
7.8 B Tree: Can anyone please help with B+ tree multi level index structure
creation? top gateoverflow.in/127
b-tree databases
Selected Answer
http://courses.cs.washington.edu/courses/cse326/08sp/lectures/11-b-trees.pdf
What is the minimum and maximum space utilization of b+ tree and b tree?
databases b-tree
What i get which is get minmum utilization and which is get maximum utilization if used.
7.10 B Tree: Minimum keys in a B-tree of order of 3 which has height = 3? top
gateoverflow.in/9095
b-tree
Selected Answer
Here is my B+ tree :
b-tree databases
The physical location of a record determined by a formula that transforms a file key into a record location is
A. Hashed file
B. B-Tree file
C. Indexed file
D. Sequential file
For the rest you dont use any formula to determine physical location of records
1.Following key values are inserted into B+ tree where each node have 2 key values .The sum of keys present at height 1
(height is at 0) is 8,5,1,7,3,12,9,6 .
2.In a database field the search key field is 9 bytes long the block size is 512 bytes , a record pointer is 6 bytes and block
pointer is 7 bytes .The largest possible order of a non leaf node in B+ Tree implementing this file structure{order defines
max no. of keys present} is
b-tree
for 2nd :
Record Pointer=6B ,
Block Pointer=7B
Block Size=512B
Order P=32 So max. number of key present in non leaf node is 32-1= 31 (Ans)
Consider a relation R (A B C) with attribute size of A as 8 bytes. Disk block size is 512 bytes and block pointer is 8 bytes. The
best choice for degree (maximum value) for B+ tree, if B+ tree was used for creating indexing on R(A B C) is__________
b-tree
8(n-1)+8n<=512
n=32
7.15 B Tree: If the order of a B-Tree is 20 , then the number of levels needed
to store 15 , 998 keys are? top gateoverflow.in/20443
If the order of a B-Tree is 20, then the number of levels needed to store 15, 998 keys are ______.
databases b-tree
Level 0 19 keys
R(ABCDE)
And i dont find it possible to convert into bcnf with dependency preserving.
Lossless join for a database in bcnf is tht joining of the decomposed table or relation will give complete relation set.
Follow any valid method but remember Dependency Preservation is not compulsorily required. Only thing compulsory is
lossless join which you know.
Therefore,conversion to BCNF will not always be Dependency Preserving but we still go for it.
If you still want to Preserve the Dependency, we arbitrarily add the attribute whose dependency was lost.
For example, say B > D was lost in BCNF, and say we have a relation(table) now which has A and D as the attributes,
then we arbitrarily add B attribute to this relation(table). NOTE: This addition doesn't violates anything. This way
now B>D is now applicable to this relation(table) and hence FD is preserved.
Why BC ? It has two attribute . why not only A it has only one attribute and which is minimal superkey?
R[A,B,C,D,E,F]
A->BCDEF
BC->ADEF
D->E
D->B
B->F
There can be Keys(CK) apart from A but not including A since a dding any more attributes to A(CK) would only lead to
SK. .
Therefore, though A is a CK, BC can also be a CK since BC doesn't contain A which would otherwise lead to SK.
The main point here is that there can be more than 1 CK for a relation. And since BC doesn't contain A, which is a key in
itself, BC is also a CK.
A → BCD
BC → DE
B→D
D→A
Canonical Cover :
A → B
A → C
B → E
B → D
D → A
Since, F is not functionally dependent on a key, there exists some redundancy in storing data. Hence, BCNF not possible
but 3NF is.
1.A−>BC
B−>DE
D−>A
CK{AF , BF, DF}
2.R1(ABCDE)R2(AF)
3..R1(ABCDE)R2(AF)
4..R1(ABCDE)R2(AF)
Verify once!
Consider the following set of functional dependency on the scheme (A, B,C) A-->BC, B-->C, A--> B, AB-->C The canonical
cover for this set is:
Selected Answer
B->C
A->B
A->B
B->C
D is the answer.
https://www.youtube.com/watch?v=Q8j4lYeVIek
7.20 Canonical Cover: Find canonical cover for the given set of functional
dependencies. top gateoverflow.in/13929
Consider the following set of functional dependency on the scheme (A, B,C)
A→BC, B→C, A→B, AB→C
Selected Answer
this is a transitive depenency A -> B -> C. After remove redundancy, we get A->B, B->C.
7.21 Canonical Normal Form: F = {X -> YZ, Y -> XZ, Z -> X} How many no.
of minimal and canonical covers are possible? top gateoverflow.in/13745
Miinimal (canonical) cover of a set of FDs is the minimal set of FDs such that all other FDs can be derived.
cartesian-product
top
S: r1(B);w2(C);????;w3(C);w1(D);w2(E)
The possible operations on S are read, write, Increment, Multiply respectively (Increment, Multiply by constant)
1. How many actions can be placed in the given schedule S such that S become non-serializable as T1→T2
a) 5 b) 7 c) 9 d)11
2. How many actions can be placed in the given schedule S such that S become non-serializable as T2→T1
a) 5 b) 7 c) 9 d)11
databases concurrency
T1 T2
R(A)
R(A)
R(B)
R(B)
W(A)
COMMIT
R(A)
W(A)
COMMIT
in the above problem identify the concurrency in the following Schedule involving 2 Transaction T1 AND T2 (r: read and w :
write )
d) Both a and b
concurrency
So , Unrepeatable read exists here.
concurrency
User has to ensure consistency..atomicity ensured by transcation manager and durability to be ensured by recovery
manager and isolation to be ensured by concurrency control system
schedule
R(A)
R(B)
R(B)
W(A)
COMMIT
R(C)
R(B)
W(C)
W(B)
R(A)
R(C)
COMMIT
COMMIT
a)conflict serializable
b)recoverable
c)cascadeless
d)all of these
according to me a)&b)
Selected Answer
http://gateoverflow.in/37446/number-of-conflict-serializible-schedules
Find the total no. of conflict serializable schedules that can be formed by t1 and t2?
http://gateoverflow.in/37446/number-of-conflict-serializible-schedules
7.28 Conflict_serializable: Serial schedule for the given schedule top gateoverflow.in/19257
conflict_serializable
Selected Answer
data cube
data cube
7.31 Data Isolation: Final values after isolation level READ COMMITTED and
READ UNCOMMITTED top gateoverflow.in/38548
databases data-isolation
1) Repeatble uncommited
2) Repeatable Read
3)Read Committed
4)Serializable
Now in Read committed , if a transaction want to work on a data item X , it will request for shared lock it wont start
immediately , it will wait for the other transaction if it working on same data item say T2 here , As soon as T2 is done , it
will gain a control over it and start exceuting . while this is running if any other transaction want to modify it will wait for
exclusive lock ,
Now in Read Uncommitted :Doesnt required any shared lock also . It will operate on data item if any other transaction to
update is working on it or reading . It is lowest Isolation level and even forgiving one.
t2 wll get set 2000 where stipened >2000 (assuming now T1 has excutted partally and t2 starts )
T1 is having READ COMMITTED : here T1 before doing operation request for shared lock on data item ,it check for any
other transaction who is updating data or working . if yes it wait .Here T2 is working so it wait . now if t1 has a lock and
other transaction want to update it , it will wait unless t1 release
t1 may have 2100 ( if t1 starts first it will acquire lock , now here at the same time if t2 starts it will set 2000 and again t1
will excute second update and set it to 2200)
t1 may get 2300 ( if t1 starts and t2 doesnt start only . it start after t1 have completed. but it says both start at approx
sam time .so no choice of 2300 )
Or if t2 has set to 2000( t2 doesnt care about other transaction processing ) and now just t1 after acquiring lock will
have 2200 and 2400.
Q18) Now in Repeatable read : If the transaction acquires lock it will read and release only after transaction ends .So that
it get the same set of values everytime . Cant see any intermediate value of other transaction .
So suppose if T1 exceuted in Repeatable read and at the same t2 is Read commited . Incase if T1 got lock first , T2 cant
excute beacuse it always wait for other transaction who is working on same variable
then it will have stipend set 1900 ( since 1900>2000 ) and then after t1 get a chance 1900-2100-2300
Consider the schema R (A, B, C, D) and the functional dependencies A->B and C->D. if the decomposition is made as R1(A,
B) and R2 (C, D) then which of the following is TRUE
database- functional-dependency
Selected Answer
It is not lossless as there is no common attribute on which two sub relations can be joined to get original one
So ans is a
databases database-constraints
Integrity constraint is meant for "integrity" of data and mark <= 100 is part of it. By English meaning D option can be
right but in Database, is there something like "Feasible Constraint"?
Ref: http://www2.amk.fi/digma.fi/www.amk.fi/opintojaksot/0303011/1146161367915/1146161783414/1146163065754/114616316796
Let R(ABCDE) be a relational schema and F ={AB->CD, ABC->E,C->E} BE A SET OF FUNCTIONAL dependencies.
1NF
2NF
3NF
BCNF
database-normalization
Selected Answer
AB is candidate key..
AB-----> CD, AB is key so BCNF
ABC ------> E , No partial dependency but E as well as C is not prime so 2NF..
C---->E, non key -----> non key so 2NF..
so overall relation is in 2NF..
4) DNS USE THE UDP FOR SOME MESSAGES WHILE SOME FOR TCP .
Selected Answer
First step: Identify the candidate keys. Candidate keys must be able to determine all other attributes. Most of the time
they can be found by just looking at the FDs. Here,
Similarly in BC->E and ED->A, E and A are prime-attributes and hence both are not partial functional dependencies.
Hence R is in 2NF.
Now 3NF states that every non-prime attribute must be dependent on the candidate key. In the given functional
dependencies, all dependent attributes are prime-attributes and hence it is trivially in 3NF.
Now BCNF requires that for every FD α − > β, α must be a super key (candidate key or its superset). This condition is
violated by all the 3 FDs given and hence R is not in BCNF.
4. All of these
database-normalization
Selected Answer
A table is in second normal form if every attribute is determined by every candidate key , but is not determined by any pure
subset of Candidate key ?
True or false
database-normalization
given the following relation, give the highest normal form the relation can be decomposed to.
relation R(N, S, C, Z) ;
N=>SCZ,
{S,C}=>Z,
Z=>SC
A) 1nf
B) 2nf
C) 3nf
D) BCNF
database-normalization databases
now since this table has transitive dependency as N->Z and Z->SC so it can't be in 3NF
database-normalization
Yes. Actually this shouldn't be a question if one understands the meaning of "trivial". Trivial basically means "the question
has no need". One example of a trivial property is:
There is no need to answer this question as it is trivially true- because all human beings have brain.
Now a non-trivial property would be
Now, this need not be true for all human beings and hence non-trivial.
Now, coming to functional dependency we say A- > B, when the same A element always causes the same B element. i.e.,
whenever A element repeats B element also repeats. If A is a composite set (x,y) coming from attributes X and Y and B is
the attribute Y (hence B ⊂ A), we are sure than whenever the A element repeats the B element also repeats. That is, the
functional dependency cannot be violated whatever be the elements - hence TRIVIAL.
top
r={a,b,c,d,e}
a->b
bc-> e
ed -> a
database-normalization
Selected Answer
So all attributes are prime attributes and it is in 3 NF.. but not in BCNF as any of the determinants is not super keys (even
one is sufficient to disprove BCNF Condition).
r={A,B,C,D}
B->C
D->A
database-normalization
Selected Answer
it`s not in bcnf because left hand sid should be a key ( super or candidate key ) .
{ bc } { da } { bd }
A-->B
databases database-normalization
Selected Answer
Yes it's in 3NF because 3NF allows those FD's X --> Y in which either :
a) X is a super key, or
b) Y is a prime attribute //(Y is prime implies X must be prime i.e. Prime ---> Prime)
database-normalization
Selected Answer
Hi
I am currently refering To IIT KGP lectures for DBMS . ( Normalisation to be specific ) . here the sir has tried to give an
alternative definition of 3NF .
We know that a 3NF is one in which non key attribute of a relation must not be fully functionally dependent on other Non
key attribute of a relation . But apart from this definition he said an alternative definition ( all the 3 bullets ) . Can anyone
just verify my given below explanation ?
database-normalization
7.45 Database Normalization: What is the best way to check for 3nd, BCNF,
partial and transitive and partial dependencies ? top gateoverflow.in/31082
I am revising DBMS for the GATE exam... Often I find it confusing that which dependency should be considered as partial ,
which should be considered as transitive..due to which my deductions about the normal form turn out to be incorrect..i have
looked up many sources on the web but all of them are too subjective and also not consistent...
Can someone please give me a resource from where I can learn about this clearly and get my doubts cleared .
Thanks
databases database-normalization
X → Y, Y → Z, Z → W
Which one of the following decompositions is not lossless (i.e., for some instance of R, the natural join of the decomposed
relations is not equal to R?
databases database-normalization
Selected Answer
Answer is right .
in table R1 R2 and R3, only W is common and it is not superkey for any table. Hence, C is not lossless (is lossy).
AB → C ;
ABD → C ;
ABC → D ;
AC → D
which the highest possible normal form for the above relation ?
database-normalization databases
Selected Answer
Any relation is not in 2NF iff PROPER SUBSET OF CANDIDATE KEY determines NON PRIME ATTRIBUTE..
AB is key here & there is no FD which Violate 2NF definition.
it is in 2NF but not in 3NF..
Above relation is in 1 NF
database-normalization
I think we can decompose to BCNF but it will violate the dependency preserving.
Here AC is the candidate key
BCNF decomposition
R1(ABC) (AC is the candidate key ) R 2(BCD) (BC+ is the candidate key) R 3(DE) ( D+=DE D is the candidate key)
Consider the following dependencies and the BOOK table in a relational database design. Determine the normal form of the
given relation.
ISBN → Title
ISBN → Publisher
Publisher → Address
for 2nf , we shouldnt have any partial dependency ( A non key shouldnt be fully functionally dependent on a subset of Ck )
But now for 3nf , if you see we have Address which is transitively dependent on ISBN . Hence Transitive dependency exists
.
A. 2NF B. 3NF
C. 4NF D. BCNF
database-normalization
{X → W, X → Y, Y → Z, Z → PQ}
The number of functional dependencies in implied FD set are invalid are ______________.
database-normalization databases
Selected Answer
All fds are valid x->y and y->z apply transitivity x->z
So x->yq
So ans is 0
The solution is given as 3NF, although it is known that BCNF offers 0% redundancy on FDs.
databases database-normalization
Selected Answer
databases database-normalization
Its D -all the above, all three conditions can favour BCNF
If every non-key attribute is functionally dependent on the primary key then the relation will be in
I think the answer should be 2NF, but in the key it is given 3NF
database-normalization databases
Should be 2NF.
7.55 Database Normalization: What is the highest normal form of the table T
? top gateoverflow.in/27801
Consider a database table T with attributes A,B,C,D,E and a set of functional dependencies :
(a). 1NF.
(b). 2NF.
(c). 3NF.
(d). BCNF
database-normalization
Selected Answer
AE -> BC BCNF As AE is CK
AC -> D BCNF as AC is CK
If we break it into CD-> B -> 2NF B is not prime & CD-> E this is 3NF, E is prime
7.56 Database Normalization: Which of the following is correct for 3nf and
bcnf? top gateoverflow.in/17006
databases database-normalization
Selected Answer
X -> Y
either X should be a super key of Y-X must be a prime attribute (part of some candidate key).
X -> Y
So, from 3NF to BCNF we lost one condition and if a relation is in 3NF but not in BCNF then this condition must hold. i.e.,
for some non-trivial FD,
X -> Y,
Now, lets take the first condition given. It says every key is simple. So, any prime attribute is a candidate key. Thus, for
any X -> Y, we have X is not a super key, and Y-X is a candidate key. Now, if Y-X is a candidate key, Y must be a super
key and from X -> Y, X must also be a super key.
For the second case, we have only one key (implied to be candidate key). Suppose, there exist a non trivial FD
X -> Y
with X not being a super key, and Y-X being a prime attribute. Now, X must contain a prime attribute here, as
otherwise it cannot determine any prime attribute. (Since Y-X is a prime attribute, replace it with X in the corresponding
candidate key and we get another candidate key). So, the only possibility is for X and Y to be part of the same key, and
then with X -> Y, that key will be a super key and not a candidate key- to make it candidate key we have to remove Y
from it.
So, in both given cases 3NF implies BCNF. Actually only when a 3NF relation contains overlapping candidate keys, it
cannot be in BCNF. In all other cases, 3NF implies BCNF.
1) dependency preservation
2)lossless join
[ I am confused right now, can I say , if a relation is in BCNF, then is it by default lossless/dependency preserving straight
away , or is it the fact that,if I derive BCNF decomposed relations using a particular algorithm, then only I can say that the
decomposed relations is lossless/dependency preserving same goes for 3NF].
Please help!
databases database-normalization
R[A,B,C,D,E,F]
A->BCDEF
BC->ADEF
D->E
D->B
B->F
Decompose this into 3NF and BCNF and find the diff ;)
7.58 Database Normalization: What is the highest normal form the given
relation is in ? top gateoverflow.in/31158
A->BCD
BC->AD
D->B.
c)3NF
d) BCNF
database-normalization databases
Selected Answer
What is minimum levels of B+ tree index required for 5000 keys and order of B+ tree node (P) is 10. (Assume P is max
pointer possible to store in B+ tree node)
Answer Given : 4
b-tree dbms
Since the maximum pointer is 10 the number of keys that could be stored is 9
At level 3 =>9*10*10=900
since we still need to store the keys we move for next level
[Edit]
at each level, we have 10h nodes, where h is height of tree. now since all keys are accommodated at the leaf nodes, and
each leaf node can hold 9 keys,
10h × 9 ≥ 5000
h ≥ 2.7
Answer is 4
The order of an internal node in a B + tree index is the maximum number of children it can have. Suppose that a child
pointer takes 3 bytes, the search field value takes 17 bytes, and the block size is 1024 bytes. The order of the internal node
is_______.
dbms b-tree
Selected Answer
3N+17N-17<=1024
So, N = 52
SNAME CPI
Deepak 8.7
Dilip 9.7
Kaustav 8.5
Pallab 9.8
Sourav 8.7
Swapnil 8.5
(select *
FROM STUDENT S1
WHERE 3> (SELECT COUNT(*)
FROM STUDENT S2
WHERE S1.CPI<=S2.CPI))
UNION
(SELECT *
FROM STUDENT S1
WHERE S1.CPI > ALL (SELECT CPI
FROM STUDENT S2
WHERE 5 >=(SELECT COUNT(*)
FROM STUDENT S3
WHERE S2.CPI <= S3.CPI)))
How many numbers of tuples are there in the output of the above query?
Selected Answer
Ans - 2
Q1 Select students who have not more than 3 students with cpi '>=' theirs
Q2 Select students who have cpi > ALL(subQ2). Similar to Q1 subQ2 selects students who have not more than 5 students
with cpi '>=' theirs
This(http://sqlfiddle.com/#!9/95e5e/7) might help to understand the chunking. Try deleting part of query and running
dbms
Selected Answer
c is foreign key referring to A, means if ( 4,3) is deleted , 4 will not be in C(foreign key) so tuple (2,4), (3,4), (6,4) will be
deleted then , now , Primary key value 2, 3 ,6 deleted so they also will not be in C as foreign key ... so tuple (5,2) , (7,2)
are removed now in similar way 5 , 7 are deleted so (9,5) also deleted so total additional 6 tuples will be deleted
A relation R is in 3NF if every non-prime attribute of R is fully functionally dependent on every key of R
True/False
dbms database-normalization
databases dbms
in the table containing attribute salary, attributes can be eno,ename, dept,ndependent along with salary.
total number of superkeys= # superkeys when eno is key + #superkeys when ename is key
= 2^3+2^3-2^2
=8+8-4=12
Q). Assume we have a table that describes subject details taught at gateforum
Class(SubjName,FacultyName,AvgRating,remarks)
Select * from
Class
(A) I1
(B) l2
(C) l3
(D) All indices l1,l2,l3 will be equally efficient for the given query
dbms
.WHAT IS TRIPLES????
dbms
Now each A can combine with 10 BC pairs resulting inro 100*10 =1000 triples
dbms
7.68 Dbms: Number of records resulted by following SQL query top gateoverflow.in/37138
Selected Answer
EXISTS return false if its input is ∅. In the given query, input to EXISTS is COUNT(*) which returns an integer value ≥ 0,
but never NULL. So, EXISTS always returns TRUE here and we get 3 rows in output.
In exists query we need to select an attribute but in above it is count(*) so no exists is taken it is executed as normal
query which doesn't contain where condition so then it results all the 3 tuples
Query -retrieve branches for which male student's avg marks of each branch greater than avg marks of female students of
the same branch.
"retrieve branches for which male student's avg marks is greater than that of female students"
SELECT R.*
FROM R,(select distinct a from S) as S1
where R.a = S1.a;
2) SELECT R.*
FROM R,(select distinct a from S) as S1
where R.a = S1.a;
select R.*
from R,S
Write appropriate SQL DDL statements for declaring the LIBRARY relational database schema of figure below. Specify the
keys and referential triggered actions.
functional-dependencies decomposition
i know how to find whether the decomposition is lossless or lossy . but in this type of question they are actually not defining
how they decompose . they are only giving a set of functional depenencies . how to solve this type of question
databases decomposition
Selected Answer
Given a relation and a set of FDs, we might never be able to form a BCNF decomposition (in any way) which preserves all
the dependencies. For example, in this question we are given a relation R(A, B, C, D).
a. A → B and B → CD are the FDs. We can decompose R to AB and BCD and all dependencies are satisfied and B is a key
of second relation meaning decomposition is lossless.
b. A → B, B → C and C → D. We can decompose R to AB, BC and CD.
c. No dependency preserving BCNF decomposition possible. Because to preserve C → A dependency we need to have C
and A in same relation as we can't imply this dependency using any transitive dependency. Similarly to preserve
AB → C, we must have ABC as a relation. But then in this decomposed relation AB and BC becomes the candidate keys
and C → A violates BCNF condition as C is not a super key.
d. A → BCD. No decomposition required. R is already in BCNF.
top
For which of the following set of functions dependencies does the relation R(A, B, C, D) has AB, CD as closed sets?
a. A → B, B → A, C → D
b. A → B, B → C, C → D, D → A
c. A → B, B → A, C → A, D → A
d. A → B, B → A, C → D, D → C
functional-dependencies decomposition
AB, CD are closed sets imply, does AB, CD cover all the attributes of R (attribute closure)
In option (A),
AB closure is : { A B }
CD closure is : { C D }
In option (B),
AB closure is : { A B C D }
CD closure is : { A B C D }
In option (C),
AB closure is : { A B }
CD closure is : { A B C D }
In option (D),
AB closure is : { A B }
CD closure is : { C D }
answer should be D)
set of attributes are closed under functional dependencies iff closure of attribute set is set itself.
(A,B)+ = {A,B}
(C,D)+ = {C,D}
and inside closed set , if C ->D then D ->C should also need to satisfy.
Only D satisfies
{a,b,c,d}+ = {a,b,c,d}
if X -> Y then Y -> X should present (directly or indirectly which we can infer from given functional dependencies.
A -> BC
CD-> E
B->D
E->A
functional-dependencies decomposition
step2:now heck for each dependencies it should or shouldn't present in set , for this we hide that particular FD for which i
m cecking and try to take closure of LHS side of that FD if we r able to derive the RHS side of that fd without using that
FD then that particular fd is not required in the set
for example for FD A->B we hide A->B and find closure of A+=A cant find B so we cant remove A->B from set thus we
check for all the FDS
for this question we cannot remove any dependencies so minimal set is {A->BC,CD->E,B->D,E->A}
top
Given relation and the FDs applicable on it. How to check whether a given decomposition is lossless and dependency
preserving?
I know that for lossless we can easily check by seeing if the common attribute in the decomposed relation is a key in one of
the relations. Will this be applicable is the common attribute is a proper subset of a key in one relation. ?
I dont know how to check for dependency preserving.. can someone please explain the steps for it ?
databases dependency-preserving
Will this be applicable is the common attribute is a proper subset of a key in one relation. ?
I dont know how to check for dependency preserving.. can someone please explain the steps for it ?
Proper steps you can see in DBMS text. If you practice, in GATE you can see each decomposed relation and what all
dependencies they satisfy. Then, also consider transitive dependency and see if these cover all the dependencies of
original relation.
B. Only D2
C. Both D1 and D2
D. Neither D1 nor D2
Selected Answer
R={ABCDEG}
AB->C
AC->B
AD->E
B->D
BC->A
E->G
dependency-preserving
from relation ABDE we determined dependency AB -> DE ; AD -> E ; B->D ; AND trivial dependency
1,null
Null,2
1,5
A Or B or AB
er er-model
Primary Key Constraint says that the Attributes part of Primary Key must not contain NULL values. They are Not Nullable.
This table does not have any Primary Key as both have null values.
Thus, this relation does not have any Key Constraint on it, allowing duplicate records to be inserted.
er-diagram databases
Here customer to account one to many relation so for each entity one table, total 2 tables.
Next account to statements one to many relation.and here statements is weak entity.so for statements one table has been
created,where number attribute of account which is Pk,add with id of statements entity and formed candidate key of that
new table.and for for account already one table has been created previously .
Next phones and customer in many to many relation ,so we already created a table for customer previously,now one table
for relation has and one table for phones has been created. So 2 more new tables.
Here we have 3 strong entity and 1 weak entity(using number as foreign key for this table) so total 4 tables needs to be
created.
databases er-diagram
3 tables reqd two store entites E1 and E.2 relationship R1 can be stored in E2 table one more table is required for
Relationship R2 which is many to many so ans is 3
7.83 Er Diagram: Minimum number of tables for the given ER Diagram gateoverflow.in/27592
top
databases er-diagram
For Relation:-
--------------------------------------------------------------------------------------
A table is required
-----------------------------------------------------------------------------------------
A table is required
-----------------------------------------------------------------------------------------
A table is required
----------------------------------------------------------------------------------------
For M:N - 1
total table:2+1+2=5
E1(A,B)
E1'(A,C)
E2(D,E)
E2'(D,F)
when R(AD) will not combine with E1(AB) then E1(ABD) A->B AND AD WILL BE THEIR AD IS CANDIDAYTE KEY PARTIALY
DEPENDANCY PRESENT SO NOT COMBINE.
7.84 Er Diagram: Minimum Number of tables for given ER-Diagram top gateoverflow.in/25525
er-diagram databases
Selected Answer
No of table will be 3
7.85 Er Diagram: Minimum number of relation for given ER diagram top gateoverflow.in/29974
Given answer is 2, but I think that for each multivalue attribute we need a relation and one for the main entity, therefore 3
should be the answer. Please correct me if I am wrong
databases er-diagram
Selected Answer
OPTION B
P Q
P1 Q1
P2 Q1
P3 Q1
Now , Becoz P has total participation , so table P has 3 records for P1, P2, P3 respectively.. But Q can have any number of
records.. So, we can't say that table 'P' will have more records than table Q..
ER2 : Here Q side total participation but P side can have any number of entities besides those who are in relationship..
P Q
P1 Q1
P2 Q2
P3 Q2
P4 Q3
Here , many to one relationship and Q side total participation - means Q will have 3 entities & P has 4 enities , (P>Q)
Here we can notice that P is key so can't repeat & hence P>=Q (P can have more records as it is in partial participation
but never less)..
databases er-model
Selected Answer
5 Relations
Each for Strong Entity sets : E1 and E2, this contributes +2 (A, B, C) and (D, E, F)
One for M:N type Relationship Set : R, this contributes +1 (A, D)
One relation for each Multi Valued Attribute which preserves Multi Valued Attribute's data : C and F, this contributes
+2 (C, C') and (F, F') where C' and F' are the multiple values corresponding to each C and F respectively.
a total of 5 Relations. Here, in all relations the determinant is a super key. So, all are in BCNF and we cannot reduce the
number 5 ensuring BCNF.
Ref: http://web.cse.ohio-state.edu/~gurari/course/cse670/cse670Ch9.xht
7.88 Er Model: Let E1 and E2 be two entities in E-R diagram with simple
single valued attributes. R1 and R2 are two relationships between E1 and E2
where R1 is one-many and R2 is many - many. R1 and R2 donot have any
attributes of their own. How many minimum number of tables are required
to represent this situation in the relational model ? top gateoverflow.in/12789
A. 4
B. 3
C. 2
D. 1
databases er-model
Selected Answer
For R1: Since it is one : many, you need just the tables for E1 and E2. E2 will have a foreign key referencing E1. Thus
multiple tuples in E2 will reference the same tuple in E1.
For R2: Since it is a many : many, you need the tables E1 and E2 as well as a 3rd table for the mappings as it can be
shown in neither E1 nor E2. In the third table, say E3, there will be references to both E1 and E2.
http://www.databaseprimer.com/pages/table-relationships/
(b) option
3 tables required.
SO , A weak entity is an entity that cannot be uniquely identified by its attributes alone . Does it mean it has duplicates and it always a multi-set ?
databases er-model
Selected Answer
Weak entity normally can be identified in connection with strong entity also . They are connected by an identifying
relation. But it does not mean that it should always have duplicates . it need not be always multi set
7.90 Er Model: how many tables will get generated for following E-R top gateoverflow.in/33284
I believe an answer is 3.
2 tables for 2 different multivalued attributes and one for entity "Dept.".
databases er-model
I think it should be 3.
One for the entity and 2 for multivalued attributes.
7.91 Er Model: Relations produced from an E-R model will always be in gateoverflow.in/1595
top
a. 1NF
b. 2NF
c. 3NF
d. 4NF
Selected Answer
1 NF.
Generally ERD is design level task and Relational model is implementation. Whenever relational model is implemented
from erd we get rid of multivalued attribute. The procedure is outlined here: http://web.cse.ohio-
state.edu/~gurari/course/cse670/cse670Ch9.xht. Multi-valued attributes are removed as M:N binary relation by repeating
the tuples and hence relation becomes 1NF. We cannot guarantee any higher normalization.
Student
SID Sname
1 Ram
2 Shyam
3 hari
SID Phone no
1 97772373733
1 97737377373
2 97873737337
2 97686373737
sid and phoneno both form the key in the new relation.
7.92 File: Which is the best file organization when data is frequently added
or deleted from a file? IETE_ELAN top gateoverflow.in/37735
Which is the best file organization when data is frequently added or deleted from a file?
Given a data file with 100 records per pages and on index page capacity of 512 index entries, how deep should be the B++
file-system databases
consider a file of 8192 records .each records is 16 bytes long and its key field is pf size 6 bytes.the file is ordered on a key
field and the file organization is unspanned .the file is stored in a file system with block size 512 bytes . and the size of the
block pointer 10 bytes.if the primary index is built on the key field of the file and a multilevel index scheme i used to store
the primary index,the number of first level and second level blocks in the multilevel index are respectively_________
file-system
Selected Answer
No of data blocks=8192/32=256
Key field 6 B
what is the advantage of keeping the Foreign Key null as we know if we make the Foreign Key null we cant reference it again
so thats a disadvantage ......so there must be some advantage which outweighs this disadvantage so whats that advantage
suppose two table EMPLOYEE(eid,ename) and DEPARTMENT(Did,Dname) and now we make eid as a foreign key , now if
we delete any Eid from EMPLOYEE and that Eid was refrenced by foriegn key of DEPARTMENT table then to maintain
refrential integrity we hav to also delete that coressponding refrenced key from DEPARTMENT.
but if we donot want to loss data of DEPARTMENT table so instead of deleting that refrenced key of foriegn key we put null
values , by this we do not loss the data of DEPARTMENT table
7.96 Form: Identify a given derivation rule is in which Normal form top gateoverflow.in/7548
I need to understand how to determine a set of rules for sentence generation is in which normal form. (1NF, 2NF, 3NF,
BCNF) from productions given. I get the theory part well but identifing from the rules for deriving is tough. So if someone
gives more idea it will be appreciated.
Thank you.
database-normalization form
The question is very unclear. I don't know what you are referring to as "set of rules for sentence generation". But here is a
general procedure for identifying the normal form of a relation with respect to a set of functional dependency (Not
productions).
1. See if domains of all the attributes contain only atomic values. If so then the relation is in 1 NF(Atomicity).
2. Identify all the candidate keys.
3. If no proper sub set of a candidate key defines a non-prime attribute then the relation is in 2 NF(Partial
dependency).
4. If for all non-trivial FDs X->Y, X is a super key or Y is a prime attribute, then the relation is in 3 NF
5. If for all non-trivial FDs X->Y, X is a super key then the relation is in BCNF.
A1 → A2
A2 A3 → A5
A4 A5 → A1
databases functional-dependencies
3, A3A4A1,A3A4A2,A3A4A5
7.98 Functional Dependencies: F1, F2, F3 are FD sets with FDs top gateoverflow.in/34577
functional-dependencies databases
F1: P->Q,Q->R
F2:P->Q,P->R
F3:P->Q,PQ->R
1) F1 and F3
F1: P->Q,Q->R
F3:P->Q,PQ->R
so F1 is not equivalent to F3
2)F1 and F2 are aslo not equivalent because P->R is not covered
F2:P->Q,P->R
F3:P->Q,PQ->R
so option B is correct
Assume that, in the suppliers relation above, each supplier and each street within a city has a unique name, and (sname, city) forms a candidate key.
I just want to ask that will there be only one FD here like
sname,city--> sid , street
For the stmt ,"each supplier and each street within a city has a unique name, " , what would be the FD ?
functional-dependencies
yes ,
FD are
sname,city--> street
functional-dependencies
(A) A->B, B->CD (B) A->B, B->C, C->D (C) AB->C, C->AD (D) A ->BCD
databases functional-dependencies
ans C)
The following functional dependency hold for relations R (A,B,C) and S(B,D,E):FD FOR BOTH THE TABLES B -> A, A -> C
The relation R contains 200 tuples and the relation s contains 100 tuples. What is the maximum 4 number of tuples possible
in natural join R|><|S?
functional-dependencies
B is the primary key. since A is functionally dependent on B and C is f.d on A so you can derive the value of A and C from
B only .
as natural join is the equijoin on the common attribute B, it will have a maximum of 100 tuples
(As B is primary key all B values in relation R are distinct Now when we join R and S it may happen that any one of 200
value may map to all 100 values or say 100 values from 200 may map to 100 values of S These are just to cases)
why can't we say that A functionally determines B from the given relation instance when it satisfies the constraints since for
unique value of A we have unique value of B this implies that A functionally determines B , so then why can't we conclude
whether A -->B holds or not ?
databases functional-dependencies
A->B hold on this relation instance, but unless the complete relation schema is known, we cannot say for sure if A->B
holds on the entire schema. It may be the case that for some other tuples. this dependency is not satisfied. One thing that
is sure is B does not functionally determine C , whether you consider this instance or the entire schema
7.104 Functional Dependencies: does A-->B for the given table top gateoverflow.in/39183
A | B
a | 2
b | a
c | 4
NULL | 6
NULL | 6
functional-dependencies
Selected Answer
We can only be sure whether the FD does not hold and we can never be sure whether the FD can hold as the values may
be differ after insertion(not for instance). So here in the question in this particular instance, A->B can hold as the values
in A are different and if both null values are same then also the value in the corresponding B is same(6) and if the value
turned out to be different then no issue. So A->B holds. But B->A doesn't hold cause if both the null values turned out to
be different (NULL values do not compare equal in SQL) then it will fail..
I have 2 questions
1) Isn't AB->C fully functionally dependent? Because the definition of full functional dependency states that no proper subset of AB can determine
C,which is the case here.
2) Does F->E exhibit partial dependency? How do I determine if its partially dependent?
functional-dependencies
Full functional dependency: if x->y then y can not determine by any of the subset of x.
let say BCD->A then A can not determined by B or C or D individually(B->A or C->A or D->A)
2) F->E is partial dependency because AF is a candidate key and no subset of Candidate Key can determine E
http://stackoverflow.com/questions/25747802/partial-dependencydatabases
X Y Z
2 8 4
2 10 6
2 12 6
6 4 4
A)XY → Z, Z → Y
B)YZ → X, Y → Z
C)YZ → X, X → Z
D)XZ → Y, Y → X
functional-dependencies
Selected Answer
Z-> Y is not satisfied as when Z = 4, Y has values 8 as well as 4. So, (A) is False.
YZ and Y are unique and hence FDs in (B) are trivially satisfied.
X->Z is not satisfied as when X=2, Z can have 4 as well as 6. So, (C) is false.
XZ -> Y is not satisfied as when XZ = {2,6}, Y can have 10 as well as 12. So, D is false.
What is the best and the most accurate way to check if a given functional dependency is partial on the set of FDs given.
Earlier, I used to follow {part of CK -> non prime attribute} as the rule, but in several of the questions I find that this rule
alone is not sufficient. Can someone give a fully working technique to solve for such cases ?
For instance, I was reading a question on stack overflow, where in a relation r(ABCD), the following FDs hold- AB->CD, AB-
>C and A->C.
As the CK is AB,the partial FDs should be A->C . But one of thetop users has commented that the dependency Ab->C is
partial and A->C is full. ?? :/
A functional dependency X → Y is a full functional dependency if removal of any attribute A from X means that the dependency does not hold any more; that is,
for any attribute A ε X, (X – {A}) does not functionally determine Y.
A
functional
dependency
X
→
Y
is
a
partial
dependency
if
some
attribute
A
ε
X
can
be
removed
from
X
and
the
dependency
still
holds ;
Consider a relation R(A, B, C) with the following functional dependencies AB → C and AC → B. A can take 20 distinct values, B
can take 10 distinct values and C can take 100 distinct values. What is the maximum possible size (in tuples) of the self join
of R on C?
A. 4,000
B. 200
C. 4,00,000
D. 20,000
databases functional-dependencies
Selected Answer
AB → C basically means whenever A,B values repeat C must also repeat. Thus this FD restrict the number of possible
tuples in R to number of possible values of A * number of possible values of B, which is 20 * 10 = 200. Now we can either
have the sane C value for all these 200 tuples or utilize all our distinct 100 values. Since we join on C, the first case would
return 200*200=40000 tuples while the second case can only return a maximum of 2*200=400 tuples when each of the
100 C value is repeated twice.
But we haven't yet considered the FD AC → B . Due to this FD, we cannot have more than 20 tuples with one C value. So
we need minimum 10 distinct C values to get our 200 tuples for R. This would mean join on C returns true for 20 tuples
(from 200 we have 10 distinct C values, meaning 20 matching ones for each C value) and we can have a maximum of
200*20 = 4000 tuples in join.
A) 4000
due to the restrictions imposed by the functional dependencies we can vary values like:
keep B and C value as constant and loop through all values of A, this gives us 20 possible combinations for the value set
to appear in the Relation R.
next on getting exhausted with the above situation we try to change the value of B, keeping C as before but FDs stops us
from doing that and the FD set asks us to change the value for C also, therefore for possible combinations of BC we get 10
different sets for which each element of set is associated with 20 values of A. 10 different because we simultaneously
change value for C as we change for B as we need maximum possible tuples in the result when performing the Self Join
on C.
On Self join we see that for such a story the same values of C are to be combined with the same values of C only Because
the join is on C.
for instance
A B C
a1 b1 c1
a2 b1 c1
a1 b2 c2
a2 b2 c2
for first row in the Relation we have with same C 20 different combinations, similarly for the second row on same value of
C there that is c1
then same is true for the third row onwards which has 20 different combinations on same value of C i.e. c2 and so on for
such 10 possible bi and ci
Given a relation R, a set of attributes X in R is said to functionally determine another set of attributes Y, also in R, (written X
→ Y) if, and only if, each X value is associated with precisely one Y value; R is then said to satisfy the functional dependency
X → Y. Equivalently, the projection \pi_{X,Y}R is a function, i.e. Y is a function of X.[1][2] In simple words, if the values for
the X attributes are known (say they are x), then the values for the Y attributes corresponding to x can be determined by
looking them up in any tuple of R containing x. Customarily X is called the determinant set and Y the dependent set. A
functional dependency FD: X → Y is called trivial if Y is a subset of X.
I could not get the last point "A functional dependency FD: X → Y is called trivial if Y is a subset of X."
Thank you :)
databases functional-dependencies
Selected Answer
The problem here is "trivial". A native English speaker wouldn't have any doubt in this. Here is one example usage of it:
More details:
http://dictionary.reference.com/browse/trivial
Now, coming to FD, we say X → Y when Y is dependent on X. That is, whenever X value changes Y value should change accordingly. Now consider X=
{A,B,C} and Y = {A}, where Y is a subset of X. Let us consider a tuple of relation R containing X and Y (second one in the below table where x represents any
value)
A B C D
x x x x
first 456 chennai -
x x x x
Here, value of X for our tuple = {first, 456,chennai}, and value of Y = {first}. Now when "first" changes to say "second",
it will change the value in both X as well as Y, as the attribute A is the same in both X and Y. So, there is no meaning in
this FD as it is always there, and hence it becomes trivial.
For example if we consider {name, rollno} rollno. here RHS is a subset of LHS , This type of dependency are called
trivial
databases functional-dependencies
Selected Answer
We know, P(A ⋃ B ⋃ C ⋃ D) = P(A) + P(B) + P(C) + P(D) - P(A∩B) - P(B∩C) - P(C∩D) - P(D∩A) + P(A∩B∩C) + P(B∩C∩A) +
P(C∩D∩A) - P(A∩B∩C∩D)
Now by (AD) , (BD) , (ED), (FD) duplicate keys of 3 element dulpicate keys possible 6. those are (ABD),,(ADE) , (ADF),
(EDB),(EDF), (BDF)
D is not present at RHS of any FD. So, it must be present in any key.
F->E makes FD another candidate key and similarly B->F makes BD also a candidate key.
In each of the above we can add any subset of the 6 remaining elements (excluding the 2 considered for the candidate
key) and we get a superkey. No. of subsets of a 6 element set = 26 = 64. And 4 times this should be 4 × 64 = 256..
But in the above case for AD, we have considered the super key ADE and similarly for ED we have considered EDA.
Similarly for {ADF, FDA} and {ADB, BDA}. Each of these would correspond to 25 = 32 cases being repeatedly added (any
combination of remaining 5 elements). Thus 3 × 32 = 96 subtractions needed. But we have done subtraction for the cases
ADEF, ADEB, ADFB twice. So, have to add 3 × 24 = 48. Here, we again do common addition for ADEFB and this requires
subtraction of 8.
Similarly we require 2 × 32 subtractions and 16 additions for {EDF, FDE}, {EDB, BDE} and 32 subtractions for {FDB, BDF}
giving 256 - 96 + 48 - 8 - 64 +16 - 32 = 120 possible super keys.
The question is an application of Inclusion-Exclusion principle. Here, the 4 candidate keys correspond to 4 sets each with
64 elements. Now, the set of all super keys will be (W = AD, X = ED, Y = FD, Z = BD)
Now, | W ∩ X | = | ADE | = 25 = 32
Also, | W ∩ X | = | W ∩ Y | = | W ∩ X | = | X ∩ Y | = | X ∩ Z | = | Y ∩ Z |
| W ∩ X ∩ Y | = | ADEF | = 24 = 16.
Also, | W ∩ X ∩ Y | = | W ∩ X ∩ Z | = | W ∩ Y ∩ Z | = | X ∩ Y ∩ Z |
| W ∩ X ∩ Y | = | ABDEF | = 8.
and due to ABED,AEFD,AEFD,ABFD is+4*(2^4) and finally with ABEFD IS -(2^3) SO total super keys are
4* (2^6)- 6(2^5)+4*(2^4)-(2^3) is the answer and such type question never be asked in gate they always intrested
to find out the no of candidate key
A relation R with 5 attributes A1, A2, A3, A4, A5. Given the following FDs
A1 → A2
A2A3 → A5
A4A5 → A1
Find the number of candidates keys that includes attribute A3
databases functional-dependencies
Selected Answer
A4 and A3 are not coming on the RHS of any FD. So, they must be in all candidate keys.
Consider A4A5, due to A4A5 -> A1 and A1-> A2, A4A5 determines {A1 A2 A4 A5}, and hence A3A4A5 is a candidate key.
3 SUCH KEYS .
1. A1A3A4
2. A2A3A4
3. A3A4A5
for attribute set D the functional dependency D->D is considerd as trival i.e. D functionally determines itself.but how for D=
{a,b,c,d,e}
now R ={(a,b),(a,c),(b,c)(e,a)}
functional-dependencies databases
The answer given is YES. But how is the dependency C -> DE preserved in this decomposition?
databases functional-dependencies
Selected Answer
and R2 : D->E
7.114 Indexing: Find best choice for degree for B+ tree, top gateoverflow.in/31428
Consider a relation R(A B C) with attribute size of A as 8 bytes. Disk block size is 512 bytes and block pointer is 8 bytes. The
best choice for degree (maximum value) for B+ tree, if B + tree was used for creating indexing on R(A B C) is _________.
Selected Answer
(p-1) keys + p Block pointers should fit in a block ie (p-1) keys + p Block pointers size <=512
(2p-1) * 8<=512
p<=65/2
p=32
if u take p=33node size becomes 520 bytes so not possible to fit in a block hence correct ans is 32
Selected Answer
order 15
so no of pointer 15.
Level 0 = 14
Level 1 = 14*15 = 210
Level 2 = 14*15*15 = 3150
7.116 Indexing: Consider the following statement about indexes top gateoverflow.in/3003
A)Only (i)
B)Only (ii)
D)None of these
databases indexing
Ans is D
Primary is always sparse. Secondary may be dense if done on a key field and sparse if done on a non-key field.
Selected Answer
Answer : B
A clustered index determines the order in which the rows of the table will be stored on disk – and it actually stores row level data in the leaf nodes of the
index itself. A non-clustered index has no effect on which the order of the rows will be stored.
http://www.programmerinterview.com/index.php/database-sql/clustered-vs-non-clustered-index/
dbms indexing
Selected Answer
DB size 512
record size 16
7.119 Indexing: shd b only dont know y a kindly check top gateoverflow.in/12119
databases indexing
so C is the answer
A file is organized so that the odering of data record is same as or close to the odering of data block in some index. Then that index is called
a. Dense
b. Sparse
c. Clustered
d. Unclustered
Solution given:
(b)
• In sparse index number of entries depends on number of data block in previous level.
• In dense index number of entries depends on number of data record in previous level.
Link:
http://gateoverflow.in/8222/gate2015-1_24
databases indexing
1. Q is extraneous so P->R
2. R is extraneous so P->Q
3. Q -> S no change
4. R is extraneous Q -> P
5. PQ -> T No change
So answer is 4
functional-dependencies minimal-cover
Minimal cover means the smallest set of FDs which can derive all other FDs. The given FDs are
AB → C
AC → B
AD → E
B→D
BE → A
B→G
Take each FD and see if any attribute on the LHS can be avoided. There is no such reductions possible. Also, the RHS of
the FDs are unique. So, I suppose the given FDs are already a minimal cover.
The candidate keys can be found as follows. If any attribute is not on the right side of any FD, it must be in any candidate
key. So, here H must be in any candidate key.
Trial and error with AB shows it can determine, C, D, E. So, ABH must be a candidate key. Since AC → B, ACH is another
candidate key. Since BE → A, BEH is another candidate key. So, totally 3 candidate keys {ABH, ACH, BEH}.
multivalued-dependency-4nf
http://ecomputernotes.com/database-system/rdbms/fourth-normal-form
7.123 Natural Join: if natural join is done then min and max no. of tuples if
referential integrity is taken and not top gateoverflow.in/15079
R(ABC) S(BDE)
natural-join referential-integrity
For R A is key and B is key for S.B is foreign key of R refering B of S.If referential integrity is taken into consideration
max and min no of tuples will be 100 and 0 (null values)if not considered max will be 100 and min will be 0(no value of B
in R matches B of S)
7.124 Natural Join: Relation between Intersection and natural inner join on
common column top gateoverflow.in/37587
Temp ⋈ temp2 = 3*3 [cross join operations] +9[checks to match two columns]
X Y Z
1 2 3
1 2 4
3 2 1
dbms natural-join
2 3 2 3
2 4 2 4
2 1 2 1
Finally
1 2 2 3
1 2 2 4
3 2 2 3
3 2 2 4
By eliminating duplicates
databases natural-join
Selected Answer
yes last row will be present for right outer join with out including last but 2
7.127 Natural Join: Maximum and minimum size of the join of two relations
top gateoverflow.in/30009
databases natural-join
Selected Answer
As the natural join take the common attribute and combines according to them lets . take a relation R(a,b,c) an a relation
S(a,p,q) such that no value of a of r is repeated in the attribute A of relation s. so natural join will take the cross product
and will search where R.a=S.a so nothing will be selected and zero tupples will be returned, while if we does not have
common attributes then it take the cross product an as it now does not which to compare as there is no common attribute
it, stops there only providing you the cartesian product.
so minimum - zero
max- R*S.
and the min max will change according to join or the constraint
Since candidate key not define so max tupple will be 20*10 = 200.
then No. of max tupple will be depend on foriegn key attribute relation so here R1 ⟕ R2 = 20
If it is Natural Join then the answer will be 10, because for all the possible conditions the relation having least number of
tuples will dominate in final result so for R JOIN S JOIN T JOIN U, as U having the least no. of tuples hence maximum number
of possible records in the result of (R JOIN S JOIN T JOIN U)=10
Consider the database shown below ,Whose schema is also shown below .What are the referential integrity constraints that
should hold on the schema ? Write appropriate SQL DDL statements to define database
DATABASE
STUDENT
NAME Student_number Class Major
Smith 17 1 CS
Brown 8 2 CS
COURSE
Course_name Course_number Credit_hours Department
Intro to Computer
CS1310 4 CS
Science
Data Structures CS3320 4 CS
Discrete
MATH2410 3 MATH
Mathematics
Databases CS3380 3 CS
SECTIONS
Section_identifier Course_number Semester Year Instructor
85 MATH2410 Fall 07 King
92 CS1310 Fall 07 Anderson
102 CS3320 Spring 08 Knuth
112 MATH2410 Fall 08 Chang
119 CS1310 Fall 08 Anderson
135 CS3380 Fall 08 Stone
GRADE_REPORT
Student_number Section_identifier Grade
17 112 B
17 119 C
8 85 A
8 92 A
8 102 B
8 135 A
PREREQUISITE
Course_number Prerequisite_number
CS3380 CS3320
CS3380 MATH2410
CS3320 CS1310
SCHEMA
STUDENT
Name Student_number Class Major
COURSE
Course_name Course_number Credit_hours Department
PREREQUISITE
Course_number Prerequisite_number
SECTION
Section_identifier Course_number Semester year Instructor
GRADE_REPORT
Student_number Section_identifier Grade
databases referential-integrity
databases relational-algebra
Selected Answer
If takes and student are the relation table then query a. first selects the tuple and then performs the NATURAL JOIN
while in query b. NATURAL JOIN is done first and then from resultant the tuples are selected satisfying the condition of
selection
Can anyone suggest me how to learn about sql and relational algebra and calculus for gate?
as i feel this is an important topic and one 2 marks ques will be asked. I can understand easy problems and problems with
solutions.
relational-algebra
i) invalid
ii) valid
7.136 Relational Algebra: Practice test-2 Relational algebra query2 top gateoverflow.in/37736
Finds Sid of students who enrolled atleast one course with credit greater than 5
Finds Sid of students who enrolled all courses with credit greater than or equal to 5
Finds Sid of students who enrolled all courses with credit less than 5
None of these
Selected Answer
πSid(σcredit<5 (course) (Natural Join)Enrolled) it will project all Sid's who enrolled all course having Credit <=4
Finally,
{All Sid's-All Sid's who enrolled all courses having Credit<=4}==All Sid's but Credit not<=4==students who enrolled all courses with
credit greater than or equal to 5.
databases relational-algebra
foreign key: set of attribute reference to primary key or alternative key of same table or other table.
maximum : consider all A in R2 are same then matched to only value of R1(A)
Y=number of record in join = 2000
7.138 Relational Algebra: division in relational algebra confirm plz top gateoverflow.in/31089
Suppose that cardinalities of relations A and B are m and n respectively, then the maximum cardinality of the resultant
relation A ÷ B is (A divides B)
m m
databases relational-algebra
Selected Answer
Ref - https://en.wikipedia.org/wiki/Relational_algebra#Division
databases relational-algebra
Selected Answer
7.140 Relational Algebra: Practice test-2 Relational algebra query top gateoverflow.in/37731
Consider the relations R(A, B) and S(B,C). Which one of the following can evaluate differently than the others?
d) πA(R⋈S)
here I guess query is :- select attribute A where table R and S has same values of their common attribute.
πA,B (R⋈S) will project tuples with a common value of B in R(A,B) and S(A,B)
πA (R - πA,B (R⋈S)) will project A from the set difference of R and π A,B (R⋈S) which ultimately will give tuples having
uncommon value of B BUT CAN HAVE SAME VALUE FOR ATTRIBUTE A.
πA(R) - ( π A (R - πA,B (R⋈S))) will again project A from the set difference of R and π A (R - πA,B (R⋈S)) which seems to give
attributes with the common value of B , which MIGHT ALSO GIVE AN EMPTY SET as the projection.
Given two R union compatible relation R 1 (A, B) and R 2 (C, D) what is the result of the operation
R1 A= C AB = D R 2?
a) R1⋃R 2 b) R 1 ⨯ R2 c) R 1 – R2 d) R1 ∩R2
relational-algebra
relational-algebra normal
Selected Answer
7.143 Relational Algebra: Why is the maximum number of tuples in full outer
join equal to m*n ? top gateoverflow.in/16082
Why is the maximum number of tuples in full outer join equal to m*n, where m is the number of attributes in one relation
and n is the attribute count in other ?
databases relational-algebra
Selected Answer
Max no of tuple returned by Full outer join is same as no of tuples in Cartesian Product i.e. m*n.
Hi , i have just written the question and answer for the below schema . I have written this according to lectures of IIT KGP .
I would request all the experts please look to my solution and point out my mistakes (if any ) :)
page 1
Page 2 :
page 3 :
page 4 :
databases relational-calculus
SUPPLIER(S_NAME,S_ADD)
S_BY(S_NAME,S_NAME,PRICE,,DOS)
Query :- find the names of those supplier who have supplied titles corresponding to all book issused by 'VIJAY'.
using relational calculus solve the query (if possible give proper explation)
databases relational-calculus
This query is quite simple in terms that its very logical... let's see this step wise
Step 1: B_name =" Vijay" present in User relation having Card_no. as the key
Step 2: Card_no is an attribute of B_by relation having Acc_no as an attribute which will be referencing to the Book
relation
Step 3: Book relation contains Title which will give titles for a particular Acc_no....we have to find Acc_no of such other
similar Titles too...
Step 4: after we successfully found out the possible Acc_no of "Titles" issued by Vijay we join S_by and Book relations to
find and display the S_name for the projected Acc_no.
∃ b ∈ B_by( a[Card_no] = b[Card_no] ∧ /* natural join of B_by(b) and User(a) for Card_no of "Vijay"*/
∃ c ∈ Book( c[Acc_no] = b[Acc_no]) ∧ /* natural join of Book(c) and B_by(b) for Acc_no of books issued to the Card_no of "VIJAY" */
∃ d ∈ Book( c[Title] = d[Title]) ∧ /* cartesian product of Book(c) with Book(d) to find Titles same as Titles issued by "VIJAY"*/
∃ e ∈ S_by( d[Acc_no] = e[Acc_no] ∧ t[S_name] = e[S_name] ) /* natural join of S_by(e) and relation d to find S_name for the all Titles issued by Vijay*/
I hope this is the correct solution. Still, any suggestion is Welcome. I face issues with brackets. Any help regarding that.
7.146 Relational Calculus: give answer for relational algebra , tuple calculas ,
and SQL top gateoverflow.in/14757
BOOK(acc_no.,year,title)
USER(card_no.,names,address)
SUPPLIER(s_name,address)
in above given relation find out the acc_no of all the book which are present in the library
in
databases relational-calculus
Select b.acc_no
From book b
From borrowed_by c)
7.147 Relational Calculus: relation calculus 'for every' type top gateoverflow.in/2485
Question:
Answer:
Please explain the answer, i am little bit confused with how relation calculus express divide operator.
relational-calculus
As you have mentioned in the question, this is a relational calculus expression and not a relational algebra one. Relational
algebra contains only algebraic operations and proportional logic. But relational calculus can contain free and bound
variables as seen here.
7.148 Relational Calculus: Find out all the books which are either issued, or
have been supplied by a supplier. top gateoverflow.in/14758
BOOK
(acc_no, year, title)
USER
(s_name, address)
BORROWED_BY
(acc_no, card_no, date of issue)
SUPPLIED_BY
(acc_no, date of supply, price, s_name)
In the above relation, find out all the books which are either issued, or have been supplied by a supplier.
databases relational-calculus
SQL Form:
select *
from book
where book.acc_no IN (select acc_no
from borrowed_by)
OR book.acc_no IN (select acc_no
from supplied_by
where s_name LIKE "%%");
A 1 2 3 4
B Null 1 2 2
Selected Answer
Now, a tuple is output if where condition is TRUE. Here the where condition is NOT EXISTS which returns true iff we give
empty set to it. So, the condition for output here is that the inner query should not return any tuple.
Based on query, the inner query returns a tuple if the 'A' value being considered exist in any of the tuple as a 'B' value.
This happens for A values, 1 and 2 and hence NOT EXISTS is FALSE for these two as the inner query returns {(2, 1)} and
{(3, 2), (4, 2)} respectively. For the tuples (3, 2) and (4, 2), the inner query returns {} and hence they are output. So, the
output is {(3, 2), (4, 2)} and answer is 2.
I believe since the variable 't' is a free variable, so option three should also be right. Second option is also correct?
relational-calculus databases
BUT, in tuple crelation calculas says that we have to make variable t which is to be range over entire table
or
t ϵprofessor ^ condition on t
7.151 Relational Calculus: write down Domain Relational Calculas query? top
gateoverflow.in/12670
employee(person-name,street,city)
works(person-name,company-name,salary)
company(company-name,city)
manages(person-name,manager-name)
Find all employees who earn more than every employee of small bank co-operation
databases relational-calculus
{ p | (∃q)(∃r) works(p q r) and ( ( ∀y) (works(x y z )^( y = small bank co-operation)) -> (∃z) (z<r) )}
If D1,D2, .. ..Dn are domains in a relational model, then the relation is a table, which is a subset of
databases relations
Exist{}=true
Not exist{}=true
All{}=true
Not all{}=true
Any{}=false
Not any{}=false
In{}=false
Not in{}=false
sql
sql databases
Selected Answer
Use the following tables for the below queries wherever table 1 and table 2 are used:
Select *
From Table 1
a. 1
b. 2
c. 3
d. 0
sql databases
Selected Answer
This inner sub query is returning column T2B of all the tuples from the table formed by cross product T1 x T2 where
columns T1B & T2B are not equal.
Table T1 has 3 tuples, & T2 has 2 tuples so T1xT2 will have 2x3 = 6 tupes.
(aa, aa)
(aa, bb)
(bb, aa)
(bb, bb)
(cc, aa)
(cc, bb).
Out of these 6 (T1B, T2B) pairs 4 will be returned where T1B & T2B are not equal.
Since the sub query is has 4 tuples in it, the Not Exists construct will return the value false for each of the 3 tuples in T1.
Since every element in column T2B of table T2 is also present in the Column T1B of table T1, the sub query in the
"Where" clause is going to return NULL. //This is incorrect.
that is this condition will always be true for every tuple in Table 1, so all the 3 tuples of table T1 will be shown in output.
Not Exists basically checks if the sub query returns any tuples or not & since the sub query is returning NULL, Where Not
Exists NULL will always be evaluated to true.
Given answer: D
Please explain
databases sql
Selected Answer
You have to select all the 'name' from relation 'students' where name are ending in 'A' and could have anything (or nothing) at the
starting.
Statement D is "select * from students where name >='A' and name <'B';"
It is also asked before and it depends on how the charter are compared, , and they are different fr different for different
dbms software
7.157 Sql: Output of sql query with group by clause top gateoverflow.in/29986
A B C
5 2 1
10 NULL 2
15 2 3
A B C
10 NULL 2
5 2 1
databases sql
Selected Answer
The group by command just return each row for unique combination of group by attributes. And every null is calculated as
a unique group . i.e. if u have one more row then with NULL u will gate 3 rows. because the both the null will be
calculated as a different group.
and it is not always the case it will return the first row. i think it is dependent on the database software . like on mysql i
got first row, while on the online sql ide . http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
this will produce the last row,
Remember one thing when you do group by clause then it will select the first row of each group so you are getting this
answer
databases sql
Selected Answer
Students who have enrolled for a course in CS department but not in ME department.
Answer is (C)
Here in 1st query we are joining Catalog and Supplier and getting those supplier and parts which are available in Catalog
In 2nd query we are doing same as 1st query but just removing those rows where Supplier name sachin
So, resulting table has only those rows where catalog.sname is sachin
databases sql
Selected Answer
the answer is b .
because We cannot compare NULL in sql with " =" sign. In SQL's three-valued logic. neither NULL equals NULL nor NULL
not-equals NULL is true. Testing whether a value is NULL requires an expression such as IS NULL or IS NOT NULL.
databases sql
option a) is correct ..
like operator is used for comparisons ...and % is used to match 0 or more character matching
ref : http://www.csee.umbc.edu/portal/help/oracle8/server.815/a67779/operator.htm
Given answer: B
I don't know how to deal with NULL in such query operations. Please explain.
sql databases
NULL = unknown
unknown AND True = unknown
unknown AND False = False
unknown AND unknown = unknown
So according to me answer is
option B) A and C are selected.
So , outer query becomes select * from table1 where not exists null ( i mean no tuple ).
databases sql
as this a dependent query as u can see one attribute of outer query is used in the condition in inner query. the approach
to this type query is.run then like nested loop of i and j.
take the first row of table specified in outer query and app the inner condition on all the rows of table specified by inner
query.
so here on first taking aa from t1. and comparing it it aa ( first row of table t2) match so nothing will come.
so at the end u will have aa,bb,bb,aa in the inner query selection. as there is no distinct keyword , duplicates will not be
removed.
now just remove these tupples from the outer quesry. u will get one tupple i.e c cc
option a it is
Which of following query finds all the professors who have not offices in any of those buildings that professor Piper has
offices in
A.
Select distinct P.profname
from professor P
Where not exists ((
Select building
from department d
where P.deptname= D.deptname )
Union (
Select building
from department D1, professor P1
Where P1.profname=’Piper’ and P1.deptname= D1.deptname ))
B.
Select distinct P.profname Prom professor P
Where not exists
(( Select building from department d where P.deptname= D.deptname )
Intersect
(Select building from department D 1., professor P1
Where P1.profname=’Piper’ and P1.deptname= D1.deptname))
C)
D) None of these
sql
Selected Answer
Option B is correct, even though it has NOT EXISTS, it checks whether set of the building(s) belonging to the "current" professor (in the outer query) has any intersection
with the set of building(s) belonging to Prof. Piper, and if they intersect, we shouldn't take the current professor, otherwise yes. This is ensured by the NOT EXISTS clause
that is dependent on the outer query this time.
sql
Selected Answer
also, all the null values are considered as null and we cannot diffrentiate between the different null values obtained.
1- sql does not treat every null same . sql treat null as unknown and we cannot compare two Null value by a equality and
the group by command also count every null as unique group,
2- the asnwer may be yes , u can create a table with no primary key which will be useless because join operation will not
be sucessful and that table will not be in 1nf.
Ans is C.
7.166 Sql: Null values while aggrigate function in query top gateoverflow.in/33301
How aggrigate functions in query will behave in data contains NULL values.
I think answer should be D as all aggrigatre functions EXCEPT count will ignore NULL values.
databases sql
Selected Answer
avg = sum( marks) / count(marks) . = count ignore null values . so count marks gives 3
so 300
Specify the updates of Exercise 3.11 using the SQL update commands.
EXERCISE 3.11 : Suppose that each of the following Update operations is applied directly to the database state shown in
Figure 3.6. Discuss all integrity constraints violated by each operation, if any, and the different ways of enforcing these
constraints.
‘999887777’ to ‘943775543’.
_____________________________________________________________________________________
FIGURE 3.6
_____________________________________________________________________________________
EMPLOYEE
Fname Minit Lname Ssn Bdate Address Sex Salary Super_ssn Dno
1955- 638
Franklin T Wong 333445555 M 40000 888665555 5
12-08 Vose,Houston,TX
1968- 3321
Alicia J Zelaya 999887777 F 25000 987654321 4
01-19 Castle,Spring,TX
1941- 291
Jennifer S Wallace 987654321 F 43000 888665555 4
06-20 Berry,Bellaire,TX
1972- 5631
Joyce A English 453453453 F 25000 333445555 5
07-31 Rice,Houston,TX
1969- 980
Ahmad V Jabbar 987987987 M 25000 987654321 4
03-29 Dallas,Houston,TX
DEPARTMENT
DEPT_LOCATIONS
Dnumber Dlocation
1 Houston
4 Stafford
5 Bellaire
5 Sugarland
5 Houston
WORKS_ON
123456789 1 32.5
123456789 2 7.5
666884444 3 40.0
453453453 1 20.0
453453453 2 20.0
333445555 2 10.0
333445555 3 10.0
333445555 10 10.0
333445555 20 10.0
999887777 30 30.0
999887777 10 10.0
987987987 10 35.0
987987987 30 5.0
987654321 30 20.0
987654321 20 15.0
888665555 20 NULL
WORKS_ON
PROJECT
ProductX 1 Bellaire 5
ProductY 2 Sugarland 5
ProductZ 3 Houston 5
Computerization 10 Stafford 4
Reorganization 20 Houston 1
Newbenefits 30 Stafford 4
DEPENDENT
sql
D is correct. http://gateoverflow.in/47/gate2012_15
List the data types that are allowed for SQL attributes.
7.171 Sql: Can you please explain the second query top gateoverflow.in/34579
sql databases
7.172 Sql: What will COUNT(*) returns if all the collection has only null
values? top gateoverflow.in/42010
What will COUNT(*) returns if all the collection has only null values???
databases sql
In SQL,when we use the count function over an attribute of the relation and that attribute contains null values for some/all
tuples of that relation than the null values will not be considered during the calculation.But if we use count(*) over some
relation than it will consider the null values as well.So count(*) will return count of all the tuples in that relation.
In case of Count (Marks) it count number of NON NULL rows. Count(Marks) discards those rows in which Null is present. Here
Domain is Marks Column.
Same Analogy with Count(*) also. It counts every non null rows.
let there is Student table S and with attributes : Name, DOB, Subject & Marks.
Now Count(*) count no of row in which atleast one column is Non NULL otherwise discard that row. If every column of a particular
row is filled with NULL (which really not a good database) then count(*) also ignore that row. For Count(*) domain is all column so
it will check null value in every column unlike Count(Marks) see NULL values only in Marks Column.
Count(), Count(*) both excludes those rows in which every column is NULL.
count(*) will return count of all the non-null tuples in the relation & ignore the count for tuples with all null values.
How does group by works. ya it make groups of the data . and what i know it will group the data. what what i found on
running on the online tutorials is that , the group by only shows me one entry for every distinct entry, can someone plz
explain the way this group by works??
sql
The group by clause will gather all of the rows together that contain data in the specified column(s) and will allow aggregate functions to be
performed on the one or more columns.
databases sql
7.175 Sql: Which of the following SQL queries find the managers of the
bid is foreign key of Account referencing Branch, cid is the foreign key of Account referencing Customer.
Which of the following SQL queries find the managers of the Branches with total asset over 10000?
a.
SELECT b.manager
From Branch b
WHERE (SELECT SUM (balance)
FROM Account a
WHERE a.bid = b.bid) > 10000
b.
SELECT b.manager From Branch b, Account a WHERE a.bid = b.bid
GROUP BY b.bid HAVING SUM (a.balance) > 10000
databases sql
i think only A is correct but not B because manager attribute shuld be in group by clause.
7.176 Sql: What is the result of the given query? top gateoverflow.in/16813
Works_On table has details of projects the employee works on and project contains details of various projects running in
various department.
What details does the above query fetches? Please explain the steps to solve this query.
sql
Gives details of employees who either don't work on a project in department no. 5 OR works on a project with essn=ssn
(social security number?)
sql
Option c is correct
Specify the following queries in SQL on the database schema of Figure 1.2.
Figure 1.2:
A database that stores
student and course
information.Caption
a. Retrieve the names of all senior students majoring in ‘CS’ (computer science).
b. Retrieve the names of all courses taught by Professor King in 2007 and
2008.
c. For each section taught by Professor King, retrieve the course number,
semester, year, and number of students who took the section.
d. Retrieve the name and transcript of each senior student (Class = 4)
majoring in CS. A transcript includes course name, course number, credit
hours, semester, year, and grade for each course completed by the student.
Retrieve the social security number of those employees who work in both the show and toy department
intersect
B)
c) Both a and b
sql
Selected Answer
A only. B is false as for a single tuple, dname cannot be both 'shoe' as well as 'toy' and hence this query returns {}.
Consider the relation Customers (custid, name , address , city , state , introducer)
List all the customers who have introduced at least one other customer
sql
Selected Answer
1 should work.
Specify the following queries in SQL on the COMPANY relational database schema shown in figure 3.5 .Show the result of
each query if it is applied to the COMPANY database in Figure 3.6
a. Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ProductX project.
b. List the names of all employees who have a dependent with the same first name as themselves
c. Find the names of all employees who are directly supervised by "Franklin Wong".
FIGURE 3.5: Schema diagram for the COMPANY relational database schema.
FIGURE 3.6:One possible database state for the COMPANY relational database schema
A relational table Employee (ENo, EName, Dept) has 88 number of tuples. What will be the result of following SQL statement?
a. 88
b. 44
c. 0
d. 87
sql databases
Selected Answer
Where E_no not in NULL - the predicate evaluates to unknown. so no rows will be printed.
7.183 Sql: What is the result of a condition when a subquery returns zero
tuples ? top gateoverflow.in/16869
I was reading an article regarding the use of ALL, SOME, ANY operators https://oracle-base.com/articles/misc/all-any-some-
comparison-conditions-in-sql . In the ALL section, it was mentioned that " If a subquery returns zero rows, the
condition evaluates to TRUE" . In the ANY section, however, it was mentioned that " If a subquery returns zero rows,
the condition evaluates to FALSE." . Why are the results of the same subquery different for two operators ? It should
evaluate to false for both the cases. What am I missing here ?
databases sql
Selected Answer
ALL ( {} ) = TRUE
ANY ( {} ) = FALSE
This is just the semantic of ALL and ANY. ALL means the condition must be true for ALL tuples and hence this becomes
trivially TRUE for {}. ANY means there must exist at least one tuple for which the condition is TRUE and hence this
becomes trivially false for {}.
Given answer: B
I don't know how to deal with NULL in such query operations. Please explain.
sql databases
given answer is wrong...null is not arithmatic comparable ..only last tuple will be qualified.
I think here even with Ph is removed from table we still get 12 Super keys. Because Salary & One of CK must be there.
24 should be ans
Answer is 2 :)
http://sqlfiddle.com/#!9/52ba3d/1
The total number of conflicts serializable that can be formed by T1 and T2 are
transactions
According to 2-phase locking protocol, if a transaction acquires an exclusive lock on any object, another transaction cannot
obtain any kind of lock on it till the first transaction unlocks it.
Is the reverse also true, i.,e., if a transaction acquires a shared lock on any item, then any other interleaving transaction
cannot acquire any kind of lock on it..? or it cannot acquire exclusive lock, but can acquire shared lock. ?
databases transactions
Selected Answer
T1 T2
s(A)r1(A)
x(B) w2(B)
If a transaction is holding a shared lock on a data item then only shared lock is possible by any other
or
If a transaction is holding a xclusive lock on a data item then neither shared nor xclusive is possible by any
other transaction on the same item
I am unable to differentiate between a strict schedule and a cascadeless schedule...although what I have understood is that
in strict schedule, we cannot perform read/write till the other transaction commits..but isnt this condition also valid for
cascadeless schedules ?
Can someone please explain by giving an example.
databases transactions
Strict schedules
---> A schedule is strict if: " A value written by a transaction T is not read or overwritten by other transactions until T
either aborts or commits.
Cascadeless schedules
---> Even if schedule is recoverable, several transactions may need to be rolled back to recover correctly.
T1 T2 T3
R(A)
R(B)
W(B)
R(A)
W(A)
R(A)
Abort
---> Cascadeless schedule: For any transactions Ti and Tj: if Tj reads data written by Ti, then Ti commits before read
operation of Tj.
Another
Solution
CASCADING ROLLBACK
An uncommitted transaction has to be rolled back because it read an item from a transaction that failed. This is the case for Se.
This form of rollback is undesirable, since it can lead to undoing a significant amount of work. It is desirable to restrict the schedules to
those where cascading rollbacks cannot occur.
A schedule is said to avoid cascading rollback if every transaction in the schedule reads only items that were written by committed
transactions. This guarantees that read items will not be discarded.
STRICT SCHEDULE
Transactions can neither read nor write an item X until the last transaction that wrote X has committed or aborted.
The process of undoing a write (X) operation of an aborted transaction is simply to restore the before image, the old-value for X.
Though this always works correctly for strict schedules, it may not work for recoverable or cascadeless schedules.
EXAMPLE:
a. 32
b. 42
c. 51
d. 52
databases transactions
http://gateoverflow.in/31867/how-many-recoverable-schedules-are-possible-from-t1-and-t2
I am trying to explain the answer. As shown on the previous question, there are 51 recoverable schedules. All Cascadeless
schedules are also Recoverable schedules. Thus, we need to find the Cascading Recoverable schedules and we can remove
them from the Recoverable Schedules to get the possible number of cascadeless schedules.
Case 1
T1 T2
r(x)
r(y)
w(x)
r(x)
w(x)
w(y)
commit
commit
Here, we can have the two last operations from T1 either before r2(x), between r2(x) and w2(x) or after w2(x). Also keep
in mind that if you count the case where both w1(y) and commit1 come before r2(x) then it will become cascadeless
schedule. We need to keep the schedule cascading but Recoverable. Number of possible ways of placing w1(y) and
commit1 in different places is 5.
Case 2
T1 T2
r(x)
w(x)
r(x)
r(y)
w(x)
w(y) commit
commit
Here also, we can have commit2 not before r1(x) since then it will also become cascadeless schedule and also commit2
cannot come after commit1 since then it will be Irrecoverable schedule. Number of possible places to have commit2 in
different places is 4.
Consider 3 transactions T1 , T2 and T3 having 2, 3 and 4 operations respectively. Find the number of concurrent schedules?
transactions databases
Selected Answer
1. We need to maintain order of operations of an individual transaction [or it won't be a schedule] in the final interleaved
schedule.
2. Out of the 9 possible positions we choose 2 places for T1 and place it operations sequentially , then we choose 3 places
for T2 and place its operation sequentially , The remaining 4 places are used for T3 .
7.192 Transactions: how many view equivalent serial schedules are possible
top gateoverflow.in/36024
how many view equivalent serial schedules are possible for the given schedule s: w1(a) r2(a) w3(a) r4(a) w5(a) r6(a)
a) 2
b) 3
c) 6
d) 8
transactions
T1
LOCK-X (A)
LOCK-S (B)
R(A)
R(B)
W(A)
UNLOCK (A)
COMMIT
UNLOCK (B)
databases transactions
Selected Answer
yeah it is conservative cause in conservative u have to acquire all lock before transaction starts,but u acn release it at any
time.but it is not strict or rigorous.in strict u can only release shared lock before commit operation,but u cannot release
xclusive lock before commit,and in rigorous u cant relaese any lock before comit.
A. Serializable
B. Repeated Read
C. Committed Read
D. Uncommitted Read
Source:https://en.wikipedia.org/wiki/Isolation_%28database_systems%29
a. 51
b. 52
c. 55
d. 56
transactions databases
Selected Answer
Ans is (a) 51
If There are two transaction Ti and Tj with x and y operation respectively then
Irrecoverable Schedule :
Ref : https://en.wikipedia.org/wiki/Schedule_(computer_science)#Unrecoverable
So to make Irrecoverable schedule in our case here there are two possibilities
To Satisfy this condition, we need to schedule w 1(x) before r 2(x) and Commit T 2 before T1.
This way our Transaction schedule of T 1 and T 2 may look like below
T1 T2
r(X)
r(Y)
w(X)
r(X)
w(Y) w(X)
Commit
Commit
All Bold Red colored and operation can be perform any order by keeping operations of each transactions in same order as
they were given, still the schedule will be Irrecoverable.
So Number of ways to arrange there bold red colored operations to make schedule = 4C1 = 4
To satisfy this condition, there only one possible way because you have to perform w 2(X) before r1(x) and Commit T 2
after commit of T 1.
T1 T2
r(X)
w(X)
r(X)
r(Y)
w(X)
w(Y)
Commit
Commit
= 56 - 5 = 51
databases transactions
Selected Answer
Consider A-> T1 is reading it and then T3 is writing to it. While reading, R-ts(A) is set to max( R-ts(A), TS (1)). So, if R-
ts(A) is So, T3 > T1
Consider B-> T2 is reading it and then T3 is again reading it and T2 is then writing to it. So, T2 > T3 (Reading only
updates R-ts and and checks only W-ts)
http://courses.cs.vt.edu/~cs5204/fall00/distributedSys/bto.html
transactions
Selected Answer
Unreapeatable problem.means we get different values in different reads.For eg in S1 say T2 read intially x=5 then T1
updated x=1 so now T2 will read x=1 here T2 has read two different values during consecutive reads This shouldnt have
been allowed as T1 has nit committed..do ans is a ie S1
databases transactions
Selected Answer
Deposit (10)
A = A+10;
View Balance:
print A
Now, suppose initial balance A is 100 someone deposits 20 by calling Deposit(10) two times and then called View Balance
to view the updated balance. If they are called sequentially no problem here. But suppose they are called concurrently:
Similarly happens in next call to Deposit. But if the read of A in second happens before the final store to A in first call, the
first call of Deposit has no effect. The update done by first Deposit is lost (when the second Deposit stores the value it will
be 110 and not 120 as it has read 100 instead of 110)- and this is called Lost update problem.
WW problem
7.198 Transactions: How is this schedule not allowed in Strict 2PL, but
allowed in 2PL ? top gateoverflow.in/18915
[ ]
T1 T2
R(A)
W(A)
R(A)
W(A)
R(B)
W(B)
Commit
Abort
How is this schedule allowed in 2PL ? In 2PL , there must be a growing phase in , which is not present in T2 ..?
This example is given in the book by Raghu Ramkrishnan on page 529 and 552 (for reference)
databases transactions
T1 T2
Lock(A)
R(A)
W(A)
Unlock(A) // Assuming that T1
does not need any more locks or
those locks before unlocking it
Lock(A)
Lock(B)
R(A)
W(A)
R(B)
W(B)
Unlock (A)
Unlock(B)
Commit
Abort
T1
T2
This is how it is possible to implement 2 Phase locking. I think you can see growing & shrinking phase. Issue is that 2
Phase locking in itself does not maintain good property like Deadlock or say recoverable schedule, just like Semaphore are
used for synchronizing but we need to use them wisely, or they can cause deadlocks ! It is possible to follow 2 Phase
locking , even when resulting schedule is not recoverable.
A. Serializable
B. Repeated Read
C. Committed Read
D. Uncommitted Read
isro2013 transactions
Answer is Serializable ---Highest isolation level and Lowest one is Read Uncommitted
We will see what violation can happen with each isolation level : violation are Dirty read , Non repeatable read, Phantom .
The first one is Read Uncommitted : So here Dirty read , Non repeatable read, Phantom . all are possible
The second One is Read Committed : It reads the data after the another transaction is committed But it doesnt guarantee
That the next time it will read the same data value then it will get same old value .. Dirty read--Not possible , Non
repeatable read--Possible , Phantom-- Possible .
Third one : Repeated Read : : It reads the data after the another transaction is committed But it guarantee That the next
time it will read the same data value then it will get same old value .. Dirty read--Not possible , Non repeatable read--not
possible, Phantom-- Possible .
Fourth One is : Serializable : It is highest and toughest isolation level . It will give always Consistent result . It would have
schedules equivalent to Serial Schedules .Dirty read--Not possible , Non repeatable read--Possible , Phantom-- Not
Possible .
The maximum number of records that can be indexed for a B+ tree of 4 levels with order 10 and root at level 1 are
_________.
Selected Answer
order 10 means here block pointer so means every node has 9 Record pointer but take care that record pointer is present
only at leaf level ,not in in internal nodes of tree becoz its B+ TREE..
Consider the LIBRARY relational database schema shown in the figure below .Choose the appropriate action (reject, cascade,
set to NULL, set to default) for each referential integrity constraint, both for the deletion of a referenced tuple and for the
update of primary key attribute value in a referenced tuple.Justify your choices
answer is non serilizable.i just can write a table to show dependency,but this question's answer is correct
view_serializable databases
Selected Answer
https://www.youtube.com/watch?v=0uhCfZ-ePy8
S: T1(A)R2(B)W2(B)R2(A)W2(B)W1(A)R3(B)W3(B)
yes of course it is a VS
dbms view_serializable
It is not strict recoverable schedule and doesn't statisfy the conflict serializable, but we have blind write so checking for
view serializable and it statisfies view serializable.
With the help of blind write how we know that given schedule is view serializable
view_serializable
It is not necessary for a schedule to have blind write in order to be view serializable , only if u find a schedule which is not
conflict serializable u go for checking whether it is view serializable or not ,Now if blind writes are there then there may be
a possibility that the schedule is view-serializable and if blind writes are not present then the schedule is not even view
serializable , So now if the schedule is view-serializable , if You are able to get a sequence of transactions so that they
follow all the constraints which are necessary for a schedule to be view-serializable then u r done .
You need to make sure that the transaction which makes last update should also make last update in the view-equivalent
schedule and the transaction which reads the initial data item should also read the initial data item in the view-equivalent
schedule , since it is a NPC problem so you can't do it in polynomial time but if u r given 2 to 3 transactions u can easily
verify if u can design a view-equivalent schedule or not .
view_serializable
The given schedule is not conflict serializable so now check for blind writes , if u get blind writes then the schedule may or
may not be view serializable but if there are no blind writes then the schedule cannot be view serializable .And here we
don't have any blind writes so the schedule is not view -equivalent to any serial schedule .
There is a cycle formation between T3 to T4 due to W(B) and T4 to T3 due to R4(A) and W3(A) . Hence the schedule is
non serializable . We cannot say anything about about view serializibility here becoz for that we need atleast 2 schedules.
Therefore ans should be D.
For 19.2.1
For 19.2.2
I know one method of checking view serializability in which we consider all the possible permutation of occurrences of
transactions and check for three conditions:
(1) Initial reads (2) W-R conflict (3) Final writes
view_serializable databases
t1 t2
w(x)
r(x)
w(x)
commit
commit
Selected Answer
if given schedule is equivalent to anyone of the serial schedule then given schedule is View Serial. for this we are checking
3 conditions as :
2. Final Write : Final write should be done by T1. No write operation is T2 so it is allowed to execute eother T1----->T2 or
T2 -----> T1 bit T2 ----->T1 not possible as condition of Initial Read. now only option left is T1 ----->T1
3. Write Read sequence : if T1 --->T2 then T2 reads value of x after second update done by T1. so T1 -----> T2 also not
possible.
schedule S:R1(X),W2(X),W1(X)
view_serializable
Selected Answer
view_serializable
[]
T1 T2
R(A)
W(A)
R(A)
W(A)
R(B)
W(B)
R(B)
W(B)
We will proceed to create the polygraph for the above schedule..my doubt is that do we need to create the polygraph for
both the items A, B or just a single polygraph for the entire schedule. If we create separate polygraphs, for A we will get t1-
>t2, and for B we will get t1->t2.. Same graph will be obtained if we draw a single polygraph
Selected Answer
you should draw a single graph.else you will not succeed to figure out the cycle,alltime,which is an important thing for
deciding conflict or non conflict serialization
Q). Consider the table employee(empid, name, department, salary) and the two queries Q1,Q2 below .Assuming that department 5 has
more than one employee, and we want to find the employees who get higher salary than anyone in the department 5 , which
one of the statements is TRUE for any arbitrary employee table?
Q1): SELECT e.empid FROM employee e WHERE NOT EXISTS (SELECT * FROM employee WHERE s.department = "5" and
s.salary ≥ e.salary)
Q2): SELECT e.empid FROM employee e WHERE e.salary > ANY (SELECT distinct salary FROM employee WHERE
s.department ="5")
a. Generalization is the result of taking the union of two or more disjoint entity sets to produce a higher level entity set.
b. Specialization is an abstraction in which relationship sets are treated as higher-level entity sets.
c. Canonical covers are used to decompose a relation into 3NF, which is a small relaxation of the BCNF condition.
d. The concurrency control management component of the database is responsible for handling the concurrency control
policies.
virtualgate databases
The inner query in Q1 will select the employee having max salary from all other employees in all departments(this will return
the max salaried employee in the entire company which belongs to dept 5), and outer query will select all employees not in
the inner query. Is this interpretation right?
In Q2, inner query gives a list of all salaries of employees in dept 5, and outer query selects those employees from entire
company who have salary greater than anyone in dept 5.
Hello,
Select * from table1 where (cond) ANY/IN/ALL/EXISTS/etc (sub query result empty)
If this is the question given and asked how many rows does it return then the answer would be ??
I know when we use > ALL for the above scenario it gives all the rows of table1.
Yes it is possible .
this is not possible . in that you have to place GROUP BY NAME . peace
Selected Answer
X initially read data from database so X should execute before Y & Z bcoz Y & Z both update x value..
Final write of y done by transaction X. That means X should execute after Y & Z because both write y.
7.220 Is there any condition in which we can say that dense index is sparse
index?? top gateoverflow.in/12442
Is there any condition in which we can say that dense index is sparse index?
databases
Selected Answer
If each block contain only one record , then dense index will act like sparse index .
2 and NULL ..
Distict keyword treat all null vaues as same and select a common tuple for all NULL value..
2 Tuples
As per intuition, natural join filters the rows based on the criteria. So, it does not really matter in what sequence we do
this filtering because the invalid rows are going to be discarded sooner or later.
Two interleaving and two Serial Total four Conflict Serialisable Schedule Possible..
If R and S are two relation in BCNF the natural join of R and S is also
in BCNF.
databases
False. It is logical, while converting a 3NF relation to BCNF we decompose a 3NF relation into two BCNF relation, and in
some cases we get lossless decomposition , so joining 2 BCNF relation is not a BCNF relation
3 Tables.
1) E2
2) E3
Has table represents phone only i.e. which customer is having which phone.
Schedule is W 1(A),R2(A),W3(C),W1(B),W2(C),R3(B),R2(B)
i think it`s allowed under TWR (so, it will allow under MVTS )
the answer is A
To me I think now
Because of 1 to 1 mapping it can merges into a single table . No need for FK .If we do then we have a problem to select
primary key . So , E1 and E2 kept separate , and we will foreign key at E2 because 70% participation at E2 ,because of
In case of E2 if i choose foreign key at E1 then participation at E1 30% , so the Null values will be increased .
Option B is correct .
• Is it conflict serializable, view serializable, serializable, recoverable, avoids cascading aborts, strict?
Commit information is not given so its not possible to conclude anything about Recoverability
Recoverable says that the which transaction is write 1st must be commit 1st , and there is no commit statement so its
recoverable but its not cascade less its cascading because T2 is reading a R(x) which is written by T1 and T1 did not
commit after writting .
but the same schedule is view serializable because due to presence of BLIND WRITE IN transaction T2 ,T3.!! :)
7.231 y not a? many time confuse in this kind of questions top gateoverflow.in/12117
Manager’s salary details are hidden from the employee. This is called as
(A) Conceptual level data hiding (B) Physical level data hiding (C) External level data hiding (D) Local level data hiding
databases
answer will be conceptual level.physical implementation is same.It is the logical structure of the entire database as seen
by DBA. It Supports each external view: any data available to a user must be contained in, or derivable from the
conceptual level.
(i) Is used for eliminating duplicate rows automatically from the output.
project operation corresponds to select operation in sql except the fact that in sql select doesnt remove duplicates cause it
is expensive but project does remove duplicate so Option A is true..
It also filter out columns ..example ->consider a realtion with attribute A ,B,C ..project can be used to o/p the column
Unary operator are those that takes only one realtion as i/p ..project,select and rename are unary operator so option C is
true
Degree of a relation means no of attributes but project can be used to o/p less number of columns as well .. so D is false
Consider a Table T with a key field K. A B tree of order P where P denotes the maximum number of record pointers in a B
tree. Assume K is 12 bytes long, disk block size is 1024 Bytes, record pointer is 6 bytes and block pointer size is 2 bytes
long. In order for each B tree node to fit in a single disk block the maximum value of P. Is answer correct?
Selected Answer
(10)
for 10,000 records we require 100 blocks as question said only one block should present at a time in a
memory with access time of 10 MS than to access the block from memory is should require atleast 980
MSEC because our word is present in 98th block so first block access is (10+reamining access of 97 blocks
will be 970 MSEC )but those 97 blocks should be replaced from secondary storage to memory and that time
should be added to 980 MSEC so i think answer should be 980 MSEC.
(11)
as primary index is built and index block contain 100 enteries ,there are 100 blocks of data file present and
each FIRST RECORD(ANCHOR RECORD) should BE MADE AS INDEX ENTRY so NO OF ANCHOR RECORDS
ARE 100 (i,e 100 BLOCKS) therefore 100 index entry in primary index
so to search index block need 10 MSEC AND AFTER THAT ACCCESING OF DATA FILE FURTHER REQUIRES
ONE BLOCK ACEESS
7.235 Consider table R(A,B,C,D,E) with FDs as A->B, BC->E and ED-> A. The
table is in which normal form? Justify your answer. top gateoverflow.in/2896
In a B+ tree index file if there are K search keys and each leaf node contains n records then number of records to be
accessed in the worst case is
a)log2nk
b) lognk
c)logceil(k)n
d)logceil(n/2)k
if we use 3 key ,4 pointer nodes. how many different B tree are there when the data file has 6 records.
First, the six data records can be divided among the B-tree leaves in the following ways: 2-2-2 or 3-3. There are no other ways to divide size records, with
2 or 3 for each leaf.
In each of these two cases, there can be only one other node, the root, and it must point to each of the two or three
leaves. Again, there are no other ways to structure 2 or 3 leaves, with each interior node having 2 or 3 children. Our
conclusion is that there are only two different B-trees for 6 data records.
http://infolab.stanford.edu/~ullman/dbsisols/sol4.html#sol43
with respect to the B+ TREE index method .select the true statements?
C. true.
Take a B+ tree with 3 keys {1,2,3} and 2 is root.. now update root value to 10.. tree will be unbalanced..
there is no question on 5nf still..... but no one knows when a question on it will pop up.. so be ready
4NF had been asked in past. Till now I haven't seen a question on 5NF.
Let order be P_leaf. Then, P_leaf ( K+pr ) + P <= Block Size. This is the formula.
Where K is size of search key, pr is record ptr size ,P is block ptr or tree ptr size.
databases
Suppose a phone book contain 500 pages and each page can contain
upto 500 records. Suppose we want to search for a particular name in a
phone book. Give a worst case bound on number of pages that must be
looked to perform a search using an index for the name of the first entry
of each page??
databases
2 (the index has 500 pages, so the entire index ts in one page; so
1 access to the index and 1 to the data).
max no of rows=min(n1,n2)
min =0
ans a
c is correct
7.244 why is the below statement regrading weak entity correct ? top gateoverflow.in/14597
Weak entity set avoids the data duplication and consequent possible inconsistencies caused by duplicating the key of the strong entity..
databases
(a) weak entity is totally participated in strong entity i.e. each element of weak entity is must have some element in
strong entity
but weak entity have not its own primary key it is identified by primary key of strong entity
(b) suppose if we duplicate the weak entity set then we have to duplicate the primary key as we know that primary key
must contain unique value which is not possible so there will be contradiction here
Selected Answer
I think C) is correct
(B) option with two tables table u can satisfy this... Dno ------>Dname Dno------>phone office as see obove
decomposition is in BCNF..
7.246 How to draw E-R model for the below scenario ? top gateoverflow.in/14378
Each employee is assigned to a project work at only one location for that project, but can be at a different location for a different
project. At a given location, an employee works on only one project. At a particular location, there can be many employees assigned
to a given project.
databases
employee works at on project . so always we make noun and object as entity so here project and employee can be entity
where as verb is the relationship . which is works at . so i think this can be the er diagram .
Selected Answer
no of serial schedules=3!=6
7.248 How should the relation be decomposed so that it is in BCNF ? top gateoverflow.in/35910
corresponding to it and if I do ABC , then I have C-->A but C is not a superkey in ABC , so how should the decomposition be done ?
databases
Here , in this example , BCNF & Dependency preservation is not simultaneously possible .
This type of problem occurs when we have AB -> C , C -> A type of Dependency.
R1 (A C D) , R2 (B C) - If we decompose like this we are having BCNF , but AB -> C dependency is lost.
R(ABCD)
AB-->C C-AD
X-->Y
Decompose into
BCNF not satisfied ,dp decomposition satisfied. If you want to satisfy BCNF You will definitely loose dp decomposition.
The database can be configured to do ordered indexing on Ap or hashing on Ap. Which of the following statements is TRUE?
(A) Ordered indexing will always outperform hashing for both queries
(B) Hashing will always outperform ordered indexing for both queries
(C) Hashing will outperform ordered indexing on Q1, but not on Q2
(D) Hashing will outperform ordered indexing on Q2, but not on Q1.
databases
Ap = C -Hashing would mean constant time to get the tuple from the index.
B and D should be the answer. If a prime attribute comes on the right side of a FD, then the left side will also become a
prime attribute due to this dependency. So, B and D options are the same.
A is avoided in 3NF.
C is the desired FD and is there in BCNF also.
Consider an Entity-Relationship (ER) model in which entity sets E1 and E2 are connected by an m : n relationship R12, E1 and E3 are
connected by a 1 : n (1 on the side of E1 and n on the side of E3) relationship R13.
E1 has two single-valued attributes a11 and a12 of which a11 is the key attribute. E2 has two single-valued attributes a21 and a22 is the key
attribute. E3 has two single-valued attributes a31 and a32 of which a31 is the key attribute. The relationships do not have any attributes.
If a relational model is derived from the above ER model, then the minimum number of relations that would be generated if all the relations are
in 3NF is ___________.
databases
Three tables would be required for three entities E1 ,E2,E3 now R12 is many to many relationship so new table will be
created with(a11,a21) as key.R13 is one to many relationship so need of extra table
E1(a11,a12)
E2(a21,a22)
R(a11,a21)
Q3). Consider the Relation R(A, B, C, D, E) and F. D ′ s are AB → CD, CD → E, E → AB then the total number of super key are:-
(A). 10
(B). 12
(C). 18
(D). None
18 Superkeys.
{AB} + is key → superkey {ABC, ABD, ABE, ABCD, ABCE, ABDE, ABCDE}
{E} ∗ is key → superkey {EA, EB, EC, , ED, EAC, EAD, EBC, EBD, ECD, EACD, EBCD}
databases
Selected Answer
Take AB- pair it with any subset of {C, D, E} - 8 super keys. (4 including E)
Take CD- same as above- 8 super keys. But ABCD and ABCDE are counted twice. So, 6 more. (3 of them including E)
Take E- with {A, B, C, D} we get 16 super keys. But 4+3 = 7 are already counted. So, 9 more.
7.253 If there are mapping constraints in the E-R diagram , can we reduce
the size of the table ? top gateoverflow.in/14344
I am not getting that how many attributes must be there in the Borrowed by table which actually represents a table since we
have the constraint that one user can borrow only one book .
databases
in above given e-r diagram one is to one relation is given since it hav both two arrows facing towards entity it means that
one user can take only one user and also conversly says that one book is borrowed by one user so in both entity book and
user one primary key that must be present in borrowed table i.e. accesetion no and card no. and one attribute is DOI of
borrowed relation so minimum attribute will be 3
7.254 what do we mean by saying that A candidate key is a super key for
which no proper subset is also a super key ? top gateoverflow.in/14305
Since candidate key is a minimal key and it is a proper subset of a super-key , then how is it that for a candidate key ,its
proper subset is not a super key ?
Selected Answer
A candidate key is the minimal superkey. That means if we try to remove some attributes from the candidate key
(minimal super key) we will no more get a superkey as it was the minimal. Hence, any proper subset of the candidate key
is not a superkey.
Sir ,I am not able to figure what these ∏ R − S(r) and ∏ R − S, S(r) expressions returns.Can u pls explain with an example?
Please do help...Thanks in advanvce..
This is the division operator. When we say (r / s)- first of all, the attribute set of r must be a super set of that of s. Now,
(r/s) will select all tuples from r, which doesn't have any missing corresponding tuple in s- i.e., it works like a quotient.
Example:
Let r = { < 10, Rahul, M, CS > , < 10, Rahul, M, Che > , < 11, Ben, M, CS > }, s = { < CS > , < Che > }
( ∏R−S ( ∏R−S(r) × (s) ) − ∏R−S ,S(r) ) - Take the cross product of r (after removing attributes of s) and s and subtract all
tuples in r. So, this returns the tuples in r × s for which r doesn't have a tuple.
∏R−S { < Rahul, M, 10, CS > , < Rahul, M, 10, Che > , < Ben, M, 11, CS > , < Ben, M, 11, Che > } − { < 10, Rahul, M, CS > , < 10, Rahul, M, Che > , < 11
= ∏R−S { < Ben, M, 11, Che > }
= { < 11, Ben, M > }
( ( ) )
So, ∏R−S (r) − ∏R−S ∏R−S (r) × (s) − ∏R−S ,S (r) = { < 10, Rahul, M > , < 11, Ben, M > } − { < 11, Ben, M > } = { < 10, Rahul, M > }
That is using division operator we are selecting the students who have selected ALL the courses.
R(ABCD) {AB----->C,C-------->D,D-------->A}
databases
For R(ABCDE) :
Decomposition into 3NF = [{ABC}, {BD}, {DEC}, {ABE} ]
Decomposition into BCNF = [{ABC}, {BD}, {ABE}] or [{ABE}, {BD}, {DEC}]
For R(ABCD) :
Decomposition into 3NF = [{ABC}, {CD}, {AD} ]
Decomposition into BCNF = [{ABC}, {CD}]
Q18). Consider the table R , with attributes A, B, C, D and E. What is the largest number of candidate keys at the same time?
a. 1
b. 5
c. 10
d. 31
As we know number of candidate keys with n number of attributes is 2n − 1.Then how to solve this question?
databases
10 is incorrect answer.
How many view equal serial schedules possible for the following
schedule?
S : w1(A) r2(A) w3(A) r4(A) w5(A) r6(A) w7(A) r8(A
databases
Selected Answer
last write on A is W7(A) . and it should be followed by R8(A). this sequence should be always appear at the end in any
euivalence schedule.
7.259 what is the relationship between weak and strong entity ? top gateoverflow.in/14043
1:1
1:M
M:1
M:N
A weak entity it self doesn't have a primary key and depends on the strong entity to form a primary key. For example
EMPLOYEE can be a strong entity and DEPENDENT a weak entity. An employee can have multiple dependents and a
dependent can have multiple concerned employees. So, the relationship is M:N, with the participation of weak entity being
TOTAL- there is no dependent without a concerned employee.
databases
Selected Answer
It will print all the tuples of the table. So, answer will be 3.
SELECT * FROM T WHERE EXISTS ( SELECT B FROM T WHERE B = 2) , that would result in 0 tuples.
http://sqlblog.com/blogs/andrew_kelly/archive/2007/12/15/exists-vs-count-the-battle-never-ends.aspx
I just read the difference between a table and a relation which actually states that a relation is a n-ary tupleof records which
cannot be duplicate while in a table we may have duplicate records so I am a bit confused that we actually represent a
relation using table only so then is it that a table without duplicate records is called a relation , plz clarify this that how do we
actually represent this relational schema in a database ?
A table is just a representation of a relation. You can say relation is a theoretical model and table is its practical
representation. A table can have duplicate entries unless it has a unique key constraint on some attribute while a relation
being a set cannot have duplicates.
Ref: http://www.quora.com/Is-there-a-difference-between-a-relation-and-a-table
Consider a relation R with 2n attributes. Assume any 2n/2 of the attributes constitutes key. Total number of super keys
possible are:
n− 1
a. 2n C2 n − 1 × (2)2
n− 1
b. 2n C2 n − 1 + (2)2
n− 1
c. 2n C2 n − 1 − (2)2
n− 1
d. 2n C2 n − 1 ÷ (2)2
databases made-easy
There are 2^n attributes in a relation R,... Any combination (2^n)/2 (i.e 2^(n-1)) keys forms a candidate key then
2n
2n − 1
number of candidate keys---> ( )
2n
2 (n − 1 ) n− 1
therefore total number of superkeys ( ) ∗ 22
2 votes -- Abhishekcs10 ( 1001 points)
databases
Selected Answer
E No Ename DeptNo
E001 A 10
E002 B 10
E003 B 5
E004 C 10
E005 D 20
E001 A 20
E003 B 10
it will give
ENo
E001
E002
E004
E003
Union
ENo
E005
E002
ENo
E005
E002
E001
E004
E003
databases
else
In above statements R1.A is outer loop variable and R.B is inner loop variable.
For R1.A=1 ∃ R.B such that R1.A = R.B => not selected
For R1.A =2 ∃ R.B such that R1.A= R.B => not selected
7.264 Explain system recovery procedure with check point record. top gateoverflow.in/4047
http://codex.cs.yale.edu/avi/db-book/db6/practice-exer-dir/16s.pdf
7.265 is canonical cover and minimal cover is same thing? top gateoverflow.in/6346
7.266 How to merge weak entities with other entities in order to get
minimum number of tables? top gateoverflow.in/6618
How to merge weak entities with other entities.I'm asking it in reference to this question-->>
http://gateoverflow.in/390/gate2008_82-83?show=390#q390
Actually i'm interseted in knowing the behaviour of weak entity with other entities in order to merge them to get the
minimized number of tables. Is it equivalent to merging of two normal entites..?If not, then what is the difference.How to
proceed in case of weak entites.?
Plz answer..
Can someone write one example of a schedule which is conflict serializable but is not allowed by 2pl protocol. I have read
that 2pl-> css, but css-> 2pl is not necessary?
T1 T2 T3
W(A)
W(A)
W(A)
W(B)
W(B)
W(B)
Where should i practice questions of DBMS other than GATE previous year papers?
Selected Answer
If you have read the concepts properly from standard resources then no need of anything other than previous year
questions. (Otherwise any number of practice won't be enough).
I am getting Lossless by applying algorithm but is this decomposition dependency preserving...?Plz explain
Selected Answer
Between R12(ABC) and R3(CD) common attribute is C and C is key in R3. Hence the decomposition is lossless.
We can straightaway see that these dependencies are preserved in the decomposed relations.
For these lets check the additional FD s that can be implied from the above three FDS.
we get
D+={DA}
D+ in G ={DCBA}
Selected Answer
Yes, it was in syllabus of 2016 and most probably 2017 too - should come in 2-3 months. Actually this is an easy portion
(nothing more to study) if you have covered Mathematical logic and set theory.
A B+ tree of order 'd' is a tree in which each internal node has between 'd' and '2d' keys values. The root has between 1 and '2d' values. What is the maximum
number of internal nodes in a B+ tree of order 4 with 52 leaves.
A. 8 B.13
C.17 D.19
C 17..
databases
0 votes -- P2 ( 17 points)
S1 is true and S3 is False as secondary index is dense...Please explain whether S2 is true or false
Dense Index are faster in general as they point to contiguous memory location. Each Dense Index points to a certain
Record therefore there only single access is required.
In Sparse Index the Index points to the Record having the highest Key. All other records are traversed by pointer from the
record having highest value. In short First the Record with highest Value is selected (1 Disk Access). This record has
further records attached to it by linked List.This List is iterated to get the desired block.(Multiple Disk Access)
Selected Answer
Ans: A
http://en.wikipedia.org/wiki/Thomas_write_rule
To check whether a given schedule is serializable or not , do we need to check only for conflict serializability or both conflict
serializability and view serializability ..?
If you are able to proof that it is conflict serializable, through precedence graph or any other algo
Then you have to test for view serializability (initial read, updated read and final write)
Because conflict serializable schedules are subset of view serializable schedule(concurrent schedules view equal to some
serial schedule i. e serializable schedules) .
We test generally first for conflict serializabilty coz its easier to test (p problem
I am currently studying database . In the Raghu Rmakhrishnan it has been written that "the DDL languages is used in both
external level and Conceptual level ". Please elaborate on this :)
databases
s2: Evert ternary relationship can be expressed with the help of aggreation concept .
3) s1 is true s2 is false
4) s1 is false s2 is true
databases
Selected Answer
Ans 2)
In the below link it is given "ternary relationships may sometimes be replaced by two binary relationships (see book
Figures 3.5 and 3.13). Semantic equivalence between ternary relationships and two binary ones are not necessarily true."
http://jcsites.juniata.edu/faculty/rhodes/dbms/ermodel
2) ternary relationship cannot always expressed with aggregation concept. If there are redundant relation then , to
overcome it we use aggregation. So it is false
http://www.cs.sfu.ca/CourseCentral/354/zaiane/material/notes/Chapter2/node15.html
7.276 If R is in BCNF and it has atleast one simple Candidate Key then R is
always in 4NF. Any explanation for this Arjun ? top gateoverflow.in/5336
Selected Answer
If R is in BCNF and no redundancy due to Multi valued attributes then it will be in 4NF.
In question they said R is already in BCNF and atleast one simple key.. one Simple key implies NO MULTI VALUED
dependency.. so relation will be in 4NF.
d) none
databases
A secondary index provides a secondary means of accessing a data file for which
some primary access already exists. The data file records could be ordered,
unordered, or hashed. The secondary index may be created on a field that is a candidate key and has a unique value in every record, or on a nonkey field with
duplicate values.
From -> Navathe DBMS !
So we need to have primary index too. Assuming we used 1 column for that, we have 4 columns remaining, using which
we can have max 4 secondary indexes !
Selected Answer
Let
X
P Q R S T
1 2 3 4 5
2 3 4 5 6
Y
P Q U V
1 2 3 4
2 4 5 6
3 4 5 6
X ⋈ Y
P Q R S T U V
1 2 3 4 5 3 4
So,
(iii) P{{<1, 2>, <2, 3> } - { {<1, 2>, <2, 3> } - {<1, 2>, <2, 4>, <3, 4> }}}
= P{1,2} = {1}
So, (i) and (iii) are the only possibility to be same. They are actually same because both are selecting tuples from the
relation with same values for (P, Q) and then projecting the value for P.
7.279 the answer says.. natural join bu i think it should be join with
equality.please clear the doubt. top gateoverflow.in/4811
Selected Answer
http://en.wikipedia.org/wiki/Join_%28SQL%29#Equi-join
databases
Selected Answer
Ans is B:
here, inner query will retrive all students who have enrolled for the course with less than 5 credits. after join operation we
are retriving SID of all those students.
now, difference operator will return all SID which are in student relation but not in the result that we can from inner
query. therefore it will return all the SID of students who have enrolled for courses with credit greater than 5.
while performing set difference operator if any student has enrolled for any subject with less than 5 credit will be
removed.
Student
Sid Sname Sage
1 a 14
2 b 23
3 c 44
4 d 22
5 e 24
Course
cid coursename credit
1 x 4
2 y 7
3 z 5
4 q 2
5 m 8
Enrolled
sid cid
1 1
2 4
2 1
3 2
4 5
5 5
Now the inner sub query does on a natural join on the relations course and enrolled followed by selection of tuples where
credit <5
N.B only attributes which are necessary for the question are taken rest are ignored.
={3,4,5}.
Now a look into enrolled relation would depict that sid 3,4,5 are mapped to cid s 2,5,5.
and cid 2,5 in course shows that they have credit 7,8 which is >5.
databases
http://en.wikipedia.org/wiki/Blind_write
7.282 Tuple Calculus Difference between 'for all' and 'such that' top gateoverflow.in/43310
then what does the following expression mean? (does it even mean anything)
Let R(ABCDE) be a relational schema and F={AB->CD, ABC->E,C->A}. The number of candidate keys are
a) 1
b) 2
c) 3
d) 4
Is there some standard way to solve such problem.. or we have to consider each Functional Dependency...?Please explain...
by lookin at the RHS side u willcome to know B is nowhere so B has to be a part of CK so u vil get two CK AB and BC
databases
databases
CUSTOMER ( Ssn )
PHONES (Number )
Implementation of an inverted list to maintain the record list for each value for a given attribute can be done by-
1) Sequential File
2) Direct File
3) Indexed File
Please explain..
2, 3 and 4 are possible for implementing inverted list. Basically we need an indexed access to the file (as in hashing) but
this might not be there in a simple sequential file.
http://orion.lcg.ufrj.br/Dr.Dobbs/books/book5/chap03.htm
Is there any SQL command which belongs to both DDL and DML?
in a) projection has subscript hid and first select has hCity="Vancouver" and second select has year =2005 as subscript
in b) projection has subscript hid and select has hCity="Vancouver" ^ year is not equal to 2005 as subscript
In second question first projection operator has subscript s_name, title and second projection operaor has title as its
subscript
book(acc_no,yr_pub,title)
user(card_no,b_name,b_address)
supplier(s_name, s_adder)
borrow(acc_no, card_no,doi)
now pie s_name,title(supply(natural join)book) gives table with attribute(s_name,title) containing all the supplier name and
title (first algebra)
now we divide first by second then it will give only those supplier name where title name of second matches with title
name first thus it will provide name of all the suppliers who supplied all the copies of book under card-no =753
if we apply cartesian product on same relation then we cannot identify the attributes so first we apply rename operation
then we will apply carteian product on same relation
Which of the following is true, after inserting 80. (If rotation allowed)
The answer must be A.As no node splitting is done.As rotation is allowed,80 will be placed on 85 position and 85 will be
placed before 90 and 95.
consider the selection of the form s a<=200(r) where r is a relation with 1000 tuples . Asume attribute values of A among the
tuples are uniformly distributed in interval [1,500]. The number of tuples return by given query are ___ .
for question no 31 ats answer will be cartesian product is superset of natural join if nd if only if we havnot applied natural
join same relation
but in question 32 here we r applying natural join on same relation teacher then we hav applied rename option then
attributes are different so caretesian product nd naturaljoin will be same for both so answer will be (c) option
http://ugcnetonline.in/question_papers_december2012.php
clustering index is the index which has a record for every search key value and the index appears in the order of records in
the database..
sparse index is the index whose index is a subset of the search key value.and the index appears in the order of records in
the database..
now there is case where in sparse index the subset of index=all search key values so you can say clustering index is
sparse index but the reverse cant be said...
Can anyone give me an example of fixed length records and variable length records with respect to any Relational table .?
databases
Selected Answer
In database system, a field can have a fixed or a variable length. A variable length field is one whose length
can be different in each record, depending on what data is stored in the field.
Variable length fields are useful because they save space. Suppose, for example, that you want to define a
NAME field. The length of each NAME field will vary according to the data placed in it.
A Fixed length record is one in which every field has a fixed length.
With Fixed-length fields, you would need to define each field to be long enough to hold the longest name.
This would be a waste of space for records that had short names
for 5 question:
i think;
(A) true
(B) false
(C) true
as fann out of B+tree is greater than B tree so that why it contain less no of levels and due to less no of level it covers
less space and therefore search time is less as comapred to B TREE..
My doubt is, T3 and T4 have blind writes, can these be conflict serializable?
databases
Selected Answer
A record size is (30+9+9+40+9+8+1+4+4)=114 and 1 B for deletion marker 1 so 115 B record size . No. of record
30000.
block size =512 B , blocking factor floor (512/115) =4 so no. of block required celin (30000/4 ) = 7500 .
SSN= key = 6 B
KEY+block pointer = 9+ 6 = 15 B
1st level :
2nd level:
3rd level
a)Classification
b)Instantiation
c)Specialization
d)Generalization
classification is answer .
In a database , the specification of data where individual data item of same type can have different sets of attribute
a) True
b) false
databases
in a database its possible to have 2 attributes of same domain (same type eg. int ) .
1) 3
2) 5
c) 15
d) 30
databases
C) 15
here we are asked that how many schedules are conflict equivalent to only S: T1 →T2 →T3
but here in these set of transactions it can be seen clearly that on executing them concurrently in any order they are
always going to result in a Serializable Schedule. Hence there are 90 serializable schedules.
but we also know that only in 3! ways we can arrange T1 , T2 and T3 . There are 6(=3!) possible combinations of serial
schedules. But we are getting 90 serializable schedules. It means that some schedules are conflict equivalent to each
other and simultaneously to a serial schedule out of those 6 serial schedules.
Then 90 is divided into packets of schedules each group(packet) being Conflict Equivalent to one among those 6 serial
schedules.
Therefore, 90/6 = 15 schedules exists in a packet. One such packet of schedules is Conflict Equivalent to serial
schedule S: T1 →T2 →T3
Selected Answer
No it is not associtive.
take A as
s.no name
1 abc
2 xyz
take B as
s.no name
1 abc
3 mno
take C as
s.no name
1 abc
4 stu
The result of set difference is tuples which are present in one relation but not in another.
the result of
(A-B)-C =
s.no name
2 xyz
A-(B-C) =
s.no name
1 abc
2 xyz
W1(X)R2(Y)R1(Y)R2(X) ?
databases
ATOMICITY IS MANAGED BY
a) Programmer
d) None of it
databases
It is the
responsibility of the transaction recovery subsystem of a DBMS to ensure atomicity
As per Database Systems Navathe !
HI ,
I am currently studying DBMS . I am having a doubt , We know that When schedules are conflict serializable it will always
give consistent result and more important concurrency too .
For the Conflict serializable we have an algorithm which says if precedence graph contain no cycle then it is serializable else
not .
T1:R1(X); X= X-10,W1(X);R1(Y);Y=Y+10;W1(Y);
T2:R2(Y);Y=Y-20;W2(Y);R2(X);X=X+20;W2(X);
S:R1(X);W1(X);R2(Y);W2(Y)R1(Y)W1(Y)R2(X);W2(X)
if you run this schedule by considering any initial value of X and Y , you will get consistent results . But if you draw a
precedence graph for this you will get a cycle , which meant it not serializable ..
So caan i say a cycle in such kind of transaction wont give correct results . we need to consider the semantics of all
operation which we usually ignore ?
databases
From statement "If S is a superkey such that {S ∩ UID} is NULL then {S ∪ UID} is also a superkey". If i delete "{S ∩ UID}
is NULL" then also statement is true. Anyway Superkey ∪ anything = Superkey only. What is d use of "{S ∩ UID} is NULL"
??
Into 2nf: try to remove the partial dependencies by decomposing the table.
Into 3nf: now remove the transitive dependency by decomposition
Into bcnf: now remove the overlapping candidate key by decomposition from the 3nf table if any
If you say how to decompose then it's a long process in that case follow a standard book you will get the algorithms
T3-->T1-->T2
Assume block size 4096 bytes,size of key is 4 bytes,size of pointer is 8 bytes.How many keys are possible per blocks for b+
tree organisation?
(a) 155
(b) 154
(c) 341
(d) 340
# of key =lower bound of ( block size/ (key + pointer))=lower bount of ( 4096/(4+8)= lower bound of (341.33)= 341
Lets say their is R(A,B,C) and FD : AB, ABC and A is key. Is it in 3NF? Explain
Selected Answer
For a relation to be in 3NF , we must have X-->Y , so either X should be a key or Y should be a prime attribute , Now with
the given FD , u can re-write them as A-->B and A-->C as (A) +=(ABC) , so you can remove B from the functional
dependency AB-->C , so that it becomes A-->C , therefore now you are left with A-->BC only and since A is a key so
clearly the FD is in 3NF .
Point : whenever You have PQ-->R and (P)+=(PQR) , then remove Q from the FD ,since P alone can determine
R so Q is redundant here , so your FD reduces to P-->R
3NF defination->
2. Y is a prime attribute
so here R(A,B,C) :A->B and AB->c.. A is a key (given) ..for AB->finding closure ->AB +=ABC ..it contains all the attributes
so it is also a key. both FD satify 1st condition so this is in 3NF
Let FD: AB-->C , A-->C .Is B extraneous ?if yes, then how can we determine B.
Selected Answer
B is useless here , it could even have been ABDFRGTYUILOP-->C , then BDFRGTYUILOP ,all these attributes are useless
since A alone can determine C , so u r left only with the functional dependency A-->C , as far as determining B is
concerned , it is a prime attribute , since AB is a candidate key here . so in the given relation schema R(ABC) , you have
only 1 functional dependency A-->C and AB is candidate key .
AB-->C
A-->C
2ND FUNCTIONAL DEPENDENCY SHOWS THAT 'A' ALONE CAN DERIVE C. SO IN 1ST FD B IS EXTRANEOUS . BECAUSE
HERE A AND B TOGETHER DERIVING C. THIS IMPLIES THAT B IS NOT REQUIRED TO DERIVE C.A ALONE CAN DERIVE
IT.AND IF WE REMOVE B, A CLOSURE WILL REMAINS THE SAME.
7.311 To decompose the give relation into 3nf and BCNF top gateoverflow.in/4348
AB->C
A->DE
B->F
F->GH
D->IJ
Selected Answer
This is what I do for it, find all attributes not appearing on RHS of FDs. These attributes must be prime attributes- must
be in present in some candidate key. Now, find their minimal cover and add other attributes so that the minimal cover
covers the entire attributes.
Here, A and B are not on RHS, so must be in candidate key. AB determines {A,B,C,D,E,F,G,H,I,J} and hence becomes the
candidate key as well.
Now, A-> D, A->E B ->F are partial FDs. So, the relation is not in 2NF.
A->DEIJ giving ADEIJ, B->F and F->GH giving BFGH and AB -> C giving ABC.
These 3 relations are in 2NF. and ABC is in BCNF. In ADEIJ, we have transitive dependencies
So, to make the table into 3NF, we make a separate relation for DIJ and FGH. So, now we get 5 relations
ABC, ADE, DIJ, BF and FGH which is in 3NF. None of the prime-attribute comes on right hand side of any FD => so as
soon as the relation is in 3NF, it is in BCNF as well. Or you can see for each non-trivial FD α → β, whether α is a candidate
key. (non-trivial means β ⊄ α)
Bank(bname, city)
Travel(pname, city)
SELECT T1.pname
FROM Travel T1
WHERE NOT EXISTS (SELECT B.city
From Bank B
Solution
I am getting as Who have travelled in any city where SBI is located
Answer given as Who have travelled in all city where SBI is located
Selected Answer
The second part of EXCEPT wil give all the cities which a person has travelled to
Now the first part of EXCEPT will give all the cities where SBI is located. say {Kolkata,TN,UP}
Now if you do EXCEPT between these two states. you will get a tuple or UP . So B has not travelled to all the states
conntaining SBI.Now the NOT EXISTS part will be FALSE (as something is being returned,in this case UP). As a result we
will not take B from the original query.
So only if a person have travelled to all the cities where SBI is present then only the EXCEPT will give NULL and the NOT
EXISTS part is TRUE, and we will return that person from the query.
Hope its clear . Its better you take tables and find out.
b)join
c)change
d)update
So bcnf decomposition is
R1(S,Z) and R2(Z,C) is lossless as Z is common attr in both reln but not dependency preserving as CS->Z not preserved
ques: F is a set of functional dependencies on realtion R(ABCDE) with F={A->ABCD,B->C,B->D} which of the following is in the closure of F?
a.) CD->B b.) C->D c).B->CD d.) BCD->A
databases
B->C
B->D
B->CD
so ans is c
15,
the precedence of graph of this schedule contain cycle.. so this schedule is not conflict serializable...
so (d) option..
A) Primary index
B) clustered index
C) secondary index on candidate key
D) all
databases
Selected Answer
AND : C
Q2:{A,C|∃B(A,B)|∊R ∧(B,C)∊S)}
Q3:∏A,C(R⨝S)
C->A
DE->F
B->D
ADD C->B to following FD.. How many different FD are there which make C as candidate key...(For simplicity assume FD
have only one attribute on LHS and RHS)
AB->CDEF
C->A
D->B
C->D
E->F
B->E
R1(ABCD) AB->CD, C->A, C->D and D->B will imply in this decomposition
1)Relation R in BCNF with atleast one simple candidate key is also in 4NF
3)Relation R in 3NF with only one compound candidate key is also in BCNF
4)Relation R in 3NF with atleast one simple candidate key is also in 4NF
1)Relation R in BCNF with atleast one simple candidate key is also in 4NF
if multivalue attribute exist in the table then every candidate key will be compound key
so here there is one simple candidate key no multivalue attribute present so surely its in 4NF also.
2)Relation R in BCNF with all candidate key simple is also in 4NF
same reason as above.
3)Relation R in 3NF with only one compound candidate key is also in BCNF
option 4 is false.
Given a block can hold either 3 records or 10 key pointers.A database contains n records , then how many blocks do we need
to hold the data file and the dense index
a)13n/30
b)n/3
c)n/10
d)n/30
Selected Answer
Selected Answer
Functional dependency X --> Y is a full functional dependency if removal of any attribute A from X means that the
dependency does not hold any more i.e. for any attribute A ϵ X, (X - {A}) does not functionally determine Y.
http://gateoverflow.in/?qa=blob&qa_blobid=10158621331044967374
7.329 which of the following are the candidate keys? top gateoverflow.in/17425
Let x,y,z,a,b,c be the attributes of an entity set E.if {x} ,{x,y}, {a,b} ,{a,b,c}, {x,y,z} are superkeys then which of the
following are the candidate keys?
Selected Answer
PQ → R
PQ → S
R→P
S→Q
Selected Answer
b)A small open diamond at the end of a line connecting two tables
c)A small closed diamond at the end of a line connecting two tables
d)A small closed triangle at the end of a line connecting two tables
Option B) A small open diamond at the end of a line connecting two tables.
In UML, aggregation is shown by an open diamond on the end of the association line that points to the parent
(aggregated) class.
The minimum number of keys in a B + tree is 3. The maximum number of keys in any non-root node is
Selected Answer
Max no of key = 8 - 1 = 7
databases
According to me both ER1 and ER2 have a many to one relation from P To Q , so does it imply that P has more no of entities
than Q or we can simply say that through an ER diagram we can't tell anything about no of entities .
databases
7.335 which of the following statements are true regarding the below ER
diagram ? top gateoverflow.in/18282
The answer to Q14 is 4 because table Y indicated by total participation every entity is participated in relationship and also
given 1:M ratio implies Table x can participate in zero or many entities.so it depends on the input we give.
Correct me If I m wrong
7.336 grouping when attribute have some null entry.. top gateoverflow.in/18280
Null will cause one group reords 1 10 11 12 will form one group
Given answer: B
I don't know what are closed set in databases. Please give some references for explaining it.
databases
databases
Let n be degree
8n+8(n-1)<=512
16n<=520
n<=32.5
n=32
For indexing used internal node structure.Because leaf node pointing to original data only.
P-1(8) + P(8)<=512
8P -8 + 8P <= 512
p <= 520/16
p <=32.5
P = 33 take ceeling
how many b tree are possible with 6 record if there are 3 key.???how to solve?
databases
Selected Answer
Sum of degrees = (I-1) * 5 + 4 + L (Each internal node except root has degree 5 and root has degree 1) = 5I + 37
3/2I = 37/2
I = 37/3 = 12.33.
So, for 38 leaf nodes we need more than 12 internal nodes, so it must be 13 internal nodes and last level not being fully
filled.
I(4-1)+1=38
I =12.33 = 13 nodes
consider unspanned blocking with 20 byte blocks. A file contains records of sizes 2,5,3,7,4,20 bytes.
the percentage of space wasted if blocks are allocated for file is?
Selected Answer
always true...
S:w1(a)r2(a)w3(a)r4(a)w5(a)r6(a)
databases
databases
In Index file block fector= key +pointer= 90% of record size +10% of record size= 100% of record size= 10
7.349 Find the title of all the books which is not yet issued? top gateoverflow.in/26862
Book_schema(Acc.no,yr_pub,title)
B.by_schema(Acc.no,Doi,Card.no)
Here CURDATE() function gives the current date.So this query will return you the titles of those books which issue date is
greater than current date means the books which are not issued yet.(This query syntax is according to SQL Server 2008)
ans given is 54
how to solve it
Let us count how many combination can be made from given condition-:
To count this first let us count how many total concurrent process can be possible .
__5__6__7__8__
so we have 5 empty space out which we have to fill with 4 operation (1,2,3,4) with repetition.
At each empty space any number of operation can come.
It is similar problem to chocolate problem.
1) 1 2 3 4 occur before 6
here n= 2 r =4
therefore (2+4-1)C4 = 5
2) 1 2 3 occur before 6
here n= 2 r= 3
therefore (2+3-1)C3 = 4 but here d can be at 3 place so total 4 *3 = 12 arrangement
databases
R(ABCDE)
AB-> CD
C->B
D->E
then A, B, C are prime attribute.. here B come in one candidate key not in both But also a prime attribute.
SO any attribute which are in any candidate key are prime attribute.
inner query first executed i.e. select manager from emp ; and this fetches 2,3,4
Now, outer query will be executed and the rows of eno.=2 or 3 or 4 will not be prined
1 a 2
databases
7.353 Can two entity sets in a relation have the same primary key? top gateoverflow.in/25201
yes, it can possible in recursive relationship.In recursive relationship the two keys(primary key and foreign
key) are the same but represent two entities of different roles to relate relationship.
Ex:-
Given,
Suppliers(sid,sname,rating)
Parts(pid,pname,color)
Catalog(sid,pid,cost)
1.Retrieve sid of the suppliers who supplied some red or some green part.
1 more way to do-- {t | ∃c∊Catalog (∃p∊ Parts( p.color="Red" ∨ p.color="Green"∧ c.pid=p.pid) ∧ t.sid=c.sid)}
I want to verify whether these TRC queries are correct or not.Also correct me if i am wrong.
Also,
1.{t.sid
|∃t∊Supplier,
∃c∊Catalog
,∃p∊
Parts(
p.color="Red"
∨
p.color="Green"
∧c.pid=p.pid
^t.sid=c.sid)}
2.{t.sid
|∃t∊Supplier,
∃c∊Catalog,∃p1,p2∊
Parts(
p1.pid
!=
p2.pid
∧c.pid=p.pid^
t.sid=c.sid)}
so ans will be C
Selected Answer
S1: False count doesn't include null values.(if allowed NULL + Anything = NULL )
S2: False average add all non null values (if allowed NULL + Anything = NULL )
S3:False projection of relational algebra is not equal to SQL select since SQL allow duplicate but relational algebra doesnt
allow i.e why we use Select distinct in SQL.
So option A
R1(p,q,r) and R2(r,s,t) with the primary key P and R respectively.the relation R1 contain 200 tuple and R2 contain 250 tuple then minimum and
maximum size find right outer join is........
For : R1 right_outer R2
Case-1: If each rows of R1 get only one matched row of R2 then result will be :250( bcz of right outer join)
Case-2: If rows of R1 doesn't get any matched row in R2 then result will be :250( bcz of right outer join)
For : R2 right_outer R1
Case-1: 200
Case-2: 200
Right outer join says that atleast all the tupples of right table should come. i think the minimum and max here will be 250
only. because first we will perform the natural join and take all right table tupples . R is the primary key of relation so
natural join on both the table will result in 200 tupples but we have to take all the remaining right into consideration so it
should be 250.
If A has 100 entities,B has 1000 entities , and C has 10 entities. What is the maximum number of triples of entities that could
be in the relationship set for R?
X-->Y means for one value of X we can have more than one value of Y
Example::deptname-->phone no
A block can hold either 12 records or 42 key pointers .A database contains 96 records , then how many blocks are required to
hold the data file and the dense Index?
a). 10
b). 12
c). 11
d). 13
databases
So total no of blocks= 12
7.360 Can anyone please help me with that UNDO and REDO concept in
recovery of transaction with commit and checkpoint? top gateoverflow.in/25576
Selected Answer
Checkpoint: Checkpoint is a mechanism where all the previous logs are removed from the system and
stored permanently in a storage disk. Checkpoint declares a point before which the DBMS was in consistent
state, and all the transactions were committed.
Recovery:When a system with concurrent transactions crashes and recovers, it behaves in the following
manner −
The recovery system reads the logs backwards from the end to the last checkpoint.
All the transactions in the undo-list are then undone and their logs are removed. All the transactions in the redo-list and
their previous logs are removed and then redone before saving their logs
Block size=1024B
Ans 7
http://nptel.ac.in/courses/IIT-MADRAS/Intro_to_Database_Systems_Design/pdf/5_Data_Storage_and_Indexing.pdf
Selected Answer
Since if we add a book to the course we have to add for each lecturer in that course
or if we add any lecturer for any course we have to add book for it .
Bank(bname,city)
Travel(pname,city)
select T1.pname from Travel T1 where not exists(select B.city from Bank B where B.bname='SBI' except select T2.city from
Travel T2 where T1.pname=T2.pname);
My question is what T1 and T2 doing here? Can anybody give an example and explain?
Here T1 and T2 refer to two copies of same table travel..basically they are alias to same table travel...this query is trying
to find pname who has visited sbi branches in all city
7.365 When the system is restarted, which one statement is true of the
recovery procedure? top gateoverflow.in/15098
Consider the following log sequence of two transactions on a bank account,initial balance 12000, that transfer 2000 to a mortgage payment and
then apply a 5% interest.
1. T1 start
2. T1 B old=12000 new=10000
3. T1 M old=0 new=2000
4. T1 commit
5. T2 start
6. T2 B old=10000 new=10500
7. T2 commit
According to me answ must be option B since after failure the transaction T1 was commited partially hence now it needs to redo both the write
operations as it does in case of deffered databse modification , although here we have immediate data base modification but still redo operation
must work similarly only that it redoes all the write operations .
databases
http://gateoverflow.in/981/gateoverflow.in
7.366 How can in the below schedule write write operation can be swapped ?
top gateoverflow.in/15147
I am nt getting how this write operation in the first case can be converted into a serial schedule in both the two cases , i.e we
are given the first set as the complete schedule now how can we convert it into serializable schedule i.e. since READ(X) of transaction T1 cannot be swapped with the WRITE(X) of T2 , hence
while drawing the graph , there must be an arrow from T1 to T2 .
Also WRITE(X) of T1 cannot be swapped with WRITE(X) of T2 hence there must be an arrow from T2 to T1 , now there comes a cycle in the graph , hence it must be not be conflict
serializable so then how can we convert that schedule into a serial schedule ?
databases
a). 1 NF
b). 2 NF
c). 3 NF
d). BCNF
Selected Answer
Imagine a scenario for programming a transfer of amount Rs.1000 from account A to B.A has 1500 B has 1500 initially
A+B=3000
A=500 B=2500
After transaction if A+B=500 then we can say that there is some problem in the coding as for database to be consistent
A+B should be 3000.
If there is no proper coding the database can enter into an inconsistent state.
b+tree
Internal nodes have form <[bp][k][bp] [k][bp] [k][bp] > order p max (p-1) keys , p are actually number of block
pointers.
blocksize*(p)+keysize(p-1)<= 512
8(p-1)+8p<=512
8p-8+8p<=512
16p<=520
p<=32.5
your are correct it should be 32 don't know why they have given 33.
I am not getting that due to Write(A) in T1 and Read(A) in T2 , I will have an edge from T1 to T2 , and then due to Write(B)
in T1 and then Read(B) in T1 , we will have an arrow from T2 to T1 , hence a cycle is formed so it should be non-conflict
serializable , so why is it conflict serializable , plz correct me where am I wrong ?
databases
T1----->T2
In first half:
Therefore T1---->T2.
7.371 How many minimal candidate eys are there? top gateoverflow.in/15356
minimum does not exist here minimum stand for only one. but c and d may be taken as minimum but this assumption is
wrong . just to match the answer of a wrong study material i am saying that .
7.372 why are both SIX and SIX not compatible to each other ? top gateoverflow.in/15411
If a node is already in SIX mode then why can't another transaction lock it again in SIX mode ?since this implies that some
another transaction is trying to apply exclusive lock on some node below this current node , so then what 's the issue ?
databases
databases
ANSWER: Q 1 , Q 2 and Q 3
EXPLANATION
Natural Join is a type of cartesian product whose selection of tuples is based on common columns of two
table.
Outer Join considers all the tuples from both the table and join them with specified attribute. Null in case of no
join of tuples possible.
SQL COMMANDS
);
EDIT:
if a node R1 is in IS mode then it may be a possibility that some node below it is in exclusive
lock then how can we lock R1 in S mode since if I apply S on it that means I am
trying to lock every node below R1 in S mode but since some node below it is already
in exclusive lock so then how can I apply S lock on it .
since may be initially R1 was in IX mode but some other transaction came and applied
IS to it that means some node below R1 can be both in exclusive mode and in shared mode if R1 is
in IS mode so than how can a transaction come and lock R1 in shared mode i.e. why are IS and S locks
compatible ?
databases
I and II only
test-series databases
databases
Selected Answer
In simple terms, the division operation, π AB (R) / πB (S) means 'A' values for which there should be 'B' value in R for every
'B' value occurring in S.
Now, we see that the combination of every row of R 2 not occurring in R 1 and so the correct option is (d).
None of these , ultimately getting no distinct values .so empty set. Apply usual rules of division and find out
databases
A B
a1 b
a2 b
a3 b
a4 b
Relation will be look like this...because cardinalities of R1 is m and of R2 is 1 So cartesian product will give the result like
above table
In a database file, the search key field is 9 bytes long the block size is 512 bytes, a record pointer is 6 bytes and block
pointer is 7 bytes. The largest possible order of a non leaf node in B+ tree implementing this file structure {order defines
maximum number of keys present} is ______.
Solution
Equation : order *( Block Ptr Size ) + ( order -1) Record Ptr Size < = Block Size
n <= 39.84
order = 39
Answer given as 31 .
How is this possible . Correct me if i am wrong
Selected Answer
My Answer is
Block Size =(n-1)key size +(n-1) record size + n* block pointer size
n is the order of b+ tree
512=(n-1)*9+(n-1) *6+n* 7
512=15n-8
n=520/15 =34.66
floor(n) =34
Selected Answer
so 3 tables are
employee(eno,ename);
dept(dno,dname)
works(eno,dno,since)
so b is ans
The minimum number of keys in a B + tree is 3. The maximum number of keys in any non-root node is ____.
Solution:
3 = ceil (n/2) -1
n = 8
answer given as 8
Solution
Similarly B---> A
I can find 2 different types of Canonical FD for the given set hence it is unique and true
databases
Selected Answer
level 1 : one node ( root node ) contains 10 block pointers as B+ tree is of order 10
level 4: contains 1000 nodes ( assuming order of leaf nodes is 10 as they didn't mention separately)
Consider a relation R(A B C) with attribute size of A as 8 bytes. Disk block size is 512 bytes and block pointer is 8 bytes. The
best choice for degree (maximum value) for B+ tree, if B + tree was used for creating indexing on R(A B C) is ______
My Calculation
16n<= 520
n<=32.5
So order will be 32 ?
Answer given as 33.
Which is correct ?
Relational scheme R with N attributes A 1, A2 …. A n. If every attribute is the Candidate Key, then how many superkeys are
possible?
databases
Selected Answer
There will be no overlapping( all subsets except phi will be super key)
S1 : R1 (C)R2 (C)W1 (A)W2 (A)W1 (C)R1 (B)R2 (B)W1 (B)W1 (D)W2 (B)W2 (D)R1 (F)W3 (E)R3 (F)
Let ′ X ′ be the number of 'blind-write' operations in the given schedule and ′ z ′ be the number of conflict equivalent serial
schedules to S1 . The value of X ∗ Z is_________.
Selected Answer
The Schedule is not conflict serializable.This can be checked by the precedence graph,it contains a cycle.It has 5 blind
writes that are the writes without any prior read of that data item.
Z+X= 0+5=5
I am unable to get that what advantage do we get when we store only records consisting of primary attributes in case of B+
tree i.e. we do not store record pointers corresponding to those key attributes , we do it only at the leaf level , doesn't it
increase the overhead since we have to come upto the leaf level and then access the data where as in case of B tree with
each node we have a record pointer associated so I guess that's more advantageous , so then why database designers prefer
B+ trees over B trees ?
databases
Selected Answer
first of all u need to understand this. we do not use AVL trees or red black trees as they grow depth wise rather than
breath wise. we prefer breath growth as the number of levels will be less and the time search time will be less due to less
number of levels.
now we prffer b+ over b because . b+ grows more breath wise than b tree. what it means is it can holds more data in
internal nodes.
suppose u have a seat which is of 6 meter. now each person requires 1m space . so total number of person that can sit =6
(b+ tree case)
now in second case everyone is carrying an extra luggage of 1 meter. so total number of person that can sit =3 (b tree
case)
the same case happens in b tree. every internal node should contain key with record pointer . which is a type of extra
field.which is not present in b +tree . due to which the number of keys a block can accumulate becomes less. and the b+
tree for the same reason can accumulate more number of keys. as more number of keys can be stored in the internal
nodes . the height of tree decreases due to which the search efficiency increases.
2ndly page fault decreases . as in one page more number of keys are stores the page fault rate decreases as there is
more probability of a hit.
I am just having one confusion that if we have a canonical cover so it doesn't have any extraneous attributes or redundancy ,
so is it always in normal form, or not always true ,i.e it may depend on whether it satisfies all the conditions for being in
normal form .
databases
Selected Answer
basically when we have a canonical cover that mens we have the non redundant functional dependecy . it will be in first
normal form only . the actuall use of canonical cover in the process of normalization is to remove the reduent and and
repeating functional dependency which make our problem easy now. There is a way how our teacher taught us all about
normalization. a live example .
according to him normalization is a war . now i am training u to be a commando of normalization. before going to war u
have to choose guns . if there are 2 set of functional dependency which mens 2 guns . u definitely will choose more
powerful else if there is only one gun u have to make it lighter so that u can fight easily. here canonical cover help us. if u
have 2 set of functional dependecy chose that is more powerful mens whic is driving more attributes, else just remove all
the redudant terms other wise u have to deal with them aterwards. now after choosing gun u have to choose bullets . so
find candidate keys . they are the bulets now u are ready to fiht the battle of normalization . now u can easily understand
that these steps are required before normalization.
T1 T2 T3
X(A)
W(A)
X(B)
U(A)
X(A)
W(A)
W(B)
U(B)
X(B)
U(A)
X(A)
W(A)
W(B)
U(B)
X(B)
W(B)
U(A)
U(B)
Since schedule is allowed to execute in 2PL then schedule is conflict serializable schedule & conflict serial schedule is the
lock point order(lock point is red colored).this way, Equivalent conflict serial schedule is T2 -> T1 -> T3
7.391 Why does Read operation conflicts with write operation ? top gateoverflow.in/15422
I am having one confusion in this concept , say T1 reads a data item A and then T1 writes on it , so we say that while
converting into a serial schedule we can't swap these two , but what's the reason behind this since whatever T1 does in its
doing with its own memory variable , hence no issue of conflict and even after T2 issues write then whatever T1 would write
would be written back into the disk so then why do we not allow read to swap with write operation .
databases
Selected Answer
you will do two things first read what is there if any and then write after that or even overwrite it.
now imagine you write and then read.. it seems both would be same i guess ..remember when you write and read you are
overwriting whatever the paper had even without knowing what it had..this time you are nt reading what was there but
you read what you wrote now or we may say you are bothered to write and then see what you wrote..
here you will always read the recent change you made
But if you read and then write you will read the previous change that could have been done by anyone else NOT ONLY
YOU ..
hence this is y they cant be swapped or we say they are differnt even in ones own transaction ..
else you would nt read what your friend wrote 2 sec ago and but read what you wrote 1 second ago.and who knows you
might need the information your friend tried to convey you but since you tot to write and then read you lost them.. ur
decission may be fatal as you ddnt listen or read what ur friend wrote and missed them
Let R and S be relational schemes such that R={a,b,c} and S={c}. Now consider
the following queries on the database:
http://gateoverflow.in/1331/gate2009_45
consider the table create table test( one integer , two integer , primary key( one) ,unique (two) ,check (one>=1 and <=10),check (two>=1 and <=5)); how many
records atmost can this table contain
1) 5 2) 10 3) 15 4) 50 ans is given 5 as they said two is unique so max 5 record but in my opinion it should be 10 as unique key can contain null also
S1: R1(C) R2(C) W1(A) W2(A) W1(C) R1(B) R2(B) W1(B) W1(D) W2(B) W2(D) R1(F) W3(E) R3(F)
let 'X' be the number of bilnd writes and 'Z' be the number of conflict equivalent serial schedules to S1. the value of X*Z
is=______
I think here no of blind writes =5 and no of conflict equivalent serial schedules=0 . because there is a loop betwwen T1 and
T2. so 5*0=0
and transactions in given schedule forming a circle so the given schedule is not conflict serializable.
so X*Y=5*0=0;
so final answer is 0;
databases
Uniformly distributed,means the tuples are distributed 1 to 100,101 to 200,..in this way,401 to 500,total 5 division,each
having 200 tuples total 1000 tuples,so now relation r less than equal to 200 means ,total 200 +200 =400 tuples
Find the minimum no of tables requires for representing the above relational model?
Department ( dno,dname)
phone number(dno,phone)
office(dno,office).
the key is we always make a new table for multivalued attribute and place the attribute with the primary key of the table.
databases
databases
The physical location of a record determined by a formula that transforms a file key into a record location is
a)Hashed file
b)B-Tree file
c)Indexed file
d)Sequential file
In hashed file physical location of record is computed using hash function so ans is a
7.401 Find no. of records in highest level of multi-level index top gateoverflow.in/16941
http://gateoverflow.in/259/gate2008_70
blocking factor of index file will be= 1024/(4+10) ( 4bytes ssn and 10 bytes block pointer. )= 73.14=73
now in primary index we know that every block has a entry in the index. so index file will need
which will contain 8 entries as each block will be having a pointer in 2 level index.( which is not an option )
clustred index file contains entry for every distinct entry , as every distinct entry in this question is taking a block . total
number of entry will be number of block . as it is stated they are evenly distributed.
512 blocks how 1000 entry all starting with a new block can exist.
i am wrong .
The maximum number of nodes in a B+ tree with order 4 and height 6 are ____________
Consider unspanned blocking with 20 byte blocks. A file contains records of sizes 2,5,3,7,4,20 bytes.
The percentage of space wasted if blocks are allocated for file is __________
is blind writes and write after reading a data item same or not
no they are not same . blind wite is . writing without reading the data item without reading it. .
It is view serializable..
we say that when any transaction is rolled-back that means it would be re-started again , so lets say if T2 reads a data item
from T1 , perform some computation on it and then writes it back onto disk and after some T1 fails , so its a dirty read
problem and we say that this schedule is not recoverable , so then if T1 is rolled back i.e. it is restarted again so then will T1
execute in a serial fashion from start till end or whether there would be still some concurrent execution between T1 and T2 .
After roll-back will the value of data item be set to its initial value or since T1 is restarted again it would be set to the value
as computed by T1 again ?
databases
It is a signal means that the transaction has ended unsuccessfully, so that any changes or effects that the
transaction may have applied to the database must be undone.
7.408 How many tuples appear in this following relational algebra top gateoverflow.in/33679
databases
Selected Answer
ANSWER: 2
EXPLANATION
For the sake of explanation, I would prefer to make a minor modification to the given relation algebra as follows -
I just renamed the relation to the left of join operation as P. Now let us see the state of two relations before the join
operation.
P S
=========== ==============
A B A B
-------------------- -------------------------
1 2 2 3
1 3 3 2
3 2 2 1
Join operation is simply a cartesian product with a condition. So before join operation, let's see what will be result of PXS
P + S
=========================
A B + A B
---------------------------------------------
1 2 2 3
1 2 3 2
1 2 2 1
1 3 2 3
1 3 3 2
1 3 2 1
3 2 2 3
3 2 3 2
3 2 2 1
Now if put a contraint on above resultant relation to select only those tuples whose P. B < S. B we get;
P + S
=========================
A B + A B
---------------------------------------------
1 2 2 3
3 2 2 3
SQL QUERIES
ρS(A,B) (πB,C (R)) -> it will project B and C coloum from table R and rename it as Table S with coloum A,B
i.e. A=B and B=C
7.410 what is the meaning of the data item actually when we write the
statement READ(A) ? top gateoverflow.in/15648
I am having some confusion in understanding the meaning of the term data item .
when we write
READ(A)
A=A-10
WRITE(A)
Now I am unable to get one point here that when we have a file consisting of various blocks and those blocks consisting of
various record and when we say that we are accessing a particular data item for reading then is this data item is a record or
some particular field inside that record .
And major confusion is that how can we simply read a field from a record during disk access , since disk access is expensive
hence we must be able to fetch the entire block from the disk , but we write only this statement like :
databases
when we have READ(A), the entire block containing A is fetched from secondary to the buffer. Then from that block the
particular field is read
What is the difference between the following two expressions, conceptually and in terms of relational algebra ?
1. names of girl students with more marks than some boy student
2. names of girl students with marks not less than some boy students
databases
x: Girl student
y: Boy student
then 1- {x|∃y(f(x)>f(y)}
2- {x|∄y(f(x)<f(y)}
thus the first query means select the girl whose mark is greater than any one of the the boy student( it has to be greater
than minimum of the marks of boy students)
and second query means to select the girl whose marks are not less than any boy student (i.e. on negation it becomes
that girls marks are greater than every boy student) thus the marks of girl should be greater than maximum marks of the
boy students.
I think conservative 2PL prevents deadlock also. What should be the answer?
in two phase locking deadlock is possible...conservative protocol is just a way to ensure that deadlock does not
happen..Impestamp protocol ensures serializability and prevents deadlocks but suffers from starvation
7.413 What is the minimum no of candidate keys for the given FD's ? gateoverflow.in/16350
top
AB->C
C->D
D->EA
E->F
F->B
databases
The answer must be AB and C...Hence only two candidate keys are present.
I am confused regrading the significance of checkpoint i.e. is it that whenever we place checkpoint does that mean that all
the data items before it have been written onto the data base , if not then why do we place it below the transactions which
have simply written the data item but not yet committed ?
databases
checkpoints are inserted in order to make the recovery process more simpler. instead of writing everything to the stable
storage at the end, we issue checkpoint in different occassion. Once a check point is encountered all the dirty pages of all
transaction ( committed and non committed ) is flushed to the stable storage. Also the transaction log is flushed to
storage
Now if there is any need of any recovery, if we need to do a redo , then we need to do it only after the checkpoing
if it is an undo also we need to do it for before the check point (for transaction which were not committed at the time of
checkpoint)
those transactions which were committed before checkpoint, there is no need to do anything.
please note in reality some transaction/ schecules may take a very long time to complete. so it is always better to use
checkpoints
Every time the attribute A appears , it is matched with the same value of attribute B but not the same value of attribute C.
which of the following is true?
Selected Answer
the option b is correct . there is just a small definition of multivalue dependencies which . if a->> c is a dependency it
means for a ,c has more than one value.
here it is saying whenever a appears b has same value which is true in case of functional dependency . if a->b exist for
every a if repeats there should be same b . so a-.b exist here and it is clearly saying c is not same which means for same
a it contains multipule value of c. so answer is b .
why not c ??
and for c
A C
1 3
1 4
now u can see that for a we have multipule value of c but c does not have multiple values for a . so we cannot say c->>a .
but we can say a->>c. and question is saying c can take different value not a .
databases
automata
So No of state =3
Only L1
Both L1 and L2
Both L1 and L3
All of the above
Selected Answer
L2 is not CFL because a PDA cannot check for prime numbers. L3 is not CFL because we cannot check repetitive words in a
PDA (we can check only if words are repeating in reverse order). So, they both cannot be DCFL also. Only L1 is DCFL.
chomsky-normal-form
Option b is correct .
http://nptel.ac.in/courses/106106049/downloads/Properties%20of%20CFL.pdf
8.4 Closure Property: The recursive sets are not closed under : top gateoverflow.in/25465
closure-property
¯
and , L = L1 ∩ L2
then L is
b) not CFL
c)DCFL
context-free closure-property
Selected Answer
L1 = CFL ,
L = CFL ∩ (DCFL )' = CFL ∩ DCFL BUT ,DCFL AND CFL both are not closed in intersection ...so it may or may not be CFL.
so answer is A)
http://gatecse.in/wiki/Closure_Property_of_Language_Families
8.6 Closure Property: True or False: DCFL is closed under set difference top
gateoverflow.in/6471
True or False: DCFL is closed under set difference
closure-property theory-of-computation
Selected Answer
Now u want to find whether L1 − L2 is dcfl or not? (if DCFL is closed under set-difference, this must be TRUE for ANY such
L1 and L2 ).
To prove this we make use of the fact that DCFL is not closed under intersection. (For example take L1 = {a b c
∗ n n ∣n≥0 }
and L2 = { an b ∗ cn }
∣ n ≥ 0 which gives L1 ∩ L2 = {
an bn cn }
∣ n ≥ 0 , which is not even a CFL.)
¯
L2
Now we can L1 ∩ L2 = L1 −
DCFL is closed under complement (If we complement the accept states of DPDA for L we get DPDA for the complement of
¯
L, but this is not true for a general PDA.) So, L2 is a DCFL, let it be R. So,
L1 ∩ L2 = L1 − R, where L1 , L2 and R are DCFLs. Now, if DCFL is closed under set difference it must also be closed under
complement. But we already showed that it is not. So, DCFL is not closed under set difference.
http://gateoverflow.in/?qa=blob&qa_blobid=8929616163903734815
closure-property theory-of-computation
8.8 Combinations: Hopcroft Ullman - Automata Theory, Need Help top gateoverflow.in/43342
Selected Answer
More info:
State 1: even number of a's and even number of b's
State 2: odd number of a's and even number of b's
State 3: even number of a's and odd number of b's
State 4: odd number of a's and odd number of b's
What is the number of states in a minimal FA which accepts all strings over (0,1)* where every string starts with 100 and
the length of the string is congruent to 1(mod4)
I am getting 11 states. Ans given is 8. While doing the cross product , is it ensured that , I will get the minimal DFA ? or do I
have to minimise after the cross product ?
theory-of-computation compound-automata
there are 8 states inclusive of dead state , sorry for the small size but I tried resizing it but it is not getting uploaded then
,But I hope its clear , u can open the image in new link tab.
If Language L1 is reducible to L2 and L2 reducible to L1, then shouldn't they both be Recursively Enumerable Languages? I
am really confused with the option given.
Construct Minimal FA that accept all binary strings ends with 01 AND length of string is EVEN .
Also find no of states in its minimal FA
compound-automata minimal-state-automata
1. All binary strings ending with 01, having regular expressoin (0 + 1) ∗ 01, having DFA M1
2. All binary strings of even length , having regular expression ((0 + 1)(0 + 1)) ∗ , having DFA M2
Take Intersection of M1 and M2 , using cross product, having x0 y0 as start state and x2 y0 as final states( where we have both
finals together)
Q\ Σ 0 1
→ x0 y0 x1 y1 x0 y1
x1 y1 x1 y0 x2 y0
x0 y1 x1 y0 x0 y0
x1 y0 x1 y1 x2 y1
x2 y0∗ x1 y1 x0 y1
x2 y1 x1 y0 x0 y0
Q\ Σ 0 1
→ x0 y0 x1 y1 x0 y1
x1 y1 x0 y0 x2 y0
x0 y1 x0 y0 x0 y0
x2 y0∗ x1 y1 x0 y1
how to approach
L = {ambn cp dq | m + n = p + q}
theory-of-computation context-free
It also can be done by a single stack. Like Push a^m and b^n, and then Pop c^p and d^q
S → aSd | X | Y | Z
X → aXc | Z
Y → bYd | Z
Z → bZc | ∊
Z → bZc | bc
i did like for stack push and pop " a & b " are coverd and later we are having stack empty? can we write this language as
theory-of-computation context-free
I think a pda cannot be drawn for this language,a stack can be used to check dependency between a and b ( push for a
&pop for b ) but for implementing dependency with c a tm will be needed thus it's nt a cfl
I read some where that if thier is one comparision at any time then only CFL otherwise CSL?
plz give proof.
context-free
Selected Answer
That is utter, absolute bullshit. The number of comparisons is ambiguous and ill-defined, so you should avoid using it to
determine where a language lies in the Chomsky hierarchy. If one could distinguish between CFL and CSL just based on
the number of comparisons, Bar-Hillel wouldn't have invented the Pumping Lemma for CFLs.
{ }
How many comparisons do you need to make in ap ∣ p ∈ Primes ? No comparisons, still CSL.
{ | }
w ≅ 0 (mod 4)
x ≥ 10, y>z
δ aw bx β γ cy dz ρ
β= γR
δ ∈ Palindromes
{ | }
α ∈ Palindromes
binary(γ) ∈ Primes OR γ = ϵ
Kolmogorov
α β γ δ complexity
δ∈ of
this answer
β ∈ Σ∗
Also, how can the production be represented in form of a formula? For example, S → aSb ∣ ε can be written as S = an bn
context-free
Selected Answer
I think this grammar is unambiguous (Note: proving unambiguity for an arbitrary CFG is undecidable!):
S → SS ∣ aA ∣ bB
A → aA ∣ α
B → bB ∣ β
About converting a grammar to a formula, the grammar is a formula! If you want a formula of the type axbycz, it is neither
always obvious nor always possible!
For example, the S → aSb ∣ SS ∣ ε can't be put into a nice looking formula. It describes balanced parenthesis, where a is the
opening paren, and b is the closing paren.
Selected Answer
For L1 we count xy using stack and if after y another y comes, it marks the start of yz and then we start popping the count
from stack. So, this is DCFL. (changing xy to yx would make it non-DCFL).
For l2 we need to see if #a ≠ #b, so we push a on stack and pop b. So, DCFL.
8.18 Context Free: Which of the language accepted by the following PDA ??
top gateoverflow.in/25178
theory-of-computation context-free
Assuming that the last state( in the transition order ) is the final state ...
The given PDA will accept the language {a xbycz : x,y,z >=0}
Please verify..
Is the grammar
S → ϵ empty?
Selected Answer
L = {ε}
Since there are no non-terminals in this grammar, it will never generate any strings. So, its language will be empty L2 = ∅
{ }
S→A
Another example would be: A→S . This grammar has a non-terminal, but it cannot be reached.
B → xyz
context-free
Selected Answer
Only L2 and L4 are CFL because there is only one comparison at one time and CFL can do one comparison.
L2 = i ≤ j or j ≤ i. So, there is no relation between i and j, and they can be anything. (The condition becomes trivial as any i
and j satisfies it). Thus, we can read all the a's without pushing into stack. To ensure that j = k, push all bs into stack.
When we encounter c's pop all b's one by one. Thus, it is a DCFL.
L4 : i = j can be checked by pushing for a's and popping for b's. If at the end of popping for b's, we end up with an empty
stack, we need to check that c's are even, which can be accomplished by a D-PDA. If we end up on a non-empty stack, we
accept. Thus, L4 is also a DCFL.
8.21 Context Free: Find the grammar that generates inherently ambiguous
context free language. top gateoverflow.in/7428
context-free theory-of-computation
IF a language is Ambiguous and that cannot be written in any other simplified way ( into unambiguous language) , then
language is Inherently ambiguous.
A Language is ambiguous if a string of language can be derived by more than one way and having different derivation
tree.
= aibick ⋃ aibjcj
S → S1 | S2
S1 → XC S2 → AY
X → aXb|ϵ Y → bYc |ϵ
C → cC|ϵ A → aA|ϵ
There is no other way to define this language , and there are strings abc, aabbcc, etc which can be derived from both S
→ S1 or S → s2 . So this language is inherent ambiguous.
a. L = { a nbndm n,m>=0 ⋃ a ibjdj i,j>=0 } which is inherently ambiguous . and strings abd,aabbdd, etc can be derived
by 2 ways
8.22 Context Free: Which of the following languages are CFL? top gateoverflow.in/471
L1 = {0 1
n m
}
∣ n ≤ m ≤ 2n L2 = {a b c
i j k ∣ i = 2j or j = 2k }
theory-of-computation context-free normal
Selected Answer
{
S→X∣Y
X → Xc ∣ P
CFG for L2 : P → aaPb ∣ ε
Y → aY ∣ Q
Q → bbPc ∣ ε
8.23 Context Free: Which of these languages are NOT context free? top gateoverflow.in/41233
Let
Which of these languages are NOT context free? Solve this question with explanation Thank you
theory-of-computation context-free
Selected Answer
l1 : This language is context free as we can push all the zeros on the stack and when 1 comes we can pop a 1, after that
when 0 comes we can again pop the zeros from the stack. If stack is empty the string is accepted else can't.
l2 : This is not context free language as if we push all the initial zeros on the stack and start to pop for each 1, we can't
compare the m number of zeros at the last.
l3 : This is not context free language. (same reason as for l2).
Let L1 = {an bmcn ∣ m, n ≥ 0} and L2 = {an cn ∣ n ≥ 0}. Both L1 and L2 are context free languages. if L = (L1 − L2 ) then L is ____.
a. Finite Language
b. Regular language
c. DCFL
d. Not DCFL
theory-of-computation context-free
Selected Answer
So,
L1 − L2 = {a b c
n m n ∣ m > 0, n ≥ 0 }
DCFL.
Consider the language L 1 = { a pbqcr / p,q,r >= 0} and L 2 = { a pbqcr / p,q,r >= 0 and p=r}
theory-of-computation context-free
Selected Answer
L1 = {ap bq cr | p, q, r ≥ 0}
L2 = {ap bq cr | p, q, r ≥ 0, p = r}
context-free
8.27 Context Free: TOC question from virtual gate top gateoverflow.in/28039
Given answer: A
Please explain
Language is regular and regular expression is : bb*cb*b Complement of L = L(G') = (a+b)* - bb*cb*b
Selected Answer
For G,
S -> bAcAb -> bcAb ->bcb
So, G is generating all strings where number of b's to the left of 'c' in the input string is greater than or equal to the
number of b's to the right. So, L(G) is context-free but not regular.
For G' we have an extra production bA -> A which can condense any number of b's. So, G' will generate all strings over b
and c containing at least one b before and after a c. This language is hence regular.
8.29 Context Sensitive: Context Sensitive Grammar - ISRO 2008/7 top gateoverflow.in/18478
S → ABCc ∣ bc
BA → AB
Bb → bb
Ab → ab
Aa → aa
A. abc
B. aab
C. abcc
D. abbc
Selected Answer
C is a useless symbol, since it cannot derive any terminal. Hence, the production S → ABCc becomes obsolete. This causes
all other symbols to become unreachable from S, they are also identified as obsolete!
Selected Answer
Complement will include all strings which are not in the given language like {a, b, c, ab, ac, ba, bc, cba, aaabbc, …}
(an bn cn )c = Σ ∗ − (an bn cn )
= {a b c ∣ p ≠ q or q ≠ r }
p q r CFL { }
∪ (a + b + c) ∗ (ba + ca + cb + cba)(a + b + c) ∗ Regular
Therefore It is a CFL as CFLs are closed under union (when we do union operation over two CFLs, we always get a CFL).
Equal No of a's ,b's and c's is not context-free, but it's complement is Context-free.
That is ,
8.31 Context Sensitive: Answer given as (C). Can't understand why ?? gateoverflow.in/36768
top
L = {0n 1n 0m ∣ n ≥ 0, m ≤ n}.
We cannot make a PDA for this as we need to do 2 infinite counts. But we can do this with an LBA and so L is CSL. Answer
should be B choice.
Let G be grammar given by all the rules except the last, and let G ′ be the grammar given by all the
rules mending the last. Which of the following is true?
Selected Answer
Now on the left of c be have only one choice bA → b, on right we have two choice Ab → A or Ab → b
so hereL(G) = {b cb | m ≥ n, m, n ≥ 1 }
m n
Now on the left of c be have two choice bA → b or bA → A ,on right we have two choice Ab → A or Ab → b
L(G ′ ) is Regular,b + cb + .
Common Data for Q14,15 &16 is given below: Ram takes two context-free languages L1 and L2
c). He forms a new language L5 by taking the first half of each string in L4 .
d). He obtains a new language L6 by taking the second half of each string in L4 .
a) finite
d).recursive set
Q15).The language L7 is
b). csl
a). recursive
Selected Answer
L= {a b a n n n |n≥1 }
{
1. aibjak | i ≠ j or j ≠ k ork ≠ i }
2. All strings starts with b.
3. a ∗ b ∗ or b ∗ a ∗ .
it will be CFL.
8.35 Counting: Let L = {a, bb} How many strings of length 10 are present in
L* ? top gateoverflow.in/15026
theory-of-computation counting
Selected Answer
as we get a string of length n, by appending "a" to a string of length n − 1 as well as by appending "bb" to a string of
length n − 2. (This works only because 'a' and 'bb' doesn't have a common character).
So,
n No. of strings
1 1
2 2
3 3
4 5
5 8
6 13
7 21
8 34
9 55
10 89
Does CSL contains empty string ? I've got contradictory statements from various sources.
Can someone for sure say whether empty string is CSL or not ! Please give the reference.
My source -> Page no 292, Chapter 11 A Hierarchy of Formal Languages & LBA, Peter linz -An Introduction To Finite
Automata, 5th Edition
"A language L is said to be CSL if there exists context sensite grammar G such that L = L(G) or L = L(G) U { }" So
Language contains empty string & Grammar does not ! as per Peter Linz "
Here
Example ->
a^nb^nc^n , n >=0, where this is CSL or Not ? This language contains empty string too !
theory-of-computation csl
Yes, it is CSL. Because empty string must be a regular language. When a string is regular and also finite, it also satisfies
higher properties like CFL, CSL and also recursive
8.37 Csl: Choose the false statement and give proper explanation to each top
gateoverflow.in/26855
L1 = {a n b 2n | n>=1 },
Selected Answer
L2 = h −1 (L1)
L2 = {p mqm, m>=1}
R= p*q*
L2 ∩R = {p mqm, m>=1}
[ note: as far as I think there are some serious typing error in this as h(q) =bb and by option a they mean same result as
I got.]
Option c is false.
Is the language given by wwRwwR, where w is any string over the binary alphabet, Context Free or Context Sensitive?
Selected Answer
L = {wwRwwR ∣ w ∈ (0 + 1) ∗ } is CSL.
Push w into stack, pop w with wR, (here stack become empty) then push w into stack , then pop w with wR, But we are not
sure (or we can't ensure) first w is same as second w, so it is not context-free.
R R
[here is another language as, L = {w1 w1 w2 w2 ∣ w1 , w2 ∈ (0 + 1) ∗ } , that is CFL.]
Is DFCL closed under complement ? If so can you provide any text for the same.
Selected Answer
Now, to get the complement of DPDA, all you have to do is to toggle the final and non-final states of the PDA. If you do
so, your PDA will still stay deterministic. Hence, DCFL are closed under compliment.
The set of all of EVEN PALINDROMES over ∑ = {0. 1} is an unambiguous language & it is not a DCFL.
a. Complement operation
c. Reversal operation
d. Prefix operation
theory-of-computation dcfl
REVERSAL
8.42 Dcfl: whether the following languages are DCFL or not??? top gateoverflow.in/32304
L1 = {an c bn } ∪ {a2n d bn }
L2 = {a3k b3k ∣ k ≥ 0 }
theory-of-computation dcfl
Selected Answer
Now If we get c, it means we have double count of b ′ s than those of a ′ s on stack. So on reading two b pop one a ( means
do nothing for one b, pop one a with one b)
Or, if we get d, it means we have same number of b ′ s, those of a ′ s. So pop one a on reading one b.
" DPDA acceptance with empty stack" & " DPDA acceptance with Final State" are not equivalent.
theory-of-computation dcfl
8.44 Decidability: Are the below two problems decidable ? top gateoverflow.in/27291
For the second one ,it is known that L' will not be CFL but then why can't we design any algorithm for it ,since it is true that
complement of CFL will never be true so then what is the essence here with respect to talking about decidable and
undecidable ?
decidability
Selected Answer
This problem is redusable to state entry problem. i.e. TM print specific letter if it enter on perticular state since state entry
problem is undecidable so it is also.
Do we reduce PCP problem to our problem X to show that X is undecidable OR we reduce the problem X to PCP to show X's
undecidability ?. A question has confused me in the terminology.
theory-of-computation decidability
Selected Answer
PCP is undecidable.
For example :
Here Q is reducible to P, that is if we know Ram can lift 5 KG dumble, it means Ram can lift any dumble of weight less
than or equal to 5 KG as lifting lighter dumble is an easier task than lifting a heavy dumble.
So we can say that Ram can lift 2 KG Dumble given he can lift 5 KG Dumble.
But note that P is not reducible to Q as the capability of lifting 2 KGs does not implies the capability of lifting 5 KGs.
Here M is reducible to N, that is if we know that Ram can not lift 2 KG Dumble then we can guarantee that he can not lift
5KG Dumble and his lifting threshold must be less than 2 KG.
Also, N is not reducible to M as if given Ram can not lift 5KGs we can not say anything about whether he would be able to
lift 2 KGs or not.
2) Decidability of a Problem is directly proportional to its easiness: So easy problems are more likely to be decidable then
the harder ones.
3) If a problem X is known to be decidable then every problem easier than X will also be decidable.
4) If a problem X is known to be undecidable then every problem harder than X will also be undecidable.
(i) If A is reducible to B and B is decidable then A must also be decidable: we know that B is decidable so we can say that
A is also decidable as A is easier than B.
(ii) If A is reducible to B and B is undecidable then A may or may not be decidable: B is undecidable but A is easier than B
so we can not say that A is undecidable.
(iii) If A is reducible to B and A is decidable than B may or may not be decidable: A is known to be decidable but since B is
harder than A we can not say anything about its decidability.
(iv)If A is reducible to B and A is undecidable then for sure B is also undecidable: A is known to be undecidable, and it is
easier than B so every problem harder than A will also be undecidable.
You can also check a previous GATE question based on the same concept
here: http://gateoverflow.in/1375/gateoverflow.in
S2: if L is R.E. and L ′ ⊆ L then L ′ is recursively enumerable because enumerator for L also enumerates L ′ .
theory-of-computation decidability
Selected Answer
S2 is false. Enumerator for L also enumerates strings in L ′ , but it might also enumerate strings not in L ′ . For example,
take L as Σ ∗ and take L ′ as a non recursively enumerable language over Σ. Now, L ′ ⊆ L
Some explanation?
decidability
(
∀x: x ∈ L1 f(x) ∈ L2 )
Further, let f −1 also be polynomial time computable.
decidability theory-of-computation
ANS (C)
It is possible to convert L1 to L2 and L2 to L1 , iff both are decidable are , both are undecidable.
1. S1 2. S2
3. Both 4. None
Selected Answer
How can a CFL be given? If it is given as the language generated by a CFG, then the problem is undecidable.
Only S1 is decidable.
I want to know how to remember which language is decidable for which property. Should I go through the proofs or should I
remember everything?
theory-of-computation decidability
Selected Answer
decidability
Is it decidable or undecidable?
decidability
Selected Answer
Given an encoding of a TM, we have to accept it if the encoded TM accepts no more than 3 words.
This is the statement of the given problem. I guess many people will have guessed the solution by now- it is undecidable
and more over not even semi-decidable because this is intuitively harder than the complement of halting problem.
We can use reduction to prove this, but it is long. So, just using Rice's theorem. We can get instances of Tyes and Tno as
follows: (any other would also do)
L(Tyes) = {0}
L(Tno ) = {0, 00, 000, 0000}
So, here L(Tyes) ⊂ L(Tno ), which means the given property (of language of Turing machines) is non-monotonic and hence as
per Rice's second theorem, the given problem is not even semi-decidable.
http://www.gatecse.in/803-2/
IF L IS DECIDABLE THEN
theory-of-computation decidability
Selected Answer
L is decidable means it is Recursive language and Recursive language are closed under Complement.So Both L and L' are
REC
8.54 Dfa: Dfa identify the language accepted by the following dfa top gateoverflow.in/35081
theory-of-computation dfa
Construct the minimal dfa that accept all binary numbers which have congruent to 2mod4
I think it is same as a language having strings ending with 10. Right na?
theory-of-computation finite-automata
Pumping Lemma used to decide/test whether the the given infinite language will be accept by DFA or Not.
Answer : D
B= a*b* and
C= (a + b)*.
A. A+B= C
B. A+Reverse(B)= C
C. Reverse(A)+B= C
D. None
finite-automata
Selected Answer
B:any no. of a's followed by any no. of b's or all strings not containing 'ba' as substring
Reverse(B):any no of b's followed by any no. of a's or all strings not containing 'ab' as substring
option b: A+Reverse(B)={ all strings containing 'ab' as substring } Union {all strings not containing 'ab' as substring} =
(a+b)* True
8.58 Finite Automata: For a length of string n,how many transactions will be
there for acceptance of the string? top gateoverflow.in/32286
For a length of string n,how many transactions will be there for acceptance of the string?
1. O(n)
2. O(n^2)
3. O(nlogn)
4. O(n^3)
theory-of-computation finite-automata
8.59 Finite Automata: Build an FA that accepts the language of all strings of
a's and b's such that next-to-last letter is an a top gateoverflow.in/10695
Build an FA that accepts the language of all strings of a's and b's such that next-to-last letter is an a.
theory-of-computation finite-automata
Selected Answer
regular expression = anything secondlast last = (a+b)* a (a+b) [ second last is a , last is either a or b ]
Let M be a DFA over the alphabet ∑ = {a,b} with exactly 2 states. Suppose further that M accepts a finite number 'n' of
distinct words. what is the maximum value of 'n' .
A) 1
B) 2
C) 3
D) 4
theory-of-computation finite-automata
M accepts only finite number of words. So, we should have a dead state and one out of two states must be a dead state
and this must be reachable from the start state. Further there shouldn't be a loop in the path from the start state to any
final state. So, the only option is for the transition on both a and b from start state to go to the dead state. This would
make the DFA accept only "empty" string by making the start state final. So, I suppose n = 0.
eg . a machine contains 2 length string ∑ = {a,b} ....... so the machine will accept finite number of elements( aa, ab
ba bb ).
but in case of infinite length line a machine starts with "a" ... then (a,ab,abb,aab,ababababba, .........so on ) .
and if a dfa contains any cycle then it will produce infinitely many sting , so for finite number of elements the dfa must not
contain any cycle . and it has only 2 states . so according to the condition if you draw this machine you will find out that
1st state must be final state and the 2nd one is used as dead state and this machine will only accept £ . If you
considered £ as word then answer will be 1 otherwise 0 . peace
finite-automata
Selected Answer
if we have n states and k input symbols and assuming that the no of final state may be any subset of these n
states.
no of final state = 2^n (as we have two possibility -->1> choose a state and keep in our subset of final state
or 2>do not choose it)
no of different dfa assuming no final state and no initial state is n^(n*k) because
input alphabate a b
so,total no of state= (no of way to select initial state)(no of way to select final state)(no of way to select
different dfa with is not designated by a final state or initial state)
= 1*2^n*n^(k*n)
8.61 Finite Automata: How many DFA with 4 state can be constructed over
alphabet a and b with desiginated intial state? top gateoverflow.in/14667
Please tell the approach , I am not getting that when initial state is designated then won't we consider it as like 4C1 since
any of the four states could be initial state since we don't know which of the states would be designated ?
finite-automata
Selected Answer
Initial state is fixed. Now from initial state, transitions for symbols a and b can be to any of the 4 states, so there are
4 ∗ 4 = 24 possibilities. Similarly, from 2nd, 3rd and 4th state, there are 24 possible transitions for each state i.e. we have
24 ∗ 24 ∗ 24 ∗ 24 = 216 possible transitions.
Each state also has 2 possibilities of being final state or not, so there are 24 possibilities for choosing final states.
theory-of-computation finite-automata
Selected Answer
B Statement is Correct.
Different DFA possible for a Language but Minimal DFA for a language is unique and here every model accepting same
language.
finite-automata theory-of-computation
now power(TM)>power(PDA)
power (PDA)power(FSM)
so A and C both are correct.
FSM+3stacks doesn't produce any benefit over FSM +2 stacks as both are TM only.
c) The nfa model always has more number of states than the dfa.
finite-automata theory-of-computation
Rest of three option may or may not true. No relation between no of states in DFA,NFA and epsilon NFA. (Max no of states
in DFA of n state NFA is 2^n. But that is maximum)
8.65 Finite Automata: What is the relation between S and S , where top
1 2 gateoverflow.in/17360
Let S1 be the size of the smallest DFA that accepts all strings, that when interpreted as an integer are multiples of 5.
Let S2 be the size of the smallest DFA that accepts all strings beginning with 1, that when interpreted as a binary integer are
multiples of 5.
theory-of-computation finite-automata
Selected Answer
If string w represents integer i, from start state Q 0 ,then assume on input string w we will go to state that corresponds
to Q (i mod 5 ) state.
( )
That is, δ Q 0 , w = Q (i mod 5 )
For example,
If w = ‘‘100 " , then i = 4.
( )
Thus δ Q 0 , ‘‘100 " = Q (4 mod 5 ) = Q 4 .
Since w represents the integer i, ‘‘w0 " will represent (2 × i) (left shifted w).
So, the transition from any state Q (i mod 5 ) on ‘‘0 " will be to the state Q (2i mod 5 ) .
(
That is, δ Q (i mod 5 ) , ‘‘0 " ) = Q (2i mod 5 ).
For example,
If w = ‘‘100 " then i = 4.
(
Thus δ Q 4 , ‘‘0 " ) = Q (2 ×4 mod 5 ) = Q3.
Similarly, ‘‘w1 " represents (2i + 1).
So, transition from state any state Q (i mod 5 ) on ‘‘1 " will lead us to the state Q (2i +1 mod 5 ) .
(
That is, δ Q (i mod 5 ) , ‘‘1 " ) = Q (2i +1 mod 5 ).
For example,
If w = ‘‘100 " , then i = 4.
(
Thus δ Q 4 , ‘‘1 " ) = Q (2 ×4 +1 mod 5 ) = Q4.
Other than the states {Q 0 , Q 1 , Q 2 , Q 3 , Q 4 }, it will also contain 2 additional states namely Q Start , Q dead to incorporate the
mechanism of rejecting strings starting with ‘‘0 " .
(
δ Q Start , ‘‘0 " ) = QDead
δ (Q Start , ‘‘1 " ) = Q 1 .
Thus DFA for L will contain 5 states, while the DFA for L ′ will contain 7 states.
finite-automata theory-of-computation
Selected Answer
Start with an acceptable string of length k − 3, and take the D → ACD path.
Start with an acceptable string of length k − 3, and take the D → ABD path.
Start with an acceptable string of length k − 2, and take the D → BD path.
( )
N(k) = 2N k − 3 + N k − 2( )
0, 0, 2, 0, 2, 4, 2, 8, 10, 12, 26, 32, 50, 84, 114, 184, 282, 412, 650, 976, 1474, …
http://ideone.com/JtmMW1
Answer: N(11) = 32
I could not find the recurrence relation, but I solved it in this way.
The regular expression for this DFA is (01 + 01)((11)* + (010)* + (001)*)* .
In how many ways we can make a string of length 11 from the RE (01 + 01)((11)* + (010)* + (001)*)*
From the (10 + 01) part of the RE, we will always have only 2 possible choices for the 2 most significant bits of the string
i.e. for “##” .
Now for the remaining 9 least significant bits i.e. for “&&&&&&&&&” we have to dwell into the
This part can have only strings whose length is a linear combination of 2 & 3 since it is the kleene closure of strings of
length 2 and 3 only.
All possible linear combinations of 2 & 3, which will produce exactly 9 will be,
2 + 2 + 2 + 3, or 3 + 3 + 3.
We have only one choice for length 2(i.e. the string 11) and two choices for length 3(i.e. strings 010 or 001).
For the part 2 + 2 + 2 + 3 => here since the order matters and 3 has two choices, the all possible strings of this type will
be à 4C1(to choose a position for the string of length 3) x 2( to choose among 010 and 001) which gives 4 x 2 = 8.
For the part 3 + 3 + 3 => order does not matters here since all strings are of same length, but each string of lenth 3 has
two choices so it will give 2^3 = 8.
& Total possible ways of forming strings of length 2 for “##” = 2 (10 or 01).
8.66 Finite Automata: 1) How many two state FA can be drawn over an
alphabet {0,1} which accepts the empty language? top gateoverflow.in/16808
finite-automata theory-of-computation
Answer should be 20 if the Finite Automata is Deterministic, and 320 if the Finite Automata is Non Deterministic, under
the ASSUMPTION that THE START STATE IS FIXED.
1. If the FA accepts the empty set, either it has no accepting states, or it has one accepting state that you cannot reach
from the other state (which must be the start state).
2. You should decide whether two automata are the same if they differ only in the names of the states. Suppose you call
the states p and q. If I design one DFA with these states, changing the name of p to q and the name of q to p gives me a
different automaton. Are these really different? What this really asks is whether your design of the DFA includes selecting
which state is the start state, or will you simply agree that all 2-state DFA's have "the start state" and "the other state"?
Now, If the automata is a DFA whose two states are A & B, start state is FIXED to be A, and each transition is defined,
then there would be total 4 transitions possible (delta(A, 0), delta(A, 1), delta(B, 0), delta(B, 1)).
If B is not a final state then each of these transition can have 2 choices (either A or B) so it will give 2^4 = 16 DFAs.
With B as the final state (which will be not accessible from A of course), delta(A, 0), delta(A, 1) will have only one
choice(i.e. A itself) and delta(B, 0), delta(B, 1) will still have 2 choices(either A or B) so it will give 2^2 = 4 DFAs.
So under these conditions, the number of DFAs that accept empty language is 16+4=20.
In case of non – determinism, it is NOT NECESSARY TO DEFINE EACH TRANSITION so any transition can have 4 possible
choices (not defined, A, B, both A&B).
Thus using the same reasoning as used for DFA, the number of NFAs that accept the empty language will be 4^4{if B is
not a final state} + ((2^2) * (4^2)){if B is the final state} = 256 + 64 = 320.
P.S. If you are NOT ASSUMING the start state to be fixed then both of the answers will be simply multiplied by 2 (since
once A can be the the start state and once B).So there will be 40 DFAs and 640 NFAs.
The number of states in a minimal finite automata accepting the empty set is_________.
theory-of-computation finite-automata
Selected Answer
1. All strings go to one state- the reject state - there is only 1 class as per Myhill-Nerode theorem and DFA also has just 1
state and no final state.
8.68 Finite Automata: FSM for Adding two integers top gateoverflow.in/16462
finite-automata
Selected Answer
Finite Automata (FA) or Finite State Machine to add two integers can be constructed using two states:
The inputs to FA will be pair of bits i.e. 00, 01, 10, and 11
The FA starts in state 1 (since carry is 0) and inputs a pair of bits. If the pair is 11, the FA outputs a 0 and switches to
state 2 (since the carry is 1), where the next pair of bits is input and is added to a carry bit of 1.
Example: Consider the addition of 52 and 21
110100 - (binary representation of 52)
010101 - (binary representation of 21)
Since adding numbers is done from right to left, The first input symbol is 01, representing a 0 in the rightmost (binary)
digit of 52 and a 1 in the rightmost digit of 21. The machine enters state q0 (since there is no carry) and outputs a 1. The
next input is 00 because both numbers have zero as the second rightmost digit. The machine enters state q0 and outputs
0. The next input is 11. The machine enters state q1 (since the carry is 1) and outputs 0. Being in state q1 means that
there is a carry from this position into the next. And the remaining bits can be worked out to get 1001001 (i.e. 73).
theory-of-computation finite-automata
8.70 Finite Automata: Model this toy by a Finite Automata top gateoverflow.in/42863
theory-of-computation finite-automata
Selected Answer
a.
Let (XXX = L, R) denote the position of the three levers x2 , x2 and x3 respectively.
Each of the three levers has 2 states and thus we get 2 × 2 × 2 = 8 possible states. But we also need to know if we are in an
accept state or not (i.e., where the ball exited). So, this requires 16 states. Let (XXX)A denote the accept state and (XXX)R
denote the reject state. For simplicity we can avoid the accept/reject part of the state on the left side of transition as the
transition is independent of that part.
1. δ(LLL, A) = (RLL)R
2. δ(LLL, B) = (LRR)R
3. δ(RLL, A) = (LRL)R
4. δ(RLL, B) = (RLR)R
5. δ(LRR, A) = (RRR)R
6. δ(LRR, B) = (LRL)A
7. δ(LRL, A) = (RRL)R
8. δ(LRL, B) = (LLR)A
9. δ(RLR, A) = (LRR)R
10. δ(RLR, B) = (RLL)A
11. δ(RRR, A) = (LLR)A
12. δ(RRR, B) = (RRL)A
13. δ(RRL, A) = (LLL)A
14. δ(RRL, B) = (RLR)A
15. δ(LLR, A) = (RLR)R
16. δ(LLR, B) = (LLL)A
"B" comes at end and there are even number of "B"s (right most path)
"B" comes at end or there are even number of "A"s (centre path) and string length is a multiple of 4 or multiple of 4
+ 3
8.71 Finite Automata: The no. of states of the FSM, required to simulate the
behavior of a computer with a memory capable fo storing 'm' words, each of
length 'n' bits is?? top gateoverflow.in/3411
a) m x 2n
b) 2mn
c) 2m+n
d) None of these
theory-of-computation finite-automata
Selected Answer
We need to find the number of different configurations possible for memory and each of these will be a state in FSM. (At
any time memory will be in one configuration and in next instance it either remains same or goes to a different
configuration)
A word is of n bits. And we have m such words. So, total number of bits = m*n.
We need a separate state for each bit combination. So, no. of states = 2 mn.
8.72 Finite Automata: Problem in Understanding the DFA, Need Help gateoverflow.in/43609
top
In page Number 65 (Red Underline part in the given Ima ge); I understand when i=1 but unable to understand when i>1 then
how the Accepting and Non-accepting State are same.
My Point is "if i > 1 then a1 or b1 may be 1. So, then How it must be both Accepting and Non-Accepting; it may be
Accepting and Non-Accepting ".
Thanks
theory-of-computation finite-automata
8.73 Finite Automata: No. of states in the minimal finite automata which
accepts the binary strings whose equivalent is divisible by 32 is ________?
top gateoverflow.in/7703
No. of states in the minimal finite automata which accepts the binary strings whose equivalent is divisible by 32 is
________?
A. 5
B. 6
C 31
D 32
theory-of-computation finite-automata
Selected Answer
Answer is 6.
For binary strings divisible by 2 we check if the last char from right is a 0.
For binary strings divisible by 2 2 we check if the last char from right is a 00.
...
For binary strings divisible by 2 5 we check if the last char from right is a 00000
So, we need 6 states for counting the number of 0's on right, from 0 to 5.
8.74 Finite Automata: Find n(K) where K is the size of string that a DFA
accepts. top gateoverflow.in/368
Q) Can anyone explain me how i can find the no of strings of length k words that is accepted by a given DFA.
theory-of-computation finite-automata
8.75 Finite Automata: DFA to accept a binary number divisible by 2 top gateoverflow.in/10366
finite-automata
for example state is 1 and input symbol is 0 , that is(10) represent [1 x 2 + 0 ] = 2 and on dividing by 2 it gives
remainder 0
so[1 x 2 + 0 ] mod 2 = 0
[ 0 x2 + 0] mod 2 → 0
[ 0 x2 + 1] mod 2 → 1
for state 1
[ 1 x2 + 0] mod 2 → 0
[ 1 x2 + 1] mod 2 → 1
8.75 Finite Automata: NFA for the language, L= (ab, ba)* would have how
many states? top gateoverflow.in/10056
theory-of-computation finite-automata
Selected Answer
Having 3 states
have 4 states
4 states.
8.76 Flip Flop: number of states of the FSM required to top gateoverflow.in/28047
number of states of the FSM required to simulate behaviour of a computer with a memory capable of storing 'm' words ,
each of length 'n' bits is ?
finite-automata flip-flop
Selected Answer
Given answer: A
Please explain
theory-of-computation grammar
Selected Answer
D option is correct. L1 and L2 are DCFL and so are CSL also. (DCFL and CFL are not closed under intersection but CSL is).
So, their intersection is CSL- context sensitive. CSL being a subset of recursive, answer here is D.
grammar
Selected Answer
A “handle” of a string is a substring that matches the RHS of a production and whose reduction to the non-terminal (on
the LHS of the production) represents one step along the reverse of a rightmost derivation toward reducing to the start
symbol.
So option d is correct.
The given answer to the problem is 1 ('a'). But I think that strings 'a+a' & 'a*a' can also be derived from the grammar.
Please correct me if I am wrong.
theory-of-computation grammar
E->E+E-> E+a->a+a
HI,
I would like someone to give clarification on how to identify a string is which grammar. I am not able to understand the
concept well. So if someone explains ii, it will be highly appreciated. Please give examples.
Thank you.
grammar
1. If you can express the language as a regular expression then the language is Regular
2. If you can recognize the language with a stack machine (Push Down automata), then it is a context free language.
3. If you can recognize the language with a Linear bound automaton (Turing machine with a finite tape), then its a context
sensitive language.
4. If you cannot construct any of the above , then it belong to Phase structured language.
Turing machine can be constructed for recognizing any recursively enumerable language.
a. S → aSa | bSb | a
b. S → aS | bS | aA | bA
A → bAc | ϵ
c. S → aA | ϵ
A → Sb
d. None of these
Selected Answer
c). L3 = {an bn ∣ n ≥ 0}
theory-of-computation identify-class-language
This is CFL , since u have to keep track of no of a's with no of b's , which can't be done by a finite automaton therefore u
need to design a PDA for it. Changing n >= 1 to n >= 0 can make it regular as then the given language will be reduced to
(a + b) ∗ .
(A) Only I (B) Only II (C) Both I & II (D) Neither I nor II
theory-of-computation identify-class-language
Selected Answer
I. is regular , all strings over {0,1} that start and ends with same symbol.
II. is also regular. we need to remove first symbol from stings accepted by L
Design DFA for L, Move with one transition from start state, and the states we reach, say some Q,mark them as new start
state, it seems we have more than one start states, then add a new state as start state and connect it with these Q with
null move.
Example
L = { all strings over {0,1} those start with 00 }, having regular expression 00(0+1)*
DFA for L
on giving symbols { 0,1} at start state we reach to q1 and q3, add new start state and connect it with q1 and q3 with ∊
moves.
After removing Null moves (∊-moves) , we have new DFA for Late(L)
having language Late(L) = { all strings over {0,1} those starts with 0 } having regular expression 0(0+1)*
Let L1 and L2 be languages over Σ and assume that L1 ∩ L2 = ϕ. if L1 is finite language and L1 ∪ L2 is regular then L2 is ____ ?
d. None of these
identify-class-language
Selected Answer
Let L2 = compl(L1). Now, L1 intersect L1 is empty and L1 union L2 is ∑* and hence regular. And L2 here is regular and
infinite - so A option is eliminated.
Now, we have L1 union L2 as regular and hence we have a DFA (say D) for it. We also have DFA for L1 (say D1). Now, we
can make a DFA for L2 (say D2) by doing D intersect compl(D1), as complement of a regular language is regular and
regular set is closed under intersect. So, L2 must be regular.
Now, consider L2 = {}. Now, L1 intersect L2 is empty and L1 union L2 is L1 which is regular. But here, L2 is regular and
finite.
a)Regular
d)none of these.
identify-class-language
Yes It will be Recursive and can't be CFL bcz if the length is in square i.e power is non-linear and whenever the length is
non linear like factorial, underoot etc then it can't be CFL
L={w0w ∣ w ∈ (0+a+b)*}
identify-class-language
8.87 Identify Class Language: Identify the class of the language top gateoverflow.in/17460
theory-of-computation identify-class-language
Selected Answer
The condition to be checked here is no. of b's following a's should be more than the no. of a's but less than twice the no.
of b's. This cannot be done using a DPDA. But for each a we can non-deterministically guess that it can generate either
one b or two bs and this way we can make a PDA. The context-free grammar would be
S → aSb ∣ aSbb ∣ ϵ
Let L1 and L2 be languages over Σ and assume that L1 ∩ L2 = ϕ. if L1 is finite language and L1 ∪ L2 is regular then L2 is ____ ?
d. None of these.
identify-class-language
As L1 is regular and L1⋃L2 is regular then L2 must be regular as RL are closed under Union. But we can't say whether L2
is finite or infinite bcz it may be or may not be finite... Correct me if I am wrong
8.89 Identify Class Language: Identify the class of the language top gateoverflow.in/20798
theory-of-computation identify-class-language
Selected Answer
Hence, it is regular.
Regular. The key observation here is that successive occurrences of abb and of bba in any string over {a, b} must alternate
along the string. To see this, one can show that in any string w, between any two occurrences of abb there is an
occurrence of bba and vice versa. Consider an arbitrary substring of w delimited by two occurrences of abb. This string has
the form abbuabb, where u is a possibly empty string. If u contains no a symbols, then the string bbua ends in bba.
Otherwise, suppose that the first a in u occurs at position i; then the string bbu1 . . . ui ends in bba. For the other direction,
again consider an arbitrary substring of w delimited by two occurrences of bba. Then the reversal wR of w has the form
abbuabb for some string u. By the above argument, wR must contain bba as a substring, so w itself contains an occurrence
of abb. For a string w, let D(w) denote the difference between the number of occurrences of abb and of bba in w. By the
above argument, for anyw, ∣ D(w) ∣≤ 1. At this point it is not difficult to see what a DFA for our language should look like.
The states should keep track of the last two symbols seen, as well as the sign of the quantity D(w). (See diagram; the
start state is qst, and the accept states are marked in thicker lines.)
(d) There exists a cfg generating the complement of the language {ww ∣ w ∈ (a + b) + }
CFLs are not closed under complement. So , how can the answer be (d) ?
theory-of-computation identify-class-language
Selected Answer
A. is clearly CSL. // CFL can do string matching in reverse order like WW r but not as WW
B. Power is quadratic . So it cant simulated by PDA .. LBA needed..
C. Again CSL. two infinite comparison on same variable 'n' simultaneously.. PDA cant simulate.
D. Yes complement of WW IS CFL.. How complement of CSL will be CFL ??
LET A be CFL & its complement is B which is CSL.. now some one asking what is complement of CSL 'B' ?? Obviously
answer will be A which is CFL only..
CFG for complement of WW :
Every odd length string will be in complement of WW.
S(odd) ----> 0A | 1A | 0 | 1
A ----> OS(odd) | 1S(odd)
S(even) ----> BC | CB
B ----> DBD | 0
C ----> DCD | 1
D ----> 0 | 1
L1 = {ww ∣ w ∈ (a + b) } +
L2 = {a b c
n n n ∣n≥1 }
L3 = {a b a b ∣ i, j ≥ 10 }
i j i j
L4 = {a b ∣ i, j ∈ (a + b) }
i j +
theory-of-computation identify-class-language
Selected Answer
K2 , complement of L2 is CFL.
As it includes
1. {aibjck, i ≠ j or j ≠ k or k ≠ i}
As It includes
1. {aibjakbl, i ≠ k, or j ≠ l}
4. All strings start with b, all string start with a and end with a , a ∗ b ∗ ,b ∗ a ∗ may be something more.
It seems typo there as i, j ∈ (a + b) + should be something as i, j ≥ 0 or i, j ≥ 1 or something similar, but any ways L4 is
regular, so its complement too.
8.92 Identify Class Language: Regular/ Non Regular . Why is L2 not regular
? top gateoverflow.in/30000
theory-of-computation identify-class-language
Selected Answer
L1 is regular, having regular expression (aa) ∗ (bb) ∗ + a(aa) ∗ b(bb) ∗ , either both m and n are even or both are odd then m + n will
be even
in case of L2
L2 = {ambn | m − n = 4}
= {ambn | m = n + 4}
= {an +4 bn }
= {aaaaan bn }
L2 is CFL.
a. {ambn cn | m! = n}
d. None of these
theory-of-computation identify-class-language
Selected Answer
for cfl if there is one comparison at one time then its a CFL.
a) ambn cn | m!=n
here two comparison first b= c and a !=b & c so not a cfl
so option c
8.94 Identify Class Language: please give proper explanation top gateoverflow.in/30762
theory-of-computation identify-class-language
Selected Answer
Regular language is closed under union. So, if we take union of 2 regular languages, we must get a regular language.
Thus, 4 is the correct answer here.
3 also won't prove L non-regular as regular union regular is regular (non-regular union regular can also be regular).
8.95 Identify Class Language: c is which type of language and why top gateoverflow.in/44238
identify-class-language
Selected Answer
Source:http://poj.org/problem?id=3220
But C has some additional feature eg. * is used as multiplication and pointer ,& is used with address and bitwise operator
etc
which can,t be handled by CFG. For handling such kind of information a Context Sensitive Grammar is required.
SO Option B is Correct.
PS: C language is not context free means using just a PDA we cannot determine if an input C program is valid (obeying C
syntax) or not.
8.96 Identify Class Language: If L2 is DCFL ,how to draw its DPDA? top gateoverflow.in/30897
L1 = {(xy)m(yz)m , m ≥ 1}
theory-of-computation identify-class-language
Selected Answer
having DPDA
having DPDA
8.97 Identify Class Language: which of these are regular sets ? top gateoverflow.in/35915
L1 = {a bp q ∣ p + q ≥ 106 }
L2 = {a bm n ∣ m − n ≥ 106 }
In both of these there is a comparison between no of a's and b's so I guess both of them should be non-regular sets but why
only L2 is non-regular ?
regular-set identify-class-language
Selected Answer
suppose we have some another number 4 instead of 106 , It is just to understand what is the meaning of conditions in L1
and L2 .
LA = {ap bq ∣ p + q ≥ 4}
Here it means each string must have length ≥ 4 and it must be in "no of a ′ s followed by no of b ′ s"
So What we need to do , need to ensure length of strings must be at least 4.(and I hope, it can be easily done by FA.)
LB = {ambn ∣ m − n ≥ 4}
Push a ′ s into stack , on reading b ′ s , pop a ′ s. At the end of b ′ s, check there are at least 4a ′ s left on stack (as, pop these a's
one by one with state change with ϵ )
Similarly, in L2 , we need to check No of a ′ s are atleast 106 more than No of b ′ s , we need stack for it, So it is non-
regular.
L1:
It's regular because only thing we have to satisfy here is length of string.we are not required to count occurrences of a&b.
A finite automaton is possible to construct whose final state will be there only on/after 10^6 length strings have already
been processed by dfa.
L2:
In language 2 there is comparison involved ,the difference between the occurrences of a and occurrences of b should be
atleast 10^6.
There are infinite strings composing of alphabet a & b whose differences would yield 10^6. So here we can't draw finite
automaton.
A) Regular
B) CFL
C) CSL
D) Rec
theory-of-computation identify-class-language
Selected Answer
Language is CFL
S → XY | YX
X → ZXZ | 0
Y → ZYZ | 1
Z → 0|1
L3 = L1 ∪ L2 or L3 = L1 ∩ L2
identify-class-language
If L1 = ϕ, L3 = L1 ∪ L2 = L2. Now, if L2 is r.e. but not recursive, options A, B and C are false. Not sure of option D.
Consider
L1 = {a b c d
n n m m ∣ m, n ≥ 1 }
L2 = {a bn n ∣n≥1 }
L3 = {(a + b) }∗
L1 - L3 is
(A) Regular (B) CFL but not regular (C) CSL but not CFL (D) None of these
theory-of-computation identify-class-language
Selected Answer
CFL
L1 − L3 = L1 , hence CFL
Proof,
L1 − L3 = {abcd, aabbcd, aaabbbccdd, …} − {ϵ, a, b, ab, aab, …}
= {abcd, aabbcd, aaabbbccdd, …}
= L1
A ′ = {xy | x1y ∈ A}. That is, A ′ consistes of all the strings obtained from a string in A by deleting in A by
(A) Regular
identify-class-language regular-set
Selected Answer
A is regular
There will be at least one transition in M such as q × 1 → q ′ ,where q ≠ q ′ ,while moving from start state to final state, and
not in closure (not is closed loop, x1y guaranteed for such transition), replace 1 by ϵ in that one transition as q × ϵ → q ′
so , after converting ϵ − NFA to DFA, that will be DFA of A ′
A ′ will be Regular
Selected Answer
Hence, regular.
Plz explain..
..........Is there any criteria on the basis of which we could identify inherently ambiguous grammar
theory-of-computation inherently-ambiguous
Answer is C
First of all , Inherent ambiguity term is used for language, not for grammar.
There is a CFG S → aS | Sa | a , which is ambiguous as we can derive one word say , aa, using different ways and having
different tree also. This CFG is ambiguous but language is not inherent ambiguous.
So you can say, for a language for which no unambiguous grammar is possible is inherent ambiguous
language
As in option C , language is two different language for which CFG cannot be designed without using
S → S1 | S2
where S1 → XY
X → aXb | ab
Y → cYd | cd
Z → bZc | bc
[other words you can check aabbccdd or aaabbbcccddd ..i,e common in both parts of language]
Explanation is given as S1, S2, S3 dont satisfy prefix property. But, why cant they be accepted by dfa (where we dont check
prefix property satisfaction). If pda was given then they would have been right, I guess.
Selected Answer
I do not know what is DFA with empty stack. So, assuming PDA with empty stack.
S1 and S2 are finite languages and hence regular and hence CFL. S3 and S4 are CFLs. PDA with empty stack can accept
the whole CFL without any exception and the language accepted by this and the PDA with acceptance by final state is one
and the same. So, the answer should be 4 as only S5 is not a CFL.
Now, consider PDA as DPDA. Now, the language accepted by a DPDA with empty stack is a proper subset of the language
accepted by a DPDA with final state. This set (accepted by DPDA with empty stack) must obey the prefix property - if w is
in L, no prefix of w must be in L, and is exactly the same as the language generated by a LR(0) grammar.
From the given sets the first 4 do not obey prefix property:
1. a prefix of ab
2. b prefix of ba
3. aab prefix of aabbbb (not DCFL also)
4. a prefix of aa (not DCFL also)
The last one is not even a CFL. So, none of these languages can be accepted by a DPDA with empty stack. A DPDA with
final state can accept the first 2 sets but not the other two.
L is ?
ϕ, {ϵ} and Σ ∗
{ϵ} and Σ ∗
ϕ and {ϵ}
Please someone explain the meaning of ∅ and comp(∅) also. This question got me confused over the meaning of ∈ also.
Selected Answer
Let L = ϕ.
Then L ′ = Σ ∗ , (L ′ ) ∗ = (Σ ∗ ) ∗ = Σ ∗ , L ∗ = ϵ, (L ∗ ) ′ = (ϵ) ′ = Σ +
Let L = ϵ.
Then L ′ = Σ + , (L ′ ) ∗ = (Σ + ) ∗ = Σ ∗ , L ∗ = ϵ, (L ∗ ) ′ = (ϵ) ′ = Σ +
Let L = Σ ∗
Then L ′ = ϕ, (L ′ ) ∗ = (ϕ) ∗ = ϵ, L ∗ = Σ ∗ , (L ∗ ) ′ = (Σ ∗ ) ′ = ϕ
S → aSa | bSb | A
A → aBb
B → aB | bB | ϵ
a. L = {ww | w ∈ (a + b) }
R ∗
b. L = {xwabbw | w, x ∈ (a + b) }
R ∗
c. L = {waxbw | w, x ∈ (a + b) }
R ∗
d. None of these
theory-of-computation ldentify-language
Look at CFG
S ⇒ waBbwR
we can say B used for generating some sting x where x could be anything i,e x ∈ (a + b) ∗
so S ⇒ waxbwR where w, x ∈ (a + b) ∗
b should be ans
But how?
Selected Answer
Both are non-trivial property of r.e. languages and hence undecidable as per Rice's theorem. Now, for semi decidability
(answering for yes cases) of A, we can feed the Turing machine strings from L one by one (using dovetailing technique to
avoid any infinite loop for some string) and as long as the language is sure to contain at least 3 strings, it will eventually
accept 3 distinct strings and we can stop. (If there are no such 3 strings, this technique goes to infinite loop and that is
why we cannot completely decide this). For B also do the same technique using replacing 3 with 1.
So, D choice.
8.109 Madeeasy Testseries: madeeasy test series pracice test 5 toc q-13 top
gateoverflow.in/37096
Let L = {(aP)*⎜P is a prime number} and Σ={a}. The minimum number of states in NFA that accepts the
language L are ________.
i don't think it is even a regular language. then how can NFA be generated?
theory-of-computation madeeasy-testseries
Selected Answer
Ans is 3 states
Let L1 = {an bmcn ∣ m, n ≥ 0} and L2 = {an cn ∣ n ≥ 0}. Both L1 and L2 are context free languages.
If L = L1 – L2 then L is ________
Finite language
Regular language
DCFL
Not DCFL
theory-of-computation madeeasy-testseries
Selected Answer
Hence DCFL.
8.111 Madeeasy Testseries: madeeasy practice test 5 TOC q-20 top gateoverflow.in/37105
theory-of-computation madeeasy-testseries
theory-of-computation minimal-state-automata
Selected Answer
8.113 Minimal State Automata: the possible no of dfa with three states top
gateoverflow.in/11767
The possible no of dfa with three states X,Y and Z, where X being always initial state for the DFA over the alphabet
{0,1}
a)5830
b)5831
c)5832
d)5932
correct answer is option C,but what is the systematic way to get it??
the first N is for no. of way to select initial state . Here N will be 1 because they told us X is only initial state .
N^(N*M) is for no. of transition functions from a set of N*M elements to a set of N elements. .
No. of possibilities for final state = 2 3 = 8 as any subset of the set of states can be the final state.
No. of possible transition functions = Number of possible functions from a set of 6 elements (Q×Σ) to a set of 3 elements
(Q)
=36 = 729
find min no of states in dfa that accepts string begining or ending with 00 or 11
theory-of-computation minimal-state-automata
Selected Answer
DFA M1 over {0, 1}, that begins with 00 or 11 having regular expression (00 + 11)(0 + 1) ∗
DFA M2 over {0, 1} that ends with 00 or 11 having regular expression (0 + 1) ∗ (00 + 11)
DFA M using cross product of M1 × M2 having start state as { x0 , y0 } and mark final state as any state contain x3 or y3 ( and
do minimization)
8.115 Minimal State Automata: find minimal dfa for L top gateoverflow.in/1105
L = {an b: n ≥ 0} ∪ {bn a: n ≥ 1}
theory-of-computation minimal-state-automata
Selected Answer
minimal-state-automata theory-of-computation
8.117 Minimal State Automata: Finding minimum states in FA. top gateoverflow.in/38084
If it is asked for minimum states required in FA for some language, we can have both NFA and DFA, and NFA has lesser
number of states but many books write that consider DFA as default. What to take into consideration in such case?NFA or
DFA?
As per previous year solution of questions based on Minimal FA they always considers DFA if nothing is specified.
8.118 Minimal State Automata: What is the number of states in the minimal
DFA with input symbols {0,1,2} where 2nd last symbol is 1? top gateoverflow.in/7373
What is the number of states in the minimal DFA with input symbols {0,1,2} where 2nd last symbol is 1?
A. 8
B. 9
C. 6
D. None
theory-of-computation minimal-state-automata
Selected Answer
B.
Whenever the question says the nth symbol from the right side is fixed and the input language has m symbols the answer
for minimal dfa is mn . So 3 2 = 9
D. None of these
accepts all strings over the alphabet {0,1} interpreted as a binary number is congruent to zero modulo n has
a)n states
b)n-1 states
c)n+1 states
basically, i didn't get what they are trying to say in this question?( correct answer is option A )
Selected Answer
Let Σ= {a}, assume language, L= { a^(2012.K) / K> 0}, what is minimum number of states needed in a DFA to recognize
L
theory-of-computation minimal-state-automata
Selected Answer
well, according to a question for matching minimal state dfa to regular expression,following match is given to be correct,but i
don't find that correct.can you guys please try to prove it's correctness or wrongness??
but how???
Selected Answer
Let M be a Non-deterministic Finite Machine. Let G be the Regular Grammar obtained from M. Which is True?
Selected Answer
I think ans is C)
8.123 Minimal State Automata: Please post the DFA for the language. gateoverflow.in/14284
top
What are the number of final states in minimal DFA, where Σ = {a, b}, if every string starts with "aa" and length of string is
not congruent to 0 mod 4?
A. 7
B. 6
C. 3
D. 5
minimal-state-automata
Selected Answer
Final states would be only those in which remainder is not 0 mod 4 i.e. remainder is either 1,2, or 3. So there will be 3
final states.
Here is the DFA : Here number on a state shows length of string mod 4.
minimal-state-automata
Selected Answer
For L = {ϵ}
8.125 Minimal State Automata: TOC FLT Test Made Easy top gateoverflow.in/31554
Q.51
What is the number of state to accept same language by DFA for above NFA (need not minimum)?
7
9
11
16
Selected Answer
answer is 7
8.126 Minimal State Automata: confusion in finding states in minimal DFA top
gateoverflow.in/37564
number of states in the dfa which accepts the binary strings whose decimal equivalent is divisible by 5 ?
minimal-state-automata theory-of-computation
state 0: num mod 5=0 or you can say all the numbers divisible by 5 falls here this is the final state indeed
your query:0 is divisible by 5 so no need to take extra care of it... it falls in the state 0
What are the Number of states in minimum DFA that accepts Binary strings when interpreted as decimal mod 12 give 0 as
remainder.Also give DFA.
minimal-state-automata theory-of-computation
Selected Answer
I m getting 5 states
0 1
-> q0 (F) q 0 q 1
q1 q2 q3
q2 q1 q2
q3 q4 q1
q4 q0 q1
8.128 Minimal State Automata: Minimum number of states in the DFA gateoverflow.in/35606
top
What is the minimum number of states in the DFA for accepting the strings (a + b) ∗ a(a + b)(a + b)
Please explain.
Selected Answer
The given RE represents a language which contains strings which can start with anything but must end with a substring
which is all strings of length 3 starting with a.
number of states required to construct dfa accepting languages L = (ab union aba)* alphabet = {a,b} is atleast??
my view:
for intersection of 2 reg langs we take cartesian product construct dfa then we mininise it ... for union of lang containing
same symbols like (111+11)*we can enumerate and produce least no.for required states but for above question like
(ab+aba)* what should i do to solve ?
minimal-state-automata theory-of-computation
Selected Answer
Instead of any confusion, it is better to design NFA for given regular expression and convert it to DFA.
If you can do that, you can simply convert it to DFA and minimize the DFA to get this:
The minimal state DFA, accepting all strings over the alphabet {0,1} where the n th symbol in every string from the right end
is a 1, has
Answer is 2^n.
http://gateoverflow.in/544/gate1991_17-b
Generalized Regular Expression for such a DFA will be: (0 + 1)*1 concatenated with a string of (n – 1) 0’s
1. Draw the corresponding NFA – It can be drawn easily. THE NFA WILL ALWAYS CONTAIN “n + 1” STATES. (Why n + 1
states always? ? : because you have to COUNT from 1 to N+1, & each state will remember a count).
NOTE – On drawing the NFA you will notice that on the whole NFA there is ONLY A SINGLE NON DETERMINISTIC
TRANSITION. That non deterministic transition will be from the start state, on input 1.
2. Change the NFA to the minimal DFA – Subset Construction can be used in this step, to convert the NFA into a
MINIMAL DFA (Subset Construction will give a minimal DFA for any value of n, you can check it by set partitioning
etc.) Since it is known that there is only one Non Deterministic Transition for any value of n, we can guarantee that if
the number of states in the NFA is x then number of states in the corresponding DFA HAVE TO BE 2^(x – 1).(Why ? ?
: refer to CAUTION)
Summarizing:
In this question, if the NFA contains n + 1 states then the minimal DFA will have 2^((n + 1) – 1) = 2^n states.
Moreover The number of final states in the DFA will be 2^(n – 1).
Example: for n = 3,
The number of states in the NFA = 3 + 1 = 4, (say A (Initial state), B, C, D (Final State)).
The only non deterministic transition in this NFA will be delta(A, 1) = {A, B}.
States in the minimal DFA: {A}(start state), {A, B}, {A, C}, {A, B, C}, {A, D}, {A, B, D}, {A, C, D}, {A, B, C, D}.
Final States in the minimal DFA: {A, D}, {A, B, D}, {A, C, D}, {A, B, C, D}.
CAUTION: I have NO PROOFS for the argument & implication I made in Step 2 (i.e."Subset Construction will always lead
to a MINIMAL DFA in this case" & "Since it is known that there is only one Non Deterministic Transition for any value of n,
we can guarantee that if the number of states in the NFA is x then number of states in the corresponding DFA HAVE TO
BE 2^(x – 1)").I concluded them by drawing DFAs for n = 1, 2, 3 and analyzing them, but my intuition says they must be
true.
ans a)2^n
We define a removable state as a state such that if we erase the state itself & the edges that come out of it, what results is a
theory-of-computation minimal-state-automata
1. Unreachable state
L is all inputs start with a over {a,b} having regular expression a(a+b)*
in above DFA q2 is unreachable state as we start from start state to final state it can be removed
resulting DFA is
2. Equivalent states
if we look at DFA q1 and q3 are equivalent [ q1 x a -> q2 and q3 x a -> q2] so we can remove any of them say q3 , so
state and outgoing edge will be removed but what about incoming edge [q2 x a ->q3 ] so q2 x a-> q3 will be replaced by
q2 x a -> q1 [as q1 is equivalent of q3]
Q. If machine M is recognizing L with n states. Then M' recognizing L* construed using Thompson's Construction will have
___ states.
a) n
b) n+1
c) n+2
d) n-1
I know that we use Thompson's construction while converting from e-NFA. I thought if some RE is accepted with n states,
then (RE)* should also be acceptable by n states. But my book says the answer as b) n+1 states.
I am not even getting their explaination as "We need one extra state to eliminate the e-moves" . How can this be done? Can
somebody plz explain.
Thanks.
8.133 Minimal State Automata: How to approach this type of question gateoverflow.in/30667
top
The number of states in DFA which accepts a language such that each block of 4 consecutive symbols of every string contain
at least two a ′ s for Σ = {a, b} is ___________. [if String length is less that 4 then it must be accepted]
minimal-state-automata theory-of-computation
Selected Answer
No of states for accepting length 4 (or more) input in each block of 4, having 2 a ′ s = 4C2 = 6
No of states for accepting length 4 (or more) input in each block of 4, having 3 a ′ s = 4C3 = 4
No of states for accepting length 4 (or more) input in each block of 4, having 4 a ′ s = 4C4 = 1
No of states for rejecting length 4 (or more) input in any block of 4, having 1 a = 1 (dead state).
Rough DFA ( bcoz of complexity of it but correct) is given below, Name of state representing a block of 4.
state {aaba} × a → {abaa} , {aaba} × b → {abab} , {abba} × a → {bbaa}, {abba} × b → {dead state}, and so on
No of state for accepting length 2 input = 4, that is {aa}, {ab}, {ba}, {bb}
No of state for accepting length 3 input = 8, that is {aaa}, {aab}, {aba}, {abb}, {baa}, {bab}, {bba}, {bbb}
No of states for accepting length 4 (or more) input in each block of 4, having 2 a ′ s = 4C2 = 6, that is {aabb}, {abab}, {abba}, {baab}, {baba}, {bbaa}
No of states for accepting length 4 (or more) input in each block of 4, having 3 a ′ s = 4C3 = 4, that is {aaab}, {aaba}, {abaa}, {baaa}
No of states for accepting length 4 (or more) input in each block of 4, having 4 a ′ s = 4C4 = 1, that is {aaaa}
No of states for rejecting length 4 (or more) input in any block of 4, having 1 a = 1 , that is {dead state}
8.134 Minimal State Automata: minimum no of states and final states gateoverflow.in/30731
top
I solved both of these qs in a traditional way,by drawing nfa and then convert them to dfa..by tthis process ans shoulbe 4
and 2..but both of them are wrong..pls check..
theory-of-computation minimal-state-automata
Selected Answer
II. 0 + 1) ∗ 10(0 + 1) ∗ , all strings contain substring 10, need 3 states, and they are asking about final state, that is only 1.
[Note:
1. all strings ending with n length string or all string contain n length substring, will always n + 1 states in minimal DFA.
2. After conversion from NFA to DFA, there are maximum probability of minimization, always look after it.]
In this question which constant should be changed , n or k while considering the DFA since then it can be either n+1 or k+1 ?
theory-of-computation minimal-state-automata
Selected Answer
it a^3,a^6.........so
n+1 state
so n+1 required.
L1:L1 contains set of strings starting with 1010 and length of string is divisible by 4.
L2:L2 contains set of strings starting woth 1010 and its equivalent decimal value divisible by 4
theory-of-computation minimal-state-automata
Selected Answer
For L2 the decimal equivalent of binary number is divisible by 4 only when last 2 digits of binary number will have
ATLEAST 2 zeros. qR is the reject state .
regular-set myhill-nerode
Selected Answer
First of all we should specify which "equivalence relation". Since not specified, I assume based on Myhill-Nerode relation.
http://courses.cs.washington.edu/courses/cse322/05wi/handouts/MyhillNerode.pdf
Class
Strings
No.
1 ϵ
2 0
3 01
4 011
0110, 01100, 01110, ...- all strings starting with 011
5
and ending in 0
01101, 011001, 011011, ... -all strings starting with
6
011 and ending with 01
011011, 0110011, 0111011, ... -all strings starting
7
with 011 and ending with another 011.
8 All strings not starting with 011
Totally 8 equivalent classes- the last one for a dead set of strings (can never be in language after appending any string).
So, the min-DFA for L will have 8 states with one being a dead state.
The number of equivalence classes which exist for the following regular expression R are ______.
R = (a + b) ∗ b(a + b + ϵ)
Selected Answer
No of equivalence classes as per Myhill Nerode equivalence relation = No of States in Minimal DFA
Strings reaching at each state in Minimal DFA, are distinguish from strings reaching at other states, that is what equivalence class mean
here.
Other things about equivalence class is that, if x and y are two strings of same class( here reaching same state), and we append some
strings z to then i.e, xz and yz, that will also reach to same equivalence class (either same or any other). Minimal DFA serve our purpose.
first state, all rejecting strings, doesn't belong to L or given regular expression.
second state, all strings ending with b or bb, means ending with b, and accepts, (a+b)*b(∊+b)
If NFA has n states, then its DFA can have______states in worst case.
2^N
Reason;
no of subset of states=2^n(as we have 2 choices for each state either we can keep it or not in our subset )
8.140 Nfa: Consider 2 scenarios: C1: For DFA (ϕ, Ʃ, δ, qo, F), if F = ϕ, then L
= Ʃ* C2: For NFA (ϕ, Ʃ, δ, qo, F) top gateoverflow.in/15010
Consider 2 scenarios:
C1: For DFA (ϕ, Ʃ, δ, qo, F),
if F = ϕ, then L = Ʃ*
C2: For NFA (ϕ, Ʃ, δ, qo, F),
if F = ϕ, then L = Ʃ*
Where F = Final states set
ϕ = Total states set
(a) Both are true (b) Both are False
(c) C1 is true, C2 is false (d) C1 is false, C2 is true
Selected Answer
C1 is true.
C2 is not True but that doesn't mean it always false. C2 sometimes true some time false.
"C2: For NFA (ϕ, Ʃ, δ, qo, F), if F = ϕ, then L = Ʃ* . Where F = Final states set, ϕ = Total states set" is neither always
TRUE nor always FALSE.
but even one case contradict then it considered as false. so answer is Option C.
{ } {
L1 = ababn ∣ n ≥ 0 ∪ aban ∣ n ≥ 0 }
{ } {
L2 = an ∣ n ≥ 1 ∪ bmak ∣ m, k ≥ 0 }
{ } {
L3 = an ∣ n ≥ 0 ∪ bna ∣ n ≥ 1 }
theory-of-computation nfa
Selected Answer
How do I construct the intersection of two NFAs? Do I need to follow the same cross product method like the DFAs? If so,
then how do I handle the epsilon transitions?
Thanks in advance!
You can use the cross-product construction on NFAs just as you would DFAs. The only changes are how you'd handle ε-transitions. Specifically, for
each state (q i, rj) in the cross-product automaton, add an ε-transition from that state to each pair of states (qk, rj) where there's an ε-transition in the
first machine from q i to qk and to each pair of states (qi, rk) where there's an ε-transition in the second machine from rj to rk.
Alternatively, you can always convert the NFAs into DFAs and then compute the cross product of those DFAs.
Or this one
Selected Answer
ϵ-closure(q1 ) = (q1 , q2 )
ϵ-closure(q2 ) = (q2 )
We can design DFA directly by taking ϵ- closure (q0 ) , i,e, (q0 , q1 , q2 ) as start state
Q\ Σ 0 1 2
->(q0 , q1 , q2 )∗ (q0 , q1 , q2 ) (q1 , q2 ) (q2 )
(q1 , q2 ) ∗ - (q1 , q2 ) (q2 )
(q2 ) ∗ - - (q2 )
- - - -
or NFA with q0 as start state and having states q0 , q1 and q2 where q2 is final state
Q\ Σ 0 1 2
->q0 q0 , q1 , q2 q1 , q2 q2
q1 - q1 , q2 q2
q2∗ - - q2
8.144 Non Regular: If L1 is Regular, and L1UL2 is regular, then L2 is? gateoverflow.in/38228
top
Is it option B or C? How?
Selected Answer
B.
let L1=(a+b)*
8.145 Non Regular: madeeasy test series pracice test 5 toc q-19 top gateoverflow.in/37098
L = {wxwy | x,y,w∈(a+b)+}
L = {xwyw | x,y,w∈(a+b)+}
L = {wxyw | x,y,w∈(a+b) +}
All of these
Selected Answer
wxyw is csl
8.146 Normal Pda: How to draw NPDA for language L = { a^i b^j c^m | m
>= min( i,j) } top gateoverflow.in/3903
My understanding :
For Language L1 :
By looking at language , it is not possible to construct PDA as it contains 2 conditions ( i > j or i < j And m ≥ min (i,j) )
But there is No Proper Prefix getting for this language , So, Prefix property , and so L1 is DCFL ( but there is no DPDA for
L1 as per my 1st conclusion ( i.e. 2 conditions -> No PDA )
I dont know correct way to construct NPDA but I tried in following way.
1) At some point PDA will assume that i < j or i > j
condition 1st : i < j
We are interested in min , so consider only i,≥ means accept "a" and skip all "b" and for each "c" , pop each "a"
Condition 2nd: i > j
We are interested in min , so consider only j means skip all "a" and accept "b" and for each "c" , pop each "b" So it is CFL.
Please correct me if it is wrong.
If above NPDA is right , then we can construct NPDA for L2 also.
But Answer part saying L2 is not CFL.
Selected Answer
Prefix property is not obeyed by all DCFLs. It is obeyed only by those languages accepted by a deterministic PDA which
accepts by empty stack- if a prefix of the string is in L, stack should have been empty before and deterministic means, this
cannot happen.
Now, a language obeys prefix property doesn't mean it is DCFL. {a nbncn | n ≥ 1} obeys prefix property but not even CFL.
L1 = { a i bj cm | m ≥ min(i,j) }
Here number of c's is greater than minimum of number of a's and number of b's. So, we can say that if number of c's is
greater than number of a's or if number of c's is greater than number of b's, we accept. i.e.,
L1 = { a ibjcm | m ≥ i OR m ≥ j) }
The OR condition here means even though we need to do two checks, we can accept in either case and hence using non-
determinism we just need a PDA to accept L1 (we non-deterministically check if m ≥ j and if m ≥ i). So, L1 is a CFL but
not DCFL.
L2 = { a i bj cm | m ≥ max(i,j) }
L2 = { a ibjcm | m ≥ i AND m ≥ j) }
The AND condition here means we need to do two checks and even non-determinism cannot help us here. This is because
if we non-deterministically guess i ≥ j, and accept if m ≥ i, suppose if the guess is wrong, then we would have accepted a
word not in L2. (In short non-determinism can help only when we have OR condition). So, L2 is not even CFL- it is a CSL.
Σ* is a language which doesn't satisfy prefix property- (if w is in L, prefix of w can also be in L). Now, is this language not
DCFL?
Your PDA for L1 is right. But suppose you use the same PDA (suitably changed) for L2. It will accept aaabcc rt? And
aaabcc is not in L2.
Let q0 and q1 be two states, with q0 always being the initial state. Let the alphabet be {a, b}.
Then, the possible number of DFA's with only these two states q0 and q1 is?
A. 32
B. 64
C. 80
D. 120
theory-of-computation number-of-dfa
Selected Answer
answer is 64,
every alphabet has two choices on every state . as on state q1 ,0 can either go to q0 or remain on q1, so at every state 4
choices are there, ans such 2 states are there so 4*4=16 is the total number of transition possible, now for final state we
have 4 possibility, while for inital state we have just one possibility. so it will be 1*4*4*4=64. if no boundation on initial
state it will be 128. (2*4*4*4)
Total number of ways in which transition can happen in a DFA with two states = Choices at state q0 × Choices at state q1 = 4 × 4 = 16
In a DFA any state can be a final state or an initial state. Here, Input state is fixed, so we need not worry about it.
total number of possibilities for the set of final states = 4
8.148 Number Of Dfa: How many DFA's exist with three states over the input
alphabet {0,1} top gateoverflow.in/10853
Thanks in advance
Selected Answer
Input set is given. So, we have 3 parts of DFA which we can change:
1. Start state
2. Transition Function
3. Final state
Transition function is from Q ⨯ Z to Q, where Q is the set of states and Z is the alphabet state. |Q| = 3, |Z| = 2. So,
number of possible transition functions = 3(3 * 2) = 3 6
Final state can be any subset of the set of states including empty set. With 3 states, we can have 2 3 = 8 possible sub
states.
= 3 × 36 × 23 = 17496
n × nnm × 2n = nmn +1 × 2n
In a DFA there might not be a difference if start state changes- as states are unlabeled usually. In such a case, we can
divide the above by number of states giving nmn × 2n possible DFAs.
. State ↓ input → 0 1
2 X 3 3
2 Y 3 3
2 Z 3 3
Total no of DFA = 3*3*3*3*3*3*2*2*2
= 5832
No of DFA with x is starting state = 5832
No of DFA with y is starting state = 5832
No of DFA with z is starting state = 5832
Total DFA = 3*5832 = 17496
8.149 Pda: how to construct pda for a^i b^j where j!=2i+1, i>=0 top gateoverflow.in/17021
i have constructed for j=2i+1 but by complementing the states do we get actual n pda of our requirement?
whether it is decidable?
pda
Yes, but works for only deterministic PDAs and has problems and won't work straight away- see below link.
http://drona.csa.iisc.ernet.in/~deepakd/atc-2011/DPDA.pdf
pda theory-of-computation
8.151 Pda: design DPDA for the given language top gateoverflow.in/20654
pda
Selected Answer
Although it looks there are 2 conditions but there is only one condition which is m ≠ n and hence the deterministic PDA is
shown above .
L= {a bn m ∣ n > m; m, n > 0 }
a) 2
b) 3
c) 4
d) 5
theory-of-computation pda
Selected Answer
if we use stack symbols as {z0,A} where initial stack symbol is {z0} and final state is {q2} than if the transition
functions are-
q2 is final state..
We cannot accept this language using empty stack. Because aaab is in L and aaabb also in L, thus violating prefix
property. So, this language must be accepted using final state as long as PDA is deterministic.
State 3 - accept
State 4 - reject
pda theory-of-computation
Selected Answer
L = a(a + b) + b
In q0 when stack is empty and an a comes, a is pushed on stack. After this for either a or b, we reach q1 without modifying
the stack. In q1 we can ignore all a's and b's without modifying the stack. Finally, we can move to q2 on a b and this pops
the a on stack (there is non-determinism here for the given PDA). And now stack is empty and PDA reached final state.
So, L is regular but infinite.
Selected Answer
Because, First in empty stack it is taking one 'a' at the top of stack.
Now, whatever a or b it takes but it doesnot change the stack value. The stack contain only that 'a'. But it should have to
take atleast one more a or b in the string. That is why it goes to state q0 to q1. Now, at last it got one 'b' for going to next
state q3 which proceeds to final state qf.
So, here we can form regular expression and also can draw dfa for a(a+b) +b . So, it will be infinite regular language.
b) Its clearly not DCFL because on input a there are more than two transition.
Now option (c) and (a) are the remaining , both are correct but option (a) is more correct with more precise description
about the language.
Because given language can be represented using Regular Expression and Its is the language accepting all the strings
of length at least 3 which starts with 'a' and ends with 'b'.
pda theory-of-computation
L1={w|w∈∑* where w visit all state of M atleast once where M is machine accepting L1
L2={w|w∈∑* where w visit all state of M equal no of times where M is machine accepting L2
pumping-lemma
To check L={02i |i is an integer} is regular or not ....i applied pumping lemma as below...Can anyone please
explain why i am not getting it as regular ?
So, u (v)i w can be written as 0 n-1 (0n)i 0 ...Take i=0, we get 0 n-1.0=0n but 0n dont belong to language as n may be odd.So i
am not getting it as regular...
theory-of-computation pumping-lemma
Pumping lemma says that "there exists an n, u, v and w". Here you took them fixed.
Let Z = 0 2n
Now, u = 0, v = 02(n-1), w = 0.
http://www.cse.msu.edu/~torng/Classes/Archives/cse460.03spring/Lectures/Module26.pdf
8.158 Pumping Lemma: Pumping Lemma RL CFL & Pumping Length top gateoverflow.in/38445
pumping-lemma theory-of-computation
pumping-lemma theory-of-computation
http://gateoverflow.in/6350/pumping-lemma
L = {wwrx where w,x belongs to {a,b}*} is Regular definitely as w can always be considered to be Epislon. So, this just becomes (a+b)* language.
no not at all..
This is from the first chapter questions of Sipser's book on TOC. I am stuck in some of the questions where we are asked to
find the pumping length of the following languages.
1. L=0 ∗ 1 + 0 + 1 ∗ ∪ 10 ∗ 1
2. L=001 U 0*1*
3. L=0*1*
4. L=10 (11* 0)* 0
5. L= ∊
theory-of-computation pumping-lemma
Selected Answer
(Definition) If L is a regular language, then there is a number p (the pumping length) such that s is any string in L of
length p or more can be written as s = xyz, satisfying the following conditions :
2. |y|>0, and
3. |xy| ≤ p.
So we need to find the minimum length string s = xyz ∈ L such that xy iz should also be L.
Remember:
ii) y should be in closure (loop) that repeats ,so that we get xyiz∈L
iii) Don't Worry about Unions, only we need to find s = xyz ∈L that satisfying i) and ii) above said.
Now
s= xyz =101 , where x=1 , y=0 and z=1 such that xyiz∈L ( that is 10*1, look i >=0)
s= xyz = 0 , where x=∊,y=0 and z=∊ such that xy iz∈L (that is 0*∊)
Q3. L = 0*1*
Q4. L = 10(11*0)*0
s = xyz = 10100 where x=10,y=10 and z=0 such that xy iz∈L (that is 10(1∊0)*0 )
Well it looks Minimum Pumping length is 5 , But it is not, We can repeat y any time (or it should be) and y ≠ ∊ that mean
we cannot use 3 or less length string from L for pumping , So y can be 10 (minimum) so minimum string S we using for
pumping is 10100 of length 5, but length 4 string can not generated from the given language (that's not our fault). So we
can say we use 4 or more length string s for pumping that belongs to L.
Q5. L= ∊
http://geeksquiz.com/gate-gate-cs-2015-set-1-question-60/
theory-of-computation pushdown-automata
Selected Answer
Given string is 101100 now u have to find which string added to this so whole string is accepted .
push 1 push 0 push 1 push 1 push 0 push skip 0 ...then start popping on next input so .. one 0 -> 1 come pop 0... then on 0 -> 0 come cant
pop and push also so sting not accepted.
push 1 push 0 push 1 push 1 push 0 push skip 0 ...then start popping on next input so .. one 0 -> 1 come pop 0... then on 1 -> 0 come pop 1
then on 1-> 0 come pop 0.... then on 0->1 come pop 0 ...then on 1-> 0 come pop q.. noe stack is empty on null aceept the string
L = {aibjckdl ∣ i + k = j + l}
Is L context free?
If yes, then draw PDA. If no, why?
Selected Answer
So, clearly L is CFL. But we can combine the two cases and there is no guess needed making L a DCFL.
The language can be like a^n b^m c^n d^m. and cannot put in one stack. So it is not CFL
pushdown-automata
context-free rank-of-nonterminal
S -> AB
->ACD ( B-> CD )
Therefore the maximum number of non terminals from the start state is 3 .
accepts no word of length zero, no word of length one, and only two words of length two (01 and 10). There is a
fairly simple recurrence equation for the number N(k) of words of length k that this automaton accepts. Discover
this recurrence and demonstrate your understanding by identifying the correct value of N(k) for some particular k.
Note: the recurrence does not have an easy-to-use closed form, so you will have to compute the first few values by
hand. You do not have to compute N(k) for any k greater than 14.
a) N(14) = 280
b) N(11) = 76
c) N(13) = 2730
d) N(11) = 32
8.167 Recursive Recursively Enumerable: turing machine plzz xplain top gateoverflow.in/29737
Let A = {⟨M⟩ ∣ M is turing machine that halts on all inputs and L(M) = L ′ for some undecidable language L ′ }. Then A is ____
a. Regular language
b. Recursive language but not regular
c. Recursively enumerable language but not recursive language
d. Non-recursively enumerable language
theory-of-computation recursive-recursively-enumerable
Selected Answer
Now, L(M) = L' for some undecidable language L' (I suppose this is a typo or else they could have said L' is some
undecidable language and the final L' should be just L).
So, this means L(M) = complement of an undecidable language. But complement of undecidable is again undecidable. But
L(M) must be decidable. So, there cannot be any such M making A = ∅ which is a regular language.
Le = {⟨M⟩ ∣ L(M) = ϕ}
theory-of-computation recursive-recursively-enumerable
Selected Answer
Lne says the input encoded TM M should not accept an string - which means M accepts ϕ . That means if we get an string
which is accepted by M then our work is done - we get an answer for the yes part. But in case we do not get a string we
have to check all infinite strings to know finally whether it will be not equal to ϕ . Therefore we do not have answer for no
part . Hence it is RE but not recursive.
Le is not even re because we do not have answer for yes part . We have to check all the infinite strings to answer whether
it finally accepts ϕ .
We can also apply Rice's theorem here. Both Lne and Le describes non-trivial properties of r.e. languages. So, as per Rice's
theorem both are undecidable. Now, Le is a non-monotonic property ( L(Tyes) ⊂ L(Tno possible for empty set and any non-
empty set respectively). So, Le is not even r.e. as per Rice's theorem part 2. Rice's theorem part 2 cannot be used for Lne
since it is not a non-monotonic property (we cannot get any Tyes, Tno such that L(Tyes ⊂ L(Tno ). So, we cannot say if it is not
r.e. using Rice's theorem and we have to use the first method for this part.
http://www.gatecse.in/rices-theorem/
theory-of-computation recursive-recursively-enumerable
https://books.google.fr/books?
id=hsxDiWvVdBcC&pg=PA281&lpg=PA281&dq=is+the+set+of+recursively+enumerable+languages+is+countable&source=bl&ots=rdGw
DM5-zIluIIH3F-
R7ilFk&hl=en&sa=X&ved=0CCcQ6AEwAWoVChMIjMidg9vcxgIVBJQeCh2GhQvO#v=onepage&q=is%20the%20set%20of%20recursively%
ˉ ˉ
Let A and B be disjoint, R.E. languages. Let A ∪ B also be recursive enumerable. What can you say about A and B?
(a) Neither A nor B is decidable is possible (b) At least one among A and B is decidable (c) Both A and B are decidable (d)
None of above
theory-of-computation recursive-recursively-enumerable
Selected Answer
It is given A and B are disjoint. So, A ∩ B = ∅ A ′ ∪ B ′ = Σ ∗ which is regular (and hence r.e. also). So, " Let A ′ ∪ B ′ also be
recursive enumerable" is not necessary in question.
Now, I say option A is true which implies options B and C are false as option A says both A and B can be non r.e. Example
for such an A and B is given below..
A = L1 = {⟨M, w, 0⟩ ∣ M halts on w}
B = L2 = {⟨M, w, 1⟩ ∣ M halts on w}
Here L1 and L2 (variants of halting problem) are r.e. and neither is recursive. The last bit is added to ensure L1 ∩ L2 = ∅.
Selected Answer
L here describes the encoding of TM which halts for all inputs. In other words, L describes the encoding of TMs whose
language is recursive. Now, this problem can be solved easily using Rice's theorem. (part 2).
L(TM) is recursive? is a non-monotonic property, because we have a TM for which L(TM) is recursive - TM yes, and we can
have another TM for which L(TM) is non-recursive- Mno and L(TM yes) subset of L(M) no. (For example L(TM yes) is ∅ and
L(TM no) is any non-recursive language). Now, all non-monotonic property of language of TM are not-even semi decidable-
their language is not recursively enumerable. So, L is not recursively enumerable.
L' can be stated as is L(M) non-recursive? This is again a non-monotonic property as we can have L(TM yes) = a non
recursive language and L(TMno) = Σ*, so that the subset condition holds. So, L' is also non-recursively enumerable.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
The question describes a language which has the encoding of the TMs that halts for every input. Now, to say this language
is recursive, we have to make another TM (this new TM is different from the encoding of TMs in L) which accept all strings
in L (which are encoding of all halting TMs). If this new TM halts for all input, then the given language is recursive. If it
halts for strings in L (may or may not halt for strings not in L), then the given language is recursively enumerable.
(The given property is of TM and not its language. So, we can't use Rice's theorem )
So, only way is reduction. If we reduce halting problem to this problem (solve halting problem assuming solution to given
problem), then we prove that L is not recursive as language of halting problem is proved to be non recursive.
First we try to solve halting problem. We assume we have a TM M for accepting L, that is given an encoding of a TM,
our TM will say "yes" if the encoded TM halts for all inputs and "no" otherwise. Now, we want to solve halting problem
using this. Halting problem is to decide if a given TM halts for a given word w. We proceed as follows:
Given an instance of halting problem (an encoding of a TM H and a word w), we make another TM N which will take any
input but simply erases that input from the input tape and simulates the moves of H on w. If H halts on w, N halts on all
inputs. If H doesn't halt on w, N won't halt on any input - reduction is perfect. Now, we simply give the encoding of N to
our assumed TM for L- M. If L says "yes"- we can say H halts on w, if L says "no"- we can say H does not halt on w - we
have solved halting problem, which can never be done. Thus, our assumption is wrong and such an M can't exist. So, L is
not recursive.
http://www.inf.ed.ac.uk/teaching/courses/ci/documents/note09.pdf
To prove L' is not recursively enumerable: (It's easier as we can directly reduce from complement of halting problem)
We can try reduction from complement of halting problem. Complement of halting problem is given a TM H and a
word w, we have to say if H does not halt on w. We proceed as follows: (same reduction as done for halting problem).
We assume we have a TM M' which semi-decides L'- that is it says "yes" if we give encoding of a TM that does not halt on
some input. (It may say "no" or loops, if the encoded TM halts on all inputs)
Given an instance of complement of halting problem (an encoding of a TM H and a word w), we make another TM N which
will take any input but simply erases that input from the input tape and simulates the moves of H on w. If H halts on w, N
halts on all inputs. If H doesn't halt on w, N won't halt on any input - reduction is perfect. Now, we give the encoding of N
to our assumed TM for L'- M', and if M' says "yes", it means N does not halt on some input- possible only if H does not halt
on w - we solved complement of halting problem using M' which is not possible. So, M' cannot possibly exist meaning L' is
not recursively enumerable.
So, L is not recursive and L' is not recursively enumerable. The only matching option is (D) - we need not prove L is not
RE.
recursive-recursively-enumerable context-free
This implies that there exists a CFL, L such that L̃ is not Context Free.
Since every Context Free Language is also a Recursive Language, L must be a Recursive Language.
Since Recursive Languages are closed under Complement, L̃ must be a Recursive Language.
"There exists a Non-Context-Free Recursive language whose complement is not is also not Context Free."
A= {a p ∣ p is a prime number . }
It is known that A is a Non-Context-Free Recursive language.
but checking
2)If it is a non-prime,
"Complement of a Recursive but not Context Free Language is Context Free. "
If L is Turing-recongnizable. Then
ˉ
(A) L and L must be decidable.
ˉ
(B) L must be decidable but L need not be.
ˉ
(C) Either L is decidable or L is not Turing recognizable.
theory-of-computation recursive-recursively-enumerable
Selected Answer
L is r. e.,
Option C.
a. Regular language
c. {⟨M⟩ | M is a TM and there exists an input which halts within 100 steps}
Selected Answer
Option B) We are given a DFA and asked to determine if a word w belongs to it. Simulate and see if the word w goes to a
final state- always decidable. (Same works for PDA, LBA and even always halting TMs)
Option C) Give an input to TM and if the input is accepted by TM in 100 steps then it will say "yes" else "no". But there is a
catch here- we are not given the input and there are infinite possible inputs. But, in 100 steps a TM cannot process more
than 100 length of the input. So, we can simulate the given TM for 100 steps for all possible strings of length 100 (this
number is finite) and decide our problem.
Option D) L(Tyes) = Σ ∗ and L(Tno ) = {an bn ∣ n > 0}. So, this is a non-trivial property of LANGUAGE OF TM, and hence according
to Rice's First Theorem, it is undecidable. Source : http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
Option D is actually non-even semi decidable and for this we can take L(Tyes) = ϕ and L(Tno ) = {an bn ∣ n > 0}, making
L(Tyes) ⊂ L(Tno ).
8.174 Recursive Recursively Enumerable: How can we say that this language
is regular? top gateoverflow.in/16588
Let A = { < M > | M is a turing machine that halts on all inputs and L(M) = L ′ for some undecidable language L ′ }. Then A is ___
a. Regular language
Selected Answer
A is having the encoding of TMs which has certain properties. So, lets look at the property.
The property of the TM being encoded is that it halts on all inputs (which means its language is recursive) and also that its
language is the complement of an undecidable language L (in question it must be L and not L ′ ).
Some issue with the given property? Yes, there is no undecidable language whose complement is recursive(decidable) as
if L is decidable its complement must also be. So, the given property is unsatisfiable and there is no TM which satisfies this
(trivially false). This makes A = {} which is nothing but a regular language.
d. None of these.
http://gatecse.in/wiki/Closure_Property_of_Language_Families
Let M range over Turing machine descriptions, Consider the set REG = { M | L(M) is a regular set } and let the complement of
REG be Co-REG.
Selected Answer
REG contains the set of all strings which are encodings of TM whose language is regular. So, REG is deciding a property of
TM- we are lucky and can make use of Rice's theorem.
Here we want to prove whether RE or not. (Rice's theorem part 1 won't help)
So, lets see if the property is non-monotonic so that we can apply Rice's theorem part 2.
For non-monotonicity, language of TM satisfying the property must be a subset of language of TM not satisfying the
property. So, if we take L(TMyes) = ∅ and T(TM no) = any non regular language, this proves the property is non-monotonic.
So, as per Rice's theorem part 2, REG is not RE.
Using the same technique we can prove Co-Reg is also not RE. Just take L(TM yes) = any non regular language and
L(TM no) = Σ*.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
L(M) is a regular set is a non-monotonic property of r.e. languages and deciding any such property is not even semi-
decidable making REG non r.e.
For Co-Reg, L(M) is a non regular set, which is also a non-monotonic property of r.e. languages and hence Co-Reg is also
non r.e.
So, D option.
http://www.gatecse.in/rices-theorem/
PS: To show monotonicity of a property, we need a r.e. language which has the property and another r.e. language which
does not have the property and the first one a proper subset of second. For REG these languages respectively can be the
empty language and any non-regular language (just one possibility) while for C-REG these respectively can be any non-
regular language and Σ ∗ .
theory-of-computation reduction
Selected Answer
2 can be TRUE. Both can be recursive as recursive set is a proper subset of r.e. set. But 1 can never be TRUE. So, given
answer is correct. But does the "polynomial" word in question carry any significance?
To say P=NP which one of the following is sufficient? (All reductions in polynomial time)
Selected Answer
Option B is the most correct answer. (To know why it is not THE correct answer read the tail section of this answer)
A problem p in NP is NP-complete if every other problem in NP can be transformed into p in polynomial time. They have
another property that given a problem in NP and a solution, we can verify deterministically in polynomial time that the
solution is indeed a valid solution or not.
P represents the class of all problems whose solution can be found in polynomial time.
This implies that all problems in NP are solvable in polynomial time. (1)
Tail
The statement of option B is incomplete. It is not enought to say that that reduction of NPC problem to a problem in P, but
the reduction should be polynomial reduction or karp reduction.
The statement which implies P=NP would be There exist a polynomial time reduction of a problem in NPC to a
problem in P. The answer is partially correct because when we say reduction, we usually mean polynomial time
answer given is option D but it think option D should be modified to (r1 (r 1 +r2 )*)* & r1 * (r 1 +r2 )* for being it correct.
theory-of-computation regular-expressions
Yes you are right . your modified version of option D will give the right option .
if yes then what is the difference b/w a*b* and a^n b^n ?if yes what is that ? if nothing then why a^n b^n is not a regular
Language ?
Forgive me if this is a stupid question .But as a non cs student i don't know what is going on in TOC .
Selected Answer
The regular lang is accepted By a Finite state Automata . It doesnt have any memory with it .
So for the first one it doesnt have any restriction to keep track how much a and how much b it has read . it wouldnt have
restriction of a, b, aaabbbbbb, abbbb,bbbbb , aabb etc
While for the second , if it has read 3 a then it should read 3 b also , but FA doesnt have memory only , it read 3 a and
then when it start reading b , it doesnt have any idea about how much a it read .
a*b* = write any no. of a and any no. of b without any condition. ( so we can design finite automata for this which take 2
state , when we able to make FA then these language are Regular)
ex: am bn here m and n are diffrent variable so we have no restriction of no. of a and no. of b are equal , less than , greater
than etc.
an bn = always as no. of a equal to no. of b.. so we cannot create FA for it. B/C comparision is present b/w a and b. ( when
comparission present then not regular ) ex. an bn c n here comparision present among a,b,c. always equal no. of a,b,c.
Selected Answer
DFA over {a,b} that accepts all strings that doesn't contain "aa" as substring.
explain with proper procedure is diagram must for such type of questions
regular-expressions
Supose
L1={pax,jax}
L2={x,ax}
then L1/L2={pa,ja,p,j}
So here
L3=L1/L2
So option C is correct.
Consider a regular expression over the alphabet set {r, s}. The following regular expressions are to be considered
1. (r ∗ s ∗ ) ∗ + (r + s + ) ∗
2. (r + s + r + ) + + (ε + r) ∗
3. (rs ∗ + sr ∗ ) ∗ + (ε + s)
4. ((rs ∗ ) ∗ r) ∗ + ((sr ∗ ) ∗ r) ∗
theory-of-computation regular-expressions
So , if we put r as null , we would be able to get s , if we put s as null ., we will able to get all r.
Q)
a)(0+1)* & 0* + 1*
b)∅* & ∅*
answer given is option C which i got why.The problem is what is wrong with option B deemed to be true?? .also is 010
present in
0* +1*??
theory-of-computation regular-expressions
option A is wrong .
a)∅* & ∈*
in my view option A should be the correct option but answer given is option D
theory-of-computation regular-expressions
Because
(A) (1*0)*1*
(B) 0 + (0 + 10)*
theory-of-computation regular-expressions
Selected Answer
0*(10*)* = (1*0)*1*
The best method to solve this kind of problem is that to solve it by taking string as example. You just check that what is
the string which can be generated by one RE, which can not be generated by other. And for this don't take a long string
as example. Take most basic string, that will give you answer most of the time. For example lets solve the above problem.
The smallest string can be generated from the given RE ( 0*(10*)*) is "epsilon".
For this only option (C) is incorrect. Because option C ((0 + 1)* 10(0 + 1)* ) can never generate "epsilon" string.
Given RE can generate "1", but option B, can not generate "1" hence option B is wrong.
Now come to option A ((1*0)*1*). This can generate the " epsilon" string and "1" too but It can not generate a string
like "00010001000", which can be generated by our given Regular expression.
0*(10*)* =∈,0,1,10,010,0010,100...........
(a+b)*=a*(b.a*)*=b*(a.b*)*
1*(0.1*)*
p(q.p)*=(p.q)*p
(1*.0)*.1*
option A)
theory-of-computation regular-expressions
Selected Answer
yes.
(b*a*) -> a
(b*a*)2 -> b
(d*c*) -> c
(d*c*)2 -> d
Consider R1 and R2 are two regular expression then equality of two regular expression compute in
regular-expressions
www.win.tue.nl/mdseminar/pres/ploeger-19-10-06.pdf
Polynomial Time.
top
Consider the regular expression R = (a + b) ∗ (aa + bb)(a + b) ∗ . Which one of the following regular expressions describes the same
language as described by R?
R3 = (a(ba) ∗ + b(ab) ∗ ) + (a + b) ∗
theory-of-computation regular-expressions
Selected Answer
Regular expression given is (a + b) ∗ (aa + bb)(a + b) ∗ , means all strings having double letter
DFA
Option B,
{ }
a (ba) ∗ (a + bb) b (ab) ∗ (b + aa)
reach to q 1still at q 1reach to q 3
+ reach to q 2still at q 2reach to q 3 (a + b) ∗
we are at state q 3 at q 3 with anything including ϵ
R2 =
Remove Edges in between q1 and q2 and then states, we will get the exact option
Note :
1. In option A, it is wrong because of (a + b) + , once we are at state q3 , then we need minimum ϵ to reach q3 , that is missing in option A
2. In option C, R 3 can generate ϵ, a and b, but we need minimum aa or bb to reach final and as per given regular expression.
(a) (i) ,(ii) are equal and (ii) , (iii) are not .
(b) (i) ,(ii) are equal and (i) , (iii) are not .
(c) (ii) ,(ii) are equal and (i) , (ii) are not .
But , my question is :
from (ii) (a ∗ /b ∗ ) ∗ : I can derive (a/ϵ) ∗ , which can give me (a)* . Isn't it so ?
theory-of-computation regular-expressions
Selected Answer
1. (a + b)*
2. (a* + b*)* =(a+b) *
3. ((null + a)b*)* = (b* + ab*)*
= ((null + b + bb + bbb + .....) + a(null + b + bb + bbb + .....))*
= (b + a + a(all string of b) + null + (all string of b except ))* //rearranging b*
= (a +b + rest) *
As of my knowledge a/b means either a or b,so we can select any one of them.
(A) (a ∗ + b ∗ + c ∗ ) ∗
(
(B) (ab) ∗ + c ∗ ∗ )
(C) (a ∗ b ∗ c ∗ ) ∗
(D) (a ∗ b ∗ + c ∗ ) ∗
theory-of-computation regular-expressions
Selected Answer
Clearly b is the answer as we can see that every one is generating aaaaabbb while the second option is not generating it .
The approach to this question is see in option b every a is has to be followed by b because it has (ab)*, and such
restriction is not in the question.
1. (a+b)*a(a+b)*(a+b)*
2. b * a b * a (a + b)*
3. (a + b)* a b* a b*
4. b * a (a + b)* a b*
5. All are generating same language.
theory-of-computation regular-expressions
this the very simple . start with the minimum strings that can be made . starting with first string every language with a as
a substring will be accepted. and minimum string will be a .but every other language minimum string will be aa. hence 1 is
not like other.
8.193 Regular Expressions: Regular expression for all strings starts with ab
and ends with bba is. top gateoverflow.in/38246
Regular expression for all strings starts with ab and ends with bba is.
a) aba*b*bba
b) ab(ab)*bba
c) ab(a+b)*bba
d) All of the mentioned
Doubt: starting with 'ab' and ending with 'bba', so 'abba' should also be accepted right?
Selected Answer
1. (a ∗ + b ∗ ) ∗
2. (a ∗ b ∗ ) ∗
3. (a + b) ∗
4. (a + b ∗ ) ∗
5. (a ∗ + b) ∗
6. (b ∗ a + a ∗ b) ∗
7. (a + ab) ∗
8. (ba + ab) ∗
regular-expressions theory-of-computation
Selected Answer
1. (a ∗ + b ∗ ) ∗
≡ (a + a ∗ + b + b ∗ ) ∗
≡ (a + b) ∗
2. (a ∗ b ∗ ) ∗
(
≡ (ϵ + a ∗ )(ϵ + b ∗ ) ∗)
≡ (ϵ + a ∗ + a∗ b∗ + b∗ ∗)
≡ (a + b) ∗
3. (a + b) ∗
4. (a + b ∗ ) ∗
(
≡ a + (b + b ∗ ) ∗ )
≡ (a + b) ∗
5. (a ∗ + b) ∗
(
≡ (a + a ∗ ) + b ∗ )
≡ (a + b) ∗
Note: Symmetric to 4
6. (b ∗ a + a ∗ b) ∗
(
≡ (a + b ∗ a) + (b + a ∗ b) ∗ )
≡ (a + b) ∗
7. (a + ab) ∗
Not equivalent to any other of these eight RegEx-es.
8. (ba + ab) ∗
Not equivalent to any other of these eight RegEx-es. Not even to 7!
a. A + B = C
b. AR + BR = C
c. AR + B = C
d. None
theory-of-computation regular-expressions
Selected Answer
B is all strings over {a,b} that doesn't contain "ba" as substring ,i.e, a*b*
so A R + B = (a+b)* = C
Option C is correct.
8.196 Regular Expressions: DFA for the given regular expressions top gateoverflow.in/13189
1. (aa*)b
2. (abab)+(aaa+b)*
regular-expressions
Selected Answer
a)set of all strings with equal number of 0s and 1s such that no prefix has 2 more than 0s than 1s nor 2 more than 1's than
0's.
b) set of all strings of 0s and 1s whose number of 0s is divisible by 5 and whose number of 1's is even.
theory-of-computation regular-expressions
How ϕ ∗ = ϵ?
Selected Answer
ϕ = {}, which is empty set. Now by definition of *, it repeats the content of a set ZERO or more times. And anything
repeated zero time is ϵ. And nothing repeated 1 or more times is nothing.
ϕ∗ = ϵ
(A) (r + s)* = r* s*
(B) (r + s)* = r* + s*
(D) r* s* = r* + s*
regular-expressions
Selected Answer
C (r + s)* = (r*s*)*
Which of the following regular expr. Generate set of all strings not containing 100 as substring.
a. 0*(1+0)*
b 0*1010*
c. 0*1*01
d. 0 *(0+1)*
theory-of-computation regular-expressions
Selected Answer
Here is correct regular expression for it. (there may be another regular expression equivalent to it)
8.201 Regular Expressions: What is the Regular Expression for top gateoverflow.in/26894
The regular expression for the language recognized by the following Finite State Automaton is?
A. 0 ∗ ∣ 0 ∗ 1 +
B. 0 ∗ ∣ 11 ∗
C. 0 ∗ ∣ 0 ∗ 1 + ∣ 0 ∗ 1 + (0 + 1) ∗
D. None of these.
regular-expressions finite-automata
Selected Answer
A= ∈ + A0 - - - - I
B = A1 + B1--------II
A= ∈0* = 0* - - - IV
Put IV in II
B = 0*1 + B1
B = 0*11* =0*1 + - - - - V
Regular expression = A + B
= 0* +0*1 +
Option a.
regular-expressions theory-of-computation
Selected Answer
non of these since all grammar are left linear! (grammar is ambiguous only if it is left and right linear both).
Given R1 + R2 ⋅ R3 = (R1 + R2 ) ⋅ (R1 + R3 ) for any R2 and R3 . Which of the following could be correct condition which always satisfies
the above equation.
1. R1 = R2
2. R1 = R3
3. R1 = ∅
Answer is given as D
regular-expressions theory-of-computation
Selected Answer
So, they are not equal. For example consider R1 = R2 = a, R3 = b. LHS = a + ab, RHS = aa + ab
When R1 = ϕ,
regular-expressions
Alphabet: {0, 1}
There could be more than one Regular Expressions expressing the same Language.
(0 + 1)*01
(1 + 01*0)*
theory-of-computation regular-expressions
A) (1*0)*1*
B) 0+(0+10)+
C) (0+1)*10(0+1)*
well according to me in option A we can get 111111...(many no of one's) without the need of 0, but same is not the case
with the original R.E posted above, where in i have to get 0's in order to get 1's in my strings. <answer given is option A>
theory-of-computation regular-expressions
Selected Answer
theory-of-computation regular-language
Ans is b
And L={ab+ba} *
theory-of-computation regular-language
8.208 Regular Language: Why this is not a regular language? top gateoverflow.in/32989
L1 = { wxwy | x,w,y ∈ (a + b) + } ,
L2 = { xwyw | x,w,y ∈ (a + b) + } ,
L3 = { wxyw | x, y, w ∈ (a+b)+ }
How can we say that L 1 , L 2 are regular but not L 3 ? Please explain.
Selected Answer
{
L1 = wxwy | x, w, y ∈ (a + b) + }
here x, y ∈ (a + b) + means any string having length ≥ 1 ,( and not a big problem).
w w
w (something) w (something)
a(something) x amust be same as earlier y + b(something) x bmust be same as earlier y
Remember x and y can be anything having length ≥ 1 , i.e, belong to (a + b) + , we are flexible with the length of x and y ,
except 0 length .
∈ (a +b ) + ∈ (a +b ) + ∈ (a +b ) + ∈ (a +b ) +
(something)x (something)y (something)x (something)y
a a + b b
here if something is not same, we can say that something is part of x and y respectively and w is simple a or b, rest is x
and y.
L1 is Regular.
{
L2 = xwyw | x, w, y ∈ (a + b) + }
w must be same at both place having length ≥ 1 , end with a or b
w w
w (something) w (something)
must be same as earliera must be same as earlierb
x (something)a y + x (something)b y
∈ (a +b ) + ∈ (a +b ) + ∈ (a +b ) + ∈ (a +b ) +
x(something) a y(something) a + x(something) b y(something) b
here if something is not same, we can say that something is part of x and y respectively and w is simple a or b, rest is x
and y.
(a + b) + a(a + b) + a + (a + b) + b(a + b) + b
L2 is Regular.
{
L3 = wxyw | x, w, y ∈ (a + b) + }
w must be same at both place having length ≥ 1 , start with a or b
w w
w (something) w (something)
a(something) amust be same as earlier b(something) bmust be same as earlier
xy + xy
Problem Problem
∈ (a +b ) + (something) ∈ (a +b ) + (something)
must be same as earlier must be same as earlier
a (something)x y a + b (something)x y b
Problem is that, there is x in right of first something , if both did not same we can say ,that can be part of x, but there is
no x or y in left/right of second something, to absorb that. ( and there is a or b , that must be remain unchanged.)
L3 is not regular.
The language (a+b)* is regular as there is a regular expression for it.But this language contains all possible strings. So it
should imply that regular language is the super-set of all languages, but clearly it isn't!
Subsets like an bn are not regular. Can someone tell me what am I missing?
regular-language theory-of-computation
Selected Answer
Let D be a regular set. So, D contains a set of strings which all can be accepted by a FA.
This means set of all context-free languages (not set of strings, rather set of set of strings), is a super set of set of all
regular languages. No need to prove this as every regular language is a CFL and there are CFLs which are not regular.
Individually there may or may not be any subset/superset relation between a regular language and a CFL. (The relation is
between set of all regular languages (RL) and set of all context-free languages (CFL)). For example the regular set {} is a
subset of any CFL and the regular set Σ ∗ is a super set of any CFL.
(Consider Indians (set of people born in India) as a subset of Asians. Now can we say an Indian - say "Mohan" a subset of
an Asian "Lee"?)
Let take ambn than its subset 'aabb' string is not Regular . (i.e anbn ⊆ ambn)
Similarly,
Therefore, according to the properties of regular languages, it is not closed under subset or superset.
8.210 Regular Language: transition diagram for the given regular language top
gateoverflow.in/35466
L={wxwr ∣ w,x∈(a,b) *}
theory-of-computation regular-language
Selected Answer
L = {wxwR ∣ w, x ∈ {a, b} ∗ }
Language is regular , we can get all string over {a, b} from x by putting w = ϵ.
Regular expression is (a + b) ∗
----------------------------------------------------------------------------------------------------
Do we include empty string in "All strings over a's and b's", to be honest I feel that answer given is incorrect, & IT should
have been "All strings over a's and b's". Because empty string is not really a string which we should count over any alphabet.
If they have said (a+b)* as first option , it was easy & Clear. But using words instead of precise notation , makes this
question confusing. Please answer this question, what should be correct answer.
theory-of-computation regular-language
Selected Answer
Above FA is accepting all strings over a and b excluding empty string so ans should be D.
[option A, all strings over {a, b}, means all strings starting from length 0, if something not explicitly given]
regular-language theory-of-computation
Selected Answer
As any string can be break in to x and y where no of a ′ s in x = no of b ′ s in y, here we are flexible in choosing length of x and
y as per our choice.
And try any other string. remember we are flexible with length of x and y.
Selected Answer
abw = wab
{
A. wwRwwRww ∣ w ∈ {a, b} + }
B. { n
a2 an ! apq ∣ p prime, q not prime, n ≥ 1 }
{
C. wXwR ∣ w, X ∈ {a, b} + }
D. {a b a b a b ∣ i, j ≥ 1 }
i j i j i j
regular-language identify-class-language
Selected Answer
we can have a X such that first and last symbol of the string are same.
so, due to the presence of that X language is reduced to the language definition where the first and the last symbol are
same
ba
bb
ab
baa
bab
bbb
bba
abb
aab
aba
I know that the language should follow some regular pattern and we should be able to construct a regex for it in order to say
it a RL. Morever it shouldnt require any kind of extra memory to store the counts.
BUT, in this given language, I can see a regular pattern, but I am not able to construct a regex. And I think that prevois
count should be remembered by the m/c.. So it should be NRL. But my book says its a RL. I am not getting how??
P.S. I wud be thankful if somebody suggests a quick method to identify given set to be RL or NRL based on pattern.
Thanks in advance :)
Did NOT looks like a regular language. Instead of analysing the exact pattern and positions of 1's and 0's in the strings of
the language, try to count the number of 0's and 1's. You will notice that, if the number of 0's in any string of this
language is i^2, then the number of 1's have to be either (i^2 + i) or (i^2 - i). I don't think that this dependency can be
preserved by any regular language. Even it does not seems like a Context Free Language to me.
L={s belongs to (0+1)*| for every prefix s' of s|n0(s')-n1(s')<=2} where n0 is number of 0s and n1 is number of 1s.Is this
regular?If yes then why
theory-of-computation regular-language
http://gateoverflow.in/992/gate2006_29
Why is an bn ∪ a ∗ b ∗ regular ?
Does this imply that a subset of non regular language can be regular ?
Selected Answer
It is necessary to understand the set of strings that are accepted by both the languages.
So when union is done on the two languages, the resultant language is the later one i.e. a*b*, which is a regular language.
Hence the union of the two is a regular language.
be the language .
No it does not imply that a subset of non regular language can be regular.
Selected Answer
Let
As mush as I know, if there is no restriction on the maximum value of x, then it can expand as much as to cover ww, making
the language regular. Please correct me if I am wrong.
hodor it's nor regular as there always have to some x . which does not matter . but what matter is there always should be
a "w".
if it was xww where x,w belongs to (a+b)* then it was regular as what ever u give as w i will always consider it as zero.
and will consider whole string in x . so if i put w = null . then
i think it will be little bit tough to understand but i prefer to visit gate cse regular language page
http://gatecse.in/wiki/Identify_the_class_of_the_language
i) is cfl,but not dcfl,since there is non determinism (by seeing b,when top of stack is a, you can either pop it or dont do
anything and wait for c and pop one a for every c and if by the end all a's are popped for every c u can accept it or if all
a's are pooped and sill c's remain.
ii)clearly csl.
iii)cfl but again not dcfl, as u can match either a's and b's or you can see whether no of a's <> no of c's(for each c pop
one a, if at the end atleast one a remain on tos and i/p string in empty or all a's are popped off still at least one c remain
on tos u can accept it.)
8.220 Regular Language: Which of the following statements is/are True? top
gateoverflow.in/14984
(a) If R is regular and N is non-regular, then there exists R + N, which is regular.
regular-language
Selected Answer
if it is Union then ,
R U N = a^nb^n, n>=0
(in general both are true but for a particular case where L and N is precisely given it may not holds true).
L = {an bm ∣ (n + m) is even}
regular-set
Yes.
Q1:Prove that Regular Sets are NOT closed under infinite union. (A counterexample suffices).
Ans1: Consider the sets {0}, {01}, {0011}, etc. Each one is regular because it only contains one string. But the infinite
union is the set {0i1i | i>=0} which we know is not regular. So the infinite union cannot be closed for regular languages.
Where we are using U to deonte union and ^ to denote intersection. Recall the complement of a regular language is regular,
and hence the complement of a not-regular language is not regular. So we can conclude that the left hand side of the
equation is not-regular, and each term in the intersection is regular. Therefore infinite intersection does not preserve
regularity.
Please explain what is infinite union/ infinite intersection and also explain the answer
theory-of-computation regular-set
Infinite union means we do union operation infinite (uncountably many) times, same with infinite intersection.
Let r = (10 + 0) * 11(0 + 1) * be a regular expression for the regular language L and let h(0) = ab and h(1) = ba a
homomorphism. What is a regular expression for h(L)? How about h −1 (L′) if L′ is given by the regular expression r ′ = (ab
+ a) * bb(a + b) *?
8.224 Regular Set: equal number of sequence, is language regular ? top gateoverflow.in/15130
theory-of-computation regular-set
Selected Answer
L1 is well known Non Regular i.e. (00)^n(11)^n. (Since there is no common character in "00" and "11" we need to keep
count of both which is not possible with a finite automata as count can be infinite).
Let L be a regular language and w be a string in L. If w can be split into x, y and z such that | xy | ≤ number of states in the
minimal DFA for L, and | y | > 0 then,
(A) ∀i ∈ N, xyiz ∉ L
(B) ∃i ∈ N, xyiz ∈ L
(C) ∀i ∈ N, xyiz ∈ L
(D) ∃i ∈ N, xyiz ∉ L
Selected Answer
(C) ∀i ∈ N, xyiz ∈ L
8.226 Regular Set: Which of the following are useful in proving a language to
be regular? top gateoverflow.in/174
1. Myhill-Nerode theorem
2. Pumping lemma
3. Drawing an NFA
4. Forming a regular expression
Selected Answer
As from the given options, Myhill-Nerode theorem is useful by providing necessary and sufficient condition for proving that
a language regular. Pumping lemma is often used to prove that a language is non-regular. Drawing an NFA can be useful
to prove a language is regular. Forming a regular expression can also help us prove if it is a regular language
d. None of these.
Selected Answer
see what the regular expression given is doing. it will generate all string having atleast one a and it will also generate null.
now all option are either generating null or the minimum instance is containing an a. so the condition atleast on a will get
satisfied so all are subsets.
The given regular expression can generate empty string or a string containing a.
(aa)* - This can be generated by the given regular expression.
(ba)* - This could also be generated by the given regular expression.
(aa)*(ba)* - This could also be generated by the given regular expression.
Let ∑ = {a, b} and Let L = { w | w contains an equal no of occurrences of substring 'ab' and 'ba' }. Thus aba ∈ L since
'aba' contains one occurrence of 'ab' and one occurence of 'ba' but abab ∉ L.
Select one:
A. L is regular.
There can be no direct step-wise procedure to solve such questions.In the above question, we need to check option wise.
A language is said to be regular if you can construct a finite automaton for it. Here is the DFA for required language.
L is regular. Because we cannot have two ab in a string without having a ba or vice-verse. So, there are only 3 states
possible- one where number of "ab" and "ba" are same, one where number of "ab" is 1 more than number of "ba" and the
final one where number of "ba" is 1 more than number of "ab". So, we just need a finite state automata to represent this.
Given that a language LA = L1 ∪ L2 , where L1 and L2 are two other languages. If LA is known to be a regular language, then
which of the following statements is necessarily TRUE?
Selected Answer
(b) is the answer because we cannot make an irregular set S regular, by adding a finite number of elements to it. This can
be proved as follows:
R = T − (F − R) R = T ∩ (F − R) ′
Now T is regular set and F is a finite set and so F-R must also be finite and hence regular also. Regular set is closed under
complement and intersection which makes R also regular.
8.230 Regular Set: which of the following is always regular top gateoverflow.in/5068
(A) P ∩ Q
(B) P-Q
(C) Σ* - P
(D) Σ* - Q
theory-of-computation regular-set
Selected Answer
ˉ
B. P − Q won't be regular when P = Σ ∗ and Q is a CFL as this will be Q and CFL complement need not even be CFL.
8.231 Rel: madeeasy test series pracice test 5 toc q-26 top gateoverflow.in/37102
{< M > | M is a TM and there exist an input whose length is less than 100, on which M halts}
{< M > | M is a TM and L(M) = {00, 11}}
{M1, M2, M3 | L(M 1) = L(M 2) ∪ L(M3)}
All of these
Only way NFA of 6 states can be reduced to DFA of one state if all remaining 5 states of NFA are useless (Unreachable etc) &
THere are no Dead State. In any normal NFA without useless states, I think we need at least same no of states in DFA (Think
about NFA which is just DFA with minimal states. !) I do not agree to 1 , as it means that all states other than start state in
NFA was useless.
Selected Answer
Consider an NFA for Σ ∗ , one which has 6 states. Every state is an accepting state, and every state is reachable. The
organisation of the transitions is irrelevant.
Regarding "Why would someone have an NFA with 5 redundant states?", that is a different question, the answer to which
doesn't affect the fact that there can be a DFA of 1 state for an NFA of 6 states.
Consider a person who is trying to convert a complicated regex into an NFA. It might not be obvious from the regex that it
is reducible to Σ ∗ , and it might not be obvious from the NFA either. So, that makes a valid usecase for an NFA with 6
states with majority of them being redundant.
running time of NFA to DFA conversion including the case where NFA has ϵ-transition is ?
theory-of-computation time-complexity
Selected Answer
L = {⟨M⟩ ∣ L(M) = Σ ∗ }
A. L is RE but L ′ is not RE
C. L is not RE but L ′ is RE
Selected Answer
Yes. Both L and L' are not RE. We can have the same reduction as done for L(M) is infinite.
Lets assume L is RE. So, we have a TM N which will say "yes" if given an encoding of a TM whose language is Σ ∗ . Now
using N we try to solve non-halting problem as follows:
A non halting problem is given as follows: Given an encoding of TM <H> and a word w, whether H does not halt on w.
That is, we have to decide if H does not halt on w. This problem is proved to be not RE and so no TM can not even say
"yes" for "yes" case of the problem.
Now, given a halting problem (<H>, w), we proceed as follows: We make a new TM say A, which on input x, just
simulates H on w for |x| steps. If H halts on w, A goes to reject state. Otherwise it accepts. So, L(A) = Σ ∗ if H does not
halt on w and L(A) = a finite set if H halts on w. (If H halts in |x| steps for w, any string with length greater than |w|,
would certainly be not in L, making L a finite set and hence can never equal Σ ∗ ).
Now, we just give the encoding of A to our assumed TM N. If N says "accept", we have that L(A) is Σ ∗ => H does not halt
on w => we solved "yes" case of not halting problem, which is not possible. Hence, our initial assumption of L is RE is
false. L is not RE.
Proving L' is not RE is easy.
L' = {<M> | L(M) is not equal to Σ ∗ }
L(M) is not equal to Σ ∗ is a non-monotonic property of TM. Because we can take TM Tyes with L(Tyes) = ϕ and Tno with
L(Tno ) = Σ ∗ . Here, Tyes satisfies the property (of being not being equal to Σ ∗ ) and Tno does not satisfy that property and
L(Tyes) ⊂ L(Tno ), making this a non-monotonic property of TM. And hence this becomes not RE as per Rice's theorem second
part.
So, both L and L' are not RE making (D) the correct answer.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
Answer is D
A. L is RE but L ′ is not RE
C. L is not RE but L ′ is RE
Selected Answer
Lets assume L is RE. So, we have a TM N which will say "yes" if given an encoding of a TM whose language is infinite. Now
using N we try to solve non-halting problem as follows:
A non halting problem is given as follows: Given an encoding of TM <H> and a word w, whether H does not halt on w.
That is, we have to decide if H does not halt on w. This problem is proved to be not RE and so no TM can not even say
"yes" for "yes" cases of the problem.
Now, given a halting problem (<H>, w), we proceed as follows: We make a new TM say A, which on input x, just
simulates H on w for |x| steps. If H halts on w, A goes to reject state. Otherwise it accepts. So, L(A) = Σ ∗ if H does not
halt on w and L(A) = a finite set if H halts on w. (If H halts in |x| steps for w, any string with length greater than |w|,
would certainly be not in L, making L a finite set).
Now, we just give the encoding of A to our assumed TM N. If N says "accept", we have that L(A) is infinite => H does not
halt on w => we solved "yes" case of not halting problem, which is not possible. Hence, our initial assumption of L is RE is
false. L is not RE.
L(M) is finite is a non-monotonic property of TM. Because we can take TM Tyes with L(Tyes) = ϕ and Tno with L(Tno ) = Σ ∗ . Here,
Tyes satisfies the property (of being finite) and Tno does not satisfy the property and L(Tyes) ⊂ L(Tno ), making this a non-
monotonic property of TM. And hence this becomes not RE as per Rice's theorem second part.
So, both L and L' are not RE making (D) the correct answer.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
"For every non deterministic TM M1 there exists an equivalent deterministic TM M2 recognizing the same
language."
turing-machine theory-of-computation
Selected Answer
"For every non deterministic TM M1 there exists an equivalent deterministic TM M2 recognizing the same language."
This statement talks about the trivial property of Turing machines. The power of Turing machines remains unaltered in
deterministic and non deterministic states. We can build a Deterministic machine for every Non Deterministic Turing
machine.
This statement is about the non trivial properties of Turing machines, that is, if you are given two Deterministic Turing
machines, it is undecidable if they both accept the same language. You can not iterate over the ∑ ∗ to check if they are
the same.
In the first statement case we don't need to iterate over the ∑ ∗ set to prove the equivalence whereas in the second case
we need to which makes it undecidable.
Selected Answer
A is Turing recognizable if TM for A, say TA outputs "yes" for "yes" cases of A- i.e.; when M accepts at most 2 distinct
inputs. But M can loop forever without accepting more than 2 distinct inputs and we can never be sure if it will or will not
accept any more input. Thus, TA may not output "yes" for "yes" cases of the language and hence A is not Turing
recognizable.
Similarly, B is Turing recognizable if TM for B, say TB outputs "yes" for "yes" cases of B- i.e.; when M accepts more than 2
distinct inputs. If M is accepting more than 2 distinct inputs, it's possible to enumerate all strings from the language
(strings of length 1 followed by strings of length 2 and so on ) and feed to M. (We should use [ dovetailing][1] technique
so that even if some string causes TM to loop forever, we can continue progress). If M is accepting more than 2 distinct
inputs we are sure that we'll encounter those strings after some finite moves of the TM. Thus TB can always output "yes"
for "yes" cases of the language and hence B is Turing recognizable.
(It's easier to see that A and B are complement to each other. TM can say "yes" for "yes" cases of B means it can say
"no" for "no" cases of A. But to make A Turing recognizable we need the output "yes" for "yes" cases of A, which is not
the case here. )
(Once we prove that B is Turing recognizable but not Turing acceptable (recursive), there is no need to check for A. The
complement of a Turing recognizable but not Turing acceptable language is always not Turing recognizable.)
[1]: http://www.xamuel.com/dovetailing/
top
Is there a one to one correspondence between problems and languages? we interchangeably use these while discussing
decidabilility and turing machines
turing-machine decidability
no atleast now i can say they don't have one to one correspondance . same language can define more than one problem.
one problem can be a subset of another problem so more than one problem can map to more than language for example.
all number divisible by 9 will be divisible by 3 also if n>9. so language defining one problem can also define another
problem so no one to one correspondance possible
8.239 Turing Machine: Which of the folowing are R.E top gateoverflow.in/19947
Which of the following problem(s) is/are Recursively enumerable or its complement is recursively enumerable?
turing-machine recursive-recursively-enumerable
Selected Answer
1. L1 = {⟨M⟩ ∣ L(M) = ϕ}
2. L2 = {⟨M⟩ ∣ L(M) = Σ } ∗
3. L3 = {⟨G⟩ ∣ G is ambiguous }
L1 not being recursively enumerable can be proved by Rice's theorem part 2 using Tyes and Tno such that L(Tyes) = ϕ and
L(Tno ) = {a} (any non-empty set) thus L(Tyes) ⊂ L(Tno ).
L1 ′ is recursively enumerable as here we can fed the TM all strings from the language and as long as it is accepting a
string, we are guaranteed to stop at some point.
L2 ′ is not even recursively enumerable. Again we can use Rice's second theorem for this using Tyes and Tno such that
L(Tyes = ϕ (any set other than Σ ∗ would do) and L(Tno ) = Σ ∗ thus L(Tyes) ⊂ L(Tno ).
Proof for L3 being undecidable can be done by reduction from Post Correspondence Problem . But L3 must be recursively
enumerable as here we have to check if a given grammar is ambiguous- we can take each word from L and see if multiple
parse tree exists- as long as grammar is ambiguous, we will eventually get a word for which there are multiple parse
trees. L3 being recursively enumerable but not recursive would mean L3 ′ is not recursively enumerable.
Construct TM tht accept al string of a's and b's where each string is even length palindrome.(here qf is final state, q0 initial
state and B blank symbol)
If pink arrow term is replaced with halt then this TM will accept even length palindrome only and if green arrow terms are
replaced with halt thn this TM will accept odd length palindrome only.
turing-machine theory-of-computation
Selected Answer
if we removed (2) and (3) from it, It will be only for Even Palindrome
top
A. m + n
B. 8mn + 4m
C. mn
D. 4mn + m
turing-machine
answer = option D
How 4mn + m is the answer? don't know. A teacher who has been teaching TOC for GATE for many year told that he
couldn't find the solution to this question, but that's the answer for it.
Solution:
We are required to simulate this turing machine. This means that we need an alternative turing machine(coz it asks how
many symbols do we need) that can function like this turing machine but have symbols which are among one of the options
below.
Consider an alternative turing machine B such that it has only 2 internal states and atmost 4mn + m symbols, can simulate
this turing machine A.
Machine B acts like machine A, by carrying the information of internal state of A via symbols present on its own tape under
the reading head and in the cell of the tape that the reading head of A will visit next(machine B also has a copy of the
input tape which is given to A).
Machine B uses a back and forth bouncing process to keep track of which state A is in and also what elementary symbol is
needed to be put back on the tape, so that its own output matches the output of machine A.
During the bouncing process the symbol printed in the new cell works like a counter that ends on the current state of A
also, retaining information as to the symbol that was printed previously in this cell.
The symbol on the tape of machine B should be either m elementary symbols or 4mn more symbols.
Bi ,j ,x,y
Here, we see that by combination of i, j, x, y we have total number of such symbols present on the tape = m × n × 2 × 2 = 4mn
as earlier defined we need to have elementary symbols on the tape too which are to be same as those in machine A, they
are m in number
so we have a total of 4mn + m symbols for machine B which it can put on the tape.
if input tape of machine A contains the symbol A13 then at the corresponding place in input tape of machine B the symbol
present will be B13
One instance of bouncing operation in this method to result in the simulation of machine A is given in the first image
posted in this answer it is in accordance with the given operation table. Using this information we can do a walkthrough
and see that the simulation is possible.
8.242 Turing Machine: what is number of states in following Turing m/c? top
gateoverflow.in/4637
What are the min number of states in Turing machine L={0^n 1^n}
For identifying 1st 0 convert it to X(change state from q0 to q1), then bypass all 0 , on reaching 1st 1 convert to Y(change
state from q1 to q2) and move left ....by pass all 0 to reach last X in leftmost end...change state to q0 ...so that we can
again follow same process....but why a change of state is required when all 0s have been converted to X....?Why do we need
q3.....?
http://www.eecs.wsu.edu/~ananth/CptS317/Lectures/TuringMachines.pdf
Please explain..................
theory-of-computation turing-machine
Selected Answer
As per your explanation, first 0 is converted into X, and then reach to first 1 that is converted in Y and so on [ 0 to X, 1 to
Y]
Then why we need q3, To ensure all 0's is converted into X, we need to check there is a Y in right of X
for example 000111BBB... lead to X00Y11BBB.. leads to XX0YY1BBB.. leads to XXXYYYBBB... using q0,q1,q3.
B is blank symbol.
so q3 ensure there is Y in right of X(all 0's is converted to X ) , q4 to ensure after all Y there is B (Blank symbol)
Our purpose is not only to convert all 0's to X and 1's to Y, but to ensure input of language ( w ∊L) is accepted and else
(w∉ L) is to rejected
Consider the following turning machine (where,, $ is represent accept the string).
a. 10100
b. 10101
c. 10110
d. 10011
turing-machine
Selected Answer
First
b 01010b b0 1010b b01010b b010 10b b01010b b01010 b b01010b b010 10b b01010b b0 1110b b 00110b b10110b b10110b
q0 q0 q0 q0 q0 q0 q1 q1 q2 q2 q2 q2 q3
→ → → → → → → → → → → → (Accepts)
Second
The above TM is performing 2's complement of the given binary string.
Now find the first one from the right end, then after that change 0 to 1 and 1 to 0 , reach to left end and accept,halt.
Let's see
01010
so reach the right end , find the first 1, that is 010 10 , the move left and change 1 to 0 and 0 to 1, 101 10, that is 2's
complement.
C is the answer.
A. {⟨M⟩ ∣ M is a TM and there exist an input whose length is less than 100, on which M halts}
B. {⟨M⟩ ∣ Mis a TM and L(M) = {00, 11}}
C. {⟨M1, M2, M3⟩ ∣ L(M1) = L(M2) ∪ L(M3)}
D. All of these
Selected Answer
a) is recursively enumerable but not recursive. If there is such an input, then we can say "yes". But for the no case we
cannot decide as we can never be sure that such an input does not exist.
b) is not RE. We can use Rice's 2nd theorem which will be most straightforward. Here we are given the encoding of a TM
and asked if the language of that machine is {00, 11}. (This is different from asking if that machine accepts 00 and 11,
which would be RE). So, now to apply Rice's 2nd theorem, we need to make 2 TMs, TMyes and TM no, with L(TM yes) =
{00,11} and L(TMno) != {00,11} and L(TM yes) subset of L(TM no). (The last condition is for non-monotonicity).
Here, we can easily get a TM no as L(TM no) can be {00, 11, 011} or any subset of sigma star containing {00, 11} except
{00, 11}. Since we get TMyes, and TM no, the given language is not RE.
c) Checking the equivalence of language of 2 TMs itself is not even semi-decidable. So, this is a double non-recursively
enumerable language. We can use Rice's 2'nd theorem here also, by taking L(TMno) = sigma star.
A. Only (i)
B. (i) and (ii)
C. (ii) and (iii)
D. All
Selected Answer
Option 2. L1 = L2 iff L1 ∖L2 = ϕ and L2 ∖L1 = ϕ
Only i) is incorrect
L is surely decidable if
(B) L ⊆ {0} ∗
(C) L ≤m{0n 1n ∣ n ≥ 0}
(D) LR is decidable
Selected Answer
both B and D are true , If L R is decidable then we can easily construct a turing machine which reverses the input and
feeds it to turing machine for LR to get turing machine for L, so L is also decidable . Similarly if L is reducible to L1 = 0 n
1n then as L1 is decidable so L is also decidable.
virtualgate
Selected Answer
and for 2 take example . a^p where p is prime and sigma * which is regular , and now pull out intersection .
Here My explanation is :
III. We run TM for n, n+1, n+2.....infinity so if it halts we can say yes but if do not halt we can't say anything because we
have to run it infinite number of times
Is my explanation correct?
Your explaination for third one is not correct. You can not run it for infinity since there should be some limit( memory
limiation) since you are not sure it will halt or not it might be possible it may keep running forever and you are waiting for
halting because you condition atleast one is still satisfied. So, third one is not decidable.
Let L be the language over the alphabet Σ={0,1} defined by the regular expression (0 + 1) ∗ 00(0 + 1) ∗ . Which one of the
following regular expressions defines the complement of L?
a) 1 ∗ 01 ∗ 01 ∗
b) (10) ∗ 11(10) ∗
c) (0 + 10) ∗ (1 + ϵ)
d) (1 + 01) ∗ (0 + ϵ)
theory-of-computation
Selected Answer
having DFA
complement of DFA
[ it will take 2 mins by state elimination or by arden's theorem to get regular expression, or even without that , check
closures at final 1 that is one of 1 and other is 01, so at final one (1 + 01) ∗ , now concentrate on final 2 , to reach final 2, we
need final 1 followed by 0, that is (1 + 01) ∗ 0 , so regular expression (add both) is (1 + 01) ∗ (ϵ + 0).]
Another way .
b) can't not generate ϵ, 0, 1 , that cannot contain 00 as substring , as minimum length string generating from regular
expression is 11 False.
If we are asked the number of states in minimum DFA, then we have to count dead state , right ?
theory-of-computation
Selected Answer
For any PDA, make a new state and do an epsilon transition to the start state and change the start state to the new state.
Similarly make a new state and make an epsilon transition from all accept states to this new state. Now, make another
new state and make an epsilon transition from the new state to this one and make this final new state the only accept
state.
Thus we get a simple PDA for any given PDA (thanks to epsilon transitions). Now, is this possible without epsilon
transition?
test-series theory-of-computation
Selected Answer
Both are correct. MAX, MIN, ROOT, HALF, CYCLE, LOG Regular languages are closed under these operations.
Let L 1 = 0*1*, L 2 = 1*0*, L 3 = (0+1)* and L 4 = 0*1*0*. Then the number of strings in the following language L are ________.
L = (L 1 ∩ L2 ) – (L 3 ∩ L4 )
Selected Answer
L 1 ∩ L 2 = 0* + 1*
L 3 ∩ L 4 = 0*1*0*
Please list down all the decidable and undecidable problems for FA, PDA, TM.
Selected Answer
http://gatecse.in/wiki/Grammar:_Decidable_and_Undecidable_Problems
theory-of-computation test-series
answer is (ii)
correct me if wrong
8.256 How to propose a recurrence equation for a given DFA over a set of q
states? top gateoverflow.in/41867
I am not able to understand the concept of recursively enumerable.Can somebody explain in easy language what is the
difference between recursively enumerable and recursive?
//Pls tell me the difference between option A and B its very confusing to me
Consider the context free grammar G with start symbol S and productions
S -> aAB | aBA | bAA | e
A -> aS | bAAA
B -> aABB | aBAB | aBBA | bS
The language generated by this grammar is
(A) The set of all strings that have exactly twice as many a's as b's
(B) The set of all strings that have exactly twice as many b's as a's
(C) The set of all strings with same number of a's and b's
(D) None of the above
Selected Answer
Try to derive any string from the above grammar. You will only be able to derive the strings in which all strings that
have exactly twice as many a's as b's., which is option A.
Selected Answer
Integer factorization is in NP but not proved to be in NP-Hard or P. So, it can go either way in future. We have 3 choices
for L depending on this, but all the 3 choices are CFLs. So, we need not worry anything and just say L is a CFL though we
do not know exactly which CFL it is.
https://en.wikipedia.org/wiki/Integer_factorization
Prime Factorisation is One of the Undecidable problem..
i think it will be d .
It is still not know . so either it will be true or false. and definitely it is decidable it is NPc wich is a part of NP. which means
it can be solved in polynomial time .
Selected Answer
L = {a b c , n, m ≥ 0 }
2
m n n
8.260 how to implement quick sort with turing machine top gateoverflow.in/42449
TM is a Super Computer. Now question redused to "Implement QUICK SORT on Computer System"
Apply Divide & Conquer
theory-of-computation
Selected Answer
I an not getting the meaning of turing recognizable language..can someone please help..
Selected Answer
If some TM can accept all strings in a language (not accept any string not in language) then the language is Turing
recognizable (recursively enumerable).
This differs from Turing decidable (recursive) in the sense that the TM need not reject an string not in L (it may instead
loop forever). So, Turing decidable proper subset of Turing recognizable.
given 2 languages :
Selected Answer
L1 is regular
Regular expression is :
Source:http://gateoverflow.in/?qa=blob&qa_blobid=3726082460590158103
Option A.
To solve this kind of problem, think that how many stack would you need to solve the problem.
We can implement (FA + n stack with FA + 2 stack). Hence By Turing Machine, we can solve any problem.
Now look at L1, To implement this we need at least one stack, hence this is not a regular grammar, by using one stack we
can implement this language hence its is Context free languages.
L2, also can not be implemented without using stack. We need One stack to implement this. Hence this is also CFL.
So answer would be C.
Which of the following languages enforces rule that a definition should occur before the use of a variables.
Selected Answer
Option b) is correct
Suppose there are logn sorted lists of n logn elements each. The time complexity of producing a sorted list of all these
elements is (use heap data structure) (A) O (n log logn) (B) theta (n logn) (C) omega (n logn) (D) omega (n^3/2)
Since total elements are logn * n logn = n(logn)^2 . heapify procedure take O(n (logn)^2) . not in option so Omega
(nlogn)
Consider the following language L = {w∈(a + b)* w has atleast as many occurrences of (bba)’s as (abb)’s}.
Which of the following statements is/are true?
S1. Language L is regular. S2. Complement of L is CFL.
S3. Complement of L is CSL. S4. Reversal of L is CFL.
Only S1
Only S2 and S4
Only S1 and S3
All of these
Answer KEY
all of these .
I really doubt how this language is regular . could someone solve this ?
theory-of-computation
Selected Answer
option B
S->aA/abc
A->aA/bB/a
B->bB/cC/b
C->cC/c
theory-of-computation
IS it,
S->Aa
A->Aa/Bb
B->Bb/Cc
C->Cc
Selected Answer
L1 = {ambn ∣ m = 4 − n}
L1 can be written as
L2 = {ambn ∣ m = n − 4}
L2 can be written as
L2 = {ambn ∣ n = m + 4}
L3 = {ambn ∣ m − n = 4}
L3 can be written as
L3 = {ambn ∣ m = n + 4}
theory-of-computation
I strongly believe u really want to use state elimination method for this . if u want to learn u can google it out and apply .
the best and efficient way is the option elimination method . it works , fast.
1- take option 1 and 4 and make the start term null. as we can take it any number of time . i will take it zero time .
theory-of-computation
DFA M1 for a ∗ b ∗
DFA M2 for b ∗ a ∗
DFA M for a ∗ b ∗ + b ∗ a ∗ for M1 ∪ M2 as {x0 y0 } as start state, and any state having any final will be final state
Q /Σ a b
→ x0 y0∗ x0 y1 x1 y0
x0 y1∗ x0 y1 x1 y2
x1 y0∗ x2 y1 x1 y0
x1 y2∗ x2 y2 x1 y2
x2 y1∗ x2 y1 x2 y2
x2 y2 x2 y2 x2 y2
8.274 difference between derivation tree and parse tree in automata theory?
top gateoverflow.in/42364
{< M > M is a TM and there exist an input whose length is less than 100, on which M halts}
{< M > M is a TM and L(M) = {00, 11}}
{M1, M2, M3 L(M 1) = L(M 2) ∪ L(M3)}
All of these
theory-of-computation
Other applications:-
https://cs.stanford.edu/people/eroberts/courses/soco/projects/2004-05/automata-theory/apps.html
theory-of-computation
Selected Answer
NFA will be as
Or
For Reference :
http://gateoverflow.in/32989/why-this-is-not-a-regular-language
the NFA given is wrong .since it will accept string that are not in the language.
but if its in languga atleast one path will be present to final state
8.279 simulate one tape turing machine with k-tape TM top gateoverflow.in/41309
a) O(n)
b) O(n^k)
c) O(n^2)
d) none of these
C) O(n^2)
Pls draw the corresponding NFA/DFA for the given Grammar which are regular here .
Selected Answer
As
I) is generating (a + b) ∗
I have a doubt. When concatenating two languages, we take the strings of the first language and concatenate it with each string of the second
language. So if I go by the definition only, the above statement is correct.
But by taking a few examples, it seems that when we concatenate two languages, some of the strings comes out to be the same. The final
concatenated language will contain strings less than |L1| * |L2|.
Therefore, the correct relation should have been |L1. L2| <= |L1| x |L2|.
Is this the right logic to answer this question? Or did I miss out on any conceptual reasons?
theory-of-computation
Option D is the right answer. First option is incorrect because b is coming after c but according to language its not
possible. Same problem occurred in option 2 and 3 also
Give minimal DFA that performs as a MOD-3 1's counter,i.e outputs a '1' each time the number of 1's in the input sequence
is a multiple of 3.
Design a (normal) DFA that accepts strings, over { 0, 1}, that ends with 111.
Now Look at DFA, q3 is a state where we get a sequence in which no of 1 ′ s is multiple of 3. so whenever we reach q3 we get
output 1.
We can design Mealy machine for it , by getting output 1 on the incoming edges on state q3 , and output 0 at all others.
Or, We can design Moore machine, by putting output 1 on the state q3 and output 0 on others.
MOORE AND MEALY MACHINES PROBLEMS WILL COMES UNDER THE GATE CS 2017 SYLLABUS OR NOT?
T/F
made-easy
There are exactly ................ different finite automata with three states x, y and z over the alphabet {a, b} where x is
total Automata=2^3*3^6
8.288 The following machine is designed with PDA acceptence by final state
to accept odd length palindromes top gateoverflow.in/37108
Now , in the given diagram , they have not mentioned the scenario :
Now , my question is - without these two transitions can we design this pda ? ( as it is done in the given ans )
theory-of-computation
According to me this question is unclear but if we thinks that ∊ represents that at the top of the stack there can be
anything then only we can say option c is correct ..
But in gate they will not ask such unclear and confusing question...
at state B
∱(B,a,a)=(B,aa) , ∱ (B,a,b)=(B,ab)
8.289 what is the class of Min(R) for a given regular language ? top gateoverflow.in/37107
Let R be any regular set .Let Min(R) is a set of all strings 'w' in R , where every proper prefix of 'w' is not in R, then to which
class of language does this Min(R) belong ?
Selected Answer
We have a regular set and we want to remove all strings such that in our set for any string, we should not have its prefix.
Now consider the DFA for L. Take all of its final states and see if there is a path to any other final state. (This is a graph
search problem). If so, then mark that final state as non-final because this path we found is essentially adding a "suffix"
to an already accepted string in L and making another string in L. Doing like this for all final states give us the DFA for
MIN(L). So, it must also be regular.
8.290 Which of the following represent the minimum no. of states in DFA
which accept all string of length atmost 5 ‘a’? top gateoverflow.in/35797
Which of the following represent the minimum no. of states in DFA which accept all string of length atmost 5 ‘ a’?
6
4
5
7
so , won't it be 7 states ?
theory-of-computation
Selected Answer
L={anbn :n>=0 ,n!=100} how to take care of the condition that n !=100 ?
Draw a DFA for n ≠ 100. Take intersection with PDA for L with n ≥ 0.
grammar
E -> E * F / F + E / F
F -> F – F / id
Selected Answer
* and + both have same precedence .- has greater precedence than + and *.
Option B is Correct.
compiler-design
Option a
First α is incorrect it shouldnt be for some string β. It has already seen t as terminal . It doeesnt have to look for β
8.295 Which of the following is the most powerful parring method top gateoverflow.in/43711
(A) LL(I)
(B) Canonical LR
(C) SLR
(D) LALR
CLR is most powerful parser among all the parser which parse more no of grammar than other.So option B.
Option c is right . Regular langauges are not capable of doing the above Mathematics operation !
Yes,
Basic concepts of complexity classes – P, NP, NP-hard, NP-complete removed from Algorithms but Reduction is there in Theory of Computati
Is Epsilon a terminal ? If yes, then why not we consider it as a separate column while making the LL(1) parsing table ?
made-easy
Correct
ww r is CFL . CFl not closed under complement so move up to chomsky hirarchy . since every CFL is CSL and Compliment of
CSL is CSL.
Consider the language given below .Find the complement of these language and Explain Complementary
language?
1. wwr | w ∈ (a , b)*
theory-of-computation
1. ∑* - ( wwr)
wwr ={ ∊,aa,bb,abba,abbbba..............}
2.∑* - ( wxwr)
wxwr=(aaa,aba,abba..........)
3.∑* - ( ww)
ww=(aa,bb,abab............)
∑* - ( ww)=(a,b,abba,abaa.............)
4.∑* - ( wxw)
wxw=(aaa,aba,abaab............)
∑* - ( wxw)=(a,b,aa,ab......................)
1. The number of symbols necessary to simulate a TM with 'm' symbols and 'n' states is-
2. Any TM with m symbols and n states can be simulated by another TM with just 2 symbols and less than
3. The number of states of the FSM,required to simulate the behaviour of a computer,with a memory capable of storing 'm'
words,each of length 'n' bits is-
S ---> PQ | SQ | PS
P --->x
Q--->y
n2
n+1
2n
2n-1
Selected Answer
n − 1 steps to get n Nonterminals, then one step to get one terminal from each Nonterminals , so n more steps so 2n − 1
steps
In case of GNF, n length string take n steps only, bcoz each production have one terminal in it.
Selected Answer
So, 011
I think it should be 011 because it says " every 0 is followed immediately by 11".
L={<M>|L(M) is regular } ,isn't it a trivial property because every TM accepts regular language.
Selected Answer
Every Turing Machine accepts regular language? Whether yes or no does not matter (I guess you meant for every regular
language we have a TM) because the property asked in question is the language of a Turing machine regular- this is true
for some and false for some and hence is non-trivial.
Is the language of Turing machine r.e.? This is true for all TM, and hence is trivial.
its similar to asking . does every program accepts the given input and rejects all thats not in input ...
and how u said that every TM accepts regular language ....u cant prove for all turing machine ...it will loop forever .
Is the answer regular because the set is a finite set? Or is it because of some other reason?
theory-of-computation
Regular Languages are closed under Prefix, Half, Root, Cycle, min, max operations.
Selected Answer
Here, we have some n, and this comes inside a set definition so it basically means we have to consider all possible values
of n. (Assuming n means a natural number). So, if n = 1, we have
When n = 2 we have
L = L1 ∪ L2 ∪ ….
Here, L1 , L2 are not regular. So, we cannot use closure property (even regular languages are not closed under infinite
union). So, we have to do some deduction. I see that
Let Σ= {0, 1} What will be the number of states in minimal DFA, if the Binary number string is congruent to (mod 8). A. 8 B.
9 C. 7 D. 4
theory-of-computation
Selected Answer
B is regular (aaa)*aaaaa
C is DCFL .
D is CFL because x belongs to 0 and 1.so we don't know exactly where is actually x, so we need to explicitly guess the 0
or 1 so that we can say after that w^R starts.
(if x is not of 0 or 1, say 2 then we know exact after that we have w^R ,then it will be DCFL)
language D ( w x wR ) is DCFL
after x pop all wR with all w whichis present in stack so dcfl
Selected Answer
push a ′ s in stack ,do nothing with b , then pop a ′ s from stack on reading a ′ s
Push a ′ s in stack, donothing on b , pop a ′ s from stack on reading a ′ s, then we left with b ′ s with empty stack, then we can't
ensure these b ′ s are one more that earlier a ′ s.
Dfa to accept strings with 0's and 1's so that no of 0's should be even and no of 1's is divisible by 3
theory-of-computation
Selected Answer
DFA M using cross product M1 × M2 , having {x0 , y0 } as start state, and mark final state where we have both finals together,
i.e.{x0y0} as final state.
Q∖Σ 0 1
→ x0 y0∗ x1 y0 x0 y1
x1 y0 x0 y0 x1 y1
x0 y1 x1 y1 x0 y2
x1 y1 x0 y1 x1 y2
x0 y2 x1 y2 x0 y0
x1 y2 x0 y2 x1 y0
8.311 Let M range over Turing machine descriptions. Consider the set REG
and let the complement of REG be Co-REG. top gateoverflow.in/39127
Let M range over Turing machine descriptions. Consider the set REG= {M | L(M) is a regular set} and let the complement of REG be Co-REG.
Which of the following is true?
theory-of-computation
/
Let L = {madeeasy2016} over Σ = {m, a, d, e, s, y, 2, 0, 1, 6}, L1 = prefix(L) and L2 = L1 Σ ∗ . The number of strings in L2 (assume L1 and L2
do not include empty string) are ______.
theory-of-computation
Selected Answer
L = {madeeasy2016}
L1 = {m, ma, mad, made, madee, madeea, madeeas, madeeasy, madeeasy2, madeeasy20, madeeasy201, madeeasy2016}
/
In general Right Quotient of L1 with L2 means L1 L2 = {x : xy ∈ L1 for some y ∈ L2 }
so In our problem
/
L2 = L1 Σ ∗ = {x : xy ∈ L1 for some y ∈ Σ ∗ }
/
for y = ϵ, L2 = L1 Σ ∗ = L1
L1/L2 = ?
So, take... x.y ∈ L as 'y' can range from epsilon to every string possible, you will find that x is actually a prefix for L. How? Say y='b', and L
contains some string like aabbb. So x becomes 'aabb'. So, if you consider all possible x (which is nothing but the quotient) , you will get prefix(L).
Now, coming to your question, L1/∑ * is nothing but prefix(L1). Thus, L2=Prefix(L1) which inturn is prefix for given string. So, just calculate
prefixes, that's it :)
Selected Answer
For D consider the regular language {0, 00}. We cannot make a DFA with a single final state. But for any NFA, we can
reduce it to an equivalent NFA with a single final state- just make a new final state, mark all final states as non-final and
add an epsilon-transition from those final states to the new one.
I m student of MCA.
or
in my view :-
transition :
(q0,a,Z0)=(q1,XZ0)
(q1, a, X) =(q1,XX)
(q1,b,X)=(q2,€)
(q2,b,X)=(q2,€)
(q2, €, Z0)=(q3,€)
transition :
(q0,€,Z0)=(q3,€)
(q0,a,Z0)=(q1,XZ0)
(q1,a,X)=(q1,XX)
(q1,b,X)=(q2,€)
(q2,b,X)=(q2,€)
(q2,€,Z0)=(q3,€)
According to Rice theorem's first part , any non-trivial property of TM is undecidable , so L1 should be undecidable , right ?
Because , we can not tell whether it will not visit q on some input within 10 steps.
theory-of-computation
Selected Answer
Both are non-trivial properties. But Rice's theorem does not say anything about properties of TM. It says about properties
of language of TM or about properties of r.e. set. So, it is not applicable to given question as here it talks about TM and
not its language.
L2 is easily decidable. We can just count the no. of states in the TM description. This is similar to counting the no. of lines
in a given C code.
L1 looks semi-decidable. But it is also decidable. With one move (step) a TM can read only 1 input letter. So, in 10 steps
the maximum input a TM can read is 10 letters. So, to decide the problem just simulate the given TM on all inputs of
length 10 for up to 10 steps. If the TM visits state q on any of them we have answer "yes" and otherwise we have answer
"no". No chance of an infinite lop here.
See here . every grammar symbol must yield a terminal ( directly or indirectly )
But if you See E -->bc ( This is only production which directly yields terminals, but this production is indirectly helping
other symbol to yield production )
Let us See
E-->bc
1.C-->Ec = bcc
2.B-->bCC= bbccbcc
But we would see our Useless symbol Definition : These are the symbols which cant be reached by Start Symbol .
So if You See F is the only symbol which cant be reached by start symbol directly or indirectly
and For second part , The number of production in G after removing null production is
S-->AaS/∈= Aa/AaS
A->SbB= SbB/bB
B->bCC
C-->cD/Ec
D-->abAA
E->bc
F-->bBC
8.318 under which language does the following set fall and why top gateoverflow.in/37441
Selected Answer
Ref : https://en.wikipedia.org/wiki/Ambiguous_grammar#Inherently_ambiguous_languages
L = { a m b n dl | m = n} U { a m b n dl | n=l}
So here the language itself there is a conflict requirement for its string. L1 is the set of strings where number of a 's and b 's
are same while L2 is the set of string where number of b's and d 's are same. Strings of type a n bn d n will have two parse
tree.
So for this language you can definitely give unambiguous grammer and even this language is regular and regular
language do not posses unambiguity.
8.319 can we find out minimum numbers of states in DFA if NFA has n states
top gateoverflow.in/34006
Selected Answer
if NFA has n states , then states in DFA will be determined by set of subsets of the states of the NFA.
say NFA has two states , q0 and q1 , then DFA may have ,any to all, of {{}, {q0 }, {q1 }, {q0 , q1 }}
Let A = {(a*b*)} and B = {bb, ba, bbb}. Then A/B represents of the following language when / is quotient operation.
a) ∅
b) {b* }
c) {a*b* }
d) None
What is the quotient operation here, and how to operate it on given languages.
theory-of-computation
Selected Answer
Definition :
Here we need to find Prefix ( x) from strings (xy) of language L1 those have some suffix ( y) and these suffix belong to L2 .
for y = bb ∈ L2
for y = bbb ∈ L2
so, L1 /L2 = a ∗ b ∗
Once we get the exact meaning of Left or Right Quotient and done with 3-4 problem, then there is no problem
Consider the NPDA < Q = {q0, q1, q2}, ∑ = {0, 1}, τ = {0, 1, ⊥ }, δ, q0, ⊥ , F = {q2} >, where (as per usual convention) Q is the set of states, ? is the
input alphabet, ? is stack alphabet, ? is the state transition function, q0 is the initial state, ⊥ is the initial stack symbol, and F is the set of accepting
states, The state transition is as follows Which one of the following sequences must follow the string 101100 so that the overall string is accepted by
the automaton?
Selected Answer
0 ∗ (01) ∗ (012) ∗
i) 012 01 can be derived from option i) but cannot derived from given regular expression
ii) 2 can be derived from option ii) but cannot derived from given regular expression.
iii) 012 cannot be derived from option iii) but can derived from given regular expression
iv)01 012 cannot be derived from option iv) but can derived from given regular expression.
8.323 under all mod conditions the language is always is regular or not if not
please explain with some examples top gateoverflow.in/12767
L = { w| No of a mod 3 = 0} // Regular
there is no way you can reach the final state then the language contains only ø .
and when you can reach the final state by giving nothing in input ( initial state = final state ) then the language
contains € .
phi means nothing not even epsilon i.e nothing not even null is accepted epsilon atleast contains epsilon i.e null string is
accepted
Epsilon means der is some element in a set whose cardinality(cardinality of that element not set cardinality) is 0.
Epsilon means der is a string of length 0 & it is accepted i.e. der is a final state.
A context free grammar G is said to be ambiguous ,if there exists some w belongs to L(G) that has at least 2 distinct
derivation trees.
I f every grammar that generate L is ambiguous then language is called inherently ambiguous ...eg for inherently
grammar is L= {a^nb^nc^m}∪{a^nb^mc^m}
http://infolab.stanford.edu/~ullman/ialc/slides/slides7.pdf
8.324 number of states of minimal nfa accepting strings of length n top gateoverflow.in/12942
My answer is :
or
theory-of-computation
Selected Answer
second one is correct , if S---> e we could not eliminate it bcoz language generate e ,and if language does not generate e
then it can be eliminate ...
s-->AB
A--->aAA/e
S-->AB/A/B/e
A-->aAA/aA/a
B-->bBB/bB/b
8.325 intersection of CFL and RL will always be regular or CFL top gateoverflow.in/13233
Always be CFL but not necessarily regular. As an example take regular language = Σ ∗ and its intersection with any CFL
gives that CFL.
let q0 and q1 are two states and q0 is always initial state over the alphabet {a,b}, the possible number of dfa's with two
states q0 and q1 are
16,32,64,80
Selected Answer
No. of possibilities for final state = 22 = 4 as any subset of the set of states can be the final state.
No. of possible transition functions = Number of possible functions from a set of 4 elements (Q × Σ) to a set of 2 elements
(Q)
= 24 = 16.
8.326 it necessary for a dfa to have to have atleast one final state? top gateoverflow.in/12487
No its not necessary . If a dfs does not has a final state then for that dfa L= { Ø } .
is the language WXW R is regular? can any one provide the proof?
so we can rewrite this language as " starting bit and ending bit are same " which is a regular language .
i assume W,X belongs to {a,b}* i will always intentionally put W=null and X=string you provide me now X belongs to
{a,b}* so the whole language is regular..
8.327 Consider following Regular Expression (i) a*b*b (a+ (ab)*)* b*(ii) a*
(ab + ba)* b*What is length of shortest string which is in both (i) & (ii)? A.
Length will be 1.
Option D.
A. L = 0 +
B. L is regular but not 0 +
C. L is context free but not regular
D. L is not context free
L={00(2),000000(6),0000000000(10)...}
Is it correct?
Yes. It is correct.
The maximum no of proper non empty sub-strings for the given 'n' length string is:
A) n*(n+1)/2 - 1
B) n*(n+1)/2
C) n*(n+1)/2 + 1
I basically want a good explanation here for whatever option you choose???thanks in advance .
theory-of-computation
Selected Answer
1. a
2. b
3. c
4. ab
5. bc
6. abc
For a string of length n, we can have 1 sub-string of length n, 2 sub-strings of length n-1, 3 sub-strings of length n-2, ... n
substrings of length 1. So, total no. of sub-strings = 1 + 2 + ... + n = n (n+1)/2
But the question asks for "proper" sub-strings. Proper sub-string means the given string (of length n) must not be
counted. So, the answer must be n(n+1)/2 - 1.
Ref: http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/StringMatch/stringMatchIntro.htm
i think
a) (a+b)* = (a+b)*(a+b)*
b) (a+b)* = a(a+b)*b(a+b)* + ∈
correct answer given is option D but obviously option B and option C both are wrong too.
Selected Answer
We can not produced string ba from option B. [Even a,b cannot be derived]
But
option C is right . [all string over {a,b} contain sub string "ab" + all string doesn't contain "ab" as sub-string = all strings
over {a,b}]
Selected Answer
Yes. It is not depend on Grammar that is ambiguous or unambiguous, that is depend on language (generated by
Grammar) accepted by DPDA or NPDA.
above Grammar is for language , Balanced parenthesis for which we can design DeterministicPDA
[ push "(" into stack and pop with ")" ]
so 3 is True.
2 is True, i guess valid parenthesis mean balanced parenthesis.
1>If a language is accepted by a DPDA then this language should have an unambiguous grammar.
2>This does not mean that all languages that have an unambiguous grammar is accepted by a DPDA (for e.g ww^r).This
language has an unambiguous grammar i.e S-->aSa | bSb | epsilon
In your question the language of valid parenthesis has an unambiguous grammar i.e S-->(S)S | epsilon..Thus there can
be a DPDA though we are not sure because of point 2.
Now we try to make a DPDA that can accept it, to be sure..we get is as...say Q1 is initial state and Q2 is final state..then
the transitions will be..
( Q1,epsilon,Z)-----> ( Q2,Z)
A language accepted by nfa is a regular language . And a regular language is left recursive or right recursive . So regular
language maybe ambiguous or unambiguous depend upon implementation . So All languages accepted by a nfa is
ambiguous or unambiguous grammar .
my question is whether we have a shortcut an idea which can help us in recognizing any language to be regular or not,in GATE .and
also what is the best way to get it properly done when you want to do it the old school way?
theory-of-computation
Selected Answer
1. Is DFA/NFA or regular expressions possible or not (especially in case of WW, WWr, W1W2.....)
5. If finite then regular.. it doesn't matter comparison or string matching or power is non linear if language is finite it must
be regular.. even finite subset of non regular is regular..
Still some more but questions base on these 5 points frequently asked in GATE..
referhrefer : http://gatecse.in/wiki/Identify_the_class_of_the_language
8.333 L = { a^n b^m, n>=4, m<=3}, What will be the regular expression for
the complement of L? top gateoverflow.in/13365
L= anbm ,n>=4,m<=3
theory-of-computation
A---> a'.ß, a'' is valid for viable prefix let y if there is derivation S-rm*-->ØAw---> Øa'ßa''w
here y=Øa' here a'' is lookahead , which is first symbol of w so for given question
S--> BB---> BaB--->--> Bab---> aBab-*-->aaaBab(rightmost derivation) so here a''=a , w=ab ,Ø=aa,
y= Baa..
reference http://www.cs.clemson.edu/course/cpsc827/material/LRk/LR1.pdf
http://tinman.cs.gsu.edu/~raj/4340/sp12/LR1.pdf
Consider this grammar: S → SS | a How many derivation trees are possible for a^4 ? (a) 3 (b) 4 (c) 5 (d) 6
theory-of-computation
i think 5 is possible . i don't think one can derive a trick for that as the production can change and there are lot of
productions . so u should make all the possible combinations . it take hardly 30 second to get to the answer. u may derive
a formula but what i prefer never learn anything till it is really required. there are hell lot of formulas to remember and
really when i went for gate paper this year i hardly think there was a question based on formula,.
L1 = {ca b } ∪ {da b }
n n n 2n
L2 = {a b c } ∪ {a b d }
n n n 2n
theory-of-computation
Selected Answer
L1 is DCFL because der is one to one comparison between no of a and b and c & d are used to identify which {ca^nb^n}
∪ {da^nb^2n} sub language execute first.
i think L2 is NCFL because union of two DCFL always be an CFL but der is no CLUE to identify which sub language
executes first thats why it is not DCFL..
I am having problem in finding the complement in the sense that I am unable to complement the relation defined between
the powers of the variables ,say I have a language like
Now what should be the procedure in order to find the complement of this relation and then proceed in calculating the
complement of the language ?
theory-of-computation
complement of a language is all the possible strings with sigma* - language strings. frame a gramer that only not accept
your language and accept everything else.
for example every string starting with b. and accept every possible case below 100 as no condition is there for that and all
strings where m<n and n>100 . i thing we included everything . this is the complement of the language
theory-of-computation
D.Context sensitive
it will be l={1^p where p is prime} ..it cant be regular as there is no pattern in the strings generated that we can
remember, also we cant generate primes using FA+ one stack ie pda.
https://en.wikipedia.org/wiki/LL_grammar
a(a+b)*a +aa (a+b)*aa but still how are we able to make sure that the power of a from the beginning is the same as the
power of from end , plz draw a finite automaton for it , I am stucked up in this .
theory-of-computation
Selected Answer
When a set definition is given, we must consider all possible cases as per the definition- i.e., for a language we must
include all possible strings satisfied by the given definition. In this question when we put n = 0, we get L = Σ ∗ and that is
the maximal set and so we don't need to consider any other value for n. And this set is regular.
let L = { Φ
ϵ
if Recursiveset(RS) = RES
if RS ≠ RES
then L is:
theory-of-computation
Answer is A, regular.
There are two choices for L but both are regular sets. Now, RS != RES, and this is a known fact. So, L = ϕ which is a
regular set.
Now, even if RE = RES? is not a proven fact, still L is a regular set. Just that we don't know which regular set it is.
c. { WXYW | X,YE(a+b)+}
d. All of these
Selected Answer
Only C is non-regular.
http://gatecse.in/wiki/Identify_the_class_of_the_language
8.342 What are the number of states needed in minimal DFA, that accepts
(1+1111)* A. 5 B. 4 C. 1 D. None top gateoverflow.in/15628
(1+1111)* is same as 1*. Single state DFA with same starting and final state.
L= {Σ ∗ }
theory-of-computation
But even Σ is not defined here and if I take ∑=a, a character and not an alphabet set, then we get a language.
L = { language }
A 4
B 3
C 2
D 1
E 6
F 5
without any doubt this language is CFL and there exists a npda which recognises it.......
NPDA will create copies of itself while checking for palindrome on its way (of scanning the Input string), where it finds a
possibility that an alphabet maybe the middle of the palindrome string.
only one state in both the cases NFA OR DFA . and by the way it is asking about minimal FA (NFA) so ans should be 1 only
.
ref : http://www.cs.odu.edu/~toida/nerzic/390teched/regular/fa/acceptor.html
8.347 change finite automata into regular expression using state elimination
method top gateoverflow.in/13510
create the DFA of the above NFA and start eliminating the state for getting the RE
(aa+bb)(a+b)*
Selected Answer
The decision problem here is given a TM M, does there exist an equivalent TM H, which runs in polynomial time and
accepts/rejects same as H and if M doesn't halt, H is free to do anything.
Here we need H to behave as M for all inputs on which M halts- so this is indeed a property of language of TM making
Rice's theorem applicable.
Is this property trivial? - No, because for some M, we can have an equivalent H as given (all NP problems), but for many
we don't have (problems outside NP). So, non-trivial property of language of TM make this problem undecidable as per
Rice's first theorem.
1. L2 has to be regular
2. L2 need not be regular
I came across this question and according to me the answer should have been option 1. But the workbook I picked up this
question from has option 2 as the answer. My reasoning was that when a regular language is concatenated with another
language, for the result to stay regular the second language has to be regular, or else the language thus obtained may
contain strings that cannot be derived through a FA.
theory-of-computation
Selected Answer
L2= {a,b} same number of a and same number of b (eg . ∊,ababba,ababba like that )
now L3 = L1.L2
regular language is concatenated with another language, for the result to stay regular the second language has
to be regular
This is wrong. Take regular language {} and concatenate with even a non r.e. language. We get {} it self which is
regular.
8.350 what is the total number of strings that can be generated from the
below FA ? top gateoverflow.in/14427
The FA above recognizes a set of stings of length 6, what is the total number of strings that can be generated from the FA?
a. 18
b. 20
c. 130
d. None
Selected Answer
In above FA, at each transition, we can either go 1 step right, or 1 step up, and to reach accepting state, we have to take
exactly 3 steps right, and 3 steps up. So basically we have to find all distinct paths from initial to final state.
There are 6 steps total to be taken, out of which we can choose 3 right steps in ( 3 ) = 20 ways. Other 3 steps will be up-
steps so we don't have a choice there.
1 4 10 20
1 3 6 10
1 2 3 4
1 1 1 1
for leftmost row vertices and last row vertices each vertex ,only one path possible, for other vertices fill in bottom up
manner, no. of strings generated or no. of diff paths to a vertex is sum of distinct paths from its left vertex and down
vertex from where arrow is coming.
theory-of-computation
Selected Answer
you can choose any one of it but always practice when you just finished a topic.
Follow these materials- if you are having trouble watch the videos given
http://www.gatecse.in/theory-of-computation/
Q). Let A = (a + b) ∗ ab(a + b) ∗ , B = a ∗ b ∗ and C = (a + b) ∗ .Then the relation between A, B and C is:
A). A + B = C
B). AR + BR = C
C). AR + B = C
D). None
http://gateoverflow.in//13162/plz-answer
8.352 If a Finite state machine that accepts a set, has no loop...eg: accepts
only 101. Is it the set regular? does it have the PUMPING LEMMA property?
(If it is regular but has no loops) top gateoverflow.in/11094
Yes its a regular language . if there is a loop in the state diagram then we can say that it produce infinitely many strings
(with some pattern) .
Pumping lemma can not used to prove the regularity of a language . if a language fails the pumping lemma test then we
can say its not a regular language but if it pass the test then the language may be regular or may not be .
Concept :
If pumping lemma fails then language is not regular..
Contrapositive of this statement :
If language is regular then pumping lemma satisfied..
So every regular set satisfy Pumping Lemma property trivially.. but reverse (i.e . If Pumping Lemma satisfy then regular)
may not be true..
Ok see ,if it accept 101 and having no loop then this language becomes finite language that means its surely regular
language , coming back to your second question it may not satisfy Pumping Lema property because Pumping Lema use for
proving non regularity always use in negative sense , means if some language satisfy its property then language is not
regular but if not satisfy its property we can't say anything about language .
8.352 Is it possible to build a Regular grammar for ( a^m a^n b^m c^n ) ? top
gateoverflow.in/10928
theory-of-computation
Selected Answer
It is CFL.
S ----> aSc| A
Now, L1 = {a, aaa, aaaaa, aaaaaaa, aaaaaaaaa, ...} (all odd length strings in a)
But just because 1 example gave regular doesn't mean L1 is always regular. But 1 example gave irregular means L2 is not
regular.
I gave this example for better understanding. To prove L2 is irregular just take A = {aa}. Now, L1 = {aa, aaaa,
aaaaaaaa, ...} which is calculating the power of 2's which cannot be done using a regular language.
Now, to prove L1 is regular we must move more formally. It is not a trivial proof and two proofs are given in the link
below for sqrt and the same logic can be extended to other roots also (just by changing the final states).
http://math.stackexchange.com/questions/332720/if-l-is-regular-prove-that-sqrtl-left-w-ww-in-l-right-is-regular
L is regular because there cannot be two "ab" in a string without a "ba" or vice versa. So, at any stage of processing the
input string, count of "ab" difference "ba" will be either 0, 1 or -1 and hence we just need a finite automaton to recognize
it.
8.356 I think the answer should be 32 but its not in options? Help me in this
question.. top gateoverflow.in/4838
Selected Answer
First of all I would like to clear that empty language is ϕ and not λ and there is only one way to have final state in finite
automata then - By not having any final state at all . Now 16 is total number of transitions possible in DFA of two states
and two inputs. So possible number of DFA's with no final state= 16 , now there are 4 more possibilities when q1 is final
state and it is not reachable from initial state.. ( courtesy @Arjun sir ) Therefore ans is 16+4=20
L(M) is a regular set is a non-monotonic property of L(TM) as we can have a TM, T yes with this property (L(TM) = ∅) and a
TM Tno which does not have this property (TM for any non-regular language) and T yes ⊂ T no. Now, all non-monotonic
properties of language of TMs are unrecognizable or their language is not recursively enumerable.
For Co-REG also, the same proof holds. We just need to change T yes to a non-regular language and T no to Σ*.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
Selected Answer
A is the answer.
Counting a finite number of steps in a TMs is always decidable. Whenever TM takes a step, increment a counter. Doing this
for 481 steps is always possible. If TM halts in between output "no", otherwise "yes".
Whether the Turing machine accepts empty string is undecidable. Easiest proof is using Rice's theorem. This is a non-
trivial property of L(TM) as there is a Turing machine accepting ϵ and is another TM which does not accept ϵ. And all non-
trivial properties of language of TMs are undecidable. (This problem is semi-decidable as if the TM accepts ϵ we can say
"yes". Only for the case when TM does not accept ϵ we cannot decide)
Hi @Arjun sir ,
Regular languages are closed under Symmetric difference and Right quotient operation.
So , in S 1 , the statement that "Regular languages are not closed under symmetric difference and quotient operation" is false .
So , S2 is only correct.
e) none of these
Minimal finite automata that accepts all strings of a and b where the nth input symbol from right hand side is 'a'
a) 2n b)2n c) n d) n+2
A. As all the symbols upto nth input from the right must be checked. and there are 2 symbols a and b. So there must be
2n states.
8.362 Let L1 is regular and L2 is CFG. Then what is L1-L2? top gateoverflow.in/4555
Selected Answer
L1 - L2 = L1 ⋂ L2'
Now CFL complement need not be CFL (as CFL's are not closed under complement). But any CFL is also a CSL and CSLs
are closed under complement. So, any CFL complement is guaranteed to be a CSL. Now, CSL intersection CSL (regular is
also a CSL) is CSL, and so L1-L2 is always Context Sensitive.
(It can also be regular or CFL but we can say always only with respect to CSL)
http://gatecse.in/wiki/Closure_Property_of_Language_Families
a) L3 = concatenation of L1 and L2
b) L4 = complement of L3
e) L7 = concatenation of L5 and L6
f) L8 = intersection of L7 and L1
Please Explain.
http://infolab.stanford.edu/~ullman/ialc/spr10/slides/rs2.pdf
L5 = first half of each string in L4 which is a regular set. Now, first half of a regular set is regular. So, L5 is regular.
http://www-bcf.usc.edu/~breichar/teaching/2011cs360/half(L)example.pdf
Second half of a regular set must also be regular (I don't have a proof now). So, L6 is regular.
L7 and L8 are also regular as regular set is closed under concatenation and intersection.
L1 = {an bn ∣ n ≥ 0}
L2 = Complement(L1 )
theory-of-computation normal
Selected Answer
L1 is clearly a DCFL and DCFL is closed under complement. Hence, L2 is also DCFL.
We can make a PDA for L2 , using the same PDA for {aⁿbⁿ} as follows:
Start by pushing each 'a' on to stack. When b comes start popping. If 'a' comes after a 'b' or 'b' comes when the stack is
empty, go to a final state from where the PDA accepts any string. Otherwise, at the end of the string, if stack is non-
empty, accept the string and if stack is empty, reject the string.
8.365 Let Σ = {a, b, c}. Which of the following statements is true ? top gateoverflow.in/69
theory-of-computation difficult
Selected Answer
Consider
L1 = {a b c d ∣ m, n ≥ 1 }
n n m m
L2 = {a b ∣ n ≥ 1 }
n n
L3 = {(a + b) } ∗
Intersection of L1 and L2 is
(A) Regular (B) CFL but not regular (C) CSL but not CFL (D) None of these
theory-of-computation normal
Selected Answer
Regular.
L1 ∩ L2
= {abcd, aabbcd, aaabbbccdd, …} ∩ {ab, aabb, aaabbb, …}
= ∅.
8.367 If anybody have some note or link to the topic like NP related
questions, Please provide. I have never been successful in answering these
If anybody have some note or link to the topic like NP related questions, Please provide. I have never been successful in
answering these type of question. Any help will be really appreciated.
check dis
http://gatecse.in/wiki/NP,_NP_Complete,_NP_Hard
yes. It is CFL and not DCFL. Only if some separating character like 'c' is at the middle it will be DCFL.
Palindrome mean that can be even palindrome or that can be odd palindrome
In even palindrome say L = w w r where we need to give a transition (in between with the help of ∊) after which we know
reverse get started.
before ∊ we need to push symbols in stack , after∊we need to pop symbol from stack
PUSH operation
then DONOTHING
δ(q,∊,a )= (q1,a)
δ(q,∊,b )= (q1,b) [State change with ∊ , a Mark now we will get w r, so we need to do POP]
δ(q1,a,a) = (q1, ∊)
δ(q1,b,b)= (q1,∊)
Then acceptance
δ(q1,∊,Z) = (qf ,∊)
So Palindrome is NCFL
Above TM
accepts language 0^+.
My Understanding :
For combination of 0's and 1's it will not halt. Will run forever. It means it is Recursive Enumerable language. ( undecidable
/ Semidecidable )
A language is nothing but a set of strings. So, a TM can accept multiple languages (if a TM accepts a language any subset
of that language is also accepted by the TM).
So, the 26 questions seems wrong- it should be language "decided by" or "recognized by" and not "accepted by". For
accepted by, we can give any language whose strings take the TM to final state. {00}, {000, 0000} etc are examples.
"Decided by" forces the TM to reject any string not in L while "recognized by" forces the TM to accept all strings in L and
not accept (reject or loop forever) any string not in L.
http://theory.stanford.edu/~trevisan/cs154-12/turing-machines-1.pdf
Selected Answer
L contains aabb, aaabbb, aaaaabbbbb, ... a kbk where k is the largest prime below 327. Now there are only a finite set of
strings in L making it a finite language. L can be accepted by a finite automaton.
Suppose we have an encoding of a fsm ... 1.is it regular? 2.does the fsm accepts its own encoding ?
I guess what you mean is weather the set of encodings of all fsms is regular.
That depends on the encoding you choose, and yes we can create an ecoding such the the set of all encodings is regular.
A fsm which accepts the set of all encodings will then accept its own encoding.
http://gatecse.in/wiki/Closure_Property_of_Language_Families
8.370 Does PDA accepts L={a^n b^n | n>=0 , n!=13}??? top gateoverflow.in/5480
If it does, how??
theory-of-computation easy
L= {a b
n n ∣ n ≥ 0, n ≠ 13 }
Consider the following Languages:
L1 = {a b
n n ∣n≥0 }
L2 = Σ ∗ − a13b13
Q-1 Why Half(L) = x | for some y such that | x | = | y | , xy is in L i.e first half of strings in L is regular? Here L is a regular language
Q-2 If h(a)=01 , h(b)=0 Find h -1(L) where L={w|w contain equal no of 1's and 0's}
Q-3 If L is regular then L1={uv:u ∈L, v∈L R} is regular? Plz explain this too..
theory-of-computation
FIRST NOTICE FOR ALL QUESTIONS it is said L is regular. hence it would have a DFA and finite number of states.
in QUESTION 1 now string are in two parts x and y. and it is said |x| = |y| .. as L is regular it would need finite steps to
generate ITS strings. and so if it takes finite steps to generate xy.. IT WOULD SURELY TAKE finite steps to generate x and
y ..the two halves .. HENCE HALF(L) IS REGULAR as x and y can be done in finite steps wich is apropert of FINITE
AUTOMATA
in QUESTION 2 it is said about homomorphic inverse ..and we know given a string homomorphic inverse is how using
alphabets we can derive a string.HERE eg 0101 can be by aa as no of 0 and 1 is equal.hence if we want n sequences it
would be of the form a n. REGULAR EXPRESSIONS ARE CLOSED UNDER HOMOMORPHIC INVERSE
in Question 3 it is said that NOTICE L1 IS made up of concatination of L and L R. . we know L has dfa and that dfa can be
reversed (by interchanging final and start start). hence L1 is nothing but a concatenation of two REgular languages and L1
IS REGULAR
NOW watch the 4 question, L1 is made up of x and y .. where x ∈ L hence REGULAR . now y ∉ L THAT MEANS IT IS
COMPLEMENT OF L . we again know we can complement DFA .. hence again it is reduced to a case of CONCATENATION
OF TWO REGULAR LANGUAGES. HENCE IT IS REGULAR
Below DFA is accepting above regular language but it is accepting null also....can anyone please give correct DFA
Selected Answer
DFA : 6 states
8.372 If any FA has three states & only one +, must it reject some inputs?
(alphabet set {a,b}) top gateoverflow.in/10670
theory-of-computation
S → AB
A → SSA|aA|∊
B → bA|a
S → AB | B
A → SSA|aA|SS|a
B → bA|a|b
S → AB | bA|a|b
A → SSA|aA|SS|a
B → bA|a|b
Now as per format we cannot have nonterminal and terminal together (as S → bA is not allowed)
now grammar is
S → AB | B'A|a|b
A → SSA|A'A|SS|a
B → B'A|a|b
A' → a
B' → b
now grammar is
S → AB | B'A|a|b
A → SA''|A'A|SS|a
B → B'A|a|b
A' → a
B' → b
A'' → SA
is final answer
Which of the following describes the minimum condition for ambiguity in a grammar?
a) Every derived word must have atleast 2 rightmost derivation
b) some word must have more than 1 leftmost derivation
c)A derived word has one rightmost and another leftmost derivation
d)each derived word has 2 leftmost and 2 rightmost derivation
Selected Answer
If a word (atleast one), that grammar generates, can be derived has two (or more) derivation that corresponds into
different derivation (parse) tree. That Grammar is ambiguous.
Ans. B is correct
c)A derived word has one rightmost and another leftmost derivation
wrong bcoz parse tree for left most derivation and rightmost derivation of a word can be same.
wrong , as no need to check each derived word, only one word having two derivation with different tree is sufficient.
right , atleast one word that can be derived by two derivation ( left, right or mix) have different tree .
Tree will be different if one word has two leftmost (or right most ) derivation .
8.376 Which of the the languages are CFL ( and not ) top gateoverflow.in/10874
Q 1.
In case of L3 , it can also be resolved using a single stack . So , this is also CFL.
Q2.
theory-of-computation
Selected Answer
Q1.
L1 = {a pc2p | p ≥ 0} is DCFL
L2 is CFL but not DCFL as we cannot deterministically check two unbounded conditions using a single check but the
conditions being OR we can do this non-deterministically.
L3 again is CFL but not DCFL. At every point we have two options- to equal the number of 0's or to double the number of
0's.
Q2.
Answer given as : e
But , my question is (P*Q*) * = {null string , any number of P , any number of Q , P followed by Q , }
whereas (P*+Q*)* = { null string , any number of P , any number of Q , P followed by Q , Q followed by P }
theory-of-computation
Selected Answer
well the answer is here . but it's far beyond my understanding . anybody plz explain .
https://courses.engr.illinois.edu/cs498374/fa2014/notes/02bis-context-free.pdf
a)[(1111+1)*0*]*
b)(1111+10+0)*
c)(111*+10*)*
d)0*(111+1)*0*
8.381 cyk algorithm is used for CFG'S to test which class of problem??? top
gateoverflow.in/6425
cyk algorithm is used for CFG'S to test which class of problem???
CYK algorithm is a dynamic programming method of order O(n^3) to find the membership property of CFG.
Selected Answer
CFL is a strict subset of CSL. CSL is closed under complement. So, CFL complement is CSL.
And CSL is a strict subset of recursive which in turn is a strict subset of recursively enumerable.
8.382 An NFA has 7 states of which 3 are final states. The maximum number
of final states in converted DFA would be ______? top gateoverflow.in/5916
theory-of-computation
We have four state which is not finale so all these state which come together to form a state in dfa are not have any finale
state in dfa.
so possible dfa state with only these 4 states is 24 = 16 and total number of state is 2 7 = 128 so total number of state
which contain final state is 128 -16 =112.
Compl(L1) is not L2 here. Complement of L1 means all strings not in L1 which means Σ* - L1
Please explain..
Selected Answer
The answer is C) Both S1 and S2 , since δ(q0,a) = δ(qf,a) for all a ∈ ∑ we know that which ever state q0 goes on any string
s, qf also goes to same state on string s, so S1 is true. S2 is also true since q0 goes to final state on x, so qf will also go
to final state on x, so any xk string will lead to final state.
Minimum state Finite Automata recognizing the language corresponding to following Regular Expression
(0*10+1*0)(01)*
Selected Answer
atleast 6 states are required in FA construction for this language, as shown below:
From that grammar consider only rules involving variables like A-> BC
Construct a directed graph from every rule of the form v ariable -> variable variable. If A-> BC then A, B and C are
nodes. There is an edge from A to B and edge from A to C.
Rank of Variable is the longest path(no of edges) starting from that node.
8.386 The number of states in a DFA accepting all the strings over {0,1} in
which 5th symbol from right hand side is always '1' is? top gateoverflow.in/7050
Selected Answer
It will be 2 5 as 2 5 possible combinations of characters are possible with the 5th last character being 1. We need to
remember each of them as any of them can be the 5th last character as we continue processing further characters.
8.387 L=set of all bit strings with even number of 1's ...Regular Expression
will be . top gateoverflow.in/15991
Options are
a) (0*10*1)*
b) 0*(10*10*)
c) 0*(10*1)*0*
d) 0*(10*1)*10*
clearly none of the answers actually match .try 110011 as already mentioned. .. I dont think ambiguous questions will be
given in GATE.
8.388 The number of different languages over any alphabet of more than one
symbol is not countable. T/F ? top gateoverflow.in/16065
it is True ,but not getting how give me proof for his . above statement from a book by hopcroft and ullman.
theory-of-computation
can give a informal proof to remember. the set of all string of a language is countable where as the set of all languages is
uncountable because we can put all the string is proper odering and then they can be enumerated . while suppose you
yake set of all languages now even first language will be having infinite strings. like the case of real number . so u will
never reach the language 2 . this he informal proof formal proof is diagonalization method.
8.389 if w ϵ (a,b)* satisfy abw = wab then length (w) is ? top gateoverflow.in/28045
8.389 what is the diff between (a+b)* and (a*b*)* ? top gateoverflow.in/28041
Selected Answer
(a b )
∗ ∗ ∗
= (( ) (
ε + a + aa + … ⋅ ε + b + bb + … )) ∗
(
= a + b + some other strings ) ∗
= (a + b) ∗
Let A= (a + b)* ab (a + b)*, B= a*b* and C= (a + b)*. Then the relation between A, B and C:
A. A+B= C
B. AR+BR= C
C. AR+B= C
D. None
theory-of-computation
Selected Answer
C = (a + b) ∗ All strings
Now,
A + B doesn't give us all the strings. For example, A + B doesn't contain the string ‘‘ba " .
Thus, A + B ≠ C
AR + BR doesn't give us all the strings. For example, AR + BR doesn't contain the string ‘‘ab " .
Thus, AR + BR ≠ C
First, lets look at which strings don't come in B. They are the ones that contain atleast one such ‘‘a " that occurs after
some ‘‘b " . For example, B doesn't contain the string ‘‘aba "
Now, we observe that all the strings that do not come in B, satisfy the property for AR, and hence come in AR.
Hence, AR + B = C
Another way to verify it is by constructing an NFA for AR + B, converting it to DFA and minimizing it.
A)7 B) 10 C) 11 D) 8
Selected Answer
0 length = 1 ( null)
1 length = 4 (G,A,T,E)
4 length = 1( GATE)
total= 1+2+3+4+1= 11
8.392 How to tell which of the languages are regular ? top gateoverflow.in/28207
theory-of-computation
Here y=x n
But in x= y n
say y = a *b*
but yn=anbn
8.393 what is the left quotient of a CFL with a regular language ? top gateoverflow.in/28698
If I take L=a^n b^n and R=(a+b)* so I am getting the value of L/R to be regular ,Am I correct ?
theory-of-computation
B is a part of xy , as y∊B
xy∊ A ,
=CFL / regular
regular= b4
Prefix(L) is superset of L
Prefix(L) contains all strings of L [as every strings is prefix of itself] ---------- (||)
8.395 The vernacular English ,if considered a formal language is a top gateoverflow.in/28785
a) Regular
b) CFL
c) CSL
8.396 Regular/Non Regular. Is the below language context free ? top gateoverflow.in/28701
theory-of-computation
Selected Answer
3. Traverse M for one transition (for given Σ ) and N for one transition (for given Σ ) , and repeat the process.
4. if We reach at common states, Mark them as New finals in DFA M (remove old final and do minimization )
[Note: in Short, design DFA for A , traverse from both directions (start and final),if reach at common states with same no of transitions, make them as new finals, result will be
DFA for Half(L) ]
No of states in minimal dfa of binary strings starting with 100 and length is congruent to 1 mod 12
theory-of-computation
L1 = { all strings over {0,1} start with 100} having regular expression 100(0+1)*
having DFA M1 :
having DFA M2 :
And we have to find L1 ∩ L2 using cross product of two DFA having x0y0 as start state and x3y1 will be final state
satisfying both conditions
States\Symbols 0 1
[Remember in case of intersection strings must be accepted by both DFA's (i.e, satisfying both conditions) so once we get dead state of any DFA that will remain
dead state, and final state will have finals of both ]
having 16 states .
16 States
theory-of-computation
Selected Answer
having 7 states
why in diagonalization method , we complement the diagonal bits first , and then prove that the language does not belong to the table so power set of all strings is
uncountable.
http://cs.stackexchange.com/questions/10780/why-is-this-true-there-are-countably-many-turing-machines
We are trying to prove that the set of languages is uncountable. So, first we assume it as countable. We define a matrix
Now, if the set of languages are countable all languages must be present here. But this is not true and to show why, we
define a new language by taking the diagonal entries of the matrix and complementing them. This complementing ensures
that at least for one string (the diagonal string for each language) our new language will be different from every other
language in the matrix, making it necessarily a new language. And that's all we want.
8.400 How to construct PDA for the given language ? top gateoverflow.in/27010
If input symbol is{ a, b} and L ={no of a's =2*no of b's } , issue here is that since we do not have any sequence so what
should be done when I see any a or b ?
Sorry for such a late reply, please check whether this answer is correct or not.
8.401 How do we empty non-terminals from the stack in this pda ? top gateoverflow.in/26987
In this one how come from q1 we are directly converting it into qf , since non-terminals have not been emptied , this
method is for converting grammar in GNF to PDA .
A) L is regular
B) L is finite
C) L is set of palindromes
If you can answer this you should know the answer because that is what Rice;s theorem part 2 says.
http://www.gatecse.in/803-2/
q0----> {q0,q1,q2} on a
q1---> {q0,q1,q2} on a
then finally for DFA I got {q0,q1,q2} and q0 as two states such that {q0,q1,q2}---> {q0,q1,q2} on a and q0 --->
{q0,q1,q2} on a ,plz tell the mistake ,I am unable to catch it.
http://gatecse.in/w/images/c/c5/2012_12.png
Selected Answer
∊-closure(q0) = {q0}
∊-closure(q1) = {q0,q1,q2}
∊-closure(q2) = {q0,q2}
States\Symbols a
->q0 {q0,q1,q2}
q1* {q0,q1,q2}
q2 {q0,q1,q2}
DFA
States\Symbols a
->q0 {q0,q1,q2}
{q0,q1,q2}* {q0,q1,q2}
L = a + = {a,aa,aaa,aaaa,aaaaa,....}
let L be language consisting of pair of tm codes and an integer (M1,M2,k) such that L(M1) intersect L(M2)contains atleast k
strings show L is RE but not recursive
Proof:
Let a turing machine M accepts the language L.
What that machine does is that for each set ⟨M1 , M2 , k⟩ (which is its own input) it simulates some strings on the machines M1 and M2 i.e. give
a string at a time to both of them as input to those machines. If they accept atleast k of those input strings presented by M to them then we
say, accepted and Halt our turing mahcine M.
So, Machine M halts and accepts on all accepted inputs. Hence, L is RE.
but, if no string is common to M1 and M2 , say, input set is ⟨a ∗ , b ∗ , 7⟩ then machine M will never halt. it keeps feeding those machines ∞ input
strings.
Hence, it does not halt on all strings which are not in the language. ∴ L is not REC.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
L={XWWr | X,W∊(a+b)+}
Here WW r is NCFL(because we can push all the term of W in a stack and W r pop those terms.So it is CFL and also here
middle term is not known . So it is NCFL)
Now reguler .CFL= CFL [Only phi . CFL=phi i.e. regular, but here phi is not possible , as X= (a+b) + ]
Consider languages L and L_{1}, each over the alphabet {a,b }, where
L_{1} = \left \{w \mid w contains some x \in L as substring \right\}
(A) I only (B) III only (C) I and III only (D) II and III only (E) I, II, and III
theory-of-computation
S1: LR = L, if and only if L is the language of palindromes. where LR is obtained by reversing all the strings of L.
S2: | L1∙ L2 | = | L1 | × | L2 |
Relation?
if A is context free language and B is a language such that B⊂A then B must be?
example:
1. L = {aibjck | i = j or j = k , i, j, k ≥ 0} is CFL.
8.411 if Lis a language of even binary number then L is? top gateoverflow.in/29906
It will be regular
construct DFA that accepts all binary numbers are divisible by either 2 or 3
Selected Answer
Find DFA M by UNION (using cross product) that accepts binary no's divisible by 2 or 3
Q↓Σ→ 0 1
→ x0 y0 ∗ x0 y0 x1 y1
x1 y1 x0 y2 x1 y0
x0 y2 ∗ x0 y1 x1 y2
x1 y0 ∗ x0 y0 x1 y1
x0 y1 ∗ x0 y2 x1 y0
x1 y2 x0 y1 x1 y2
States x0 y0 and x1 y0 are equivalents (clearly as in table) so one of them can be removed (minimization)
Minimized DFA M
Q↓Σ→ 0 1
→ x0 y0 ∗ x0 y0 x1 y1
x1 y1 x0 y2 x0 y0
x0 y2 ∗ x0 y1 x1 y2
x0 y1 ∗ x0 y2 x0 y0
x1 y2 x0 y1 x1 y2
having 5 states
I have gone through this link already but still couldn't catch up the logic , so please clarify what is it trying to convey ?
http://cs.stackexchange.com/questions/44195/pda-transformation-between-acceptance-by-empty-stack-and-final-states?
rq=1
theory-of-computation
8.414 Let L ≤ ML′ denote that language L is mapping reducible (many to one
reducible) to language L top gateoverflow.in/32216
Let L ≤ ML′ denote that language L is mapping reducible (many to one reducible) to language L′. Which one of the following
is True?
Could anyone please solve this and explain the this reducibility logic ?
After accepting 312929 strings it will accepting inputs, but here it accepts all. So, here is a chance of forming loop.(we can
think like dfa, when dfa accepts all, it forms a self loop on last state). But when we examining loop doesnot gives 'yes'
answer. So, 'yes' answer not possible. According to rice theorem it will be non trivial property. So, M will be non recursive
enumerable here.
∂(q1,0)={q2,q3}, ∂(q1,1)={q1},
∂(q2,0)={q1,q2}, ∂(q2,1)=∅,
∂(q3,0)={q2}, ∂(q3,1)={q1,q2},
One that can be implemented with PDA (with the help of one stack), will be CFL.
Push a ′ s into stack, pop them with b ′ s (as we need to check m = n or not) , now if stack is empty and c is in input, it means
m = n holds, now push c ′ s and then pop c ′ s with d ′ s , if stack again goes empty and we have nothing in input it mean k = l
(that is what we required) , accepted.
L2 is not cfl.
Push a ′ s into stack, then Push b ′ s into stack , pop b ′ s with c ′ s (as we need to check n = k or not), suppose n = k holds, means
when we get d in input , we have a ′ s on stack. now we have to check k = l , i.e, no of d ′ s = no of c ′ s , it is not possible as we
don't have c ′ s now to check it.
Ex;
A→Aa/a(left rec)
A→aA/a(right rec)
You can do vice versa.Note : In case of Left Linear or Right Linear not for all.
8.418 what is the union of DCFL with a regular language ? top gateoverflow.in/29260
Complement of L2 will be DCFL ,Now when we take the union with regular , the resulting language should be also DCFL , so
answer should be option C , why is it given as option a ?
theory-of-computation
Selected Answer
¯
it is clear from the diagram that L1 ∪ L2 = L = Σ ∗ = (a + b) ∗
Note :
¯ ¯ ¯
m n
It is very often to see, that we thought L2 = {a b | m = n}= {ambn | m ≠ n} but remember L2 also contain simple a, or a ∗ or b ∗ or b ∗ a ∗ or
strings as aba or many things.
¯
Actually L2 = Σ ∗ − {an bn }
Ans will be (a mbn m,n>=0) ⋃ (b m a n m≠ n) //since both said a should come first then b come.
most aprropriate is a
8.419 find which of the following CFL which are not, plz discuss one by one..
top gateoverflow.in/29205
1. L={a i b j ck | k=max{i,j}}
2. L={0n 1m | m≤n2}
3. L={0n 1m | m≠n2}
2) Not CFL.
n m 2
L={0 1 | m≤n }
3)Not CFL.
L={0n 1m | m≠n2}
Same as previous
4)Yes CFL.
5)Yes it is NCFL
6) Not CFL
7)Yes it is CFL.
L={ai bj | 2i=3j}
S->aaSbbb/aabbb
8)Yes CFL.
c
L ={xz | (∃y)[|x|=|y|=|z|, xyz∈L]} ,
=regular ⋂ (CFL)'
if any language is given , how we can determine that its grammar is ambiguous or unambiguous
8.421 why is the infinite intersection of regular languages not regular ? top
gateoverflow.in/29331
I have gone through this link but still couldn't understand this , it is telling according to demorgan's law ,Now If I consider L
to be an irregular language so
(L1'∪L2'∪L3'∪......infinite)'= Now this will give infinite intersection of regular languages ,and this is irregular ,but how ?
http://www.eecs.berkeley.edu/~luca/cs172-07/solutions/practice1-sol.pdf
theory-of-computation
theory-of-computation
8.423 what is the relation between CFG , LL(K) ,LR(K) and regular grammars
? top gateoverflow.in/29786
I am unable to get the basic difference between these and which one are actually parsed by a top down parser and a bottom
up parser ?
theory-of-computation
http://gateoverflow.in/28207/how-to-tell-which-of-the-languages-are-regular
8.425 Is the intersection of a CFL with another CFL decidable ? top gateoverflow.in/29618
If the problem is L(G1)∩L(G2)= Empty , then if G1 and G2 are both cfl's then is it decidable ?
According to me it should be decidable since if the intersection is regular then we can identify whether the language is empty
or not and if it is CFL then also through the grammar we can check it out seeing the start symbol .
theory-of-computation
Selected Answer
NO.
CFLs are not closed under intersection. If you make an intersection of two CFLs, you may or may not get a CFL.
But the intersection of CFL with a regular language is always CFL. There are ways to do it.
So, CFL intersection CFL is undecidable while CFL intersection regular language is decidable.
Answer = option B
given l={anbn⋂anbncn}
cfl
csl
reg
dcfl
none
theory-of-computation
Selected Answer
a^n b^n and a^n b^n c^n have no string in common (assuming positive n) . Hence the language given in question is
empty.
8.428 How can we say r* and r+ may be equal?? Is it correct? top gateoverflow.in/19119
Selected Answer
not at all.
r ∗ = empty string(ε) and all strings of length ≥ 1.
r + = only all strings of length ≥ 1. This doesn't contain the empty string ε
CFL
CSL
none
DCFL
Selected Answer
& since CFLs are closed under concatenation, L = L1L2 should be a CFL.
l={anblak:n+l+k>5}
a.CFL
b.CSL
c.REGULAR
d.none
theory-of-computation
Selected Answer
--------------------------------------------------------------------------------------------
another approach:
Now since the language {w | w ∊ a*b*a* and |w| <= 5} contains a finite number of strings in it, we can say that it is also
regular.
Can someone give the intuition behind this ? Moreover an example will also be helpful ..
theory-of-computation
Selected Answer
∞
⋂
L = i =1 Li = L1 ∩ L2 ∩ L3 ∩ …
Note that L = {a p
}
∣ p is prime .
Another easy example would be (this one with unions as opposed to intersections):
Now consider L = The infinite union of the sequence of languages L1 , L2 , … That is,
∞
⋃
L = i =1 Li = L1 ∪ L2 ∪ L3 ∪ …
L1= Set of all strings having equal number of 00 and 11. L2= Set of all strings having equal number of 01 and 10. (a) Both
are Regular (b) Both are Context free (c) L1 is regular, L2 is Context Free (d) L1 is CF, L2 is Regular
ans will be d)
L2 can be considered as all of the stings start and with same elements (0 or 1 )
all FA is regular language but every regular language is not FA.?? wt does it mean.??
theory-of-computation
theory-of-computation
Option A :
Option B :
is correct .
top
http://gatecse.in/wiki/Identify_the_class_of_the_language
9.
L = { wxwy ∣ w, x, y ∈ (a + b)+}
The given is a set definition. So, the set must include all strings satisfying the definition.
Now, as per our definition w, x, y can be any non zero length string over {a, b} and w starts the string followed by x and
again w and ending with y.
Now, any string must start with either a or b. Lets consider the first case:
Starting with a:
So, here w can be a, aa, ab, aaa, …. Whatever be w, it must repeat after x and minimum length of x is 1.
Similarly, given any string of length at least 4, I can split it like this to w, x and y provided the first character repeats at
some point other than the end, and there is no split possible if there is no repeat (There might be multiple splits possible,
but that doesn't cause any problem- as long as a single split is there, the string is in L). So, if we can just ensure this
repeat, we found the condition for a string to be in L. And this condition check can be done using a regular expression
a(a + b) + a(a + b) + ∣ b(a + b) + b(a + b) + ).
8.436 no of state in minimal finite automata that accept the string from
alphabet {a,b,c} top gateoverflow.in/18324
no of state in minimal finite automata that accept the string from alphabet {a,b,c} where no of a is divisible by 2 or 3 and no
of c is divisible by 6?? plzz explain!!!
if X is the set of States which count na(No of as) then possible states for counting a will be X={ (naMod20, naMod30),
(naMod20,naMod31),(naMod20,naMod32), (naMod21,naMod30)} Here (Mod20,Mod30) means the state where naMod2=0
and naMod3=0, Similarly interpret the others. Now Y is the set of states which count nc(No ofcs) then possible states will
be. Y={ncMod60, ncMod61, .........,ncMod65} : ncMod60 means the state where ncMod6=0 similarly interpret the others.
Now the possible states for the machine will be : Z={X*Y} ={(namod20,namod30,ncMod60), ......
(naMod21,naMod30,ncMod65). so no of State will be |Z|=24.You can get some idea from the below image how the state
could be look like. for X Set,
1) an bn ∪ an b2n ; n ≥ 0
2) an cbn ∪ an db2n ; n ≥ 0
theory-of-computation
Selected Answer
Reason: given a input after reading all a's we will not deterministically know whether to pop out 'a' for single 'b'
(a^nb^n)or double 'b'(a^nb^2n)
2)It is in DCFL
Reason: you can use 'c' and 'd' to deterministically decide whether it is a^nb^n or a^nb^2n after reading all a and the
next ip charecter
3) it is in DCFL
Reason: you can use 'c' and 'd' to deterministically decide whether it is a^nb^n or a^nb^2n after reading the first ip
charecter(i.e,.whether the first char is c or d)
1)(r1*)*=r1*
2)r1*(r1+r2)*=(r1+r2)*
3)(r1+r2)*=(r1*r2*)*
4)(r1r2)*=r1*r2*
1- (a*)*=a*
r1*(r1+r2)*=(r1+r2)*
putting r1* as null we can generate the rhs. and if we take into consideration r1still all the strings are included
3 is also equivalent .
but 4th is saying r1should always followed by r2 but the RHS can generate r1r1.
1.((a+b)(a+b)(a+b))*
2.(b+ab*ab*a)*
3.[(b*ab*)+(b*ab*ab*)+(b*ab*ab*ab*)+(b*ab*ab*ab*ab*)]+[b+(ab*ab*ab*ab*a)]*
8.440 Turing machine checks for unequal number of a's and b's top gateoverflow.in/16330
We need to desing a turing machine which accepts strings of a's and b's such that the number of a's and number of b's in
the string w are not equal.
What is the minimum number of states needed for such a turing machine
1- " every single tape turing machine can be converted to equivalent turing machine with 3 states "
2- " every single tape turing machine can be converted to a equivalent 2 state multitape turing machine."
search google for the proof. its valid point. so now the answer can be 2,3 depending on the fact it is multitape or single
tape or if u can make it using 2 state or one state which i think is not possible
consider the following CFG find minimum no of productions when converted in GNF form
S->AA|0
A->SS|1
Replace S by A1 and A by A2 + a new variable Z we get the same grammar but in GNF:
which of the following is FALSE with respect to possible outcomes of executing a Turing Machine over a given input?
Selected Answer
If the input belongs to a recursive language, either it may halt and accept the input or it may halt and reject the input.
If the input belongs to a recursively enumerable language, then either it may halt and accept the input or it may never
halt.
I don't think it can halt by changing the input, because TM just transits from one state to another state on a given input. It
only does the transitions that it is supposed to do on the given input as per it's definition.
TM is like a slave and input is like the command given by a master, so possibly it can not alter commands given to it.
However I am not very sure about it.
L=b^m right??
Selected Answer
L1 : set of all the strings that have some number of a’s followed by ANY number of b’s followed by exactly the same
number of c’s as the number of a’s.
For example: ac, abc, abbc, aacc, aabcc all these strings are in L1.
L2 : set of all the strings that have any number of a’s followed by exactly the same number of c’s, but NO b’s in between
a’s & c’s. For Example: ac, aacc, aaaccc, aaaacccc all these strings belongs to L2.
Since L = L1 - L2 , L is the the set of all strings that consists of any number of a’s followed by ATLEAST one b, followed by
exactly the same number of c’s as the number of a’s.
i.e. L = {a^n b^m c^n | m>0, n>=0} For example: abc, abbc, abbbc, abbbbc, aabcc aabbcc all these strings belongs to
L.
L is not a regular language since we can not keep count & compare powers using regular language.(Pumping Lemma can
be used to show that L is not regular)
On reading an ‘a’ push that into stack, on reading a ‘b’ do not alter stack, on reading a ‘c’ pop an ‘a’ from the stack, at last
if number of a’s will be equal to number of b’s in the string, the stack will become empty & thus the string will be in L
otherwise it won’t.
Thus L is a DCFL.
Let L=(a^P)* |P is a prime no. then minimum no of states in NFA that accepts the language L is : _____
i think no nfa can accept this language. so the no of states is 0 in NFA. but ans is given :3
Selected Answer
L = {aa, aaa, aaaa, aaaaa, …} becaue there is a * at end and (aa + aaa) ∗ it self will generate all strings in a and we don't need to
consider further prime numbers.
i.e., L contains all strings in a except a. So, we need a start state, another state for single a and then a final state. So, 3
states (for both DFA and NFA).
the formula is n^(n*m+1)*2^n ,where n=no of states and m= no of input symbols. right??
Selected Answer
Q - set of states
Δ - transition function Δ: Q × Σ → Q
q0 - start state
We are given n states and m input symbols. So, first 2 components won't change.
F can be any subset of states and for n states we can have 2n possible subsets.
Δ is a function and no. of possible functions from a set of n × m elements to a set of n elements is nnm.
8.446 Identify the class of given mod based language top gateoverflow.in/25089
A) CFL
B) CSL
C) DCFL
D) REC
E) RE
theory-of-computation
8.446 If DFA is constructed from NFA using lazy subset construction method
, is it guaranteed to be the minimized DFA ? top gateoverflow.in/25136
8.447 what happens when we take union of two languages and then take its
reversal ? top gateoverflow.in/26590
(L1 UNION L2 )^r =L1^r UNION L2^r this equality must hold true ,but I read somewhere so this equality wasn't true , so
what is the conclusion ?
theory-of-computation
I believe you are correct, the equality should be true in every case.
In (L1 U L2) r we are firstly combining sets and then taking each string from the combined set and reversing it.
In case of L1 r U L2r we are firstly reversing each string and then combining the sets of reversed strings.
Clearly Union is an operation on sets & Reversal is an operation on strings of the set.
Since ultimately you are going to reverse all the strings in L1 & L2 it does not matters whether you reverse them before
Union or after.
8.448 what happens when we take cartesian product of two DFA's ? top gateoverflow.in/26417
when we take the cartesian product of two DFA's then what happens to the dead state of two DFA's , do we combine it also
in the cartesian product ?
Given L1= (011)*01 and L2= 101 find L1/L2? A. (011)*01 B.(011)* C. 101 D. None of the above
( 011 ) ∗ 01
101
L1/L2 =
( 011 ) ∗ 01101
101
= = (011) ∗ 01
optionA
8.451 what is the regular expression equivalent to the DFA ? top gateoverflow.in/26639
I tried it through state elimination method but I am getting stucked at the outgoing edge from D to A .
Selected Answer
FA given :
Remove State B
Removing State C
Simplify it
A=∊ + D0 ------- I
B= A0+D1 -------II
C=A1 -----------III
D=B1+C0 --------- IV
D= (A0+D1)1+A10
=A(01+10) +D11
D= A(01+10)(11)* - - - - - V
Put V in I
A=∊+A(01+10)(11)*0
A= ((01+10)(11)*0)* - - - - VI
Put VI in V
I tried till k=5 and then got 2 as no of words ,N(1)=N(3)=0 ,N(2)=N(4)=N(5)=2
N(0) = N(1) = 0
N(2) = 2
N(k) = 2N(k − 3) + N(k − 2) is the recurrence relation as we can get a string in L by appending "001" or "010" to a string in L
(by looking from final state) or by appending "11".
Thus,
N(3) = 0
N(4) = 2
N(5) = 4
N(6) = 2
N(7) = 8
N(8) = 10
N(9) = 12
N(10) = 26
N(11) = 32
N(12) = 50
N(13) = 84
N(14) = 114
8.454 how to approach this kind of questions , any algorithm ??? top gateoverflow.in/26755
Which one of the following strings is not accepted by the finite automaton described by the regular expression (0 + 1(01 ∗ 0) ∗ 1) ∗
?
1100100011011001011
0110100010111010010
0100011010111010101
1101001101100010011
theory-of-computation
Selected Answer
Yes, design Dfa for given regular expression, and traverse the input, if with given we reach the final state, then input is
accepted else rejected.
DFA
[ Note: if input string is small, it is better to try combination from regular expression, well for this problem, I feel DFA is
much better]
Please share some good resources and questions which can make it easier for me to understand and apply Rice theorem.
theory-of-computation
http://www.gatecse.in/803-2/
Number of states in the minimized DFA that accepts all strings over alphabets Σ = {0, 1} in which number of 0 ′ s is divisible by
8 or number of 0 ′ s is divisible by 16 is _______.
Selected Answer
L1 = number of 0's divisible of 8 , we will have 8 states, ( as each state represent modulo-8)
L2= number of 0's divisible of 16, those are divisible of 16 are already divisible of 8, is already present is L1, i.e, L2 is
subset of L1.
So L1 U L2 = L1 only
we will have simple DFA over {0,1},such that no of 0's are divisible of 8 , having 8 states only
Selected Answer
first row of table consist of 10 entries(columns) the next row contains 9 then next one contains 8 and so on.. until the last
row which contains just one entry.
n(n + 1) 10 × 11
entries in CYK algorithm = 2 = 2 = 55
I believe, qi = qj is the correct answer. Here is the proof idea: Since w is non empty, assume w = ax, where 'a' is the first
letter of string w and x is the remaining part(x can or cannot be empty). Clearly state q0 and qf will wind up in same state
after reading first symbol of string w, since delta(q0, a) = delta(qf, a). Let us suppose that delta(q0, a) = delta(qf, a) = P.
Then for both q0 and qf after scanning the first symbol 'a' they will reach state P and after reaching P, delta_hat(P, x) will
be common to both of them. Hence delta_hat(q0, w) = delta_hat(qf, w).
theory-of-computation
Let the operation is concatenate. as no operation is given . i think we should consider it as concatenate. so Q may or may
no be regular for ex . p=X | x∈(a+b)* now assume that q be a language ww. w belong to the same domain as x. so now
the new language p.q= L={xww∣w,x∈(a+b)∗}
xww which will be regular. q may or may not be regular and cfl . it can be csl also..
Q can be anything
Take P as ∅
∅L = ∅
B may be or may not be regular. e.g Let A = a ∗ b ∗ andB = an bn thenA\cupB = a ∗ b ∗ but consider A = abandB = an bn thenA ∪ B = an bn
which is not regular.
Yes, S2 is not correct cause if the language generated by it is bound to contain ∈ then we cannot remove that. Doing so
will alter the language definition.
So S2 is false.
S → bA
A → aA|∊
we will get
S → bA|b
A → aA|a
Yes,for S2 only if we are not getting , null in language , directly ,S → ∊ , or indirectly, S → A, A → ∊ (for example)
Suppose we have a language L and it is finite, now if we take a complement of language L than what can we say about the
language L / ?
a.) Language is decidable
b.) Undecidable??
theory-of-computation
Now complement of that language is just do nonfinal state as final and also final state as nonfinal. So, it is also a DFA.
L = Regular
Complement of any language L is L ′ = Σ ∗ − L. The given language is DCFL and not regular and hence its complement
cannot be regular as regular set is closed under complement. Since DCFL too is closed under complement, L ′ is DCFL.
8.465 Which of the following is true? (L′ is the Complement of language L) top
gateoverflow.in/32217
1. L is decidable
2. L′ is decidable
3. L and L′ both are decidable
4. L is undecidable
computer-networks ace-test-series
Selected Answer
ip string : 011111101
01111110 is considered flag and not data , ..so if u want to send data 011111101
u need to stuff extra 0 after 5 consecutive ones so that will be not treated as flag or delimiter and will be considered data
9.2 Back Off Delay: Cn-ques1 ethernet and csma-cd top gateoverflow.in/27094
Suppose two nodes, A and B, are attached to opposite ends of a 900 m cable, and that they each have one frame of 1000
bits (including all headers and preambles) to send to each other. Both nodes attempt to transmit at time t=0. Suppose there
are four repeaters between A and B, each inserting a 20 bit delay. Assume the transmission rate is 10 Mbps, and CSMA/CD
with backoff intervals of multiples of 512 bits is used. After the first collision, A draws K=0 and B draws K=1 in the
exponential backoff protocol. Ignore the jam signal.
Ques-1. What is the one-way propagation delay (including repeater delays) between A and B in seconds. Assume that the
signal propagation speed is 2 * 108m/sec.
Ques-3. Now suppose that only A has a packet to send and that the repeaters are replaced with bridges. Suppose that each
bridge has a 20 bit processing delay in addition to a store-and-forward delay. At what time in seconds is A's packet delivered
at B?
For 2nd ques.I am not getting how to take collision and back off delay...
C]Each Bridge introduces additional 1000-bit store-and-forward delay and 20-bit processing delay. Total delay introduced
is 4080-bit time or 408 µs. Transmission delay is 1000-bit time or 100 µs. Propagation delay is 4.5 µs. A’s packet reaches
B at time 408 + 100 + 4.5 = 512.5µs
9.3 Computer: Question on hamming code with even parity top gateoverflow.in/38551
9.4 Congestion Control: What is the size of current sender's window? (TCP
congestion control) top gateoverflow.in/31421
During a TCP connection, the size of the window advertized by the receiver is 20KB. The last byte sent by the sender is
20480 and and the last byte acknowledged by the receiver is 8384. If the current congestion window is 18KB, then current
size of sender's window is _______ (in KB) ?
As far as I know, the current effective size should be "Adv. Window - (Unacknowledged bytes)" . But, the results in an
ambiguity here. As it will give approx (20kb-12kb) = 8KB . But , how is this ever possible because congestion window is
already 18KB??
Given solution:
I couldn't understand from reaching 1KB to 16KB why it took 50ms not 40ms. Please check
Selected Answer
1||2|| 4|| 8 ||16|| 17|| 18|| 19|| 20|| 21|| 22|| 23|| 24|| 25|| 26|| 27|| 28|| 29|| 30|| 31|| 32
Just Count the no. of vertical lines thats the ans ie., 20*10=200 msec irrespective what is all given in solution just stick to
ur concept :)
A TCP machine is sending windows of 65,535 bytes over a 1-Gbps channel that has a 10-msec one-way delay. What is the maximum throughput
achievable? What is the line efficiency?
Answer:
One window can be sent every 20 msec. This gives 50 windows/sec, for a maximum data rate of about 3.3 million bytes/sec. The line efficiency is then 26.4
Mbps/1000 Mbps or 2.6%.
But they have taken 20 msec as RTT and in the question they have given 10 msec one-way delay. Why they have taken RTT? why we can't use one-way
delay itself ?
computer-networks congestion-control
throughput = efficiency * BW
consider "additive increase multiplicative decrease".one MSS is 512B.If TCP sender don't perceive path as congested
What will be congestion window size after 4RTTs provided congestion window is assigned MSS initially
congestion-control
After 4 RTTS:
1->2->4->8->16
congestion-control
9.9 Congestion Control: slow start - tcp congestion control top gateoverflow.in/37567
Q).Suppose that TCP congestion window is set to 28KB and time-out occurs.The window size after the next six successful
transmission bursts (Assume maximum segment size is 2KB and TCP uses congestion avoidance) is _______(in KB)
2,4,8,14,16,18 so Ans=18
10 RTT
so 10*50=500
2mss,4mss,8mss,........
congestion-control
We start the "slow start phase" with the window size given .... but after the threshold we always increase by 1MSS So
according to your question if threshold is at 16MSS then you will do like 2 4 8 16 and then 17 18 till timeout.
cwnd = 1MSS
ssthresh = 6MSS
1MSS sent
so 11RTT
2KB --> 4KB --> 8KB --> 12KB --> 14KB --> 16KB --> 18KB --> 20KB -- > 22KB --> 24KB
Total 10 RTT..
19. Suppose we want to transmit the message 1011 0010 0100 1011
and protect it from errors using the CRC8 polynomial
x8 + x2 + x1 + 1.
(a) Use polynomial long division to determine the message that
should be transmitted.
(b) Suppose the leftmost bit of the message is inverted due to
noise on the transmission link. What is the result of the
receiver’s CRC calculation? How does the receiver know that
an error has occurred?
a) The remainder is 10010011. So the message is 1011 0010 0100 1011 10010011
9.14 Crc Polynomial: CRC can detect all bursts of upto m errors if generator
polynomial G(x) is of degree? top gateoverflow.in/7238
crc-polynomial computer-networks
CRC can only detect bust error of length m if the generator polynomial is of degree m. If you can recall how we generate
the CRC for a particular message.
2. sender findes the reminder of the binary division of the message witht the generator polynomial (Note: the reminder
can be of the length atmost m).
3. sender adds the reminder to the message and send it to the reciver.
4. reciver again divides the message with the generator polynomial and see if the reminder is zero.
5. since we need to change atleast m+1 bits to make the message with CRC code have zero reminder when divided by
the polynomial. I can detect all busrst errors of length m.
18. Suppose we want to transmit the message 11100011 and protect it from errors using the CRC polynomial x3 + 1. (a)
Use polynomial long division to determine the message that should be transmitted. (b) Suppose the leftmost bit of the
message is inverted due to noise on the transmission link. What is the result of the receiver’s CRC calculation? How does the
receiver know that an error has occurred?
At receiver side remainder=100 (it should have been zero)so error occured
If the frame to be transmitted is 1101011011 and the CRC polynomial to be used for generating checksum is x4 + x + 1, than
what is the transmitted frame?
A. 11010110111011
B. 11010110111101
C. 11010110111110
D. 11010110111001
Answer is 11010110111110
computer-networks cryptography
Selected Answer
so ans is 1 and 3 ie c
answer = option A
What will be the cipher text produced by the following cipher function for the plain text ISRO with key k = 7. [ Consider
′ A ′ = 0, ′ B ′ = 1, . . . . ′ Z ′ = 25]
A. RJCH
B. QIBG
C. GQPM
D. XPIN
isro2013 cryptography
Answer is A
BY THE WAY IN THE ABOVE FUNCTION M STANDS FOR 1 character one by one of input
So just from the first character you can get answer RJCH
isro2013 cryptography
@srestha
A symmetric is one which use same key for Encryption and Decryption
Infact it should be DES AES and tripple DES as block cipher ( or fiestal ) They amke use of P and S boxes .
csma-cd
computer-networks csma-cd
Jamming signal is like a negative acknowledgement used to inform all the nodes connected to a link that collision
occurred.
Suppose a node P is transmitting frames to other node Q which is 200 km away from P.
Now suppose the frame sent by P to Q collides with another frame, at a point very near to Q after travelling 199.99 km,
then to inform node P about collision, the jamming signal has to travel almost 200 km.
So in the worst case, P will get informed about collision only after two way propagation delay.
& if P receives jamming signal after it has completed its frame transmission, then will never know that which frame
caused the collision & that the frame that it sent to Q has been collided & lost.
So the frame that P is going to transmit should be large enough to be transmitted until a longest two way propagation
time.
http://gateoverflow.in/?qa=blob&qa_blobid=5597532308294999298
csma-cd
9.23 Csma Cd: In P-persistent CSMA network there are 5 systems in a slot.
The probability of station not transmitting the data is 0.6. Only two stations
should transmit the data to avoid collision. What is the probability that
channel is collision free? top gateoverflow.in/7537
In P-persistent CSMA network there are 5 systems in a slot. The probability of station not transmitting the data
is 0.6. Only two stations should transmit the data to avoid collision. What is the probability that channel is
collision free?
I solved this as P (no collision) = either 2 stations are transmitting or 1 station or none.
computer-networks csma-cd
In question ask only two stations transmit. So, we consider two stations only.
probability =5C2(0.42)(0.63)=0.3456
Two csma/cd stations are trying to send frames..After each frame is sent they contend for channel using backoff exponential
algorithm?What is probability that contention ends on round k?
computer-networks csma-cd
Contention ends on round k means that earlier in k-1 trial it didn't succeed and finally it succeeded on kth Contention.
We wish to send a message of size 150,000 bytes over the network. There are four hops, each of length 20km and running
at 100 Mb/s. Before sending we split the message into 1500 byte packets. What is the end-to-end delay of the message?
# The switches "store and forward " packets along the path.
# For each hop, propagation speed = speed of light in copper = c = 2 * 10^8 m/s.
delay computer-networks
S----R1------R2------R3--------R4--------D
Since Router/switches are store and forward device we wont consider ack time
S R1 R2 R3 R4 D
0 215 430 645 860 1075
15 230 445 660 875 1090
computer-networks distance-vector-routing
Selected Answer
A is right.
delay A to B = 4
A to D = 5
A to c =6.
A B C D E F
0 4 8 8 7 6
via B B B B B B
2nd case
A B C D E F
0 10 6 8 13 10
via C C C C C C
3rd case
A B C D E F
0 6 8 5 8 11
via D D D D D D
final table is
A B C D E F
0 4 6 5 7 6
- B C D B B
In distance vector routing how the distance vectors are update when two paths have same cost
A- [0 ∞ 1 2]
B- [∞ 0 3 2]
C- [1 3 0 ∞]
D- [2 2 ∞ 0]
what will be distance vector of A after 1 iteration. Please mention via node and why u choose that node??
computer-networks distance-vector-routing
Show that two-dimensional parity provides the receiver enough information to correct any 1-bit error (assuming the receiver
knows only 1 bit is bad), but not any 2-bit error.
In the question above we are talking about parity -- which is one of the methods used for Error Correction and detection
ROW 1 : 1 1 1
Row 2 : 0 1 1
Row 3 : 1 0 1
now what we need to do we need to calculate parity ( assume even parity of 1 ) rowwise and columnwise .
So for rowise ( ROW 1) we will get parity bit as 1 ( we need to make even no of ones by counting parity and databits )
now sender sends data and even parity bits that it calculate (rowwise and coloumnwise)
Row 1 : 1 1 1
Row 2 : 0 1 1
Row 3 : 1 0 1
Assume he get
1 0 1
0 1 1
1 0 1
for row 2 : it is 0
for row 3 it is 0
col 1 : 0
col2 : 1
col 3 : 1
here the third bit doenst match it gt change from 1-- 0 ( second column)
Now the intersection or position of first row and 2 column , we have an error
And look the under lined 0 ( above ) . It is an erro bit . since we know the postion we flip the bit to 1
But sometimes we cant detect also beacuse parity bits might get corrupted with data bits . so that they satisfy even parity
criteria .
( you can try for out 2 bits :)) -- Just change any 2 bits and follow same procedure you wont be able to find out position
of that on reciever side
The fact when we cant distinguish or find error even with the help of parity bits . Such errors are called meaningful
errors
With 1 parity bit we can detect all 1-bit errors. Show that at least one generalization fails, as follows:
(b) Find an N (not necessarily minimal) such that no 32-bit error detection code applied to N-bit blocks can detect all errors
altering up to 8 bits.
With 1 parity bit we can detect all 1-bit errors. Show that at least one generalization fails, as follows:
(a) Show that if messages m are 8 bits long, then there is no error detection code e = e(m) of size 2 bits that can detect all 2-
bit errors. Hint: Consider the set M of all 8-bit messages with a single 1 bit; note that any message from M can be
transmuted into any other with a 2-bit error, and show that some pair of messages m 1 and m 2 in M must have the same error
code e.
How many check bits are required for 16 bit data word to detect 2 bit errors and single bit correction using hamming code?
A. 5
B. 6
C. 7
D. 8
isro2013 error-detection
How many parity bits will be required for transmitting a 16-bit data ?
a 6 b 3 c 2 d 1
error-detection
Selected Answer
n is data bit
n ≤ 2k − k − 1
n = 16
16 ≤ 2k − k − 1
k=5
collision domain is the set of LAN interfaces whose frames could collide with each other, but not with frames sent by any
other devices in the network. The collision is happened when to computer in same time want to use bandwidth. The
CSMA/CD algorithm that deals with the issue of collisions, and some of the differences between how hubs and switches
operate to create either a single collision domain (hubs) or many collision domains (switches). Generally speaking in easy
terms, A collision domain is a set of network interface cards (NIC) for which a frame sent by one NIC could result in a
collision with a frame sent by any other NIC in the same collision domain.
http://gateoverflow.in/18788/ethernet-layer-switch-is-a-network-element-type-which-gives
9.34 Ethernet: An image is 1600 x 1200 pixel with 3 bytes/pixel .The time
taken to transmit it over gigabit ethernet is top gateoverflow.in/18291
An image is 1600 ∗ 1200 pixels with 3 bytes/pixel .Assume that the image is incompressible.The time taken to transmit the
image over a gigabit ethernet (in ms) is _______________.
computer-networks ethernet
Selected Answer
1600*1200 pixels
1 pixels---------------- 3 bytes
than 1600*1200-----------3*1600*1200 bytes
=5760000 bytes
=46.08msec
computer-networks ethernet
Address transmission Left to right byte by byte ,however each byte is sent first LSB then MSB.
it will be multicast
ethernet
Selected Answer
Its gigabit ethernet => 1 gigabits per second => 10 9 bits per second.
1
9
=> 46080000 bits = 10 * 46080000 = 0.046080 sec = 46.08 ms
if an ethernet station collide 4 time in trying to transmit a single frame how long might it be before the next attempt?
a)768 microsec
b)819.2 microsec
c)409.6 microsec
d)none
ethernet
Selected Answer
In general, after the cth failed attempt, resend the frame after k · 51.2μs, where k is a random integer
between 0 and 2c − 1
so here max waiting time occurs when we choose the value of k max between 0 to 2^4 - 1 = 15
ref: https://en.wikipedia.org/wiki/Exponential_backoff
In the Ethernet, which field is actually added at the physical layer and is not part of the frame.
A. Preamble
B. CRC
C. Address
D. Location
The first field(Preamble) of 802.3 frame contains 7 bytes of alternating 0s and 1s that alerts the receiving system to the
coming frame and enables it to synchronize its input timing. Preamble is added at the physical layer and is not part of the
frame.
computer-networks ethernet
Selected Answer
In CSMA/CD, for success, only 1 station should transmit while others shouldn't.
For max P(success), differentiate and equate to zero(line in limits to get maxima and minima).
We get P(max)=1/e
1
1 1
e
p (max)
Number of times we need to try before getting 1st success= = =e
transmissiontime(Tt )
hi
regards
Piyush
(c). a and b
(d). a or c
computer-networks ethernet
Ethernet is connectionless.Upper layer protocols(not all) like TCP establishes connection.Connection is implemented
through software and connection oriented Ethernet is also there but by default Ethernet is connectionless.
Q If probability of frame reaching safely is 0.1 then mean number of transmissions of a frame to make it success is _____.
Selected Answer
=10
fragmentation
fragmentation is done by network layer as per according to size of MTU(MAXIMUM transfer unit).
Consider three IP networks A, B and C. Host HA in networks ‘A’ sends message each containing 180 B of application data to
a host HC in network HC. The TCP layer prefixes 20 Bytes header to
the message. This passes through on intermediate network ‘B’. The maximum packet size, including 20B IP headers in each
network is:
A. 500 Bytes
B. 100 Bytes
C.1000 Bytes
The network A and B are connected through 512 Kbps link, while B and C are connected by a 256 Kbps link.
1. Assuming that the packets are correctly delivered, how many Bytes including headers, are
delivered to IP layer at destination for one application message in the best case? Consider only data packets.
A. 220 B.240 C. 260 D. 280
2. What is the rate at which application data is transferred to host HC? Ignore errors,
acknowledgements and other overheads?
A. 196 Kbps B. 177.23 Kbps C. 354.5 Kbps D. 325.5 Kbps
Selected Answer
1.Application layer can recieve any amount of data ..in the given question A recieves 180 Byte of data and sends it to
transport layer.
2.transport layer on recieving it adds a header of 20 Bytes to it total frame size=180+20=200B and sends it to network
layer.
3.network layer on recieving 200 B of data adds 20 Bytes of header total length=220 Bytes..as maximum packet
size=1000 B so no need of fragmentation and then it sends to network B.
4 As B can recieve 100 byte of data only but A is sending 220 byte of data...first of all 20 byte of is removed by network
layer of B and then divide it into 3 fragments (80+20),(80+20),(40+20) ...and then send it to network C.
PART B..
=166.15KBps
part C->
with fragmentation=260
Why is it 416 ?
Selected Answer
Mtu is 440
Ip header =20
9.45 Frame: Calculating frame length when bit rate, propagation delay(in
bits) and length of link is given. top gateoverflow.in/37881
Assume CSMA/CD protocol. Find the least frame length in bytes for a 2 Mbps bit rate and 1.5km long network where propagation delay is 4.25
nano seconds per metre _______
TT=2PT
PT=4.25nsx1.5km= 6.375μs
TT=2PT
Framelength/2x106= 2x6.375μs
Consider a Go Back N sliding window protocol that uses a frame size of 2KB to send data on a 10KBPS link with a Round Trip Time of
100 milli seconds.To achieve a link utilization of 50%, the minimum number of bits required to represent the sequence number field
is _____ .
Here per frame transmission time is 0.2 seconds & given RTT is 0.1 second.
How it is possible?
Selected Answer
=2*2 10 / 10 * 2 10 sec
=1/5 sec= 0.2 sec=200ms
=ceil(log(3/2)) = 1
Station A needs to send a message consisting of 15 packets to station ‘B’ using a sling window (window size 4) and go-back-
N error control strategy. All packets are ready and immediately available for transmission. If every 6th packet that ‘A’
transmits gets lost (but no Acks from ‘B’ ever gets lost), then what is the number of packets that ‘A’ will transmit for sending
the message to ‘B’ ? (a) 29 (b) 33 (c) 27 (d) 25
Selected Answer
1 2 3 4 5 6 7 8 9 6 7 8 9 10 11 8 9 10 11 12 13 10 11 12 13 14 15 12 13 14 15 14 15
Total 33
Station A needs to send a message consisting of 15 packets to station ‘B’ using a sling window (window size 4) and go-back-
N error control strategy. All packets are ready and immediately available for transmission. If every 6th packet that ‘A’
transmits gets lost (but no Acks from ‘B’ ever gets lost), then what is the number of packets that ‘A’ will transmit for sending
the message to ‘B’ ?
(a) 29
(b) 33
(c) 27
(d) 25
Selected Answer
Since every 6th packet get lost : packets will be send like shown below
1 2 3 4 5 6 (lost) 7 8 9
6 7 8 (lost) 9 10 11
8 9 10(lost) 11 12 13
10 11 12 (lost) 13 14 15
12 13 14(lost) 15
14 15
Station X needs to send a message consisting of 12 packets to station Y using GBN with window size = 4. All packets are
ready and available for transmission. If every 7th packet that X transmits gets lost (but no ACK loss), total how many
packets X needs to transmit?
1 2 3 4 5 6 7 8 9 10 7 8 9 10 11 12 10 11 12
packet 7 is lost
packet 10 is lost
sliding-window go-back-n
Selected Answer
PD = 1000km/(2 * 10^8) = 5 ms
Ref: http://web.mit.edu/modiano/www/6.263/lec3-4.pdf
please explain.
computer-networks hamming-code
We have to transfer m message bits, and employ error correction. For that purpose let no of parity bits added be p. Now
error can occur in m message bits or p parity bits or no error therefore total
2^p >=m+p+1
coz after receiving parity bits using those p bits we must be able to identify all these possibilities.
eg
0 0 0 ( no change in p4,p2,p1 after calculating at receiver end) it means no error in data and parity
If its
Consider a network having a host P connected to another host Q via two routers Rl and R2. P is connected to R1 through a
link that can support a maximum frame length of 1024 bytes including header of size 12 bytes. R1 is connected to R2
through a link that supports a maximum frame length of 256 bytes including an 8bytes header. R2 is connected to the host Q
through the link that can support a maximum frame length of 512 bytes including the frame header of 12bytes. Suppose a
TCP message having 800bytes of data and 20 bytes of TCP header is passed to the IP at host P for delivery to Q. Find the
total number of bytes that are sent from host P to Q (including all the headers).
http://gateoverflow.in/?qa=blob&qa_blobid=626145120644117638
ip header
Ans 868
A Router outside the organization received a packet 224.240.7.91. Consider following steps that a router may take:
1. The router looks in its routing table to find out how to route the packet to the destination
2. The router looks at the first byte of the address to find the class
3. The default mask for the class is ANDED (logical AND operation) and address is found.
In case, more than one steps are taken, mention the sequence of steps also.
a) If the ethernet destination address of the arriving frame belongs to the router, accept the frame, else drop it.
e) If the IP destination address is in the forwarding table, forward to the correct outgoing port(s) for the next hop.
f) Find the ethernet destination address for the next hop router.
There should not be any need of finding the class of the IP address if we are going to use forwarding table for finding the next hop.So step 2
should not be taken.
Also if the router will have an entry for the destination IP address of the packet, it will forward the packet otherwise it will simply drop the
packet.So step 3 should not be taken.
Am I missing something?
take the first entry of the rounting table and and with subnet mask of that entry, if it is match just send it to the interface,
else go to next . till you hit a default entry, i think router does not use the class address instead it already have the n/w id
+ subnet mask of n/w.
A. Unicast addressing
B. Multicast addressing
C. Broadcast addressing
D. Anycast addressing
Selected Answer
C)Broadcast Addressing
http://serverfault.com/questions/227442/why-cant-ipv6-send-broadcasts
ipv6
9.56 Ipv6: IPv6 does not support which of the following addressing modes?
top gateoverflow.in/17043
a)Unicast addressing
b)Multicast addressing
c)Broadcast addressing
d)Anycast addressing
ipv6
Selected Answer
C) Broadcast Addressing. IPv6 does not implement traditional IP broadcast, and therefore does not define broadcast
addresses. In IPv6, the same result can be achieved by sending a packet to the link-local all nodes multicast group which
is analogous to IPv4 multicast.
9.57 Jnuee 2006: Computer Networks question JNUEE 2006 top gateoverflow.in/32120
Sliding Window Protocol with Selective Reject/Repeat gives better performance than other protocols when
In case of selective repeat suppose sender is sending n packet then receiver has to wait for n packet .So
buffer requirement is high in case of selective repeat .
So Option A is Correct.
leaky-bucket computer-networks
Selected Answer
Leaky Bucket strategy tries to give the average of all bursty outputs :
Ans B.
top
network-addressing
So I suggest ANS is 1.
1 is the answer. 127.XXX are reserved for loopback though 127.0.0.1 is the usual implemented one (just a convention).
http://en.utrace.de/whois/127.100.100.100
9.60 Network Addressing: What is the IP address for last host of subnet to
which given IP belongs? top gateoverflow.in/37745
My solution :
1 0 0 0 1 0 1 0 AND
1 1 1 1 0 0 0 0 <---- SUBNET MASK last octact
So , 201.59.60.254
computer-networks network-addressing
Selected Answer
1 0 0 0 1 0 1 0
1 1 1 1 0 0 0 0 <---- SUBNET MASK last octact
In Subnet mask you have four 1's ,it means 4 bit have been borrowed from host.
And Total Host Possible is 2^4-2---> given that it's a Class C IP Address.
In the Network Id Don't change the Subnet part because it doesn't belong to host.
We can't put all 1's to the Host bits because it belongs to the broadcast address.
As in the question it was not mentioned Last Host of the last subnet,you can't put all 1's to the Subnet part.
A class c n/w has been connected to a router with mask 255.255.255.49. a packet with ip 195.200.180.173 arrived at
router.find the no of subnet in the network.
computer-networks network-addressing
8 subnets will be there in class c host id bits are 8 and that are the last ones . in the last ones we have taken 3 bits i.e(
32, 16, 1) . for sbnetting convention is that , take the bits from starting but we can take bits from anywhere . so by 3 bits
8 subnets are possible .
The protocol data unit for the transport layer in the internet stack is
A. Segment
B. Message
C. Datagram
D. Frame
isro2013 network-protocols
9.63 Network Security: Kurose Ross, 6th Edition PN0 744 top gateoverflow.in/30596
Revise Question 7
network-security
a=10023
b=10004
=92
a=1023
b=10004
n=10000
network-security computer-networks
9.65 Network Security: SHA 1 hash algo. create N-bit message digest out of
a message of 512bit blocks. So is has a message digest of_? top gateoverflow.in/28879
SHA 1 hash algo. create N-bit message digest out of a message of 512bit blocks. So is has a message digest of_?
A.4 words of 32bits
B.5 words of 32bits
C.16 words of 32bits
D.8 words of 32bits
network-security computer-networks
A packet filtering firewall Block some hosts from accessing the network
Packet filtering works on 3 layer of OSI model .Most of the work is done between the network and physical layers.
it is (D) as answer
9.67 Network Security: Kurose Ross 6th Edition PN 746 R32 top gateoverflow.in/30615
R32. Why must an application gateway work in conjunction with a router filter to be effective?
network-security computer-networks
9.68 Network Security: Kurose Ross 6th Edition PN 745 R17 top gateoverflow.in/30607
R17. What does it mean to say that a nonce is a once-in-a-lifetime value? In whose
lifetime?
Ans given -> Once in a lifetimes means that the entity sending the nonce will never again use that value to check whether another entity is “live”.
network-security computer-networks
Two hosts are connected via a packet switch with 10 7 bits per second links. Each link has a propagation delay of 20
microseconds. The switch begins forwarding a packet 35 microseconds after it receives the same. If 100 bits of data are to
be transmitted between the two hosts using a packet size of 500 bits, the time elapsed between the transmission of the first
bit of data and the reception of the last bit of the data in microseconds is _____.
computer-networks network-switching
Selected Answer
Since packet size is 500 bits even though we need only 100 bits, we have to send 500 bits.
Transmission time for 500 bits = Time for 500 bits to travel
So, after 50 microseconds he packet is completely transmitted. But the packet must reach the other end and this happens
exactly after propagation delay which here is 20 microseconds. So, the switch receives the packet after 50 + 20 = 70
microseconds.
Given in question, switch forwards after 35 microseconds. So, after 70 + 35 = 105 microseconds, the switch forwards the
packet and at 105 + 70 = 175 microseconds the receiver receives the last bit of data. (70 is same as the time to reach
the switch as propagation delay is same for the two links as given in question).
Q 30). Consider a route in a store and forward networking going through 9 intermediate nodes.The packet contains 1100 bits
and are transmitted at 64 Kpbs . Assume propogation delay over the links are negligible.As packet travels along the route, it
encounters an average of 5 packets when it arrives at each node. How long does it take for the packets to get to the receiver
if the nodes transmit on a " first come first served" basis (in ms) ?
network-switching
is the total time in ckt switching is more than the packet switching
network-switching
It depends. the total time in circuit switch is setup time + transmission time+ propagation delay + end up time.
while in packet switching it only take the transmission time and propagation delay . but transmission is done at every
hope.
circuit switch is like connecting a lan between two computer while packet switching is like transfering data using the
internet in between.
if the data is in a bulk. lan will be usefull while if it is a small packet then packet switch will be best.
PS: In virtual packet switching resouce allocation is done during setup, while in datagram packet switching, there is no
allocation. http://www.slideshare.net/mukeshnt/chap-8-switching
Suppose a switch is built using a computer workstation and that it can forward packets at a rate of 500, 000 packets per
second, regardless (within limits) of size. Assume the workstation uses direct memory access (DMA) to move data in and out
of its main memory, which has a bandwidth of 2 Gbps, and that the I/O bus has a bandwidth of 1 Gbps. At what packet size
would the bus bandwidth become the limiting factor?
peterson-davie numerical-type
The CRC algorithm as presented in this chapter requires lots of bit manipulations. It is, however, possible to do polynomial
long division taking multiple bits at a time, via a table-driven method, that enables efficient software implementations of
CRC.We outline the strategy here for long division 3 bits at a time (see Table 2.5); in practice, we would divide 8 bits at a
time, and the table would have 256 entries. Let the divisor polynomial C = C(x) be x3 + x2 + 1, or 1101. To build the table for C,
we take each 3-bit sequence, p, append three trailing 0s, and then find the quotient q = p ⌢ 000 ÷ C,
Ignoring the remainder. The third column is the product C × q, the first 3 bits of which should equal p.
peterson-davie numerical-type
The CRC algorithm as presented in this chapter requires lots of bit manipulations. It is, however, possible to do polynomial
long division taking multiple bits at a time, via a table-driven method, that enables efficient software implementations of
CRC.We outline the strategy here for long division 3 bits at a time (see Table 2.5); in practice, we would divide 8 bits at a
time, and the table would have 256 entries. Let the divisor polynomial C = C(x) be x3 + x2 + 1, or 1101. To build the table for C,
we take each 3-bit sequence, p, append three trailing 0s, and then find the quotient q = p ⌢ 000 ÷ C,
Ignoring the remainder. The third column is the product C × q, the first 3 bits of which should equal p
(c) Use the table to divide 101001011001100 by C. Hint: The first 3 bits of the dividend are p = 101, so from the table
the corresponding first 3 bits of the quotient are q = 110.Write the 110 above the second 3 bits of the dividend, and subtract
C × q = 101110, again from the table, from the first 6 bits of the dividend. Keep going in groups of 3 bits. There should be no
remainder.
peterson-davie numerical-type
The CRC algorithm as presented in this chapter requires lots of bit manipulations. It is, however, possible to do polynomial
long division taking multiple bits at a time, via a table-driven method, that enables efficient software implementations of
CRC.We outline the strategy here for long division 3 bits at a time (see Table 2.5); in practice, we would divide 8 bits at a
time, and the table would have 256 entries. Let the divisor polynomial C = C(x) be x3 + x2 + 1, or 1101. To build the table for C,
we take each 3-bit sequence, p, append three trailing 0s, and then find the quotient q = p ⌢ 000 ÷ C,
Ignoring the remainder. The third column is the product C × q, the first 3 bits of which should equal p.
(a) Verify, for p = 110, that the quotients q = p ⌢ 000 ÷ C and q = p ⌢ 111 ÷ C are the same; that is, it doesn’t matter what
the trailing bits are.
peterson-davie numerical-type
Suppose we want to transmit the message 11100011 and protect it from errors using the CRC polynomial x3 + 1.
(a) Use polynomial long division to determine the message that should be transmitted.
peterson-davie numerical-type
Selected Answer
Prove that the Internet checksum computation shown in the text is independent of byte order (host order or network order)
except that the bytes in the final checksum should be swapped later to be in the correct order. Specifically, show that the
sum of 16-bit words can be computed in either byte order. For example, if the one’s complement sum (denoted by +′) of 16-
bit words is represented as follows,
[A, B] + ′ [C, D] + ′ . . . + ′ [Y, Z]
The following swapped sum is the same as the original sum above:
[B, A] + ′ [D, C] + ′ . . . + ′ [Z, Y]
peterson-davie numerical-type
Show that the Internet checksum can be computed by first taking the 32-bit ones complement sum of the buffer in 32-bit
units, then taking the 16-bit ones complement sum of the upper and lower half words, and finishing as before by
complementing the result. (To take a 32-bit ones complement sum on 32-bit twos complement hardware, you need access to
the “overflow” bit.)
Suppose we want to transmit the message 11100011 and protect it from errors using the CRC polynomial x3 + 1.
(b) Suppose the leftmost bit of the message is inverted due to noise on the transmission link. What is the result of the
receiver’s CRC calculation? How does the receiver know that an error has occurred?
peterson-davie numerical-type
Selected Answer
its easy
Now we know That in this CRC calculation remainder what we get is padded with message
So when we apply 11100011/ 1001 ( using mod 2 operator ) we get Remainder as 100
So from the sender side message that would be transmitted is 11100011 100 ( message + remainder )
Now this message is send over channel but now according to given condition it is said due to noise , The leftmost bit get
changed
Now the things that happen on Reciever side : It take (message + reaminder ) / 1001 Now for this divison if it get
remainder 000 then your message is perfect or correct
Now if i do (1100011 100)/ 1001 = you will get remainder as 010 which is not equal to required 000
Note that if your CRc Polynomial is n bit then the remainder will be n-1 bits
Suppose we want to transmit the message 1011001001001011 and protect it from errors using the CRC8 polynomial.
x8 + x2 + x1 + 1
peterson-davie numerical-type
message is 1011001001001011
CRC is 100000111
Suppose we want to transmit the message 1011001001001011 and protect it from errors using the CRC8 polynomial
x8 + x2 + x1 + 1
(b) Suppose the leftmost bit of the message is inverted due to noise on the transmission link. What is the result of the
receiver’s CRC calculation? How does the receiver know that an error has occurred?
peterson-davie numerical-type
pag
page 2 :
(b) Suggest a suitable timeout value for the ARQ algorithm to use.
peterson-davie numerical-type
Here PT=200µs
RTT=400µs
Timeout =2*RTT
=800µs
Suppose A is connected to B via an intermediate router R, as in the previous problem. The A − R link is instantaneous, but the
R − B link transmits only one packet each second, one at a time (so two packets take 2 seconds). Assume A sends to B using
the sliding window protocol with SWS = 4. For Time = 0, 1, 2, 3, 4, state what packets arrive at and are sent from A and B. How
large does the queue at R grow?
peterson-davie numerical-type
Suppose the round-trip propagation delay for Ethernet is 46.4μs. This yields a minimum packet size of 512 bits (464 bits
corresponding to propagation delay + 48 bits of jam signal).
(a) What happens to the minimum packet size if the delay time is held constant, and the signalling rate rises to 100 Mbps?
peterson-davie numerical-type
Suppose A is connected to B via an intermediate router R, as shown in Figure 2.37. The A − R and R − B links each accept
and transmit only one packet per second in each direction (so two packets take 2 seconds), and the two directions
transmit independently. Assume A sends to B using the sliding window protocol with SWS = 4.
(b) What happens if the links have a propagation delay of 1.0 second, but accept immediately as many packets as are offered
(i.e., latency = 1 second but bandwidth is infinite)?
peterson-davie numerical-type
Give some details of how you might augment the sliding window protocol with flow control by having ACKs carry additional
information that reduces the SWS as the receiver runs out of buffer space. Illustrate your protocol with a timeline for a
transmission; assume the initial SWS and RWS are 4, the link speed is instantaneous, and the receiver can free buffers at the
rate of one per second (i.e., the receiver is the bottleneck). Show what happens at T = 0, T = 1, . . . . . . , T = 4 seconds.
peterson-davie numerical-type
Suppose the round-trip propagation delay for Ethernet is 46.4μs. This yields a minimum packet size of 512 bits (464 bits
corresponding to propagation delay +48 bits of jam signal).
(c) If compatibility were not an issue, how might the specifications be written so as to permit a smaller minimum packet
size?
peterson-davie numerical-type
(Figure 2.37)
Suppose A is connected to B via an intermediate router R, as shown in Figure 2.37. The A − R and R − B links each accept
and transmit only one packet per second in each direction (so two packets take 2 seconds), and the two directions
transmit independently. Assume A sends to B using the sliding window protocol with SWS = 4.
(a) For Time = 0, 1, 2, 3, 4, 5, state what packets arrive at and leave each node, or label them on a timeline.
peterson-davie numerical-type
Coaxial cable Ethernet was limited to a maximum of 500m between repeaters, which regenerate the signal to 100% of its
original amplitude. Along one 500-m segment, the signal could decay to no less than 14% of its original value (8.5dB). Along
1500 m, then, the decay might be (0.14)3 = 0.3%. Such a signal, even along 2500 m, is still strong enough to be read; why then
are repeaters required every 500 m?
Suppose you are designing a sliding window protocol for a 1-Mbps point-to-point link to the stationary satellite revolving
around the Earth at an altitude of 3 × 104 km. Assuming that each frame carries 1 KB of data, what is the minimum number of
bits you need for the sequence number in the following cases? Assume the speed of light is 3 × 108 m/s.
peterson-davie numerical-type
Here PT=(3*10^3*10^4)/(3*10^8)
=.1 sec
TT=8192*10^-6 sec
=25
Here SWS=RWS
So Sequence bit =6
The 1982 Ethernet specification allowed between any two stations up to 1500mof coaxial cable, 1000mof other point-to-point
link cable, and two repeaters. Each station or repeater connects to the coaxial cable via up to 50mof “drop cable.” Typical
delays associated with each device are given in Table 2.6 (where c = speed of light in a vacuum = 3 × 108 m/s). What is the
worst-case round-trip propagation delay, measured in bits, due to the sources listed? (This list is not complete;
other sources of delay include sense time and signal rise time.)
peterson-davie numerical-type
(a) Compute the one-way propagation delay for this link, assuming that the speed of light is 2 × 108 m/s in the fiber.
peterson-davie numerical-type
Solution . Propagation time= time to reach first bit from sender side to reciever side.
(c) Why might it still be possible for the ARQ algorithm to time out and retransmit a frame, given this timeout value?
peterson-davie numerical-type
Suppose you are designing a sliding window protocol for a 1-Mbps point-to-point link to the moon, which has a one-way
latency of 1.25 seconds. Assuming that each frame carries 1 KB of data, what is the minimum number of bits you need for
the sequence number?
peterson-davie numerical-type
so from sender to reciever = sender to Moon + Moon to sender = 2 × sender to Moon = 2.50 s
Total no. of bits transmitted in RTT= 2 × P.T. ×Bandwidth = 2× 2.50 × 1 ×106 = 5× 106 bits
No. of frame transmitted = Total no. of bits transmitted in RTT / frame size
so for sliding window protocol use anyone protocol go back, selective repeat etc
Suppose you are designing a sliding window protocol for a 1-Mbps point-to-point link to the stationary satellite revolving
around the Earth at an altitude of 3 × 104 km. Assuming that each frame carries 1 KB of data, what is the minimum number of
bits you need for the sequence number in the following cases? Assume the speed of light is 3 × 108 m/s.
(a) RWS = 1
peterson-davie numerical-type
Here PT=(3*10^3*10^4)/(3*10^8)
=.1 sec
TT=8192*10^-6 sec
=25
If RWS=1
No of sequence bit=5
Suppose the round-trip propagation delay for Ethernet is 46.4μs. This yields a minimum packet size of 512 bits (464 bits
corresponding to propagation delay +48 bits of jam signal).
peterson-davie numerical-type
1. Physical Layer
2. Session Layer
3. Transport Layer
4. Data Link Layer
Solution
Solution Given as
osi-protocol
Suppose an IP packet is fragmented into 10 fragments, each with a 1% (independent) probability of loss. To a reasonable
approximation, this means there is a 10% chance of losing the whole packet due to loss of a fragment. What is the
probability of net loss of the whole packet if the packet is transmitted twice,
(a) Assuming all fragments received must have been part of the same transmission?
a)The probability of loosing both the packet is=0.1(chances of loosing 1st packet)*0.1(chances of loosing 2nd
packet)=0.01
Suppose an IP packet is fragmented into 10 fragments, each with a 1% (independent) probability of loss. To a reasonable
approximation, this means there is a 10% chance of losing the whole packet due to loss of a fragment. What is the
probability of net loss of the whole packet if the packet is transmitted twice,
(c) Explain how use of the Ident field might be applicable here.
c)An implementation might (though generally most do not) use the same value for Ident when a packet had to be
retransmitted. .
Suppose an IP packet is fragmented into 10 fragments, each with a 1% (independent) probability of loss. To a reasonable
approximation, this means there is a 10% chance of losing the whole packet due to loss of a fragment. What is the
probability of net loss of the whole packet if the packet is transmitted twice,
(b) Assuming any given fragment may have been part of either transmission?
Suppose a 10-Mbps Ethernet hub (repeater) is replaced by a 10-Mbps switch, in an environment where all traffic is between a
single server and N "clients." Because all traffic must still traverse the server-switch link, nominally there is no improvement
in bandwidth.
(b) What other advantages and drawbacks might a switch offer versus a hub?
peterson-davie descriptive
Some signalling errors can cause entire ranges of bits in a packet to be overwritten by all 0s or all 1s. Suppose all the bits in
the packet, including the Internet checksum, are overwritten. Could a packet with all 0s or all 1s be a legal IPv4 packet? Will
the Internet checksum catch that error? Why or why not?
peterson-davie descriptive
No, this would not be legal, as the packet has structure to it and is not just a collection of data.
All 0's and 1's over the entire packet will change the VER and HLEN fields resulting in non IPV4 packets.
The starting 4 bit of IP Packet decide whether the packet is IP4 or IPV6.other than this possibility if other possibilty occur then the router
will understand that it is modified by noise.
Why does the Offset field in the IP header measure the offset in 8-byte units? (Hint: Recall that the Offset field is 13 bits
long.)
peterson-davie descriptive
The IPv4 header allocates only 13 bits to the Offset field, but a packet’s length can be up to 2 16 -1.
In order to support fragmentation of a maximum-sized packet, we must count offsets in multiples of 2 16−13= 23bytes.
A stage of an n × n banyan network consists of (n/2)2 × 2 switching elements. The first stage directs packets to the correct half
of the network, the next stage to the correct quarter, and so on, until the packet is routed to the correct output. Derive an
expression for the number of 2 × 2 switching elements needed to make an n × n banyan network. Verify your answer for n = 8.
What aspect of IP addresses makes it necessary to have one address per network interface, rather than just one per host? In
light of your answer, why does IP tolerate point-to-point interfaces that have nonunique addresses or no addresses?
peterson-davie descriptive
http://www.freesoft.org/CIE/RFC/1812/24.htm
Suppose a 10-Mbps Ethernet hub (repeater) is replaced by a 10-Mbps switch, in an environment where all traffic is between a
single server and N "clients. "Because all traffic must still traverse the server switch link, nominally there is no improvement
in bandwidth.
peterson-davie descriptive
Suppose a TCP message that contains 1024 bytes of data and 20 bytes of TCP header is passed to IP for delivery across two
networks interconnected by a router (i.e., it travels from the source host to a router to the destination host). The first
network has an MTU of 1024 bytes; the second has an MTU of 576 bytes. Each network's MTU gives the size of the largest IP
datagram that can be carried in a link layer frame. Give the sizes and offsets of the sequence of fragments delivered to the
network layer at the destination host. Assume all IP headers are 20 bytes.
peterson-davie descriptive
Before entering the first network,we have an IP datagram of 1024+20(TCP header)+20(IP header)=1064 bytes.so the IP
payload is 1044 bytes .This datagram needs to split into 2 fragments.
When fragment 1 goes through the second network,it needs to be split into two fragments.Each fragment can contain at
most 576-20=556 bytes of data.since 556 bytes is not a multiple of 8,each fragment can in fact contain atmost 552 bytes
of data.so we have following 2 fragments:
The fragment that reach the destination are 3,4 and 2.They are assembled in this order this is because their offsets are in
increasing order(0,69,125).
Path MTU is the smallest MTU of any link on the current path (route) between two hosts. Assume we could discover the path
MTU of the path used in the previous exercise, and that we use this value as the MTU for all the path segments. Give the
sizes and offsets of the sequence of fragments delivered to the network layer at the destination host.
peterson-davie descriptive
http://gateoverflow.in/43636/peterson-davie-3-36
we know Path MTU is the smallest MTU of any link on the current path (route) between two hosts.
This would be fragmented into 2 fragments of size 552 and 496 bytes.
There are 2 packets in total if we use Path MTU.In previous case, we needed 3 packets.
Show that the Internet checksum will never be 0xFFFF (that is, the final value of sum will not be 0x0000) unless every byte in
the buffer is 0. (Internet specifications in fact require that a checksum of 0x0000 be transmitted as 0xFFFF; the value 0x0000 is
then reserved for an omitted checksum. Note that, in ones complement arithmetic, 0x0000 and 0xFFFF are both
representations of the number 0).
peterson-davie descriptive
Suppose that we run the sliding window algorithm with SWS = 5 and RWS = 3, and no out-of-order arrivals.
peterson-davie descriptive
Suppose that we run the sliding window algorithm with SWS = 5 and RWS = 3, and no out-of-order arrivals.
(c) State a general rule for the minimum MaxSeqNum in terms of SWS and RWS.
peterson-davie descriptive
Consider the situation in the previous exercise, except this time assume that the router has a queue size of 1; that is, it can
hold one packet in addition to the one it is sending (in each direction). Let A ′ s timeout be 5 seconds, and let SWS again be 4.
Show what happens at each second from Time = 0 until all four packets from the first window-full are successfully delivered.
peterson-davie descriptive
What kind of problems can arise when two hosts on the same Ethernet share the same hardware address? Describe what
happens and why that behavior is a problem.
peterson-davie descriptive
Suppose that we run the sliding window algorithm with SWS = 5 and RWS = 3, and no out-of-order arrivals.
(a) Find the smallest value for MaxSeqNum. You may assume that it suffices to find the smallest MaxSeqNum such that if
DATA[MaxSeqNum] is in the receive window, then DATA[0] can no longer arrive.
peterson-davie descriptive
Consider the sliding window algorithm with SWS = RWS = 3, with no out-of-order arrivals and with infinite-precision sequence
numbers.
(b) Show that if ACK[6] may be sent (or, more literally, that DATA[5] is in the sending window), then ACK[2] (or earlier) cannot
be received.
These amount to a proof of the formula given in Section 2.5.2, particularized to the case SWS = 3. Note that part (b) implies
that the scenario of the previous problem cannot be reversed to involve a failure to distinguish ACK[0] and ACK[5].
peterson-davie descriptive
Draw a timeline diagram for the sliding window algorithm with SWS = RWS = 4 frames in the following two situations. Assume
the receiver sends a duplicate acknowledgment if it does not receive the expected frame. For example, it sends DUPACK[2]
when it expects to see Frame[2] but receives Frame[3] instead. Also, the receiver sends a cumulative acknowledgment after
it receives all the outstanding frames. For example, it sends ACK[5] when it receives the lost frame Frame[2] after it already
received Frame[3], Frame[4], and Frame[5]. Use a timeout interval of about 2 × RTT.
(a) Frame 2 is lost. Retransmission takes place upon timeout (as usual).
peterson-davie descriptive
Draw a timeline diagram for the sliding window algorithm with SWS = RWS = 4 frames in the following two situations. Assume
the receiver sends a duplicate acknowledgment if it does not receive the expected frame. For example, it sends DUPACK[2]
when it expects to see Frame[2] but receives Frame[3] instead. Also, the receiver sends a cumulative acknowledgment after
it receives all the outstanding frames. For example, it sends ACK[5] when it receives the lost frame Frame[2] after it already
received Frame[3], Frame[4], and Frame[5]. Use a timeout interval of about 2 × RTT.
(b) Frame 2 is lost. Retransmission takes place either upon receipt of the first DUPACK or upon timeout. Does this scheme
reduce the transaction time? (Note that some end-to-end protocols, such as variants of TCP, use similar schemes for fast
retransmission.)
peterson-davie descriptive
Suppose that we attempt to run the sliding window algorithm with SWS = RWS = 3 and with MaxSeqNum = 5. The Nth packet
DATA[N] thus actually contains N mod 5 in its sequence number field. Give an example in which the algorithm becomes
confused; that is, a scenario in which the receiver expects DATA[5] and accepts DATA[0] - which has the same transmitted
sequence number - in its stead. No packets may arrive out of order. Note that this implies MaxSeqNum ≥ 6 is necessary as
well as sufficient.
peterson-davie descriptive
Suppose the Ethernet transmission algorithm is modified as follows: After each successful transmission attempt, a host waits
one or two slot times before attempting to transmit again, and otherwise backs off the usual way.
(a) Explain why the capture effect of the previous exercise is now much less likely.
peterson-davie descriptive
Suppose the Ethernet transmission algorithm is modified as follows: After each successful transmission attempt, a host waits
one or two slot times before attempting to transmit again, and otherwise backs off the usual way.
(b) Show how the strategy above can now lead to a pair of hosts capturing the Ethernet, alternating transmissions, and
locking out a third.
peterson-davie descriptive
Cell switching methods (like ATM) essentially always use virtual circuit switching rather than datagram forwarding. Give a
specific argument why this is so (consider the preceding question).
peterson-davie descriptive
Suppose a workstation has an I/O bus speed of 800 Mbps and memory bandwidth of 2 Gbps. Assuming direct memory access
(DMA) is used to move data in and out of main memory, how many interfaces to 100-Mbps Ethernet links could a switch
based on this workstation handle?
peterson-davie descriptive
Suppose that a switch is designed to have both input and output FIFO buffering. As packets arrive on an input port they are
inserted at the tail of the FIFO. The switch then tries to forward the packets at the head of each FIFO to the tail of the
appropriate output FIFO.
(a) Explain under what circumstances such a switch can lose a packet destined for an output port whose FIFO is empty
peterson-davie descriptive
What percentage of an ATM link's total bandwidth is consumed by the ATM cell headers? Ignore padding to fill cells or ATM
adaptation layer headers.
peterson-davie descriptive
Suppose a bridge has two of its ports on the same network. How might the bridge detect and correct this?
peterson-davie descriptive
Suppose the Ethernet transmission algorithm is modified as follows: After each successful transmission attempt, a host waits
one or two slot times before attempting to transmit again, and otherwise backs off the usual way.
(c) Suppose the Ethernet transmission algorithm is modified as follows: After each successful transmission attempt, a host
waits one or two slot times before attempting to transmit again, and otherwise backs off the usual way.
peterson-davie descriptive
For the network given in Figure 3.45, give the datagram forwarding table for each node. The links are labeled with relative
costs; your tables should forward each packet via the lowest-cost path to its destination.
peterson-davie descriptive
A 3 C
C 1 E
B 2 E
D 2 E
E 1 C
F 6 C
Give forwarding tables for switches S1 to S4 in Figure 3.46. Each switch should have a default routing entry, chosen to
forward packets with unrecognized destination addresses toward OUT. Any specific destination table entries duplicated by
the default entry should then be eliminated.
peterson-davie descriptive
A,B 1,2 3
1,3 2
C 2,3 1
D 2 1
Draw a timeline diagram for the sliding window algorithm with SWS = RWS = 3 frames, for the following two situations. Use a
timeout interval of about 2 × RTT
peterson-davie descriptive
Consider the sliding window algorithm with SWS = RWS = 3, with no out-of-order arrivals and with infinite-precision sequence
numbers
(a) Show that if DATA[6] is in the receive window, then DATA[0] (or in general any older data) cannot arrive at the receiver
(and hence that MaxSeqNum = 6 would have sufficed).
These amount to a proof of the formula given in Section 2.5.2, particularized to the case SWS = 3. Note that part (b) implies
that the scenario of the previous problem cannot be reversed to involve a failure to distinguish ACK[0] and ACK[5].
peterson-davie descriptive
Suppose that a switch is designed to have both input and output FIFO buffering. As packets arrive on an input port they are
inserted at the tail of the FIFO. The switch then tries to forward the packets at the head of each FIFO to the tail of the
appropriate output FIFO.
peterson-davie descriptive
The text suggests that the sliding window protocol can be used to implement flow control. We can imagine doing this by
having the receiver delay ACKs, that is, not send the ACK until there is free buffer space to hold the next frame. In doing so,
each ACK would simultaneously acknowledge the receipt of the last frame and tell the source that there is now free buffer
space available to hold the next frame. Explain why implementing flow control in this way is not a good idea.
peterson-davie descriptive
Draw a timeline diagram for the sliding window algorithm with SWS = RWS = 3 frames, for the following two situations. Use a
timeout interval of about 2 × RTT.
peterson-davie descriptive
Suppose that a switch is designed to have both input and output FIFO buffering. As packets arrive on an input port they are
inserted at the tail of the FIFO. The switch then tries to forward the packets at the head of each FIFO to the tail of the
appropriate output FIFO.
(c) Assume that the FIFO buffering memory can be redistributed freely. Suggest a reshuffling of the buffers that avoids the
above problem, and explain why it does so.
peterson-davie descriptive
Suppose that one byte in a buffer covered by the Internet checksum algorithm needs to be decremented (e.g., a header hop
count field). Give an algorithm to compute the revised checksum without rescanning the entire buffer. Your algorithm should
consider whether the byte in question is low order or high order.
peterson-davie descriptive
Suppose that a switch is designed to have both input and output FIFO buffering. As packets arrive on an input port they are
inserted at the tail of the FIFO. The switch then tries to forward the packets at the head of each FIFO to the tail of the
appropriate output FIFO.
(c) Assume that the FIFO buffering memory can be redistributed freely. Suggest a reshuffling of the buffers that avoids the
above problem, and explain why it does so.
peterson-davie descriptive
Consider an ARQ protocol that uses only negative acknowledgments (NAKs), but no positive acknowledgments (ACKs).
Describe what timeouts would have to be scheduled. Explain why an ACK-based protocol is usually preferred to a NAK-based
protocol.
peterson-davie descriptive
In stop-and-wait transmission, suppose that both sender and receiver retransmit their last frame immediately on receipt of a
duplicate ACK or data frame; such a strategy is superficially reasonable because receipt of such a duplicate is most likely to
mean the other side has experienced a timeout.
(b) Suppose that, like data, ACKs are retransmitted if there is no response within the timeout period. Suppose also that both
sides use the same timeout interval. Identify a reasonably likely scenario for triggering the Sorcerer’s Apprentice bug.
peterson-davie descriptive
Implicit in the stop-and-wait scenarios of Figure 2.17 is the notion that the receiver will retransmit its ACK immediately
on receipt of the duplicate data frame. Suppose instead that the receiver keeps its own timer and retransmits its ACK only
after the next expected frame has not arrived within the timeout interval. Draw timelines illustrating the scenarios in Figure
2.17(b) to (d); assume the receiver’s timeout value is twice the sender’s. Also redraw (c) assuming the receiver’s timeout value
is half the sender’s.
peterson-davie descriptive
Describe a protocol combining the sliding window algorithm with selective ACKs. Your protocol should retransmit promptly,
but not if a frame simply arrives one or two positions out of order. Your protocol should also make explicit what happens if
several consecutive frames are lost.
peterson-davie descriptive
In stop-and-wait transmission, suppose that both sender and receiver retransmit their last frame immediately on receipt of a
duplicate ACK or data frame; such a strategy is superficially reasonable because receipt of such a duplicate is most likely to
mean the other side has experienced a timeout.
(a) Draw a timeline showing what will happen if the first data frame is somehow duplicated, but no frame is lost. How long
will the duplications continue? This situation is known as the Sorcerer’s Apprentice bug.
peterson-davie descriptive
9.143 Probability: What is the max # of users can an ISP serve @least 95%
of the time assuming probability of each user being active is .1? top gateoverflow.in/25402
esP
SI
na
nac
sresu
fo
m
u
rm
n
e
u
bm
ix
aeht
si
W
tah
gnieb
resu
hcae
fo
yt i l ib a
b
orp
ISP has edge router with 200Mbps (1Mbps=10^6 bits per sec) and wants to provide each user with 2Mbps connection.
computer-networks probability
pure_aloha
Selected Answer
(1024/50)bits-----> 1 second
So N*(1024/50)=18% of 48*1000
N=Floor(421.875)
N=421
25. Suppose you are designing a sliding window protocol for a 1-Mbps point-to-point link to the stationary satellite revolving
around the Earth at an altitude of 3 × 104 km. Assuming that each frame carries 1 KB of data, what is the minimum number
of bits you need for the sequence number in the following cases? Assume the speed of light is 3 × 10 8 m/s. (a) RWS=1 (b)
RWS=SWS
computer-networks reference-book
13. Suppose a 1-Gbps point-to-point link is being set up between the Earth and a new lunar colony. The distance from the moon to the Earth is
approximately 385,000 km, and data travels over the link at the speed of light—3 × 108 m/s.
(b) Using the RTT as the delay, calculate the delay × bandwidth product for the link.
computer-networks reference-book
tp=385000*10^3/3*10^8=1.28 sec
1)RTT=2*1.28=2.56
3)bandwidth delay product gives no of bits which can be sent in one rtt
? 25MB
min time=25MB*2.56/10^9
=0.512 sec
24. Consider a network with a ring topology, link bandwidths of 100 Mbps, and propagation speed 2 × 108 m/s. What would
the circumference of the loop be to exactly contain one 1500-byte packet, assuming nodes do not introduce delay? What
would the circumference be if there was a node every 100 m, and each node introduced 10 bits of delay?
computer-networks reference-book
16. Calculate the latency (from first bit sent to last bit received) for
the following:
(a) 100-Mbps Ethernet with a single store-and-forward switch in
the path and a packet size of 12,000 bits. Assume that each
link introduces a propagation delay of 10 µs and that the
switch begins retransmitting immediately after it has finished
receiving the packet.
(b) Same as (a) but with three switches.
(c) Same as (a), but assume the switch implements “cutthrough” switching; it is able to begin retransmitting the
packet after the first 200 bits have been received.
computer-networks reference-book
so total latency=260us
3)For “cut-through”, a switch needs to only decode the 200 bits before it begins to forward. This takes 2 us. This delay
replaces the switch transmit delays in the previous answer for a total delay of one transmit delay + 3 cut through
decoding delays + 4 propagation delays = 120+3*2+4*10=166 us
=312.5(313 aprox)
No of seq no=312.5*2=625
computer-networks reference-book
computer-networks reference-book
so L/B = d/v
19. Calculate the delay × bandwidth product for the following links.
Use one-way delay, measured from first bit sent to first bit
received.
(a) 100-Mbps Ethernet with a delay of 10 µs.
(b) 100-Mbps Ethernet with a single store-and-forward switch
like that of Exercise 16(b), packet size of 12,000 bits, and 10 µs
per link propagation delay.
(c) 1.5-Mbps T1 link, with a transcontinental one-way delay of
50 ms.
(d) 1.5-Mbps T1 link between two groundstations
communicating via a satellite in geosynchronous orbit,
35,900 km high. The only delay is speed-of-light propagation
delay from Earth to the satellite and back.
computer-networks reference-book
18. Calculate the effective bandwidth for the following cases. For (a) and (b) assume there is a steady supply of data to send; for (c) simply
calculate the average over 12 hours. (a) 100-Mbps Ethernet through three store-and-forward switches as in Exercise 16(b). Switches can send
on one link while receiving on the other. (b) Same as (a) but with the sender having to wait for a 50-byte acknowledgment packet after sending
each 12,000-bit data packet. (c) Overnight (12-hour) shipment of 100 DVDs that hold 4.7 GB each.
computer-networks reference-book
21. Suppose a host has a 1-MB file that is to be sent to another host.
The file takes 1 second of CPU time to compress 50% or 2 seconds
to compress 60%.
(a) Calculate the bandwidth at which each compression option
takes the same total compression + transmission time.
(a) Explain why latency does not affect your answer.
computer-networks reference-book
15. For each of the following operations on a remote file server, discuss whether they are more likely to be delay sensitive or bandwidth sensitive: (a) Open a file.
(b) Read the contents of a file. (c) List the contents of a directory. (d) Display the attributes of a file.
computer-networks reference-book
9.156 Ring: What does it mean when the propagation delay is given in bits?
top gateoverflow.in/14345
Studying ring latency for Ring topology, there were few mentions of propagation delay in bits. While I have learned to
convert the time given in bits to seconds, what does the statement means when it says "the propagation delay of a
channel is 10 bits"?
I came to a conclusion that for a bit to propagate the whole channel and reach at the end of the channel there must be 10
bits in the channel. Or in short, the capacity of the channel is 10 bits.
computer-networks ring
Selected Answer
As you must know, the propagation delay (measured in time units) doesn't depend on the channel bandwidth and is a characteristic of the transmission media
used. Given by tp= l./v , where "l" is the length of the cable and "v" is the velocity of signal in that media.
Coming to your question, if the propagation delay is given in bits, then not only the media but also the bandwidth or data rate of the channel has a role to play.
The propagation delay in bits is the amount of data(bits) transmitted by the sender (A) in time t p. You can observe that in this time, the first bit reaches
the receiver and simultaneously the last bit is transmitted by the sender. So in other words you can say propagation delay in bits is the no. of bits required to fill
up the channel. P.D.(bits)=tp(s)×bw(bps)
So saying it is the capacity of the channel maybe misleading to some extent as we can have same propagational delay in bits for different pairs of channel
bandwidth and media. Rather you can say it is the combined capacity of the channel+media.
But again in the specific cases such as Ethernet or Token ring where the media is more or less fixed (10base5 etc) you CAN say that it is the capacity of the
channel only.
9.157 Routers Bridge Hubs Switches: Peterson Davie 3.27 top gateoverflow.in/43611
Suppose a workstation has an I/O bus speed of 1 Gbps and memory bandwidth of 2 Gbps. Assuming DMA is used to move
data in and out of main memory, how many interfaces to 100-Mbps Ethernet links could a switch based on this workstation
handle?
Selected Answer
Memory bandwidth is the rate at which data can be read from or stored into a semiconductor memory by a processor.
I/O buses connect the CPU to all other components, except RAM. Data are moved on the buses from one component to
another, and data from other components to the CPU and RAM. The I/O buses differ from the system bus in speed.
A bottleneck, in a communications context, is a point in the enterprise where the flow of data is impaired or stopped
entirely. Effectively, there isn't enough data handling capacity to handle the current volume of traffic.
Effective bandwidth that the I/O bus can provide is 1000/2 =500Mbps because each packet crosses the I/O bus twice.
if delays are recorded as 8 Bit numbers in 50 router network and delay vector are exchanged twice a second how much
bandwidth per full duplex line is chewed by distributed routing algorithm. Assume each router has 3 lines to other routers
a)400 bps
b)800 bps
c)1200 now
d) none
routing
if delays are recorded as 8 bit numbers in a 50 router network and delay vectors are excahngesd twice a second
how much bandwidth per(full duplex)line is chewed up by the distributed routing algorithm? assume that each
router has three lines to other routers.
a) 400 bps
b)800 bps
c)1200 bps
d)None of these
Answer is :- B
computer-networks routing
Question : We go with larger subnet mask in case of two matches. !! Why ? I know that's fact and
called https://en.wikipedia.org/wiki/Longest_prefix_match !! What is already setup in the backend side so that we're
choosing one with the larger subnet mask??
2) I guess this question has some relation with the previous one.
If i have to divide a network in 5 unequal subnets. then which is the correct method ?
I think we choose the subnet mask with longest match because it's more reliable in determining route to deliver packets
while routing.
As for the second part of the question, it would be given how many hosts you need to accommodate in each subnet.
Subnet mask can be adjusted accordingly to suit your needs.
Reference: https://learningnetwork.cisco.com/thread/64710
9.161 Rsa: how to solve it how to calculate m & e?? top gateoverflow.in/11981
Using data p=3, q=11, n=pq, d=7 in RSA algorithm find the cipher text of the given plain text SUZANNE
(A) BUTAEEZ
(B) SUZANNE
(C) XYZABCD
(D) ABCDXYZ
Selected Answer
explanation
Given:
aplpha is 0.5
computer-networks rto
=0.5*20+0.5*40
=10+20=30ms
What is the maximum number of characters (7 bits + parity) that can be transmitted in a second on a 19.2 Kbps line. This
asynchronous transmission requires 1 start bit and 1 stop bit.
A. 192
B. 240
C. 1920
D. 1966
isro2013 serial-communication
Selected Answer
bandwidth is 19.2Kbps
I think
Since it is asynchronous whenver you are sending it would require 1 start and stop bit
in what protocol or protocols, it is possible for the sender to receive an ack for a packet that falls outside of its
current window
computer-networks sliding-window
Ans is d
this is the concept of delayed ack which can occur in any of the protocol
I was thinking of using this formula, η = 1 +2a for this question. What is wrong in using it. Please explain
computer-networks sliding-window
Selected Answer
In SWP, if windows size of the sender is 5, transmission delay is 15ms and propagation delay is 25ms.
So,if first packet is transmitted on link, will it wait for the windows size to fill completely or it will start propagating?
computer-networks sliding-window
Selected Answer
Yes, it will start propagating as soon as it is available. SWP means we cannot send more packets than the size of window.
computer-networks sliding-window
Line efficiency will increase , only when we have some hops between sender and receiver.
For this question we will consider that there is no hop between sender and receiver so , dividing a constant message in k
frames or increase the number of frames to ( k+i),will not effect link utilization.
consider sliding window algorithm with Ws =9 and Wr=7 and no out of order arrivals .what is smallest value of Max
sequence number?
a) 7 b)15 c)8 d )16
sliding-window
seq no = Ws + Wr = 16.
so max seq no = 15
9.169 Sliding Window: point to point link to the moon top gateoverflow.in/30750
Suppose you are designing the sliding window protocol for a 1 Mbps point to point link to the moon, which has one way
latency(delay) of 1.25 seconds. assuming that each frame carries 1 KB of data, What is minimum number of bits you need
for sequence number?
computer-networks sliding-window
so here w=(10^6*2*1.25)/(1*1024*8)
=305
so here 2^n-1=305
n=9 bits
What should be the throughput in sliding window protocol for a window size of 100 bits in terms of mbps is?.If RTT is equal to
100microsec and bandwidth is 10mbps
computer-networks sliding-window
Selected Answer
= 100/(100 * 10)
= 0.1
9.171 Sliding Window: Which utilization formula to use and why? top gateoverflow.in/18765
Consider sliding window protocol for a 10 MBps point to point link with propagation delay of 2 sec. If frame size is of 4kB
then what wil be the minimum number of bits number required for the sequence number?
Which approach to take and why? Notice the difference in frame numbers, why does this arise and which one is correct. The
answer is not affected in this question.
computer-networks sliding-window
Selected Answer
Now, if you blindly follow the formula you will always have confusion. If we imagine the actual scenario- its all very easy.
For maximum utilization, the sender must send frames continuously until the ACK of first packet send comes back. This
time for arrival of ACK is called RTT.
RTT = Propagation time for frame (time for the first bit of frame to reach destination) + Time for frame to transmit (Time
difference between first and last bit of frame to reach destination) + Propagation time for ACK + Transmission time for
ACK.
Now, no, of bytes that could be sent during this time = 10MBps * 4000.4ms = 40004 KB = 10001 frames.
Now, for sending 10001 frames we need lg10001 = 15 bits for the sequence number field.
Consider three nodes A, B, C connected in series. Node A is connected to Node B via 3Gbps link, 500km length. The links are full
duplex, but no other traffic on the links. A large file is to be sent from node A to node C. Packets are 1024bytes.Assume
velocity of propagation as 2 × 108 m/sec.
Q2). Suppose an end to end sliding window protocol is used what is the optimal value of sender’s window
(a). 28 (b). 38
(c). 54 (d). 72
sliding-window
In sliding window protocol, assume a 3-bit sequence number field. A and B have windows, which has 3-bit sequence number.
If A sends 3 frames and waits for all the 3 acknowledgments until the timer expires. Which of the following "could not be"
the sender's "window size" after the timer expires. Assume receiver receives all the three frames correctly. But ACK's send
by receivers may be lost.
a. 4
b. 7
c. 6
d. 5
answer is given as 4.
sliding-window computer-networks
I think its a hint A sends 3 frame and wait for all frame means it using Selective Repeat protocol coz it doesn't support
Cumulative ACK it support individual ACK for each frame which is lost or NAK if no frame is lost.
So in Selective repeat protocol Max SWS = Max sequence number +1/2= 7+1/2 = 4
Here ACK is lost so after time expires it again sends 3 frame since in first attempt he sent 3 frame and it was expecting for
ACK but didn't get!
Rtt=2*pt or pt
sliding-window
Rtt=2*pt or pt
sliding-window
As the Name suggest RTT = Round Trip Time means Total time to travel one round(from sender to the Receiver and again
Receiver to the Sender). So it doesn't depend on either the link is Simplex or full duplex. It will be always 2*Propagation
delay
9.176 Sliding Window: window size in sliding window protocol top gateoverflow.in/19905
A 50kbps satellite channel with 550ms round trip propagation delay using sliding window protocol sends 2000 bits frame then
window size, w will be:
w >= 7.75bits
w >= 14.5bits
w >= 15.5bits
w >= 20.5bits
computer-networks sliding-window
My Answer is
B) Explain R.T.T. clearly for Stop n Wait , Go-Back-N , Selective Repeat ARQ .
sliding-window computer-networks
Consider a slotted aloha channel with bandwidth 5Mbps. if frame size is equal to 10 user slots then what is effective data
rate of a user if every 2nd slot is occupied by him?(Assume data if required)
slotted_aloha
You have two computers, A and B, sharing a wireless network in your room. The network runs the slotted Aloha protocol with
equal-sized packets. You want B to get twice the throughout over the wireless network as A whenever both nodes are
backlogged. You configure A to send packets with probability p. What should you set the transmission probability of B to, in
order to achieve your throughout goal?
a. p/(1 + p)
b. p/(1 + 2p)
c. 2p/(1 + p)
d. 1/2
slotted_aloha
Option C is correct.
slotted Aloha - Time is divided in slots, so, either A or B transmits only at beginning of a slot.
x - xp = 2* (p - xp)
=> x + xp = 2p
9.180 Stop And Wait: Calculating link utilization in stop and wait protocol top
gateoverflow.in/37229
Given solution:
1 1
Please explain.
stop-and-wait sliding-window
Take upto 4 places of decimal or approximate to 8.24 its giving right answer...
1/(1 + 8.2397)=0.12136
Selected Answer
TT
TT + 2PT
η=
0.1ms
= 0.1ms + 2 × 1sec
0.1ms
= 0.1ms + 2 × 1000ms
= 4.99975 × 10 −5
answer for Q.9 = η and if that's the efficiency then the actual bandwidth that was utilized is η × C
As the name suggests, after sending 1 packet, Stop & Wait protocol stops & waits until the ACK is received or a time out
occurs.
That is transmission rate is 100 bits per RTT, or 100 bits per 2 second.
Now link utilization = Current transmission rate / rate at which we could have transmit the data using the full capacity of
the link (or channel)
We can see here Stop & Wait can be astoundingly inefficient, hence we need sliding window protocols.
Choosing appropriate windows size in sliding window protocol leads to quite higher link utilizations.
If the packet size is 1KB and propagation time is 15ms, the channel capacity is 109 b/s then find the transmission time and
utilization of sender in stop and wait protocol.
stop-and-wait
Selected Answer
Sender Utilization = Fraction of Time Sender is busy (Same as link utilization which is the fraction of time the link is
carrying useful data)
In Stop-and-wait, sender can retransmit only when ACK arrives for the send data which requires 1 transmission time for
the data packet, 1 propagation delay for the data packet to reach the receiver, 1 propagation delay for the ACK to reach
the sender. (ACK normally being small its transmission time can be ignored unless given in question). So,
Transmission Time 0.008 0.001
Utilization = Transmission Time +2 ×Propagation Time = 0.008+2 ×15 = 30.008 = 0.000266 = 0.026%.
9.183 Stop And Wait: Transmission rate in a 3 node 2 link sliding window
system top gateoverflow.in/18636
The distance between A to B is 4000 km. The distance between B and C is 1000 km.The propogation delay is 5 micro sec/
km for both the links. The data rate between A and B is 100kbps. Both the links are full duplex. All data frames are 1000 bits
long and ACK frames are negligible. Window size is 4.
What is the required transmission rate (in kbps) between B and C so that buffers of node B are not flooded?
A. 100
B.150
C.200
D.250
In order to ensure no flooding, data transfer rate between B-C must be same (or greater) as that between A-B.
Lets consider the no. of bits transmitted by A until it receives ACK and let time for this be S.
S = 2* Propagation delay + Transmission delay for packet + Transmission delay for ACK
= 2*20 ms + 10 ms + 0
= 50ms.
Window size is 4.
So, in 50ms, A could send up to 4 packets = 4000 bits. Data rate being 100 kbps, allows upto 100 *50 = 5000 bits in
50ms, so we are fine and we have effective data rate of 4kb/50ms = 80kbps.
Now, we know that in every 50ms, we are getting 4000 bits at B. (with a buffer of size 4000 bits we can assume no
flooding for this)
Lets consider the no. of bits transmitted by B until it receives ACK and let time for this be T.
T = 2* Propagation delay + Transmission delay for packet + Transmission delay for ACK
In T ms, B sends 1000 bits. We want B to send at 80kbps which implies T = 1000/80 = 12.5ms
What will be the efficiency of a Stop and Wait protocol, if the transmission time for a frame is 20ns and the propagation time
is 30ns?
A. 20%
B. 25%
C. 40%
D. 66%
Efficiency= 20 / (20+2*30)
= 20/80 =0.25
Bandwidth of a link is 1000 Mbps and round trip time is given as 250 μ sec. If frame size is 500 bits, the utilization (in percentage) of channel when STOP and WAIT ARQ is used is _______.
stop-and-wait made-easy
Selected Answer
9.186 Stop And Wait: Efficiency of Stop n Wait protocol top gateoverflow.in/17750
What will happen if Ttrans> (Ttrans+2*Tprop) in efficiency formula of stop n wait protocol? What it logically mean?
stop-and-wait
Selected Answer
this is not possible , you are saying like this A>A+B (A and B are positive number )
Anyway in stop and wait you have to wait for acknowledge . (even if Tx>2Tp) if Tp is negligible then only efficiency is
going to be 1 .
It means you are transmitting through a balck hole where time is moving backward . so that at the other point of time you
got the same packet till at one point you are still transffering it . ASTROPHYSICS. " time is relative" it is definitely
possible Theoretically. my personal opinion is that time cannot run backwards. it can squeeze or slow down.
9.187 Stop And Wait: CN stop and wait bandwidth is 1.5 Mbps top gateoverflow.in/30743
If the bandwidth f the line is 1.5 Mbps, RTT is 45ms and packet size is 1KB, then find link utilization stop and wait protocol.
stop-and-wait computer-networks
subnetting computer-networks
Selected Answer
Since organistation has 30 hosts, Class C network with /24 Prefix should be used since it can support 254 hosts.
Now there are 30 hosts, so the minimum number of bits required for host number is 5, since 25 − 2 is 30.
ii) what is address of 4th last host of 2nd last subnet in the company ?
subnetting
181.55.249.191
An organization is granted the block 150.36.0.0/16.The administrator wants to create 512 subnets.
Find number of addresses in each subnet. Find the first and last addresses in subnet 1.
(A) 128, 150.36.0.1 and 150.36.0.127 (B) 128, 150.36.0.129 and 150.36.0.255
(C) 126, 150.36.0.1 and 150.36.0.126 (D) 126, 150.36.0.129 and 150.36.0.254.
subnetting
Ans - c
512 subnets => 9 bits from host id are reserved. Therefore, 150.36.NNNNNNNN.NHHHHHHH is our scenario. There the
first network id is : 150.36.00000000.00000000 => 150.36.0.0 and the first usable IP address is 150.36.0.1 The
broadcast address of this subnet will be 150.36.0.127 => The last usable IP address of first subnet will be : 150.36.0.126
subnetting
1st block -- 210.69.92.0 to 210.69.92.63 (the address given in the qs is resides in this block)
so 2nd last block is 3rd block.. and the last host is which usable 210.69.92.190 /26.
so answer is A
top
Dept1 (with X link) has 287 hosts. Dept2 (with Y link) has 510 hosts. Dept3 (with Z link) has 254 hosts.
Qstn: If above network uses class C network 192.203.16.0 then find DBA for dept Y. (Assume all are in the same network.)
How can this be done? Dept2 has 510 hosts , so 9 bits needed. But as it is a Class C IP, can you get my confusion? Kindly
help me clarify it. How to even proceed for this qstn?
subnetting computer-networks
Selected Answer
First of all this question is wrong. This complete network can not be configured with single class C network. !
Yes, Y can not be configured because 510 > 254 (Maximum hosts configurable in any class C) !
Two computers A and B are configured as follows. A has IP address 203.197.17.157 and netmask
255.255.128.0. B has IP address 203.192.192.201 and netmask 255.255.192.0. Which one of the following
statements is true?
computer-networks subnetting
= 203.197.0.0
= 203.197.0.0
--> As, both AND operation gives similar result . So, A assume B on same Network .
= 203.192.128.0
= 203.192.192.0
--> As,both AND operation gives different result . So, B assume A is on different network.
In class C , if subnet mask is 255.255.255.224 then calculates number of subnet? (A) 6 (B) 8 (C) 4 (D) None of the Above
subnetting
The default mask for the class C address of 192.x.x.x is 255.255.255.0 The mask in the example is 255.255.255.224 (using 3
extra bits for subnetting, above and beyond the default). So 2^3 is 8 combinations:
In the old days, we couldn't use the all 000 or all 111 combination for subnetting, so the formula was 2^extra
bits used for custom subnetting, or 2^3 in our example, -2 (for the 2 that used to not be able to be used),
which would leave 6.
Today, current IOS&Cisco has the ability to use the 000 and 111 option with an option called subnet zero and so on
current IOS there would be 8 possible subnets, not just 6.
An internet service provider (ISP) has the following chunk of IP address available with it: 192.248.128.0/22. The ISP wants
to give half of this chunk to organization A and one fourth of remaining half to organization B and organization C then what
is the valid allocation of address to A, B and C?
(A) 192.248.128./23, 192.248.128.0/23, 192.24S.128.0/25
(B) 192.248.128.0/23, 192.248.128.0/25, 192.248.128.0/25
(C) 192.248.128.0/22, 192.248.128.0/23, 192.248.128.0/24
(D) None
http://gateoverflow.in/?qa=blob&qa_blobid=12308793692587589147
computer-networks subnetting
192.248.128.0/22
Total host possible = 32 - 22 = 10 = > 2^10 = 1024
A. Class A, 3
B. Class A, 8
C. Class B, 3
D. Class B, 32
And next 3 ones used for subnet . Since 3 ones so number of subnet is 2^3=8.
So answer is b
Consider 100 mbps network with 24 bit sequence number field find the wrap around time for sequence no?
tcp
sequence possible=2^24.
wraparound time=(2^24)/100Mbps
9.197 Tcp: An ACK number in TCP always means that top gateoverflow.in/32817
computer-networks tcp
Answer is D none of the above.cause, The client sets the segment's sequence number to a " random value".then ,the server replies with a ACK. The
acknowledgment number is set to one more than the received sequence number + 1.
You are hired to design a reliable byte stream protocol that uses a sliding window protocol like TCP .The protocol
will run over 1Gbps n/w. the RTT is 140 ns and maximum segment lifetime (MSL)is 60sec.
How many bits would you require in the Advertise window field of TCP header to keep pipe full??
computer-networks tcp
q1) Max. amount of data that can be send by the sender = 140 ns * 1 Gbps = 140 b = 140/8 B
No. of bits needed to represent 140/8 B of data < = No. of bits needed to represent 2^8/2^3 B of data
No. of bits needed to represent 140/8 B of data is at most 5 bits.
Advertised window field needs 5 bit so that it can send 140/8 B of data to keep the pipe full.
Five segments of data of sizes 100B , 400B , 200B , 300B and 50B are sent using TCP and PSH bit is set on each of the segments. There are no
retransmission timeouts. The acks received are 101,101, 701,701, and 1051. In which order are the segments received
tcp
PS : if no ACK was lost then sequence will be 100B ----> 300B ----> 400B -----> 50B----> 300B
tcp
In TCP while connection establishment there is pure acknowledgement. I have read that the pure acknowledgements do not
consume a sequence number as the receiver does not include acknowledgement while merging the segments. The data is
extracted and sequenced according to sequence number.
But then what goes into the sequence number field while sending the pure ack. It has to be a number anyways...but what is
the number kept and why...??
tcp computer-networks
1.connection establishment
2.data transfer
3.connection termination
1.connection establishment-
but in DATA TRANSFER phase there is a field in TCP header acknowledgement number (NOT GET CONFUSE WITH ACK
FLAG)
Consider a TCP connection using the slow start congestion control scheme with an initial threshold value of 64 kB and a Maximum Segment Size (MSS) of 2 kB. The receiver’s advertised
window is initially 32 kB. The first transmission attempt is numbered 0, and all transmission attempts are successful except for the timeouts on attempt number 4. Which of the following
represents size of sender’s congestion window at attempt number 10?
tcp computer-networks
0 1
1 2
2 4
3 8
5 1
6 2
7 4
10 10
10MSS = 20Kb
9.203 Tcp: Find the size of Sender's window if: top gateoverflow.in/32145
During a TCP connection, the size of the window advertised by the receiver is 20 KB. The last byte sent by the sender is
20480 and the last byte acknowledged by the receiver is 8384. If the current congestion window is 18 KB, then the current
size of the sender's window is _______ (in KB).
computer-networks tcp
Selected Answer
in TCP congestion window changes dynamically depending on congestion window , advertised window by receiver ,
amount data unacknowledged .
Reason :
in sliding window protocol , until acknowledgment received, copy of transmitted data kept in buffer.
as this 11.8 KB is not acknowledged till now, this data is present in buffer , so (effective window size ) the amount of data
that is possible to transmit before acknowledgement received is
Suppose a client C repeatedly connects via TCP to a given port on a server S, and that each time it is C that initiates the
close. If time-wait state lasts for 60 seconds, then how many TCP connections a second can 'C' make with all available
ports? Assume client port are in the range of 1024 to 5119.
A) 70 per sec B)10 per sec C) 13 per sec D) 100 per sec
computer-networks tcp
Selected Answer
Due to time-wait state of 60s, any repeated connection to same port requires an interval of at least 60s.
Now assume a time interval of Ns. Number of TCP connections possible in this time = 4096*N/60 (as after every 60s, a
port can be reused for a new connection).
So, average number of connections that can be opened per second = 4096*N/(60 * N) = 4096/60 ≈ 70
http://www.isi.edu/touch/pubs/infocomm99/infocomm99-web/
What should be the answer?? I think 1st and 3rd are correct?!
computer-networks tcp
computer-networks tcp
Selected Answer
TCP and UDP both provides error control (although UDP uses only Checksum) and multiplexing.
Consider a system generating 20 bit frames and connected through a shared 20kbps channel. Find throughput in percent if slotted ALOHA is
used and frame rate is 1000 fps.
Tp
Tt
In a token ring, if a < 1, i.e < 1 , then will not the data get corrupted because it will come in contact with the data that is
still being transmitted ?
token-ring computer-networks
Selected Answer
yes . it will corrupt the data thats why if we want to apply such type of topologies bit delayer were introduced in between
so that the data may not collide . so we always calculate first . whether a is less than 1 then we calculate the bit delayer
required and then apply it in somewhere in the middle . it delays the data for some time.
9.209 Wifi: What do you suggest to study for WiFi and IPv6? top gateoverflow.in/28706
Topics such as
WiFi
IPv6
are introduced for the first time in the revised syllabus for GATE. If there are people working in this area or are in proximity
of the topics above, please suggest what are technically important areas among these technologies.
For Ipv6 :
1.Advertising of message like unicast ,multicast, anycast
2.Special IP address for loopback,DHCP,Multicast
3.IPv6 address Hierarchy
4.Jumbograms(basic conept)
5.IPv4 in IPv6
6.IPv6 Header
7.Extension headers basic only like types and basic usage.
8.Flow label
WiFi :
1.Basic concepts
2.Why CSMA/CD is not used in WiFi.
3.Architecture
4.AdHoc : IBSS
5.Distributed Systems
6.IFS(Inter frame space)
7.Collision avoidance
8.Poll cycle
9.Hidden node
10.Physical and Virtual Carrier sense
11.Exposed terminal
12.WiFi (802.11) Frame format
13.Frame control (from frame format) .
Just go through this below mentioned site only once. I guess this more than enough for gate related to the IPv6 and
Wireless Basics.
IPv6 : http://www.9tut.com/ipv6-tutorial
Wireless: http://www.9tut.com/wireless-tutorial
For ipv6 refer 1)chapter 20 of data communication and networking fourth edition forouzan 2)chapter 27 of tcp/ip protocol
suite forouzan
Two ground stations are connected by a 10Mbps satellite link. The altitude of the satellite is 36,000km and the speed of the
signal is 3x108 m/sec. What should be the packet size for channel utilization of 50% using GBN sliding window protocol.
Window size is 100. Assume that the acknowledgement packets are negligible in size and there are no errors during
communcations.
a) 1.5 Kbytes
b) 3 Kbytes
c) 4.5 Kbytes
d) 6 Kbytes
utilization=50%=1/2
Now,
Utilization =N/(1+2a)
or,1/2=100/(1+2tp /tt)
Ans (a)
9.211 Workbook Question: What is the total time required from the below
communication? top gateoverflow.in/32087
Host A is sending data to host B over a full duplex link. A and B are using the sliding window protocol for flow control. The
sender and receiver window sizes are 5 packets each. Data packets (sent only from A to B) are all 1000 bytes long and the
transmission time for such a packet is 50 μsec. Acknowledgement packets (sent only from B to A) are very small and require
negligible transmission time. The propagation delay over the link is 200 μsec. What is the total time required in this
communication?
a) 250 μsec
b) 200 μsec
c) 275 μsec
d) 450 μsec
9.212 Workbook Question: What are the advantages of star topology? gateoverflow.in/32049
top
Because star topology if one cable is down , other cable could connect the whole device. So, better secure than bus
topology.
http://computernetworkingnotes.com/network-technologies/network-topologies.html
9.213 ISRO 2011/1 : Encoding technique used in Gigabit ethernet over optic
fiber medium? top gateoverflow.in/19325
Encoding technique used to transmit the signal in Gigabit Ethernet technology over optic fiber medium is ???
A) differential manchester
C) 4B/5B encoding
D) 8B/10B encoding
isro computer-networks
for gigabit ethernet encoding technique used is 8B/10B and for standard ethernet it is manchester encoding
An ISP is granted a block of addresses starting with 190.100.0.0/16 (65,536 addresses). The ISP
needs to distribute these addresses to three groups of customers as follows:
a. The first group has 64 customers; each needs 256 addresses.
b. The second group has 128 customers; each needs 128 addresses.
c. The third group has 128 customers; each needs 64 addresses.
Design the subblocks and find out how many addresses are still available after these allocations
Selected Answer
Group 2 : 2^14
Group 3 : 2 ^13
since there are chunks of 2^14 we first allot these addresses to the groups by dividing in 4 parts
Group 1 :
Group 2 :
190.100.64.0/18 to 190.100.127.255/18
Group 3 :
or 190.100.128.0/19 to 190.100.159.255/19
190.100.160.0/19 to 190.100.191.255/19
and
190.100.192.0/18 to 190.100.255.255/18
the protocol in play here has a minimum header length of 20 Bytes how can you ask someone to go below this value?
An organization having class A network wants a subnet for 510 departments.The subnet mask should be?
Selected Answer
since it is a class A network so , first byte will be used for network id and the rest 3 byte will be used for subnet and host
id.
Since , there should be 510 departments and hence the address space of the network should be divided into 510 parts.
so,the lefstmost 9 bit of the 3 byte will be 1 as it will be fixed to divide the add space in 512 parts.
When congestion window size is greater than reciever window size then congestion control is used.
http://www.idc-online.com/technical_references/pdfs/data_communications/Leaky_Bucket_Algorithm.pdf
9.217 A sender sends a series of packets to the same destination using 5 bit
sequence numbers. top gateoverflow.in/17884
A sender sends a series of packets to the same destination using 5 bit sequence numbers. If the sequence number starts
with 0, what is the sequence number after sending 100 packets ?
Now 97 98 99 100
0 1 2 3
9.218 for the 8 bit word 00111001,the check bits stored with it would we
0111 top gateoverflow.in/19183
for the 8 bit word 00111001,the check bits stored with it would we 0111.suppose when the word is read from memory ,the
check bits are calculated to be 1101. what is the data word that was read from memory
Data is transmitted continuously at 2.048 Mbps rate for 10 hours and received 512 bit errors.What is the bit error rate?
a)6.9e -9
b)6.9e-6
c)69e-9
d)4e -9
9.220 from only IP address can we recognise that how many subnet bits are
there and how many host bits are there.??? top gateoverflow.in/18248
Caption
--no of bits n of netid can be predicted according to the class used in addressing in classful notation and it will be given in
\n formate in classless notation.
-----to recognise each subnet,we should have unique id for each subnet.since there is 2 m subnet so, m bit will be
needed for subnetting and rest will be used for hostid.
NOTE- we should use the leftmost bit of (32-n) bit for subnetting which will ensure serial addresses to be serial but it is
not always necessary bt practically this is the only way
Selected Answer
PT= 25(given)
b)Authentication
c)obtaining IP address
The main idea of LDAP is to keep in one place all the information of a user (contact details, login, password, permissions), so that it is easier to
maintain by network administrators.
9.223 The encoding technique used to transmit the signal in giga ethernet
technology over fiber optic medium is top gateoverflow.in/18138
The encoding technique used to transmit the signal in giga ethernet technology over fiber optic medium is
computer-networks
8B/10B.
8 Bit data converted into 10 bit data. 8B/10B is combination of 5B/6B and 3B/4B.
9.224 ethernet layer-2 switch is a network element type which gives gateoverflow.in/18788
top
Selected Answer
Switch act as a collision domain separator not not as a broadcast domain separator.
9.225 In which layer of network architecture , the secured socket layer (SSL)
is used? top gateoverflow.in/18114
In which layer of network architecture , the secured socket layer (SSL) is used?
a)physical layer
b)session layer
c)application layer
d)presentation layer
(b) option
most probably it should in be session layer
SSL name itself tells that it is higly secured layer which is used during our payments gateway .
Eg: when we are used to go for online payment ,that payment gateway is considered in ssl layer..
a)Wake up:ready->running
b)Dispatch:ready->running
c)Block:ready->running
d)Timer runout:ready->blocked
Selected Answer
Dispatch:ready to running
So ans is b
9.227 Time taken for the entire message to reach from source to destination
top gateoverflow.in/42515
A 64000-byte message is to be transmitted over a 2-hop path in a storeand- forward packet-switching network. The network
limits packets to a maximum size of 2032 bytes including a 32-byte header. The transmission lines in the network are error
free and have a speed of 50 Mbps. Each hop is 1000 km long and the signal propagates at the speed of light (3 × 108
meters per second). Assume that queuing and processing delays at the intermediate node are negligible. How long does it
take to deliver the entire message from the source to the destination?
My solution
Limiting size of packet including header =2032 bytes. so we'll get 64000/2000=32 packets
As it is 2 Hop and uses store and forward we have to send it through each hop where each hop will first store and then
transmit. We have 32 packets need to be sent.
Time taken for the first packet to reach destination- Transmission time sender+propagation time up to 1st hop +
Transmission time of 1st hop+ propagation time up to 2nd hop + Transmission time of 2nd hop+ propagation time up to
receiver
The second packet would have transferred immediately just after the first packet transmission is over at sender.
The first packet transmission ends at 32.512 msec at sender. So the second packet will just start after this time. Hence a
dealy of 32.512msec will occur for the second packet to reach the destination. Similarly for next upcoming packets.
Hence to send all the 32 packets to receiver it takes 107.526+ 31*32.512 msec= 1115.398 msec
Can anyone confirm this answer. Please help if any error is there .
computer-networks
1 packet's RTT + (31 * (max(Transmissinon time,Propagation time ))) since total 32 packets needs to send
am i right??
i have not used deviation and still got the answer using ERTT=IRTT*alpha+(1-alpha)*NRTT.what is the use of deviation in
this question?
test-series
A group of 2n − 1 routers are interconnected in a centralized binary tree with a router at each tree node . Router 1
communicates with Router j by sending a message to the root of the tree. The root then sends a message back down to j
Derive an approximate expression for the minimum number of hops per message for large N , assuming that all the router
pairs are equally likely
1). 2N − 4
2). N − 4/2
3). N − 4/2
4). N − 4
computer-networks
Answer is 2N-4
In Nth level of tree each node(router) will take n-1 hops to tranfer to root and half of the total routers are on this level.
(n-1)*1/2 hops
N-1 level 's nodes will take n-2 hops to tranfer to root and half of the remaining routers are on this level. (n-2)*1/4 hops
N-2 level 's nodes will take n-3 hops to tranfer to root and half of the remaining routers are on this level. (n-3)*1/8 hops
N-3 level 's nodes will take n-4 hops to tranfer to root and half of the remaining routers are on this level. (n-4)*1/16 hops
= n-2
Assume 10 Mbps Ethernet and two stations A and B on it’s same segment. The RTT between two nodes is 650 bit times. A
and B start transmitting frame and collision occurs and both sends 30-bit jam signal. Find the time at which both nodes A
and B sense an idle channel (in μsec).
9.231 Question on calculating total transmission time between two hosts top
gateoverflow.in/38930
I am not able to convince myself why transmission time needs to be added for each link if store and forward is not being
forward. Please check
computer-networks
In synchronous transmission, 5 eight bit characters are included in 30 eight bit information characters. If bit rate of sender is 4200 bits/sec, what is the bit rate of receiver (in bits per sec)?
computer-networks made-easy
Time required for sending = 240 bits / 4200 bits/sec = 24/420 sec
how many keys are required for n indiviuals to communicate using secret and public key
What is the total over header bits (Headers & Retransmission) with data frames consisting of 40 bit header and 3960 data bits.
ACK frames never occur. NAK frames are 40 bits ,the error rate (in bits) for frame is 2% and for NAK frame is negligible (upto 2
decimal place)
ans-:120.80
made-easy test-series
Selected Answer
2% is error rate that means 2 NAK frame for every 100 DATA frames..
80 bit per 100 frame for NAK..
bcause of 2 NAK frame we will again send 2 data frame i.e. 2*4000 = 8000 bit
Total (Data + Overhead) bit sent = 4000*100 + 80 + 8000 = 408080 bit
Original Data = 3960*100 = 396000 bit
is it correct?
made-easy test-series
Selected Answer
Yes it is correct. As a Class C and if this IP is used as DHCP or in local network it is treated and preferred as 0.0.0.x
For a class C network if IP address of a computer is 200.99.39.112 and subnet mask is 255.255.255.224 the first host of
first subnet (represent last octet) is ________.
made-easy test-series
Selected Answer
All 0s in Host id part represent 1st address of network (Subnet) and all 1s in Host id id part represent Directed Broadcast
address of that Network (Subnet)..
In case of Subnet u r allowed to take all 0s as well as all 1s as Subnet bit bt Host should not be all 0s or All 1s..
Consider a 40 kbit/s network link connecting the earth to the moon. The moon is about 1.5 light-seconds from earth.
If a sliding-window protocol is used instead, what is the smallest window size that achieves the maximum data rate?
Solution provided:
My doubt is y we are not taking tramission delay? Inorder to achieve maximum utilisation sender ha sto send frames
continuosly until ack received.
RTT=TD+PD(Frame)+TD(ack)+PD(ack)
=3.2secs
number of packets=16
To find minimum window size we need to find no of frames which can be sent in one RTT
Window size=1024kbps*100ms/512*8
=25
Which 2 control signals are used for handshaking between computer and modem for existence ?
computer-networks
A packet begining a destination address 132.81.68.132 arrive at the router . on which of the interfaces it cant be forwarded ?
computer-networks
a is the answer as the destination address is class-b ip address and on AND ing with subnet mask on match will be
obtained
9.241 consider the token bucket with maximum rate R=20 Mbps. suppose we
want to make sure that.. top gateoverflow.in/20010
Consider a token bucket with maximum rate R = 20 Mbps suppose we want to make sure that the maximum rate can only
be sent for at-most 5 seconds at a time , and at- most 150 Mb can be sent over any 10 second window. Consider the
required value for the bucket depth (b) in Mb
We are sending the maximum rate for 5 seconds,so we send 20 ∗ 5 = 100 Mb in 5 seconds. We can only send 150 Mb in
any 10-second window, so 150 − 100 = 50 Mb, we can send in the remaining 5 seconds, so rate = 50/5 = 10 Mbps. Now,
in order to ensure the bucket has enough tokens to sustain a 5-second burst at 20 Mbps, we require b = (M − rate) ∗ 5 =
(20 − 10) ∗ 5 = 50 Mb bucket depth.
4) DNS USE THE UDP FOR SOME MESSAGES WHILE SOME FOR TCP .
computer-networks
Selected Answer
9.243 total delay in sliding window and without sliding window top gateoverflow.in/19906
amount of time it would take to send 500 packets using 6-packet size window and without sliding window will be, when the
time to send in one direction is 5 ms
31000, 5000
4600, 21600
5000, 30000
With sliding protocol throughput will be n (size of the packet) times of stop and wait(n.B/1+2a).Here without sliding
window means simple stop and wait.As n=6,from the option c we can see that 5000 × 6=30000.Hence c will b the
answer.Time to send 5 ms i have not considered
9.244 Efficiency of token ring under delayed token release/ early token
release/ intermediate token release top gateoverflow.in/19833
Compute utilization of token ring LAN where all stations are queued to send. Given the following parameters:
no. of stations=25
data rate=100Mbps
we can't tell what is the ACK 1000 in TCP , as it depends on initial random sequence number.
bandwidth of a link is 1000 Mbps and round trip time is 250 micro seconds.If the frame size is 500 bits the link utilization (
IN %) of channel using stop and wait protocol is ?
Selected Answer
Efficiency=tt/(tt+2tp)
or Efficiency=1/ 1+ 2pt/tt
=1/1+250/0.5
=1/501
= 1.9960 * 10 -4
=0.000199
is anythng wrong?
Suppose an IP packet has been fragmented. Then which of the following is a set of fragments?
computer-networks
Concept is all Fragment offset (except last fragment) should be multiple of 8. bcoz Fragment Offset size if 13 bit and data
coming from Transport layer is of size 16 bit so we need scaling. To store 16 bit data into 13 bit Fragment offset we need
scaling of 8.
9.247 the set of all equivalence classes of a set with cardiity c top gateoverflow.in/41171
Selected Answer
computer-networks
and there is discussions regarding pop3. it is stateful until download, as well as stateless across sessions.
in a sliding window protocol assume a 3 bit sequence number field. A and B have windows which has 3 bit sequence
number.If A sends 3 frames and waits for all three acknowledgments until the timer expires.Which of the following could not
be the sender's window size after the timer expires.Assume receiver receives all the three frames correctly but ack from
4, 7, 5, 6
So 4 is not possible
9.248 Does TDM affect the bandwidth of the link ? top gateoverflow.in/41800
computer-networks
Selected Answer
Time Division Multiplexing means that multiple users are allowed to transmit on a communication channel in a Round
Robin manner.
Example:
Say there are 4 users and time slot is 5 seconds. It means in first 5s, user 1 can transmit data, in next 5s user 2 can
transmit data and so on, cycle repeats beginning from user 1 again.
Effect On Bandwidth
In Ideal situations, where every station is working properly, it does not effect bandwidth. But there can be many cases,
where wastage of bandwidth occurs and these are:
1. If a user in its time slot does not have any data to transmit, it leads to complete wastage of bandwidth.
2. If a user machine goes down due to failure then also the entire bandwidth is wasted.
For the above 2 mentioned scenarios, frequency division multiplexing is more fault tolerant.
Fragment Offset change when another router further dived the packet .
A certain population of ALOHA users manages to generate 70 request/sec.If the time is slotted in units of 50 msec,then
channel load would be
a)4.25
b)3.5
c)450
d)350
(b) option
(70*50)/1000
=3.5
9.251 Two stations 'A' and 'B' are connected via a point to point link and
exchange frames.. top gateoverflow.in/17353
Two stations 'A' and 'B' are connected via a point to point link and exchange frames with m=3 where m is the size of the
sequence number field in bits. Station 'A' sends frames in the following order(fig).
What will be the buffer frames in the current window of 'A' just after the time-out and what are the values of X and Y if go-
computer-networks
Selected Answer
NAK is used for selective repeat ARQ!!! the ans should be option C. Because frame 2 has been lost and that's why the
frames 3 and 4 has been discarded.So after the time out the sender should resend frame 2.Therefore X=2 and Y=3.The
buffer frames of the current window is 2345670
0 4 6 5 7 6
I guess the confusion is in getting the RTT. For RTT should we add 1pt or 2pt? It is actually 1pt for frame + 1pt for ACK.
Now ACK being small, 1pt for ACK is usually ignored. When ACK is piggy backed, we use pt for ACK = pt for frame, and
hence use 2pt.
9.254 which of the following IP can be used by both source and destination>
top gateoverflow.in/6387
iv. is Directed Broadcast address which is also always used as Destination Address.
9.254 each bridge seemsto be interconnected. then how to get this spanning
tree? top gateoverflow.in/6272
9.254 TCP implements SWP for flow control. It advertises window field in
TCP header is used for this purpose then compute it's value if MaxRcvBuffer
is 100 Bytes, NextByteExpected is 51 and LastByteRead is 40 ________. top
gateoverflow.in/6333
At transport layer "pseodoheader" is attached with each outgoing data from transport layer(along with data from upper layer
and its own header).Psedoheader is a part or snapshot of header from network layer.. My question is being upper layer of
network layer how transport layer generates the pseodoheader,, which is generated by network layer in as next step...
http://www.tcpipguide.com/free/t_TCPChecksumCalculationandtheTCPPseudoHeader-2.htm
9.256 There are 200 computers in a lab which are attached to an ethernet 10
Mbps with a coaxial cable of 1500m .The packets are 800 bits long/ The
propagation speed is 2*10^8 m/sec. On avg how many packets can each
comp. send per second ? top gateoverflow.in/9561
There are 200 computers in a lab which are attached to an ethernet 10 Mbps with a coaxial cable of 1500m .The packets are
800 bits long. The propagation speed is 2*10^8 m/sec. On avg how many packets can each computer send per second ?
Options 1) 42 packets/sec 2) 44 packets/sec 3) 62 packets/sec 4) None
Response:
Simplex
Half duplex
Full duplex
None of these
Selected Answer
I think It is simplex.
half duplex is a two way communication but one way at a time not simultaneous (eg. as walkie-talkie over and out)
From P to R1:
Maximum frame length supported is 1024 and 820 + 12 is within one frame- 832 bytes transferred.
From R1 to R2:
Maximum frame length is 256 bytes including 8 bytes header. We have 832 - 12 = 820 bytes (IP header added by P would
be removed here). So, this requires ceil (820/(256 - 8)) = 4 frames - 3 * 256 + 820 - (248*3) + 8 = 852 bytes
transferred.
From R2 to Q:
We need to send 248 bytes in a frame and maximum frame length is 512 bytes including 12 bytes header. So, four
frames frames are required - 3 * (248 + 12) + (76 + 12) = 868 bytes transferred.
What setting of THT (token holding time) will be optimal for a network that had only one station active at a time?
Response:
10 ms
Infinity
Can't say
Selected Answer
Infinity. With just one active station for optimal network, the Token Holding Time must be as large as possible.
Response:
Cumulative ACK
Independent ACK
Piggybacking ACK
None of these
piggybacking ack, because in token ring, frame contains a frame status byte which have two bits A(Address recognized)
and C(frame copied) which are initially and 0 and 0 after sending data received by destination they are changed by 1 and
1 and coming back to the sender with A =1 and C =1 which is piggybacking ack .
Ref: http://www.cs.montana.edu/~halla/csci466/lectures/lec10-2.7-token.html
A 100 Km long cable runs at 154 Mbps data rate. The prop speed in the cable is 2/3 of light. how many bits fit in the cable ?
1) 772
2) 700
3) 782
4) 770
Selected Answer
d 105
v 2 ×108
tp = = = 0.5 × 10 −3
9.261 The round trip delay for a 100 Mbps Ethernet having 48 bit jamming
signal is 64 * 10^-6 sec. What is the minimum frame size? 1. 400 bytes 2.
800 bytes 3. 600 bytes 4. 1400 bytes top gateoverflow.in/5987
2 * propagation delay + transmission time for jamming signal <= transmission time for frame
64 μs + 48/100 μs <= transmission time for frame
64.48 μs <= l/100 μs
l >= 6448 bits >= 806 bytes.
1 bit delay means time to transmit 1 bit..which is 10'^-7 sec...the length will be traveled by signal in this time is
2*10^8*10^-7 meters=20 meters..1 bit delay is equivalent to 20 meters on cable
Subnettting is done by chossing bits from host. So in order to make 64 subnets we have to carry log2(64)= 6bits from
host.
Now look NID.NID.XXXXXXXX.XXXXXXXX we carry 6 bits and we know subnet mask contain 1 for NID and subnet bits and
0 for host bits so Mask will be 11111111.11111111.11111100.00000000 : 255.255.252.0
I would say Access Control List is one of the way to implement Authorization .
I rem a bit of it
But what i think if they say Physical data ( it mean we are actually talking about files records and all ) Who has access to
which is captured by Access Control
But acCess control link is not usually used through tmatrIx .it takes a lot of space . Because it captures both right for all
the files in a system
where with user we will associated all the files it can access and in which mode
Then i will just have this information stored for it . I wont have any related to C ---Z . That why this method was more
favourable over access Control ( Because in Access Control if user dont work with C---Z files also then also information
about is stored by setting bit 0 )
// i have choosen system security as my final year subject . You can read Information security by Mark Stamp .
Seriosusly a good book
L>=2*(d/v)*B
>=2*(1000/2*108)*4*109
It says "
sing the special character of <DEL> and <STX> and <ETX> for start/end framing, the message:
AB<DEL>C<STX><ETX>DE
<STX>AB<DEL><DEL>C<DEL><STX><DEL><ETX>DE<ETX>...<STX>
"
but they state that the problem with this method is
" We can't use this method in situation like this when message is
<DEL><STX>A<DEL><ETX>
"
converting this <DEL><STX>A<DEL><ETX> to our codeword will give output something like this
<STX><DEL><DEL><DEL><STX>A<DEL><DEL><DEL><ETX><ETX>
Can 255.255.31.0 be a n/w mask..? mask is cont. no of 1's and then no of 0's.. So in this case it
is..11111111.11111111.00011111.00000000.. how come 1 has come in between ..? plz explain ..
Yes this is a discontinuous subnet mask.But practically these are not being used a lot nowadays.
Mostly Such kind mask is used in many question where you have given many IP addresses and
they will ask whether the IP addressed could belong to this same network or not.
Selected Answer
From Wikipedia:
Let the size of congestion window of a TCP connection be 32 KB when a timeout occurs. The round trip time of the
connection is 100 msec and the maximum segment size used is 2 KB. The time taken (in msec) by the TCP connection to get
back to 32 KB congestion window is _________.
Selected Answer
http://gateoverflow.in/1794/gate2014-1_27?show=1794#q1794
Which algorithm is used to shape the bursty traffic into a fixed rate traffic by averaging the data rate?
isro2013 computer-networks
Its D.
what is the length of subnet ID. plz someone explain me with an example..plz..
If we have to make 4 subnets then we have to choose 2 bits (00, 01,10,11) . As it is class C, 3 octets are for NID and 1
octet is for HID. Among Hosts we have to choose 2 bits so no of remaining hosts are configured from last 6 bits i.e. 2^6 -
2
If odd parity is used for ASCII error detection the number of 0's per 8 bit symbol is
a) even
b) odd
c) Indeterminant
if Odd parity is used, there should be odd number of 1's in 8 bit symbol.
Suppose two systems are there in two different LANs, LAN-1 and LAN-2 respectively.System-1 (present in LAN-1) wants to
communicate to system-2(present in LAN-2), for which sys-1 needs the MAC ddress of that system in adition to its IP
address.So, it sends an ARP request messgae which contains the destination IP address which is broadcasted by the switch
present at the interface of LAN-2.
My doubt is, how does the system-2 will come to know, that the request messgae belongs to it..? I think dest. IP which is
present inside the ARP request message belongs to the public IP(of the LAN).[correct me, if i am wrong].Then,how the
system-2 is going to reslove that request packet belongs to it..? Please explain.
basically u don't even need to know the mac address of the final host. always the mac address which will be used will be
the next hope. which in this case will be default gateway. and arp request outside the network are not entertained .
Selected Answer
https://en.wikipedia.org/wiki/Address_Resolution_Protocol
computer-networks gate-2009
Part 1)
The 15 bit wide clock counter can produce 2 15 sequence numbers, producing 1 every 100 milliseconds. (1 msec = 10 -3
sec)
⇒ 215 sequence numbers can be produced in 2 15 x 100 x 10-3 seconds = 3276.8 sec ⇒ 54.61 minutes.
As the sequence numbers will start repeating after the expiry of lifetime (which is given as 60 sec, we dont have any
issue)
Part 2)
Which of the following is widely used inside the telephone system for long-haul data traffic ?
(A) ISDN
(B) ATM
(C) Frame Relay
(D) ISTN
255.255.31.0 =
Supernet means combination of two or more networks (or subnets) with a common Classless Inter-Domain Routing
(CIDR) . So max supernet subnet mask for this will be Class b subnet mask . 255.255.0.0 .
If the transmission delay is 200ms and throughput is 50 then what is the RTT for the Ethernet
(A). 40ms
(B). 80ms
(C). 20ms
(D).None
computer-networks
T.T
200
9.277 what is the value of the decryption key if the value of the encryption
key is 27? top gateoverflow.in/17421
In a system an RSA algorithm with p=5 and q=11,is implemented for data security.what is the value of the decryption key if
the value of the encryption key is 27?
a)3
b)7
c)27
d)40
Selected Answer
Answer of above ,
p=5 , q=11 , encryption key(e) = 27
n = p*q = 5*11= 55
φ(n) = (p - 1) * (q - 1) = 4 * 10 = 40
Given[e = 27], d such that (d * e) % φ(n) = 1
A 5-stage pipelined processor has Instruction Fetch (IF), Instruction Decode (ID), Opearnd Fetch (OF), Perform Operation
(PO) and Write Operand (WO) stages. The IF, ID, OF and WO stages take 1 clock cycle each for any instruction. The PO
stage takes 1 clock cycle for ADD and SUB instructions, 3 clock cycles for MUL instruction and 6 clock cycles for DIV
instruction respectively. Operand forwarding is used in the pipeline. What is the number of clock cycles needed to execute
the following sequence of instructions?
(A) 13
(B) 15
(C) 17
(D) 19
Which of the following transmission media is not readily suitable to CSMA operation?
a)Radio
b)Optical fibers
c)Coaxial cable
d)Twisted pair
a) Radio. Wireless transceivers can't send and receive on the same channel at the same time, so they can't detect
collisions.
in radio a large number of channels may be there and csma cd cannot be used as , the collision may not be detected . it is
used in lan technologies where there is a physical wire.
a. Radio
Selected Answer
A packet filtering firewall will be able to look only till network layer because at that layer it is called packed. so it will be
able to take decision on all the info it can see at that layer. at that layer ip of users are available . so it can discard
packets according to ip. so answer d. option a require a layer 4 firewall. (tl) option b requires layer 5 firewall (application
layer) and option c may also need layer 5 .
Selected Answer
there is nothing called as lan frame. there are ethernet frames. so if they are talking about the ethernet frame then the
answer will be c
if question is asking where the actual data is present in a ip datagram. it is after tcp header as the ipdatagram contains
tcp segment. so it is like .
A IP packet has arrived in which the fragmentation offset value is 100,the value of HLEN is 5 and the value of total length
field is 200.what is the number of the last byte?
a)194
b)394
c)979
d)1179
Selected Answer
Data length=200-4*5=180
Ans c
Selected Answer
Ans a.
This topic is from ICMP and I dont think its in GATE syllabus anymore. Still it goes like this :
Original TS : Time at which sender sent packet acc to its own clock.
Recieving TS : Time at which reciever recieves that packet acc to its own clock.
Transmit TS : Time at which reciever sent a reply of that packet acc to its own clock.
Returned TS : Time at which sender of recieves the reply acc to its own clock.
RTT
=> Sender sent the packet at 46 and reciever should have recieved it at 56 , but its recieving it at 59, => its 3 ms ahead.
So it should set its clock 3 ms behind to sync with sender.
Assume that each character code consists of 8 bits. The number of characters
that can be transmitted per second through an synchronous serial line at 2400
baud rate, and with two stop bits, is:
(a) 109 (b) 216 (c) 218 (d) 219
isro
Selected Answer
The baud rate is the rate at which information is transferred in a communication channel. Serial ports use two-level
(binary) signaling, so the data rate in bits per second is equal to the symbol rate
in bauds. Ref: https://en.wikipedia.org/wiki/Serial_port#Speed.
"2400 baud" means that the serial port is capable of transferring a maximum of 2400 bits per second."
An eight bit data (which is a char) requires 1 start bit, 2 stop bits = 11 bits.
Since we can only count the fully transmitted ones, we take floor = 218.
b)Simulating a network
d)option
VLAN:actuall physically system can be placed anywhere but logically they are belonging to a group.
Network architects set up VLANs to provide the network segmentation services traditionally provided only by routers in LAN
configurations
https://en.wikipedia.org/wiki/Virtual_LAN#Uses
9.286 Which of the following is not a valid multicast MAC address? top gateoverflow.in/17449
a)01:00:5E:00:00:00
b)01:00:5E:00:00:FF
c)01:00:5E:00:FF:FF
d)01:00:5E:FF:FF:FF
Selected Answer
Answer : D
multicast MAC Address range of 01-00-5E-00-00-00 to 01-00-5E-7F-FF-FF
Source: http://www.aiotestking.com/juniper/what-is-a-valid-multicast-mac-address/
9.287 which of the following is not an address of this organization? top gateoverflow.in/17446
An organization is granted the block 130.3412.64/26.it needs to have 4 subnets.which of the following is not an address of
this organization?
a)130.34.12.124
b)130.34.12.89
c)130.34.12.70
d)130.34.12.132
Selected Answer
The 4 subnets :
130.34.12.64-130.34.12.79
130.34.12.80-130.34.12.95
130.34.12.96-132.34.12.111
130.34.12.112-130.34.12.127
So ans is d
A supernet has a first address of 205.16.32.0 and a supernet mask of 255.255.248.0. A router receives 4 packets with the
following destination addresses.which packet belongs to this supernet?
a)205.16.42.56
b)205.17.32.76
c)205.16.31.10
d)205.16.39.44
Selected Answer
AND ip address and supernet mask whichever option gives address of supernet is the ans
Let bandwidth of a token ring is 4 Mbps and THT be 15ms. What is the maximum frame size
and maximum payload size
computer-networks
till which layer the loopback packet goes . i mean to ask that the lowest layer till which packet travel and then come back. I
read that it goes to data link layer . but is the point to send it to data link layer as the address 127 is know at the network
layer. at the same page i also read that it will return as the address 127 will be known . which is know at network layer . so i
m confussed till which point the packet will go .
computer-networks
It should return from Network Layer of the host in my opinion, however i was'nt able to find exact answer to this question .
Why do we have the Loopback address and why is it 127.0.0.1??? Early on when the Department of Defense in the US was designing TCP/IP, they decided that
they should reserve a portion of the space for testing. They rather randomly selected the 127 space for this purpose. In fact - it is the entire space 127 space that
they reserved. Many do not realize this, since the most common implementation is to assign 127.0.0.1. So try pinging the address 127.1.2.3 on your PC and it
might just respond if your vendor supports testing with other numbers in the reserved loopback space.
What is the fact that your machine responds to 127.0.0.1 really telling you???
This is telling you that TCP/IP is properly initialized on your device. You might not have external interfaces set up properly,but the TCP/IP stack is
indeed there and it is functional once you do the remaining required configurations.
Notice the creators of TCP/IP had no idea there would be an IP address shortage when they selected this space! They sure wasted a lot of addresses for this
testing purpose.
Remember also that you can create your own loopback interfaces on Cisco devices. For example, you can do this:
interface loopback 101
ip address 10.10.10.1 255.255.255.0
This creates a virtual interface on your device that you can use for a wide variety of purposes - like testing a feature!
reference:https://learningnetwork.cisco.com/thread/52391
in IPV6 what is the total number of router between source and destination.please explain every step
Q). Consider a TCP machine having window size 32KB over a 512Mbps channel that has one way delay of 20msec . The line
efficiency in percentage is __________.
Selected Answer
= 2 * 20ms = 40 ms.
= 32 * 8/40 * 512
= 0.0125
= 1.25%
https://www.switch.ch/network/tools/tcp_throughput/?mss=1460&rtt=80&loss=1e-
06&bw=512&rtt2=40&win=32&Calculate=Calculate
9.293 Q:- why it is said that one of the key characteristic of distance vector
routing is knowledge about the entire network while one of the key
characteristic of link state routing is knowledge about the neighborhood ??
top gateoverflow.in/14005
computer-networks
this one is simple and intersting just make the colum arrangement as below
3 1 5 2 4
L A Y E R (assign number from 1 onwards as per aplhabetical order e.g A=1 E=2.....) IGNORE ""
C O M P U
T E R N E
T W O R K
NOW write all letters of column 1 then 2 3,4,5 and ans will be OEWPNRCTTSUEKMRO
9.293 A bridge uses IP address and router uses MAC address- true or false top
gateoverflow.in/43610
FALSE
Given code word 1110001010 is to be transmitted with even parity check bit. The encoded word to be transmitted for this
code is
(A) 11100010101 (B) 11100010100
(C) 1110001010 (D) 111000101
computer-networks ugcnet-june-2013-3
Selected Answer
because even parity will make it even no of 1`s , i mean see in the transmitted data 1110001010 there are five 1 which is
odd . to make it even it will add extra 1 as parity . so it will be 11100010101 .
9.295 In stop and wait protocol , every 4th packet is lost.Find number of
packets ? top gateoverflow.in/14772
In stop and wait protocol , every 4th packet is lost.If 8 packets are being sent, Find number of packets ?
Answer given is : 10
Selected Answer
Stop and Wait are easy to calculate- a resent happens only for the lost packet.
ACK won't be counted as packets as they are usually very very small.
9.296 255.255.31.0 how many number of subnets and hosts are there if it is
subnet mask. top gateoverflow.in/15197
Which combination of the following features will suffice to characterize an OS as a multi-programmed OS?
(A) More than one program may be loaded into main memory at the same time for execution.
(B) If a program waits for certain events such as I/O, another program is immediately scheduled for execution.
(C) If the execution of a program terminates, another program is immediately scheduled for execution.
A. A
B. A and B
C. A and C
D. A, B and C
so as we know that there are 5 classes where d and e class are not used for networking and there is no subnet in them .
so basically if classes is not given subnet can vary .but here it is simple d and e cannot be used so we just ruled out the d
and e definitely this is class c network. subnet mast that tells the number of 1 bits in the network id field are 8+8+5=21.
no of subnet will be see the last octate . 8-5=3 so we have actually borrowed 3 but from the network id .so number of
subnet will be 2^3=8 . 2^ because by one bit i can only represent 2 possiblity
assuming classfull ip addressing. for cidr the data is insufficient to tell the number of subnets.
9.296 what are the ip address used by CIDR address 192.168.10.0/20 give
the range top gateoverflow.in/15914
the /20 states that there are 20 network bits in this so just leave them and for range just put all 0's in host bits and then
all 1 in that .
192.168.00001010.00000000.. so range will be from 192.168.0.0 to 192.168.15.255. note that you are given an ip in
this range it does not means that range will start after it only .
The subnet mask for a particular network is 255.255.252.0. Which of the following pairs of
IP addresses could belong to this network?
A. 172.57.88.62 and 172.57.87.233
B. 10.35.28.2 and 10.35.29.4
C. 191.203.31.87 and 191.234.31.88
D. 128.8.129.43 and 128.8.131.42
Selected Answer
To prevent signal alteration, what is the maximum number of repeaters that can be placed on one 10 Base 5 or 10 Base 2
network?
computer-networks
Selected Answer
the answer is 4
The IEEE802.3 specifications state the rules of network extension. The maximum number of the repeaters that can be used in one transmission path between two nodes is four, the
maximum number of network segment between two nodes is five.
Imagine 2 LAN bridges, both connecting a pair of 802.4 networks.The first bridge is faced with 100 512 byte frames per
seconds that must be forwarded. The second is faced with 200 4096 byte frame per second. Which bridge do you think will
need the faster CPU?
I know that the answer is first case but why ? Acc to me the context switches and all depends on the number of frames
passing through point which is higher in second case. So how is it that ans if first case ?
computer-networks
At some places it is written that Baud rate = 2 * Bit rate and some places its written that Bit rate = 2 * Baud rate? I am
confused, what is the relation between the two ?
computer-networks
Bit rate is a measure of the number of data bits (that's 0's and 1's) transmitted in one second. A figure of 2400 bits per
second means 2400 zeros or ones can be transmitted in one second, hence the abbreviation 'bps'. Baud rate by
definition means the number of times a signal in a communications channel changes state.It may vary.like in Manchester
encoding and differential Manchester encoding baud rate= 2*bit rate.
Baud rate is mostly used in telecommunication and electronics, representing symbol per second or pulses per second,
whereas bit rate is simply bit per second. To be simple, the major difference is that symbol may contain more than 1 bit,
say n bits, which makes baud rate n times smaller than bit rate.
Suppose a situation where we need to represent a serial-communication signal, we will use 8-bit as one symbol to
represent the info. If the symbol rate is 4800 baud, then that translates into an overall bit rate of 38400 bits/s. This could
also be true for wireless communication area where you will need multiple bits for purpose of modulation to achieve
broadband transmission, instead of simple baseline transmission.
(100Base5) is thick Ethernet = Bandwidth of 100 Mbps and the maximum length of cables
is 500 meters .
Now ,we have-->Bandwidth = 100 Mbps
= 0.0x microsec
[ As CSMA/CD ,transmission time must be greater than twice the propagation delay ]
in terms of confidentiality.
digital signature ncrypts the message but doesnt provide confidentiality.
WHY?
It encrypt the contents using senders private key anybody can open it using public key and It just ensure the authenticity
and integrity of the msg .
However
Confidentiality can be provided by further encrypting the entire message plus signature with either the receiver's public
key (public-keyencryption) or a shared secret key (symmetric encryption)
Plz explain it .
its made easy question, they have provided solution for A and marked C as correct
Selected Answer
Totalnumberofrequest / second
As average station makes 36 request / hour. So each station makes a request every 3600 sec / 36 request = 100 sec.
Total load is 10000 requests per 100 sec, i.e., 10000 / 100 = 100 request per second.
Number of slots in 1 second = 1 sec / 100 microsec = 10000 slots per second.
100 1
10000 100
Totalchannelload = =
Nodes A and B are connected with 100 Mbps ethernet segment with 6 microsec pop.delay between them.Suppose A,B send
frames at t=0 and frames get collided.after first collision A draws k=0 and bdraws k=1.if jam signal is ignored and timeout is
1 RTT then at what time A's packet gets completely delivered to B...assume packet size 1000 bits.
a)28 microsec
b)16 microsec
c)22 microsec
d)38 microsec
Selected Answer
at t=0 both A and B transmit and after 1RTT i.e (TT+2PT) =10+12 =22 microsecond collision detected
A will again transmit while B wait for P.T i.e(6 microsecond) and A segment reach B after TT+PT=10+6=16
9.305 How long does it take for the packet to get to the receiver? top gateoverflow.in/33787
Consider a route in a store and forward network going through 9 intermediate nodes. The packet contains 1100 bits and are
transmitted at 64 Kbps. Assume propagation delay over the links are negligible. As a packet travels along the route, it
encounters an average of 5 packets when it arrives at each node. How long does it take for the packet to get to the receiver if
the nodes transmit on a "first come first served" basis (in ms) ?
computer-networks
Selected Answer
Here, packet goes like this - sender > 9 intermediate nodes > receiver
Frame Size
So, for this packet to be transmitted for first intermediate node = 6 * T.T.
= 55 T.T. = 55 * 17.1875
my ans 25
my ans 19
Selected Answer
My Answer is
solve in detail...........
Bandwidth of a link is 1000 Mbps and RTT is given as 250 micro seconds. If frame size is 500 bits. the utilization(in %age) of
channel when stop and wait ARQ used is _________.
computer-networks
Selected Answer
lu%=(TT/TT+2PT)*100
TT=data/ bandwidth
=500/1000*106
=0.5 microsec
RTT=250microsec
so LU %=(0.5/0.5+250)
=0.5/250.5
=0.00199 *100
=0.199
≅0.2(ans)
computer-networks
Selected Answer
so offset of fifth ie last packet= starting address of fifth packet /8=1120/8=140 (1120 as 4 packets carry 1120 bytes)
The intermediate router between source and destination do not need the following information in IP header
a.Protocol
b.Identification number
c.Source IP
d.Version
But according to me Identification number is not required at router. because identification number is used for
reassembling of packets. and Reassembling is not done at router.
plz clarify.......
Selected Answer
Routers do Fragmentation of packets in case of MTU size is less than packet size. They will need to include Identification
no in Fragments !
Yes, Protocol, Identification number, Source IP and Version, all are required by the intermediate routers.
Identification number is required due to fragmentation done my the intermediate routers. In case of MTU size is less than
the size of the packet, so here identification number is required in fragments.
Protocol, Source IP and version are also necessary to process and send the packets correctly.
the round trip delay between sender and receiver is 160ms and the bottleneck bandwidth of the link is 256 kbps.Sender uses
sliding window protocol to send a 64 byte packet.The optimal size of the window that sender should use is ?
=256kbps*160ms/64*8
=80
W=(256*10^3*160*10^-3)/(64*8)
=80bits.
Assume that SWP is designed for a 1mbps point to point link to the moon which has 1 way latency(delay) of 1.25sec
Assuming that each frame carry 1KB of data, find
n = tx+2tp / tx
tx = 8 * 10^-3 / 10^-6 = 8 ms
tp = 1250 ms
if packet size is 1KB and propogation time 15msec, channel capacity 10^9 b/s , find transmission time and sender utilization in stop and wait protocol ?
Selected Answer
Tt = 6.4 * 10 -4 sec
Selected Answer
My Answer is
if 50 stations are there and if each slot contain 25 microsec then what would be max waiting time for a station for safe
transmission
a)200 b)300 c)250 d)400
A sends 2 frames of 1000 bit each to B via switch S.Bandwidth=10Mbps propogation delay over links=5us find time when
second packet reaches B completely
Frame 2 will be recieved at reciever after ≈ 310 µs ,if switch uses a store and forward mechanism.
http://inst.eecs.berkeley.edu/~ee122/fa09/notes/04-Performancex6.pdf
so efficiency of ethernet=1/6.44+a
efficiency=1/1.644=60.8%
so throughput=efficiency*throughput=60 kbps(approx)
A 8-node network runs the carrier sense Multiple Access (CSMA) MAC protocol. The maximum data rate of the network is 10
Megabits/s. Including retries, each node sends traffic according to some unknown random process at an average rate of 1
Megabit/s per node. Given that the network's utilization is 0.75. No packets get dropped in the network except due to
collisions, and each node's average queue size is 5 packets. What fraction of packets sent by the nodes (including retries)
experience a collision?_________% (correct to two decimal places).
A and B are the only two stations on an Ethernet. Each has a steady queue of
frames to send. Both A and B attempt to transmit a frame, collide, and A wins
the first backoff race. At the end of this successful transmission by A, both A and B attempt to transmit and collide. The
probability that A wins the second backoff race is
(a) 0.5 (b) 0.625 (c) 0.75 (d) 1.0
Selected Answer
After 2nd Collison a collision no =1 and B collision no=2(as A win first race)
So possible cases are
A B
0 0
0 1
0 2
0 3
1 0
1 1
1 2
1 3
Thus p (a win 2nd Collison )=5/8=.625
Φ(n)=2*4 = 8
This will simply give you whether a number is prime or not. Now the point is whatever the value you choose for a will give
that both 'a ' and 'p' are coprime to each other so that coprime concept we use while finding primitive roots. For
example if you want to find whether number 3 is primitive root of modulo 7 then you have to take in consideration
coprimes of 7 which you can do with Fermat's Little Theorem.
Selected Answer
slow start
0 2 KB
1 4 KB
2 8 KB
3 16 KB
now new threshold = 32 / 2 =16 KB .. again it statrts from initial segment size
5 2 KB
6 4 KB
7 8 KB
(NB:in some problem we add initial mss size given in problem in additive increase,in some case we add 1 mss .gate will
give marks for both)
9 17 KB
10 18 KB
so answer is 18 KB.
(if we take initial mss size then answer will be 20 KB ,but as per definition 18 KB will be the answer)
The router connecting a company's network to the internet applies the mask 255.255.255.192 to the
destination address of incoming IP packets. If one of the incoming packet has a destination address of
154.33.7.220, then find the network ID, subnet bits and host ID bits of incoming packets respectively
a. 154.33.7, 11. 011100
b. 154.33, 11000000. 011100
c. 154.33, 0000011111. 011100
d. 154.33.7. 011111. 011100
My Answer is
Since IP is 154.33.7.220 so it belongs to Class B
so the network bits are first 16 bits
Therefore network id is 154.33.0.0
Subnet mask is 255.255.255.192
In subnet mask number of 1's represent Network or subnet bits
255.255.11111111.11000000
and 154. 33.00000111.11011100
--------------------------------------------
154.33. 00000111.11 011100
------------------ -----------
subnetid hostid
Selected Answer
--> Frame length = 2500 bits , Number of nodes = 100 , Transmission rate = 10^8 bps (given).
Selected Answer
mtu is 480.
payload is 460 B.
my ans 65ms
slow start
mss - 2 KB
4 KB
8 KB
16 KB
32 KB
5 th RTT will be 32 to 64 KB
A channel has propagation delay of 10 ms .For 320 bits frame what will be channel bit rate if stop -n-wait give efficiency of
50%?
I have solved this using 2 approaches but getting different answers(as in the picture). Can anyone plz explain where i am
wrong?
Your first approach is not understandable. Why are you multiplying propagation delay with the Bandwidth? I think it will
not give total amount of data that could be sent.
Method 2 is correct.
What will be sender's and receiver's window size that are not possible in SR protocol?
D. 5,4
http://gateoverflow.in/?qa=blob&qa_blobid=18152128369856966495
9.335 assume 10 Mbps Ethernet and two station A and B on it's same
segment....... top gateoverflow.in/30343
assume 10 Mbps Ethernet and two station A and B on it's same segment. The RTT between two nodes is 650 bit times. A and
B start transmitting frame and collision occure and both sends 30 bit jam signal. find the time at which both nodes A and B
sense an idle channel(in micro sec)_____
http://gateoverflow.in/?qa=blob&qa_blobid=3365268112291698752
21
TTL field is modified only at Network layer. When a packets routes through Router/Network layer it checks the value of
TTL field and accepts the packets and decrements the value of ttl by 1 if it is not 0. In Case if it is 0 then network layer
simply discards the packets. LANs (HUbs) work at data link layer. Here packets is passing through 2 routers R1 and R2. so
at the router it will be decremented to 24-1-1 = 22. Now t the Receiver end also it will pass through Network layer and
there also it will be decremented by 1. Finally at the Receiver end value of TTL field will be 22-1 = 21.
100 nodes are connected to a 1000 meter length coaxial cable,using some protocol each node can transmit 50 frames/sec.
where the average frame length is 2500 bits.the transmisson rate at each node is 100 mbps.what is the numeric value of
efficiency of the protocol(in %)?
80%....
Why CWS = 1 and increase it at an exponential rate to catch up to SSThresh before slowing down ?
If TCP knows that the congestion is near TWS = SSThresh, then why not just set CWS = SSThresh ?
(CWS =congestion win size,TWS =Transmission win size,SST hresh =slow start thresold )
computer-networks
1000=2^n+1 - 2
log 998 = n+1
n= 9.96-1
n= 8.96 for 1000 packets
You can also calculate direct but for 9th(summation will be 1023) packet you will get 900/60 = 15 minutes
9.340 Suppose host A want to send a large file to host B. .. top gateoverflow.in/30344
Suppose host A want to send a large file to host B. the path from host A to host B has 3 links of rates R1=512 Kbps, R2=2
Mbps and R3=1 Mbps. what is the throughput for the file transfer(in Kbytes per minuts)_____
512 kbps....
They r connected in series even though one of channel is fast it has to wait for another channel to complete it's work...till
ack come from the slower channel or data comes from slower channel...faster channel has to wait...
P52. Consider a network in which all nodes are connected to three other nodes. In
a single time step, a node can receive all transmitted broadcast packets from
its neighbors, duplicate the packets, and send them to all of its neighbors
(except to the node that sent a given packet). At the next time step, neighboring
nodes can receive, duplicate, and forward these packets, and so on. Suppose that uncontrolled flooding is used to provide broadcast in such a
network. At time step t, how many copies of the broadcast packet will be
transmitted, assuming that during time step 1, a single broadcast packet is
transmitted by the source node to its three neighbors.
computer-networks
Then this nodes will have 2 children( 2 because it already connected to it parent node)
At step 1 3 packet
So at step t =3×2^t-1
computer-networks
part a)
= 5333.33 + 100 = 5433.33 ms
part b)
= 100 + 1000(16/3) + 999(50)
part c)
part d)
But again in last R.T.T time taken will be '0' , so will not consider this
A 255.255.248.0
B. 255.255.252.0
C. 255.255.254.0
D. 255.255.255.0
Selected Answer
168.17.00000111.11111111
a. 255.255.11111000.00000000
b.255.255.11111100.00000000
c.255.255.11111110.00000000
d.255.255.11111111.00000000
A group of N stations share 100 Kbps slotted ALOHA channel. Each station output, a 500 bits frame on an average of 5000
ms; even if previous one has not been sent. What is the required value of N?
Compute the fraction of the bandwidth that is wasted on overhead (headers and retransmissions) for protocol 6 on a heavily
loaded 50 kbps satellite channel with data frames consisting of 40 header and 3960 data bits. Assume that the signal
propagation time from the earth to the satellite is 270 msec. ACK frames never occur. NAK frames are 40 bits. The error rate
for data frames is 1% and the error rate for NAK frames is negligible. The sequence numbers are 8 bits.
computer-networks
Let's take total 100 packets has to send 1% error means 1packet lost...
(8040/100*4000+4040)*100%
=1.989% overhead
test-series computer-networks
A link carries data from n connections. In TDM, the data rate of link is _______ time faster and uni-duration is
________________ time shorter than a single link connection.
a)n,n
b)(n+1),(n+1)
c)n, n+1
d)(n+1),n
Please explain
let the size of the congestion window of a TCP connection be 32KB.When time out occurs the maximum segment size used is
2KB.If the time taken by the TCP connection to get 32 KB congestion window size is 480 ms than the RTT is??
Selected Answer
2---4---8---16---18---20--22--24---26--28--30---32
12RTT=480ms
1RTT=40ms
9.350 Pick the systems that can be used in both priority and non-priority
modes top gateoverflow.in/32819
computer-networks
When a signal travels through a transmission medium, its power becomes 100 times. Then there would be power
computer-networks made-easy
computer-networks made-easy
Which of following options is not an useful property of manchester line code for ethernet
a)continuous energy
c)no dc component
try this...........
=160ms*256kbps /64*8
=80
An organization is granted the block 150.36.0.0/16.The administrator wants to create 512 subnets. Find number of
addresses in each subnet.
clarify.....
so no of host =2^7-2=126
no of address=128
What will be the sum of the checksum and data if there are no errors?-0 or +0?This question is from Arihant
It should be +0, since we get all digits 0 in the answer if the data is correct. For -0 we should get a negative sign 1 in the
beginning of the digits.
Selected Answer
first approach...
MSS - 2 KB
4 KB
8 KB
18 KB
20 KB
22 KB
24 KB
26KB
28KB
30 KB
32 KB
total 12 RTT
so RTT = 40 ms
2 nd approach
MSS - 2 KB
4 KB
8 KB
17KB
18KB
19 KB
20 KB
21 KB
22 KB
23 KB
24 KB
25 KB
26 KB
27 KB
28 KB
29 KB
30 KB
31 KB
32 KB KB
20 RTT =480 ms
RTT= 24 ms.
I did it 2 way cause,some solution considers ,in the time of additive increase ,just add the the initial mss size,some
solution consider it as strictly 1 mss.
REF:
1. http://gateoverflow.in/2156/gate2012_45
2. http://gateoverflow.in/1794/gate2014-1_27
3) Redundant servers can trace the record back to it's creation time so that it can be validated
4) None of these
Selected Answer
Should be 2 cached copies expire automatically after sotme time.this is done to get fresh data ue updated data and not
cached data
First Backoff Race (X(0,1) ,Y(0,1))possible combinations : (0,0) (0,1) (1,0) (1,1)
Second Backoff Race (x,Y) possible combinations: ((here x packet is getting in collision second time so for X(0,1,2,3) and
Y(0,1))
compute the fraction of bandwidth that is wasted on overhead on a heavily loaded 50kbps satellite channel with data frames consisting of 40 header and 3960 data
bits .
ACK frames never occur.NAK frames are 40 bits .Error rate for data frames is 1% and error rate for NAK frames is negilgible .
In this one it is not mentioned how many frames do we send so then how can we calculate total no of bits in this ?
It will send a data frame again,( the frame size is 4000 bits)
Total wastage= (4000) lost data frame + (4000) retransmit lost data frame + (40) Nak bits = 8040 bits
computer-networks
A and B are 4 hops apart on a Circuit Switched Network where each hop is 100 mile long. Per hop processing delay is 5µs.
Packets are 1500 Bytes long. All links have a Transmission speed of 56Kbps. speed of light in wire is 125,000 miles/s. If B
sends a 10 packet message to A, how long will it take A to receive message up to the last bit?
my question can more than one meesage can be in one segment and can more than one segment be in one datagram and
more than one datagram can be present in one frame
computer-networks
Lets start with TL ipv4 maximum data could be transmitted is 64kB (16 bit in Total Length Field See IpV4 Header )
65535 B
In Data Link Layer If we are using Ethernet It can hold upto 1500B
Network Layer Divide Segments According to Which layer is creating bottle neck ( according to data mentioned here
bottle neck will be caused by DLL . No NL takes packets of size 1460 B )
Application Layer can send any amount of data to NL and it the duty of NL to divide the data to fit into one segment .
A and B are 4 hops apart on a Packet Switched Network where each hop is 100 mile long. Per hop processing delay is 5µs.
Packets are 1500 Bytes long. All links have a Transmission speed of 56Kbps. speed of light in wire is 125,000 miles/s. If B
sends a 10 packet message to A, how long will it take A to receive message up to the last bit?
Station X needs to send a message consisting of 12 packets to Station Y using a siding window (window size 4) and go-back-
n error control strategy. All packets are ready and immediately available for transmission. If every 7th packet that X
transmits gets lost (but no acks from Y ever get lost), then the number of packets that X will transmit for sending the
message to Y are _______.
A 1 Mbps satellite link connects two ground stations. The altitude of the satellite is 6000 km and speed of the signal is 3 ×
108 m/s. What should be the packet size for a channel utilization of 50% for a satellite link using go-back-63 sliding window
protocol?
Assume that the acknowledgment packets are negligible in size and that there are no errors during communication.
its a triabgle and just with the height of trinage i cannot determine base of the triabgle
Consider a link of length 1000 km with 10 9 bps rate connecting a sender and receiver. Assume a fixed packet length of 2500
bytes and sender always has packets to send. Packets are never lost or corrupted in the connection. The necessary window
size to achieve 90% utilization for a sliding window protocol is _________ (Assume signal propagation is 2 μsec per km
[Approximately])
TT=2500*8/(10^9)=20μsec
PD=2*1000=2000μsec
efficiency=w*TT/(TT+2PT)
0.9=w*(1/201)
w=201*0.9=180.9=181
In stop and wait ARQ system bandwidth delay product is 80000 bits..1 bit takes 20 ms to make round trip..if link utilization
is only 10%,then what is size of frame in bytes?
Selected Answer
In stop and wait ARQ only one packet is sent before acknowledgement received.
Bandwidth*RTT = 80,000bits
0.90 TT = 0.10*RTT
A is sending packets to E using a reliable transport protocol. Each link above can transmit one packet per second. There are no queues or other sources of
delays at the nodes (except the transmission delay of course).
computer-networks
9.371 Consider the two hosts A and B are connected via a Router as shown
below top gateoverflow.in/36506
computer-networks
computer-networks
Keylogger is kind of malware which records your keystrokes while you are typing also it may spy/monitor your computer.
And Keylogger might be programmed such that keylogger will send that keystrokes back to the hacker.
Keystrokes will include all kind of typing you do from keyboard like username,passwords,chatting etc
While most of the keyloggers does not track mouse movements and other things as its primary purpose is keylogging, but
they can be also used for screen capture,packet sniffing,information stealing etc.
Keylogger might be in Firewall-Network Security.
Consider a Sliding Window Protocol for a 10MBps point- to -point link with propagation delay of 2sec. If frame size is 4 kB.
The minimum number of bits required for the sequence number is what?
Selected Answer
T trans=4*!0^3/(10*10^6)=4/10000=.0004sec=.4ms
therefore, Sequence(min)=1+2*5000=10001
Selected Answer
1.Swp
3.Tcp Ip header
4.Fragmentation
5.Subnet , Supernet
8.RSA algorithm
Consider a TCP connection using the slow start congestion control scheme with an initial threshold value of 64 kB and a
Maximum Segment Size (MSS) of 2 kB. The receiver’s advertised window is initially 32 kB. The first transmission attempt is
numbered 0, and all transmission attempts are successful except for the timeouts on attempt number 4. Which of the
following represents size of sender’s congestion window at attempt number 10?
Selected Answer
0-2
1-4
2-8
3-16
4-32(lost)
5-2
6-4
7-8
9-18
10-20
my answer: 20
made easy answer given: 18!
Consider a source computer (S) transmitting a file of size 106 bits to a destination computer (D) over a network of three
routers (R1 , R2 and R3) and four links (L1, L2, L3 and L4). L1 connects S to R1; L2 connects R1 to R2; L3 connects R2 to
R3; and L3 connects R3 to D. Let each link be of length 100 km. Assume signals travel over each link at a speed of 108
meters per second. Assume that the link bandwidth on each link is 1 Mbps. Let the file be broken down into 1000 packets
each of size 1000 bits. What is the total sum of transmission and propagation delays in transmitting the file from S to D?
1) 1007
2) 1010
3) 3000
4) 3003
propogation delay from Source computer (S) to R1 = (Distance) / (Link Speed) = 10^5/10^8 = 1ms
Total prorogation delay to travel from S to D = 4*1 ms = 4ms ( since four links are in between L1, L2, L3 and L4)
transmission delay for 1 packet = (Number of Bits in one packet) / Bandwidth = (1000/10^6) = 1ms.
total transmission delay for 1 packet = 4 * 1ms = 4ms ( since four links are in between L1, L2, L3 and L4)
The first packet will take 8ms to reach Destination Computer (D). While first packet was reaching D, other packets must have been
processing in parallel. So D will receive remaining packets 1 packet per 1 ms from R3. So remaining 999 packets will take 999 ms. And total
time will be 999 + 8 = 1007 ms
The measurement of slotted aloha channel with infinite number of users shows that 10% slots are idle. what is the channel
load(G)?
computer-networks
An organization is granted the block 190.76.0.0/16. The administrator wants to create 1024 subnets using 10 bits. The first
and last addresses in subnet 1024 respectively are?
header bits=40
NAK bits=40
retransmitted bits=4000*0.02=80
9.380 what is the meaning of zero subnet and dba subnet top gateoverflow.in/26311
If a network address is subnetted, the first subnet obtained after subnetting the network address is called subnet zero.
Consider a Class B address, 172.16.0.0. By default the Class B address 172.16.0.0 has 16 bits reserved for representing the host portion,
thus allowing 65534 (216-2) valid host addresses. If network 172.16.0.0/16 is subnetted by borrowing three bits from the host portion, eight
(23) subnets are obtained.Then first subnet of first network 172.16.0.0/19 is called subnet zero.
Direct broadcast address used to broadcast a datagram in particular network. It is the last address of subnet and can be hear by all hosts in subnet. Like
sender wants broadcast in a network having network ID 192.168.23.0 then sender has to mention receiver address as 192.168.23.255.
9.381 relation between full duplex and baseband transmission top gateoverflow.in/25452
if a link is using baseband transmission for e.g Ethernet....thats means one signal can pass through the link at a time.....that
means a baseband transmission can never be full duplex??? can anyone explain what is the relation between baseband
transmissions, broadband transmissions, full-duplex and half duplex link?
Selected Answer
Baseband transmission is bidirectional and uses digital signal.But in baseband transmission sending and receiving can not
be done at same time.So it's half duplex transmission.
Broadband transmission is unidirectional and uses analog signal.2 channels are required-1 for sending and 1 for
receiving.Hence it's simplex transmission for 1 channel but 2 wires working together makes it duplex.
The network consists of 4 hosts distributed as shown below: Assume this network uses CSMA/CD . And signal travels at 3 X
105 km/sec
(a).600 bits
computer-networks
in CSMA/CD-
L/B = 2(D/V)
AND WITH MINIMUM DISTANCE OF 90KM WE WILL GET 600BITS ..WITH DISTANCE OF 40,51,54,57 WE WILL GET <400
BITS....
SO 90 KM SATISFIES
computer-networks
In packet switching network packet are routed from source to destination along a single path having 2 intermediate nodes ,if
message size is 48 bytes and each packet contain header of 6 bytes then find optimal packet size...
The key here to solve this problem is the fact that packet transmissions from intermidiate switches (routers here) can be
overlapped.
Case(1): Message is not at all splitted and no. of packets (of 54B each) is 1...
Transmission Time @ switch R1 = 30/bandwidth ......{note 2 packets are transmitted on the line in parallel}
----------------
With 4 packets of 18B each: Total time = 72/b + 18/b + 18/b = 108/bandwidth
With 6 packets of 14B each : Total time = 84/b + 14/b + 14/b = 112/bandwidth
------------
Thus for sending entire file in minimum time with error-free channel (to save retransmissions of bigger packet sizes) one
should go for a split of 4 packets where each packet is having the size of 18B.
------------
TIP - There was a question in Gate-14 (Set 1) which is based on this very concept :)
MY QUESTION IS:
In Go BACK-N:
A 1 Mbps satellite link connects two ground stations. The altitude of the satellite is 6000 km and speed of the signal is 3 ×
108 m/s. What should be the packet size for a channel utilization of 50% for a satellite link using go-back-63 sliding window
protocol?
Assume that the acknowledgment packets are negligible in size and that there are no errors during communication.
Consider the effect of using slow start on a line with 5 millisec round trip time and no congestion. The receiver window is 36
KB and the maximum segment size = 2 KB. The time (in milliseconds) before the first full window can be sent is ________.
I want to have an idea about how the divisions are done.Please explain
it will be like
145.75.0.0/24 to 145.75.0.255/24 for 1st customer(as each customer have 256 address)
....
now group 2 64 address so need 6 bit for host and remaining are 26 bits
147.75.128.128/26 to 147.75.128.191/26(3rd
147.75.129.0/26 to 147.75.129.63/26(5th)
......
so B is correct
Ans is B.
for 1st group 128 customer and each need 256 address{Note: they call address not host}
So 1st group have address range
145.75.0.0 - 145.75.127.255.
now 2nd group
128 customer and 64 address So
145.75.10000000.00 {rest 6 bit for address contain by each customer} -> 1st customer of 2nd group
145.75.10000000.01 {rest 6 bit for address contain by each customer} -> 2nd customer of 2nd group
145.75.10000000.10 {rest 6 bit for address contain by each customer} -> 3rd customer of 2nd group
and so on
145.75.10011111.11 {rest 6 bit for address contain by each customer} -> 128th customer of 2nd group
means 145.75.159.192 {for 1st address of 128th customer all 6 bit will be 0's, So 11000000=192} and subnet is
8+8+8+2=26
So 145.75.159.192/26
The initial congestion window size over a TCP is 1. If slow start algorithm is used and the size of congestion window
incremented by 1 whenever an ACK is received i.e. after first rounda trip time congestion window size is 2 segments. Assume
that connection never leaves slow start. The number of RTT’s to send 3999 segments are _______.
Selected Answer
wind=2...... RTT =1
wind=8...... RTT=1+2+3
.....
wind=2048..... RTT=1+2+3+4+....11=66
Now after this for every ack 2 packets so to send remaining 1951/2
when window size reaches 2048 66 round trips. Now for remaining packets 3999-2048=1951. For every ack one packet
will be sent so required RTT = 1951/2=975.5. so total would be 1041
is it right approach?
For a class C network if IP address of a computer is 200.99.39.112 and subnet mask is 255.255.255.224 the first host of
first subnet (represent last octet) is ________.
My doubt is :
Since , we are using 3 bits for subnet here , ( as 224 means 1110 0000 )
000
I mean to say , first subnet : 000 , so 1st host in 1st subnet : 000 0 0001 , which is 1
computer-networks
make diffrence in net id and subnet id .. ooo is net id and 001 is subnt
If an Ethernet station collides 3 times in trying to transmit a single frame, how long might it wait before the next attempt?
D]None of these
Consider a 107 bps link that is 400km long, with a queue large enough to hold 2000 packets. Assume that packets arrive at the
queue with an average rate of 4000 packets per second and that the average packet length is 2000 bits. Find the average
number of packets in the queue?
link 107bps
Efficiency=(0.2/(0.2+2*500))*100
=(0.2/1000.2)*100
=0.019%= 0.02%
Its ans given by many aspirant as C but why not its D ??As our goal is to achieve perfect hashing rather than collision .Just take the example of any real world
application like gmail,yahoo,hotmail all of them are designed such that the two passwords should not generate the same Hash Value
i. A hash function (these are often used for computing digital signatures) is an injective function.
ii. A. encryption technique such as DES performs a permutation on the elements of its input alphabet.
Which one of the following options is valid for the above two statements?
Consider a reliable byte stream protocol that use SWP running over 100 Mbps network .Propagation delay is 80 ms and
maximum segment lifetime is 80 s
a) How many bits are needed for receiver window size in TCP?
B)
=30 bits
Suppose a host X with IP address 192.16.1.97 is connected through two routers R 1 and R 2 to another host Y with IP address
10.1.1.7. Router R1 has two IP addresses 192.16.1.135 and 192.16.1.110. Router R 2 has two IP addresses 10.1.1.67 and
10.1.1.155. The network mask used is 255.255.255.224. Which IP address should X configure its gateway?
X has IP address 192.16.1.97 with 192.16.1.011***** as network id in the last octet. So, the gateway should also have the same network id
as 192.16.1.011*****. 192.16.1.110 has the same Network ID and hence should be the gateway for X node.
9.396 Please clear some doubt in channel sensing part of computer networks
top gateoverflow.in/35107
Q1 )
Suppose ‘A’ and ‘B’ are on same 10Mbps Ethernet segment and the propagation delay
between two nodes is 275 bit times. Suppose A and B are on two ends of the wire and tries to send a frame at time t=0 and
frames collide. Then at what time (in bits) they finish transmitting a jam signal. Assume 48 bit jam signal.
A. 598 B. 323 C. 502 D. 227
Here in this question , time taken to send the jam signal is => Tp + (time taken to send 48 bit jam signal , i.e 48 bit times =
(275 + 48 ) =323 bit times
Q2)
Assume 10 Mbps Ethernet and two stations A and B on it’s same segment. The RTT between two nodes is 650 bit times. A
and B start transmitting frame and collision occurs and both sends 30-bit jam signal. Find the time at which both nodes A
and B sense an idle channel (in μsec).
Here , Tp = 0.5 * RTT = 325 bit times , so , add 30 bit jam signal = 325 + 30 = 355 bit times.
But they have also added Tp once again , 355 + 325 = 680 bit times.
Can you please justify the last Tp addition part ? Is it due to the fact that , in order to sense the channel idle , we need send
one bit , so , one propagation delay is needed ?
computer-networks
Tp = 0.5 * RTT = 325 bit times , so , add 30 bit jam signal = 325 + 30 = 355 bit times.
Both nodes A and B need to sense an idle channel. This would need propogation of these Jamming signals. So, another Tp
would be added to 355 bit times.
The following is a dump header of UDP HEADER in hexadecimal format 5EFA00FD001C3297, what is the total length of user
datagram? is a packet form client to server or vice versa?
computer-networks
9.398 Find NID and Host ID bits, given destination address & mask to apply.
top gateoverflow.in/34740
computer-networks
answer = option C
My question is what would be the ans if intruder is sniffing at Router 1 ??? then according to me ans should be option c and
d
Q.27 An IP machine Q has a path to another IP machine H via three IP routers R1, R2, and R3.
Q—R1—R2—R3—H
H acts as an HTTP server, and Q connects to H via HTTP and downloads a file. Session layer
encryption is used, with DES as the shared key encryption protocol. Consider the following four
pieces of information:
[I1] The URL of the file downloaded by Q
Selected Answer
Yes, packet sniffing at R1 will have information about TCP port number for Q and H, IP address of Q and H, and the link
layer address of Q only, since the DLL will only know the address of the immediately connected physical link (ie MAC
address) and not aware of the DLL of the H node, which is, although on 'a logical' link with Q, but different physical link
with R1.
Suppose the round trip propagation delay for 10Mbps Ethernet has 24.2micro sec The network has 48bit jamming signal
then what is minimum frame size in bits
Selected Answer
Min frame size is the data to be sent in 29 microsec = 29*10^-6 * 10 * 10^6 = 290 bits
Suppose A and B are on same 10Mbps ethernet segment and the propogation delay between nodes is 225 bit times.
Suppose A and B send frames at t=0 , the frames collide then at what time they finish travelling a 48 bit jam signal ?
In this question how come propogation delay is in bit times , it should be transmission time which is equal to length of frame / bandwidth .
computer-networks
find the netwrok id of given network by anding 255.255.192.0 with the given ip 157.106.46.234 so it will give.
157.106.0.0 . now take the ips and and with the subnet mask . if the same network id is obtained then its in same
network/ a is in the same network while b is not . because option d
How to solve modulus of large exponential like 191^15 mod 719 using fast modular arithmetic with left to right binary form.
computer-networks
Selected Answer
Method I
191^15 % 719
m=191
n=719
e=15 write in binary 01111
d= binary bits
Three rule to be followed during process
1.intially d = 1
2.if d=0 do d^2%n and write it as new d
3.if d=1 do d^2*m % n and write it as new d
0 1 1 1 1
intial d=1 do d^2%n 1 1 531 326 403
m * 191 191 191 191
d*m%n=new d 1 191 42 432 40
therefore 191^15%719 = 40
191^15 %719
=(191^3%719)^5
=(42^5%719)
=40
Well Network Layer switch is called Router. This is little confusing.. ( Link layers switch is called bridge :P )
computer-networks test-series
When switch is mentioned, it refers to L2 device only. L3 switch term came late when the switches started coming with
routable configs. It's not a proper official term.
repeater-->phy layer
hub-------->phy layer
switch--->phy+data link
9.405 What are the basics Equations Useful in Computer Network top gateoverflow.in/35300
Propogation Delay
Transmission Delay
Line Utilisation
Link Utilisation
RTT
(or)
I found the 2d quation used in SWP problems But didn't understand why transmission time is not taken into consideration ?
9.406 What is the maximum data rate per connection ? top gateoverflow.in/35309
computer-networks
What is the total over header bits (Headers & Retransmission) with data frames consisting of 40 bit header and 3960 data
bits. ACK frames never occur. NAK frames are 40 bits, the error rate for frame is 2% and for NAK frame is negligible.
1. 80.4
2. 80.8
3. 160.4
4. None of these.
http://gateoverflow.in/30612/gateoverflow.in
9.410 IPv6 Question - Which of the following is/are true? top gateoverflow.in/36187
a) Only S 1
b) Only S 2
c) Both S 1 and S 2
d) Neither S 1 nor S 2
Selected Answer
only S2.IPV6 connection oriented,but ipv4 connectionless.Header size of both are different
D) Neither S1 nor S2
9.411 For example, if C is 100 Mbps, the mean frame length, 1/µ, is 10,000
bits, top gateoverflow.in/27555
For example, if C is 100 Mbps, the mean frame length, 1/µ, is 10,000 bits, and the frame arrival rate, l, is 5000 frames/sec, then T = 200 µsec. Note that if we
ignored the queueing delay and just asked how long it takes to send a 10,000 bit frame on a 100-Mbps network, we would get the (incorrect) answer of 100
µsec. That result only holds when there is no contention for the channel.
Now let us divide the single channel into N independent subchannels, each with capacity C/N bps. The mean input rate on each of the subchannels will now
be l/N. Recomputing T we get
9.412 How many TCP connections can be opened between two ports? gateoverflow.in/27724
top
computer-networks
Selected Answer
At any time between two particular end hosts, only one TCP connection can be there between any two ports.
A TCP connection is uniquely identified by 5 pieces of information in the TCP and IP headers.
1. IP Source Address(IPSA)
2. IP Destination Address(IPDA)
IPSA & IPDA uniquely identify the end hosts & the Protocol ID field in the IP datagram tell us the connection is TCP.
The TCP source and destination port numbers identify the application processes on the end hosts.
Together AT ANY INSTANT, all 5 fields uniquely identify the TCP connection internet wide.
Whenever a TCP connection initiates, the end host who initiates the connection, picks a unique source port ID.
But in a TCP header the source port ID can not be more than 16 bits, so at a time we can have 2 16 = 64k different
connections, between a pair of end hosts, if the end host at the other end always listens at a specific port number.
When a TCP connection closes, the port number become available for reuse.
how to approach
computer-networks
Is there any way of calculating binary equivalent of the given IP address on the virtual calculator provided? Or we need to
use manual calculations for it?
If TCP round trip time is currently 20 ms and ACK comes in after 30 ms then what is the timeout period for next
transmission . Use α=0.9 and β=2
Suppose a TCP entity receive 2MB file from application layer and IP layer is willing to carry blocks of max size 1600 B.
Calculate amount of overhead incurred from segmenting file into packet sized units. Assume both TCP and IP header of 20 B.
IP can carry max block size=1600B in which 40B will be TCP+IP header.
#packets=2MB/1560B
=2*(2^20)/1560=1344.328=1345(approx)
Total overhead=1345*40=53800B
Let a file of 16 GB has to be transferrred from host A to host B. Assume an MSS size of 2048B. Then what is maximum
number of segments that can be transferred such that TCP sequence no don't get exhausted.Assume TCP sequence field 32
bits
100.1.2.0/25
100.1.2.128/26
100.1.2.192/26
computer-networks
Which of the following IP address requires approval from ISP for obtaining them?
why are these address special that they have to be approved from ISP?
Selected Answer
1st and 3rd IP address are private ip address of class B and class C respectively.
Private IP range:
these can be used by intra-network, ip allocation by your home wifi router to your laptop, mobiles etc (class c, thats why
most of the router admin panel can be accessed at class c address that is 192.168.x.x by default) as a NAT.
2nd and 4th IP does not belong to private IP thus they are with ISP.
digital-logic adder
(Assumption: Nothing mentioned ,so any number of inputs are possible in and gate)
Therefore, for 8 bit no. of and gates required = 1+2+3...+8 = 36 (Hence n*(n+1)/2)
When two BCD numbers 0x14 and 0x08 are added what is the binary representation of the resultant number?
A. 0x22
B. 0x1c
C. 0x16
D. Results in overflow.
0X14=14
0X08=8
number-representation binary-codes
Selected Answer
Examples :
How many of 16 boolean functions in 2 variables x and y can be represented using only the given set of operators, variables x
and y ,and values 0 and 1?
a) { ∼ }
b) { ⋅ }
c) { + }
d) { ⋅ , + }
digital-logic boolean-algebra
f0=0, f1= x.y, f2=x.y', f3= x, f4=x'.y, f5=y, f6=x xor y, f7= x +y, f8=(x+y)' , f9= x xnor y, f10=y',
f11=x+y', f12 = x', f13= x'+y, f14=(x.y)', f15=1
a) {~} = using only NOT , we can get only f0=0, f15=1, f5=y,f6=x,f10=y',f12=x' (6 functions)
b){.} = using AND only f0=0, f1=x.y,f15 =1 , f5=y,f6= x(5 functions){ using idempotentency properties}
a) The only function values we can get are x, y, 0, 1, x', y', Therefore the answer is 6.
b) Since x.x = x, x.1 = x, and x.0 = 0 for all x, the only functions we can get are x, y, 0, 1, and xy.
Therefore the answer is 5.
c) By duality the answer here has to be the same as the answer to part (b), 5.
d) We can get the 6 distinct functions x, y, 0, 1, xy and x+y. Any further applications of these
operations,however, returns us to one of these functions. For example, xy+ y=x
Thanks to pramod!!
10.5 Boolean Algebra: The number of possible boolean functions that can be
defined for n boolean variables over n valued boolean algebra is top gateoverflow.in/32446
digital-logic boolean-algebra
Selected Answer
n
So no of boolean func=22
permutation boolean-algebra
|R|=4
here n=4
Ans 4^16
10.8 Boolean Expressions: How to solve this boolean Exp? top gateoverflow.in/18210
boolean-expressions digital-logic
10.9 Boolean Expressions: Boolean expression from venn diagram top gateoverflow.in/29476
The Boolean Expression for the shaded area in the venn diagram.
¯
ˉ
a. ACW + ABCW
ˉ
b. ABC + ABW
c. (A + B + C)W
ˉ
d. AW + BW + AB
digital-logic boolean-expressions
Selected Answer
F=a-(b+c)+b-(a+c)+c-(a+c)
=> a(b+c)'+b(a+c)'+c(a+b)'
f=(A'B'C +ABC)+(A'BC'+ABC)+(AB'C'+ABC)
=A'B'C +A'BC'+AB'C'+ABC
=A⨁B⨁C
top
(A + B) ⋅ (B + C) ⋅ (C + A)
boolean-expressions
Selected Answer
Given: (A + B) ⋅ (B + C) ⋅ (C + A)
Associative (A + B) ⋅ (B + C)
abc = (ab)c ( )
⋅ (C + A)
Distributive BB
x(y + z) = xy + xz
(AB + AC + + BC) ) ⋅ (C + A)
Idempotent B + BC
xx = x
(AB + AC + )
⋅ (C + A)
Associative, (AB + AC + B) ⋅ (C + A)
Absorption
x + xy = x
AA CC AA
Distributive
ABC + B + A + C + BC + BA
AC
Idempotent ABC + AB
+ AC + AC + BC + BA
Associative, AB BA
Absorption + AC + BC +
Idempotent AB + AC + BC
AB + AC + BC
Given answer: D
Except C I couldn't prove other options as equal.
digital-logic boolean-expressions
Selected Answer
A) Consensus Theorem
B) Consensus Theorem (after applying distributive law)
C) De Morgan's Law
D) Non-sense.
answer = option D
1. is Consensus property.
3. is demorgn law
digital-logic booths-algorithm
Selected Answer
then calculate no. of +1 and -1 's which is total no. of addition/subtraction operation required.
http://gateoverflow.in/3753/gate2005-it_8
10.13 Canonical Normal Form: Kindly have a try .... IN canonical POS form
following equation is written as (ABC)=AB+BC+AC (A)πM(0,1,2,4)
(B)πM(3,5,6,7) (A)πM(0,1,2,3) (A)πM(4,5,6,7) top gateoverflow.in/2824
Kindly have a try .... IN canonical POS form following equation is written as
F(A,B,C)=AB+BC+AC
(A)πM(0,1,2,4)
(B)πM(3,5,6,7)
(C)πM(0,1,2,3)
(D)πM(4,5,6,7)
digital-logic canonical-normal-form
Selected Answer
F(A, B, C) = AB + BC + AC
= ABC ′ + ABC + A ′ BC + AB ′ C
F(A, B, C) = Σm(3, 5, 6, 7)
F ′ (A, B, C) = Σm(0, 1, 2, 4)
F ′ (A, B, C) = m 0 + m 1 + m 2 + m 4
(F ′ ) ′ (A, B, C) = (m 0 + m 1 + m 2 + m 4 ) ′
F(A, B, C) = (M0 M1 M2 M4 )
F(A, B, C) = πM(0, 12, 4) (Complement of a minterm is its corresponding maxterm, for example, m 0 = A ′ B ′ C ′ and
m 0′ = (A ′ B ′ C ′ ) ′ = A + B + C = M0 )
Ref: http://www.cs.uiuc.edu/class/sp08/cs231/lectures/04-Kmap.pdf
First take the function, this is in SOP so find the min terms of the equations
For Finding the MAX TERMS subtract these min terms from whole possible terms with 3 variable which are
{0,1,2,3,4,5,6,7}- {3,5,6,7} = (0,1,2,4)
ans is option A
A will be the answer try to put this value on karnaugh map and remaining will be your answer.
A. A + A'BCD
B. AB + CD
C. A + BCD
D. ABC + D
Selected Answer
Option C
¯
Q).Consider the circuit shown below of 2:1 MUX is given by the function g = ac + bc
combinational circuits
Selected Answer
According to the function g=ac +bc' when c=0 ,data on line b will be selected and if c=1 data on ine a will be
seected .
=(xy' + Ex'y)
note; the g function is given to determine the 0th and 1th line of the mux.
Given answer: A
Please explain
digital-logic circuits
Selected Answer
A should be 1
B&C both cant be 0 therefore using truth table B+C
For D it can be either 0 or 1 therefore D+D'
id D then =0 then P=1 if D=1 P'=1
Doing and operation A.(B+C)(D'P+DP')
10.17 Clock Frequency: Maximum clock frequency for the circuit top gateoverflow.in/36329
In the following digital circuit shown above, the worst case delay is of 30 nsec and the AND gate has delay of 10 nsec. The
maximum clock frequency of the circuit to operate is _ MHz.
1 1
f Clk
So, ≤ 40
Here, we will just add the flip-flop delay once? The solution gives the frequency as 14.2 MHz, adding the delay due to flip-
flop twice. Why?
10.18 Clock Frequency: What is the o/p according to given timing diagram?
top gateoverflow.in/33015
a) A = 0, 1, 0, 0, B = 1, 0, 1, 1
b) A = 1, 0, 1, 1, B = 0, 1, 0, 0
c) A = 1, 1, 0, 0, B = 1, 1, 0, 0
d) A = 0, 1, 0, 0, B = 0, 1, 0, 0
I thought it would be (c) as previous states should persist for 1st clock. But answer given is (a). Can somebody please
explain??
Selected Answer
I know , this is pretty basic question , still could not get it right
¯
I got the answer as B + C
digital-logic combinational
It's easy . just use the k Map in this type of questions. it will take u fast to the simplification. the terms here one are.
0,2,4,6. all lies at the
bc->
a |
00 01 11 10
0 1 1
1 1 1
subcube of 4 will be formed. and will give answer c'. now we are just oring b with it. so answer is b+c'.
How many half adders are required to realize the following 4 functions?
f1 = A ⊕ B ⊕ C
¯ ¯
f2 = ABC + ABC
¯ ¯ ¯
f3 = ABC + (A + B)C
f4 = ABC
combinational
The initial state of a MOD 16 down counter is 0110 . After 37 clock pulses, the state of the counter will be
A. 0001
B. 1011
C. 1101
D. 1010
counter
Selected Answer
I.
II
37 mod 16 = 5.
As it is a down counter, it will be 5 states down from 0110 = 0110 - 0101= 0001.
Please Explain the inverted clock. How is the first Flip flop getting the Clock input?
What Cr(complement) means?
And how to judge MSB LSB
counter
Selected Answer
Cr(compliment) means clear bits on logic zero input, so when A = 1 and B = 1 the flip flops are clear and are reset 000,
as this is a up counter and it is clear on A =1 B =1 , it will be cleared on ABC = 110 which is 6 so it is mod 6 counter.
10.23 Counter: If the initial stage of mod-11 counter is 0110, then what will
be the counting sequence for next 24 clock pulses? top gateoverflow.in/17409
If the initial stage of mod-11 counter is 0110, then what will be the counting sequence for next 24 clock pulses?
What will be counting sequence for the next 17 clock pulses if the counter is mod-16 down counter and the initial value is
1110?
counter
Selected Answer
(1) ANS-1000
1->2->3->..................10->1
WHEN START FROM 0110 AFTER 22 CLOCK IT REACH AT THAT STATE THEN I HV REMAINING 2 CLOCK
THEN FORWARD TWO STATE THEN WE GET 1000.
(2) ANS-1101
Selected Answer
It is an asynchronous counter.
then
A B C
1 0 1
this is old 1 Change to 1 Change to 0
Actually 110 is not result in states, and counter get cleared (with new B as 1, and Old A as 1).
We get states as 0, 1, 2, 3, 4, 5, 0, 1, . . . .
MOD6 Counter.
Selected Answer
125..
cascading two modulo M and modulo N counter gives modulo M*N counter..
flip-flop counter
Selected Answer
00 − 10 − 11 − 01 − 00
Q2 Q1 Q 2+ Q 1+
0 0 1 0
0 1 0 0
1 0 1 1
1 1 0 1
Now we have present state and next state, use excitation table of T flip-flop
Q2 Q1 Q 2+ Q 1+ T2 T1
0 0 1 0 1 0
0 1 0 0 0 1
1 0 1 1 0 1
1 1 0 1 1 0
G 1 = T1 = Q 2 ⊕ Q 1
G 2 = T2 = Q 2 ⊙ Q 1
1. So for constructing mod 8 counter we need minimum of states 4(we have to count only 8 not by shifting so i decided to
use 4 states rather 8),
to represent 2 state - 1 ff needed so for representing 4 states(mod 8 counter) - 2 ff needed .....whether using 2ff can we
construct mod 8 counter?
2. I tried by constructing states representing 0 as 00 ; 1,3,5,7 as 01; 2,6 as 10 and 4 as 11 (see diag below) and I
constructed the mod 8 counter using present state and next state (i took this as random not inorder but according to diag),
making last transition as 11 to 00; remaining can be anything ,though we have 2 variable and 8 transitions so I used normal
algebraic reduction for constructing combi.circuit.... whether my approach is correct ?refer diag 2
counter finite-automata
actually counter and num mod 8 dfa is 2 different thing. mod 8 counter is a ckt which generate a sequence of 8 different
state without taking any input wherease dfa goes to next state by consuming input . mod 8 counter needs only 3 states so
3 fflops. ur method doesnt seems correct . check it https://www.cs.tau.ac.il/~nin/Courses/mivne98/counters/
A. xy + zx ′
B. xy + zx ′ + wyz
C. xy + zx ′ + yz
D. xy + zx ′ + wz
Selected Answer
Hazard occurred because a variable and its complement passed through different number of logic operations.
In other words, if a variable and its complement are present in different product terms, may cause Hazards.
A 3 line to 8 line Decoder is used to implement a 3-variable Boolean function as shown in figure.
ˉ ˉ ˉ
A. XY + YZ + XYZ
ˉ ˉ
B. XZ + YZ + XYZ
ˉ ˉ ˉ
C. XY + XZ + XYZ
ˉY ˉ ˉ ˉ
D. X + XZ + XYZ
ZYX ....
NOW TAKE 0's outside and it will be NAND GATE now it says when enteries are either (1,3,5,6) we get 1
so fill 1 at those places and it will turn out to be Z'Y'X+Z'YX+ZY'X+ZYX' THAT MATCHES WITH c
10.30 Demux: Why are demux not universal combinational circuit? top gateoverflow.in/38112
It contains a NOT and an AND. Then, why is it not universal? Using demorgans law can't we get OR?
Demux is not a universal gate as it has only 1 input line, hence boolean expression can be implemented.
10.31 Digital: The boolean expression f(x,y,z) in its canonical form for the
decoder circuit shown below is top gateoverflow.in/35123
digital digital-logic
The decoder will be enable only when z is 0, it means at minterms 1, 3, 5, and 7 we will get all Decoder outputs as 0, so F
will be 0 at minterms 1, 3, 5 and 7, we need to check Function F only at minterms 0, 2, 4 and 6.
10.32 Digital: A digital circuit which compares two numbers A2A1A0 and
B2B1B0 is shown in figure top gateoverflow.in/35122
digital-logic digital
Selected Answer
¯
(A2 ⊕ B2 ) ⊕ (A1 ⊕ B1 ) ⊕ (A0 ⊕ B0 ) = (A ⊕ B ) ⊙ (A ⊕ B ) ⊕ (A ⊕ B ) = (A ⊕ B ) ⊕ (A ⊕ B ) ⊙ (A ⊕ B )
2 2 1 1 0 0 2 2 1 1 0 0
a) ((0 ⊕ 1) ⊕ (1 ⊕ 1)) ⊙ (0 ⊕ 1) = 1 ⊙ 1 = 1
b) ((0 ⊕ 1) ⊕ (1 ⊕ 0)) ⊙ (0 ⊕ 1) = 0 ⊙ 1 = 0
c) ((1 ⊕ 1) ⊕ (0 ⊕ 1)) ⊙ (1 ⊕ 0) = 1 ⊙ 1 = 1
d)((1 ⊕ 0) ⊕ (0 ⊕ 1)) ⊙ (1 ⊕ 1) = 0 ⊙ 0 = 1
Another way,
Xor gives 1 when having odd no's of 1 ′ s in input, otherwise 0. so take the complement of that result of xor, will get 1 for
option a,c,d and 0 for option b.
Firstly EXNOR gate gives Output as 1 When all the inputs are 0's or all the inputs are 1's
If you observe in option 2 when u do xor with corresponding bits all are 1's
10.33 Dual Function: Computing the dual of the boolean function top gateoverflow.in/36297
Suppose, f(A, B, C, D) = ∑ m(0, 2, 4, 6) is a boolean expression, expressed in minterm form. How can I calculate and express the
dual of the function?
I have tried the method using the exact definition, but it turns out to be very cumbersome and prone to errors. Any other
method?
Selected Answer
f(A, B, C, D) = Σm(0, 2, 4, 6)
f(A, B, C, D) = A ′ B ′ C ′ D ′ + A ′ B ′ CD ′ + A ′ BC ′ D ′ + A ′ BCD ′
Dual of f,
fd (A, B, C, D) = (A ′ + B ′ + C ′ + D ′ ). (A ′ + B ′ + C + D ′ ). (A ′ + B + C ′ + D ′ ). (A ′ + B + C + D ′ )
That's it.
Note:
In Complement of f, that is f ′ , we need to replace all variable, say x , by it complement variables , say x ′ , also.
Selected Answer
EX-OR, A ⊕ B = A ′ B + AB ′
[Note :
In Dual, Replace AND with OR , OR with AND and replace 1's by 0's and 0's by 1's
In complement, In addition to above, we also replace Binary variables by its complement's, mean x by x' or x' by x.
In case of EX-OR , dual of EX-OR is same as its complement, but for different expression, it may differ. ]
= ((A'B)' . (B'A))'
=(A+B')(B+A')
answer = option D
its the Law of Duality which is applied on the entire equation/formula not on just an expression.
for more info check : http://math.stackexchange.com/questions/408409/duality-principle-in-boolean-algebra
digital-logic flip-flop
Selected Answer
J1 = Q 0 , K1 = Q 0′ , Q 1+ = J1 Q 1′ + K1′ Q 1 = Q 0 Q 1′ + Q 0 Q 1 = Q 0
J0 = Q 1′ , K0 = Q 1 , Q 0+ = J0 Q 0′ + K0′ Q 0 = Q 1′ Q 0′ + Q 1′ Q 0 = Q 1′
Q 1+ Q 0+
Initially 0 0
CP-1 0 1
CP-2 1 1
CP-3 1 0
CP-4 0 0
it is a mod 4 counter, after every 4th clock pulse, it will return to initial.
333mod4 = 1 , so after 332 clock pulse it will return to 00 and on 333rd it will reach to 01.
In a three stage counter, using RS flip flops what will be the value of the counter after giving 9 pulses to its input? Assume
that the value of counter before giving any pulses is 1.
A. 1
B. 2
C. 9
D. 10
Selected Answer
3 stage counter with RS FF is 3 bit counter, so after every 8 clock pulse, it will return to initial state.
Initial state is 1, state after 8 clock pulse will be 1, So, after 9th clock pulse , state will be 2.
10.37 Flip Flop: What happens when the input of a flip flop changes exactly
at the time of the clock pulse transition? top gateoverflow.in/17717
flip-flop digital-logic
It depends upon implementation . say if its a D Flip flop then it will change the output (if 0 then 1 like that ), if J K then it
may change or not ,
say both of J and K are attached to input . then input 1010101 , then for 0 (j=0 k= 0)it will not change the state .
10.38 Flip Flop: Design a counter for the following binary sequence:
0,4,5,3,1,6,2,7 and repeat.Use JK flip-flops | IIIT-Hyderbad top gateoverflow.in/42222
Design a counter for the following binary sequence: 0,4,5,3,1,6,2,7 and repeat.Use JK flip-flops
digital-logic flip-flop
Selected Answer
Please see the solution in the image below. putting image because lot of editing required.
10.39 Flip Flop: When a JK flip flop is constructed from an SR flip flop gateoverflow.in/32443
top
a) S = JQ, R = K+JQ
b) J = S, K = R
c) J = SR'Q, K = S'(R+Q)
d) S = JQ', R = KQ
flip-flop digital-logic
D) S=JQ', R=KQ
To eliminate racing condition when S=1 & R=1, we connect S=JQ' & R=KQ
they say the exponent can't be all ones so if can't be all ones then how the exponent - bias came to be 127. the maximum
exponent should be 254 and it should be 126. and why we use -126 while finding denormalized number.
digital-logic floating-point-representation
Selected Answer
Denormalized numbers are for filling the gap between 0 and the smallest positive number in normalized representation.
This link should be good.
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
functional-completeness
A set of Boolean function is called functionally complete, if all other Boolean functions can be constructed from this set.
As, from this set we can derive NOR,NAND,XOR, XNOR,etc any type of function.
A set is said to functionally complete if we can derive a set witch is already functionally complete. Eg. of functionally
complete set {AND ,OR,NOT}, {OR,NOT},{AND,NOT} So to prove a boolean functionally complete derive any one of the
above.
Any set of Boolean operators that is sufficient to represent all Boolean expressions is said to be complete. Which of the
following is not complete?
A. {NOT, OR}
B. {NOR}
C. {AND, OR}
D. {AND, NOT}
isro2013 functional-completeness
Selected Answer
NAND AND NOR are universal gate and with the help of these gates we can implement any other function. Hence they are
called functionally complete
option a)
http://www.chaloma.be/birkenstock-sandales-femmes-c-51.html Pas besoin de porter le kilt pour être en Scottish... Composition : dessus coton 100% -
intérieur laine 100% - semelle feutre avec patin caoutchouc anti-dérapant. La charentaise est un chausson chaud, confortable et léger. Livrée avec une trousse cadeau. ATTENTION CHAUSSE
PETIT : nous vous conseillons de prendre une pointure au-dessus. 2 articles ou...
functional-dependencies
What is this ? It is not a sales website you should go somewhere else to sale your Sandales. And it is not a functional
dependencies Question.nor DLD.
I read somewhere that gray code is self-complementing but I couldn't find any explanation for that. Please tell if anyone has
some idea about it.
digital-logic gray-code
Selected Answer
It's not self complementing because as per definition of Self Complementing "9 complement of number and 1's
complement of digits must be same"
0001 -> 0001(Gray Code) I's complement :1110 9's complement (9-1 = 8):: 1000 so it's not same
digital-logic gray-code
Selected Answer
The decimal equivalents of 01440000 a 32- bit hexadecimal representation of IEEE single-precision floating point number is
a. 1.11 × 2 −125
b. 1.88 × 2 −125
c. 1.68 × 2 −124
d. 1.88 × 2 −129
floating-point-representation ieee-representation
Selected Answer
01440000
1.53125 * 2^-125
In the standard IEEE 754 single precision floating point representation, there is 1 bit for sign,23 bits for fraction and 8 bits
for exponent .what is the precision in terms of the number of decimal digits?
a) 5 b) 6 c)7 d) 8
number-representation ieee-representation
1.2 × 108 - precision is just 2 and rest we have 8 zeroes which might not be accurate.
So, in IEEE 754 floating point representation we have 23 precision bits and we also have one implied bit before '.' making
it 24 precision bits. With 24 bits we can represent 24log2 = 7 decimal digits.
Given explanation.
digital-logic k-map
Minimal Type
10.48 K Map: Let f(x,y,z) = x' + y'x + xz be a switching function. Which one
of the following is valid? top gateoverflow.in/6650
A. y ′ x is a prime implicant of f
B. xz is a minterm of f
C. xz is an implicant of f
D. y is a prime implicant of f
digital-logic k-map
Selected Answer
xz is an implicant and ¬y is both prime and essential prime implicant. The sop would be z + ¬x + ¬y.
Ref: https://en.wikipedia.org/wiki/Implicant
How to comprehend this k-map? Usually we have 00,01,10,11 terms in K-map. But what does those (C+D) terms signify
k-map digital-logic
answer is (B+D)
They have taken 1 extra combination which is already a subset of 2 other combos. Is it because that they have asked ALL
POSSIBLE k-maps??? Is it right?
No it is 14 only..
1 Quad and 3 Pair.
a . (abc)' + bc + ac = c
c . ab + a'c + bc = ab +ac
d . ab + ac' = b
digital logic
Selected Answer
a)(abc)'+bc+ac=a'+b'+c'+bc +ac
=a'+ac+b'+c+bc
= a'+c+b'+c'+b
=a'+1
=1
so a is incorrect
b)(a+b)(a'(b'+c'))'+b'c'+a'c'=(a+b)(a+bc)+b'c'+a'c'
=a+abc+ab+bc+b'c'+a'c'
=a(1+bc+b)+bc+b'c'+a'c'
=a+bc+b'c'+a'c'
≠1
so b is incorrect
d)ab+ac'!=b
what is the maximum counting speed of 4-bit binary counter which is composed of flip-flops with a propagation delay of
25ns?
digital logic
i think it will be 25 ns because it is given , the maximum speed, which can be attained by sychronous counter only.
The number of two input multiplexers required to construct a 210 input multiplexer is,
A. 31
B. 10
C. 127
D. 1023
Selected Answer
2 10
multiplexer
we have a 8*1 Mux and a 4 variable boolean function(say w,x,y,z) .So , to implement a 4 variable boolean
function by using a 8*1 mux
1.>we need to apply any three of the input to the three selection line of mux which can be done in 24 ways.
(The first selection line s 0 can be w or x or y or z and in the same way s1 has 3 possibilty ,s2 has 2 possibilty
so,for each possible combination out of those 24 combination we will get a completly different ckt but the
functionality of all thesr ckt will be same.
multiplexer
digital-logic multiplexer
Selected Answer
F = A ′ B ′ I0 + A ′ BI1 + AB ′ I2 + ABI3
F(A, B, C) = Σm(1, 3, 4, 6)
Consider the Boolean function f(A, B, C, D) = Π(1, 2, 4, 5, 6, 8, 10). Determine the minimum number of NOR gates required to
implement the function f. Assume both primed and unprimed variables are available.
digital-logic nand-nor
C′D ′ C′D CD CD ′
A′B′ 0 0 0
A′B 0 0 0
AB
AB ′ 0 0
F = (A + C)(A + D)(B + D)
F = (A + CD)(B + D)
¯
¯ ¯
(A + CD) + (B + D)
F=
¯
¯
¯
¯
′ ′
(A + C + D ) + (B + D)
F=
i am getting ABD'+ACD'.
A(B+C)D'(P+P')
A. 4
B. 5
C. 6
D. 8
isro2013 number-representation
Selected Answer
Answer 5
(1102)3=1⨉33+1⨉32+2=38
(123)x=1⨉x2+2x+3
x=5
Two eight bit bytes 11000011 and 01001100 are added. What are the values of the overflow, carry and zero flags respectively, if
the arithmetic unit of the CPU uses 2's complement form?
A. 0, 1, 1 ′
B. 1, 1, 0
C. 1, 0, 1
D. 0, 1, 0
Selected Answer
I think it is D
11000011
01001100
The zero flag will be set if result is 0 . but here the result is not 0 so zero flag is set to 0
where Carry out is carry from MSB (bit 8 ) // taking byte as from bit1 to bit 8
So carry out = 1
carry in 1
So option d
number-representation
d>n log10 2
25=n*.3010
n=83 Apx
A. OR gate
B. AND gate
C. NAND gate
D. XOR gate
isro2013 number-representation
Selected Answer
One way to detect it is to XOR the carry in and the carry out.
1. If the sum of two positive numbers yields a negative result, the sum has overflowed.
2. If the sum of two negative numbers yields a positive result, the sum has overflowed.
3. Otherwise, the sum has not overflowed.
It is important to note the overflow and carry out can each occur without the other. In unsigned numbers, carry out is
equivalent to overflow. In two's complement, carry out tells you nothing about overflow.
The reason for the rules is that overflow in two's complement occurs, not when a bit is carried out out of the left column, but
when one is carried into it. That is, when there is a carry into the sign. The rules detect this error by examining the sign of the
result. A negative and positive added together cannot overflow, because the sum is between the addends. Since both of the
addends fit within the allowable range of numbers, and their sum is between them, it must fit as well.
Given
number-representation
Selected Answer
here is my solution
SHORTCUT:
Just take last digit of each term and compare, 5+4=9, but it is coming as 3, so divide it by such a number so that
remainder will remain 3. so, 6 is the answer.
If we use diminished radix representation then representation for 0 will be b^n-1 where b is the base so this representation
is for 0 , how come we are associating +0 and -0 for this ?
Normally also we have representation for 0 , so again this b^n-1 is a representation for 0 so why to associate sign to it ?
number-representation
Selected Answer
lets take example for all the cases. signed , unsigned , 1;s and 2's . i think they generated the system by dividing all the
numbers into half,. But they even willingly can't represent +0 and -0 see this
10 -10 +0 -0
unsigned 1010 n/a 0000 n/a
signed 01010 11010 00000 10000
1's 01010 10101 00000 11111
2's 01010 10110 00000 00000
everything other than zero has different form except zero . so even though they thought of following the same convention
it could not be followed.
Please provide codes for 0-9 decimal using 4311 code..i am little bit confused in it..I know the property that addition 9
makes it self complemetory..but how m nt understanding..plz help..
number-representation
Selected Answer
n 4311
0 0000
1 0001
2 0011
3 0100
4 0101
5 1010
6 1011
7 1100
8 1110
9 1111
1). There is property, of self complementing code, that,code of 9 ′ s of a decimal number is obtained directly by changing
0 ′ s to 1 ′ s and 1 ′ s to 0 ′ s
example: 9 ′ s complement of 2 is 7, change 0 ′ s to 1 ′ s and 1 ′ s to 0 ′ s in 4311 code of 2 , we will get 1100, that is 4311 code of 7
2). Interesting thing I found that sum of weights of self-complementing weighted code makes a total of 9, i.e,
4 + 3 + 1 + 1 = 9, checked with other self-complementing codes as 2421, 84 − 2 − 1, 5211, and 642 − 3.
number-representation
number-representation
Selected Answer
(34C)16 =(1514)8
two 2's complement nos. having sign bits x and y are added and the sign bit of result is z. Then the occurrence of overflow is
indicated by the expression???
So, here Cn is 'z' and C(n-1) is x+y . Whose XORing gives me.. x'y'z + xz' + yz'.
How many programmable fuses are required in a PLA which takes 16 inputs and gives 8 outputs? It has to use 8 OR gates
and 32 AND gates.
A. 1032
B. 776
C. 1284
D. 1536
radix
Selected Answer
r3=3
self dual-function
Option d is right .
10.72 Sequential: what is 9 clock cycles what are output at q0 q1 q2? gateoverflow.in/16030
top
Selected Answer
Starting 000
10.73 Sequential: A switch tail ring counter is made by using a single D FF. top
gateoverflow.in/32444
A switch-tail ring counter is made by using a single D FF. The resulting circuit is
Answer is d.
https://www.youtube.com/watch?v=NgHdSqy1YKw
10.74 Sequential: Which of the following circuit is called Latch top gateoverflow.in/32442
made-easy sequential
sequential digital-logic
If all the flip flops are initially cleared then the count after 115 clock pulses ( Q 2Q 1Q 0) is ________.
Selected Answer
J0 = 1, K0 = Q 2 , Q 0+ = Q 0′ + Q 2′ = (Q 0 Q 2 ) ′
J1 = Q 0 ⊙ Q 2′ , K1 = 1, Q 1+ = (Q 0 ⊕ Q 2 )Q 1′
J2 = Q 1 , K2 = 1, Q 2+ = Q 1 Q 2′
Clock Pulse Q 2 Q 1 Q 0
Initially 000
1 001
2 011
3 101
4 000
So This is a mod- 4 counter, and it reach to initial state after every 4 clock pulses.
115mod4 = 3, it means it will reach to initial states after 112 clock pulses. so at Clock pulse 115 it will be move 3 up in
sequence and reach to state 101
0->1->3->5->0
now 115%4 =3
you get to 5.
A sequential circuit with two D flip-flops A and B, two inputs x and y, and one output z is specified by the following next-state
and output equations :
A(t + 1) = x ′ y + xB
B(t + 1) = x ′ A + xB
z=A
digital-logic sequential
Q 3+ = Q 2
Q 2+ = Q 1
Q 1+ = Q 0
Q 0+ = D
D = (Q 3 ⊙ Q 2 ) ⊙ Q 0
Q0 Q1 Q2 Q3 D
initially 0 0 0 1 1
CP-1st 1 0 0 0 1
CP-2nd 1 1 0 0 1
CP-3rd 1 1 1 0 0
CP-4th 0 1 1 1 0
CP-5th 0 0 1 1 0
CP-6th 0 0 0 1 −
decimal number are represented in sign magnitude form +9286 and +801 convert them to signed 10s complement and
perform following operations( 1 digit required for sign)
1)-9286+ (+801)
2)-9286+(-801)
1)-9286+ (+801)=
-9286=100000-9286= 90714
100000-91515=-8485
2)-9286+(-801)
-9286=90714
-801=99199
90714+99199=89913
100000-89913=-10087
BCD
2421 code
6311 code
Selected Answer
BCD conversation :- Convert each digit into groups of four binary digits equivalent.
Add +3 in each digit then convert into groups of four binary digit equivalent.
2421 CODE :- Represent each decimal digit in binary with respect to weight 2 4 2 1.
6311 CODE :- Represent each decimal digit in binary with respect to weight 6 3 1 1.
2-4-2-1 0110 0010 0100 1110 (This is not unique since the representation in 2-4-2-1 varies) Each digit is
represented as the summation like 6 is obtained 4+2 , so bit position 4,2 is made 1 in the first digit )
6-3-1-1 1000 0011 0110 1011 (This representation is also not unique and is one of the representations.
digital-logic
Selected Answer
Possibilities
001,,,,,,010,,,,100....111
001-> A2 B2=(00,11) ,A1 B1=(00,11) ,A0B0=(10,01).....means we have 2x2x2 = 8 ways ...similarly for all ..
TOTAL 4x8=32
All the logic gates in the circuit shown below have finite propagation delay. The circuit can be used as a clock generator, if
a) X = 0
b) X = 1
c) X = 0 or 1
d) X = Y
Selected Answer
so , At x = 1 , the above circuit will generate the sequence of 0,1,0,1.. , can be used as clock generator.
A JK flip flop has propagation delay of 13ns. what is the largest MOD ripple counter that can be constructed using such flip
flop and can be operated upto 10MHZ?
1.MOD - 32
2 MOD - 64
3 MOD - 128
4 MOD - 256
Selected Answer
For ripple counter T(clock) >= N*(propagation delay of FF) // N is no of FF as the output from the final flipflop comes only
after propagation delay of all n FFs.
Ref: http://mti.kvk.uni-obuda.hu/adat/tananyag/digit2/angolkepzes/dt_2_lecture04w.pdf
In figure, initially Q = A = B = 0. After three clock triggers, the states of Q, A and B will be respectively is ___________.
Selected Answer
Q goes 0 to 1 ,
work as positive edge
Clock pulse 1 Old Q =0 New Q = 1 trigger to Counter old AB = 00 New AB = 01
clock,
Counter goes UP
Q goes 1 to 0 ,
work as negative edge
Clock Pulse 2 Old Q =1 New Q =0 trigger to Counter old AB = 01 New AB = 01
clock,
No change at Counter
Q goes 0 to 1 ,
work as positive edge
Clock Pulse 3 Old Q =0 New Q = 1 trigger to Counter old AB = 01 New AB = 10
clock,
Counter goes UP
digital-logic
In 2’s complement the significant information is contained in the 1’s of positive numbers and 0’s of the negative numbers.
Integer
2's Complement
Signed Unsigned
5 5 0000 0101
4 4 0000 0100
3 3 0000 0011
2 2 0000 0010
1 1 0000 0001
0 0 0000 0000
The most significant (leftmost) bit indicates the sign of the integer; therefore it is sometimes called the sign bit.
10.89 ugc net dec 2012 paper 2 code 87 computer science & application top
gateoverflow.in/11695
http://ugcnetonline.in/question_papers_december2012.php
The answer is A . C can`t be 0 so option(c) is canceled and if you put option (b) values then Y= 0 (i think 'f' is Y here ). So
(b) is canceled . Remaining A and D both satisfied the circuit (Y =1 ) but if you see they say the "STEADY state" , so
before turning on the circuit the value of Y (f) may be 0 , now
option (d) then A(1) nand 0(f) = 1 ------> B(1) nand 1 = 0 -----> C(1) and 0 = 0 (f)
option (a) then A(0) nand 0(f) = 1 ------> B(0) nand 1 = 1 -----> C(1) and 1 = 1 (f) satisfied the circuit .
In a K-Map , it was found that essential prime implicants are covering all terms except 2 minterms . Those 2 minterms are in
turn covered by 3 non-essential prime implicants each , so how to approach for calculating no of minimal SOP's ?
Given explanation:
I always fail to solve such questions. Please tell what is the approach to solve such problems?
digital-logic
sorry i hav not equipment to drow this so to cover green color 1 there are two only possible way to group these green 1's
so EPI are
(a)B'D'
(b)AC'D'
SO ONLY 2 EPI
10.94 Calculating number of NAND gates required for building a circuit gateoverflow.in/36802
top
I want to know is there any standard way to find out number of NAND
digital-logic
My Answer is
In Question they have asked to find no. of nand gates so get sop form of that function and have nand gates at last nand gate replace it with or gate representation of nand gate
If No. of Nor gates are asked then get pos form of function and have all nor gates replace last nor gate with and representation of nor gate
10.95 The digital operations such as AND, OR, NOT can be performed by
using top gateoverflow.in/3321
The digital operations such as AND, OR, NOT can be performed by using
A)switches
B)amplifiers
C)rectifiers
D)oscillators
digital-logic
Selected Answer
A collection of logical operators is called functionally complete if every compound proposition is logically equivalent to a
compound proposition involving only these logical operators.
So here option A is correct. NOT & OR form a functionally complete collection of logical operators.
Selected Answer
The number of AND gates are present inside a 5-bit carry look ahead generator circuit are ______.
f=A'B'C+A'B'C'
Assume that inputs are available only in true and boolean constants 1
and 0 are available.
this f = a'b'c +a'b'c =a'b' =(a+b)' which is NOR of a and b and to implement a NOR gate two 2:1 multiplexers are
required. Therefore answer is 2.
so three 2:1 mux required to implement this function ( if you use 2:1 MUX only)
and if we use a not gate then this function can be implemented by only one 2:1 MUX .
Answer is B )
A binary counter is being pulsed by a 256 KHz clock signal.The output frequency from the MSB flip-flop is 2 KHz. The MOD
number is _______ .
Selected Answer
f out
fout = N
256
2= N
N = 128
10.102 how many flip flops are required to design modulo-272 counter A.8
B.9 C.27 D.11 top gateoverflow.in/12684
THE
digital-logic
Selected Answer
(b) option
10.103 what is the ans of this question? how to slove it? top gateoverflow.in/34780
Caption
So
If initially ABC = 000 then after how many clock pulses the circuit will reach its initial stage?
a) 5
b) 6
c) 7
d) 8
Selected Answer
JC = B, KC = B ′ , So C + = JCC ′ + KC′ C = BC ′ + BC = B
So,A + = C ′ , B + = A, and C + = B
000
100
110
111
011
001
000
Note:
′
1. Characterstic equation of JK FF , Qt+1 = JQt + K ′ Qt and of D FF, Qt+1 = D
2. It is a Johnson counter , having n flip-flops or (n-bit Johnson counter), and having 2n states.
(√41)B =(5)10
The value of ‘B ’ is _____.
Selected Answer
(√41)b = (5)10
now(41)b means
therefore 4b+1 = 25
then b = 6 .
An application uses UDP to send 7300 bytes of data in a single message on a path with MTU 1500 and there is an error in one of the datagrams transmitted. The
application is a reliable one and so retransmits the data again. If the same application is written to use TCP instead of UDP and there is an error in one of the
datagrams transmitted, what is the difference in bytes retransmitted using UDP as compared to TCP
computer-networks
Difference =5800
Since Udp is being used there is no reciever window and buffer that will store out of order datagrams and since its given
that the application is relaible it retransmits the whole message again.
Now Tcp has got buffer at reciving window that stores out of order segemants.
Assuming a datagram of 1500 bytes (MTU) is having error,the rest will be stored and ack will be generated for this missing
segement.Thus only this 1 would be retransmitted by the sender (after RTO or recieving 3 consective Ack's)
Selected Answer
XYZ ABC
000 010
001 011
010 100
011 101
100 010
101 011
110 100
111 101
A = Y, B = Y', C = Z
digital-logic
Selected Answer
now i got OR as well as NOT gate from GATE3, i will make all GATE by using OR + NOT GATE..
digital-logic test-series
refer this
http://cse10-iitkgp.virtual-labs.ac.in/cla_design.html
according to this for a 4 bit adder there has to be 2*4=8 gate levels. i.e. 2 per adder (AND and OR) and total 4 adders in
a 4 bit adder.
10.111 Total propagation delay in Carry look ahead adderIn a 4-b top gateoverflow.in/35865
In a 4-bit carry look ahead adder, the propagation delay of Ex-OR gate is 20ns ,AND and OR gates is 10 ns.The sum and
carry output of full adder takes 20ns and 10ns respectively.The total propagation delay of the above adder in ns is
__________
digital-logic test-series
20ns for Ex-OR GATE + 10ns For Internal NAND GATE + 10ns For next level OR GATE + 20ns for External Ex_OR GATE.
Total : 20ns + 10ns + 10ns + 20ns = 60ns
a)Unique
b)Not Unique
c)Depend on Mapping
d)Can't say
Selected Answer
The number of Clock pulses needed to change the contents of an 8-bit-up-counter from (10101011) to (00111010) is
______________
digital-logic made-easy
Selected Answer
A dual - slope analog to digital converter uses a N- bit counter,when input signal Va is being integrated ,the counter is
allowed to count up to a value
a) 2^N -2
b)2^N-1
c) Proportional to Va
d)inversely proportional to Va
digital-logic test-series
digital-logic
Selected Answer
¯
′ ′
NAND with invert input = OR as A B = A + B
So
P(x, y, z) = Σ(1, 2, 4, 7)
= x ′ y ′ z + x ′ yz ′ + xy ′ z ′ + xyz
= x ′ (y ′ z + yz ′ ) + x(y ′ z ′ + yz)
= x ′ (y ⊕ z) + x(y ⊕ z) ′
= x⊕y⊕z
Q(x, y, z) = Σ(3, 5, 6, 7)
= x ′ yz + xy ′ z + xyz ′ + xyz
= yz + xz + xy
Note:
After getting P(x, y, z) = Σ(1, 2, 4, 7) and Q(x, y, z) = Σ(3, 5, 6, 7), it must be clear, they are SUM and CARRY output of Full Adder.
My Answer is
Z = f(A,B,C) = + B + AB + AC
Selected Answer
A'B'C' : 000
ABC' : 110
= min { 0, 2, 3, 5, 6, 7}
0 1 3 2
4 5 7 6
B + AC + A'C'
10.117 Derive the time complexity of the carry lookahead adder. top gateoverflow.in/42416
time-complexity
digital-logic
take 2s complement of 101 1100 1110.101 which is 010 0011 0001. 011
add it to 1100 0000 0001 0010.0010 0101.
digital-logic
digital-logic
Selected Answer
Consider a state 100 representing 001 as Q2 is the rightmost in figure. The FFs are triggered on rising edge (0-1).
Ignoring the flip flop delays as it is asynchronous counter,
sir , plzz check it in above explanation i hav done this question for negative edge triggering so it will give up counter but if
i will do it by positive edge triggering then we will get down counter
So how we convert Binary no. to BCD :- just ADD 0110 into Binary Number
So 1100+0110= 10010 (make pair of 4 from right So 0001 0010 which is 12)
0001 1011.1100
+
0000 0110.0110
=
0010 0010.0010
now make pair of 4 and we see
22.2
So ans is B
A decimal parallel adder that add n decimal digits needs how many BCD adder stages
1. n
2. 2n
3. 1
4 n^2
I want to know how the bit pattern 00, 01 ,10,11 may be obtained using a counter (2 JK flip flops, synchronous).
next
clock J K
state
old
0 dc dc
value
old
1 0 0
value
1 0 1 0
1 1 0 1
1 1 1 toggle
DESIRED OUTPUT IS : 00 01 10 11
= (xy)' .z + (xy)' .w
We can tie the inputs 'x' and 'y' to 1 s t NAND gate to implement the function (xy)' and the output of this gate can be
connected to the inputs of the 2nd and 3 rd NAND gate.The other remaining input of the 2nd and 3 rd NAND gate will be 'w' and 'z'.The
output of 2nd and 3 rd NAND gate will than be connected to the inputs of the 4 th NAND gate.
digital-logic
A prime implicant is one which is power of 2 in size . say if you have prime implicant of size 2^2 = (4) then each element
would be adjacent to 2 elements
Option a
In K-map it was found out that essential prime implicants are covering all terms except 2 minterms.
Those 2 minterms are in turn covered by 3 non-essential prime implicants each.
What is the number of minimal Sum of product expression?.
digital-logic
First things we are going to add essential prime implicants in every min SOP + Extra min terms we have to add
Here extra min term which is required is 2 .So we have to cover those 2 min terms using extra terms .In order to cover each min terms they are saying that we
have 3 choices because they are saying that 2 minterms are in turn covered by 3 non-essential prime implicants each.
So
essential prime implicants +____+____ Here for each Blank we have 3 choices so 3*3 =9
10.125 Can you please explain how there will be 2n-1 gates will be required ?
top gateoverflow.in/8913
See here:
http://deploy.virtual-labs.ac.in/labs/cse13/array_multiplier/Experiment.php?tid=T006&code=C001
digital-logic
When UP/DOWN' input is 1, counter counts up and otherwise the counter counts down. So, for the negative edge of the
clock, the counting sequence will be
1 2 1 2 3 2 3 4 3 ...
The second clock produces 2, and after wards for every consecutive 3 pulses, we get an increment. So, we get 16 for clock
pulse number
2 + 3(16 − 2) = 44.
10.127 No. of P.I, ESPI,Redundant P.I, Minimal SOP, Minimal Expressions. top
gateoverflow.in/44028
For the given function f(A,B,C,D)=∑ (0, 4, 5, 10, 11, 13, 15) , find the following?
1) How many Prime Implicants are there?
2) How many Essential Prime Implicants are there?
3)How many Redundant Prime Implicants are there?
4) What is Minimal SOP?
5) How many minimal expressions are there?
digital-logic
digital-logic
Selected Answer
J K Qt+1
0 0 Qt
0 1 0
1 0 1
¯
1 1 Qt
digital-logic
Selected Answer
digital-logic
Selected Answer
D = X' Z + Y Z' which an be compared with eq D = J Q' + K' Q hence option D is correct
Selected Answer
My answer :- RS 60 :)
digital-logic
¯
¯ ¯
1.Q3. Q2.Q3
Y= ( )
=Q3+Q2Q3
10.132 The three outputs x1x2x3 from a 8 x3 priority enxoder top gateoverflow.in/43813
Output Q0
Output Q1
Output Q2
Then the final Boolean expression for the priority encoder including the zero inputs is defined as:
In practice these zero inputs would be ignored allowing the implementation of the final Boolean expression for the outputs of the 8-to-3 priority encoder. We can constructed a
simple encoder from the expression above using individual OR gates as follows.
A combinational circuit is to be designed to implement a boolean Function with 3 Boolean Variables which gives output 1 if all
the inputs have same value, otherwise give 0 . If only basic gate (AND,OR,NOT) are available and if complimneted variable
is not available , then determine the minimum no of gates to design the circuit ?
1) 3
2) 4
3) 5
4) 6
And is C
digital-logic
ae+ad(c+1)+bd
ae+ad+bd
X = A'B+A'B'C'
= A'(B+B'C')
=A'(B+B')(B+C')
10.137 The state transistion diagram for the logic circuit is ? top gateoverflow.in/9579
gate2012-ec
Hence D choice.
If we take a n bit register to store result of addition/subtraction of two n bit unsigned binary numbers , then if the end-carry
occurs , then the end-carry is the part of the result . Is it overflow or not ?
If we take a n bit register to store result of addition/subtraction two n bit signed binary numbers , then if the end-carry
occurs ,then it is the sign-bit of the result . Is it overflow or not ?
digital-logic
Selected Answer
"If we take a n bit register to store result of addition/subtraction of two n bit unsigned binary numbers , then if the end-carry occurs , then the end-carry is the part
of the result . Is it overflow or not ?"
It is indeed overflow. But overflow means nothing for unsigned operations. It is meant only for signed operations. If the carry happens out of the most significant
bit position, then result is wrong and this is denoted by CARRY flag for unsigned numbers.
"If we take a n bit register to store result of addition/subtraction two n bit signed binary numbers , then if the end-carry occurs ,then it is the sign-bit of the result .
Is it overflow or not ?"
Yes. It is overflow. And we get wrong answer here (since sign changes). And this is exactly why overflow flag is used for signed operations.
Overflow is useful for signed operations while carry flag is useful for unsigned operations.
http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt
digital-logic
Selected Answer
2 select line A and B will work as address lines, so we have 4 addresses (or words)
Solution:
This counter can count 0 to 7 (mod 8 ,without this or two input gate ) . it will count like this 000 001 ......... 101 110 111
.
the question says its a mod 6 counter so with the help of OR gate we can do it .
whenever MSB and middle significant bit get 1 their corresponding C ` value get 0 . so if we use OR gate then only for the input
value of 0 0 , it produced 0 and the counter gets cleared .
and it look like this 000 001 010 011 100 101 000 001 ..... ( whenever 1st two bit gets 1 its get cleared means when 110 appear
immediately C1 C2 C3 goes to 0 ... means 000 )
10.140 how many NAND gate required for AC+BD+AB top gateoverflow.in/37443
According to me it should be 4.
1 for (AC)'
1 for (BD)'
1 for (AB)'
A 4 bit presetable UP counter has preset input as 0101. The preset operation takes place as soon as the counter reaches
1111.The modulus of the counter is -
5,10,11,15
mod 11 counter is sufficient with the combination circuit that add 101 to state outputs.
a) S1 is true
b) S2 is true
d) none of them
One multiplexer is used for one function as it has only one output line
and decoder can be used to implement any function as if we have n input line it give 2 n output line , one for each
minterm.
In a multiplication of two 3 digit numbers (a2 a1 a0 ) and (b2 b1 b0) how many AND,XOR and OR
gates required?
Selected Answer
a2 a1 a0
× b2 b1 b0
− − − − − −
a2 b0 a1 b0 a0 b0
a2 b1 a1 b1 a0 b1 ×
a2 b2 a1 b2 a0 b2 × ×
− − − − − −
M5 M4 M3 M2 M1 M0
then
To get M2 , we have to add 3bits + 1carry. so Need one full adder and one half adder, there will be two carry's.
To get M3 , we have to add 2bits + 2carry's, So need one full adder and one half adder, there will be two carry's
A particular number system has 18 symbols from 0 to 9 , A,S,C,D,E,F,G and T. If two numbers GATE and CSE are given to
the adder the output of the adder is
a) G7CA
b) T76C
c) T7CA
d) T5SA
A -10,S-11...T-17
So
GATE --> 16 10 17 14
CSE --> 12 11 14
-------------------------------------------
T5SA <-- 17 5 11 10
So option d is correct
10.145 Couldn't understand how to approach this problem on digital logic top
gateoverflow.in/38553
Q) What is the maximum clock frequency that the sequential circuit which has the longest flip-flops delay of 2ns , the longest
setup time and hold time among the flip-flops of 1.5ns and 1ns, and the longest combinational path consists of 15 NAND
gates with tPLH = 1ns and tPLH = 0.8ns can run on for reliable operations? (31.74) MHz(correct to two decimal places).
digital-logic
digital-logic
Given f1 = Σm (1, 2, 4, 6, 7)
f 2 = Σm (2, 3, 4, 5)
f 3 = Σm (0, 1, 2, 3)
f 4 = Σm (0, 2, 4, 6)
If the boolean function fd is dual of f 4, then the boolean function ‘f’ is ____________.
Σm (0, 1, 2, 3, 4, 5, 6, 7)
Σm (0, 1, 2, 3, 6, 7)
Σm (0, 1, 2, 3, 7)
None of these
Selected Answer
p = f1 XOR f2 = {1,3,5,6,7}
q= (p AND f3)' = {1,3}' = {0,2,4,5,6,7}
given F=∑m(0,2,4,6)
Selected Answer
Complement of Function,
F ′ (x, y, z) = Π M(0, 2, 4, 6)
F ′ (x, y, z) = Σm(1, 3, 5, 7)
Dual of Function,
Fd (x, y, z) = M7 . M5 . M3 . M1
Fd (x, y, z) = Π M(1, 3, 5, 7)
Fd (x, y, z) = Σm(0, 2, 4, 6)
Note:
In Complement of f, that is f ′ , we need to replace all variable, say x , by it complement variables , say x ′ , also.
Refer : http://gateoverflow.in/36297/computing-the-dual-of-the-boolean-function
A input function can take values {0,1,2,4,6,7} and the output can take {0,2,4,6}.
Then how many bits (lines) are required for input and output ?
My doubt is: Since only 4 different states are required to be represented (for output) , so why not use only 2 bits?
digital-logic
Answer:
That's it.
A combinational circuit is to be designed to implement a boolean Function with 3 Boolean Variables which gives output 1 if all
the inputs have same value, otherwise give 0 . If only basic gate (AND,OR,NOT) are available and if complimented variable
is not available , then determine the minimum no of gates to design the circuit ?
1) 3
2) 4
3) 5
4) 6
like if f(x,y,z)=0,1,2,3,
then complement = 4,5,6,7
Selected Answer
yes!
Complement of dual
Dual of complement
dual of it,FN(w ′ , x ′ , y ′ , z ′ , + , . , 1, 0)
Example:
consider a + b' .
i)( COMPLEMENT OF DUAL)its dual is ab'. now the complement is (ab')'=a'+b
ii)(DUAL OF COMPLEMENT)its complement is a'b. dual would be a'+b.
1)Address translation
2)Memory Allocation
3)Cache management
4)All
a computer uses 8 digit mantissa and 2 digit exponent. If a=0.052 and b=28E+11 then b+a-b will be
result in overflow
underflow
5.28E+11
Ans is 9
How many 32K *1 RAM chips are needed to provide a memory capacity of 256K bytes?
a) 8
b) 32
c) 64
d) 128
Selected Answer
No of chips=256K*8/32K*1
=64
10.157 How to realize the Boolean Expression C + B ′ A using Gates? top gateoverflow.in/19936
digital-logic
C+B'A = (C+A)(C+B')
10.158 32 bit floating point representation of given decimal number top gateoverflow.in/19675
(A) 010001101111110111000000000000
(B) 110001101111110111000000000000
(C) 011010101111110111000000..
(D) 11101010111110111000000..
#include<stdio.h>
int main() {
float f = 3.284e4;
printf("%f 0x%02x%02x%02x%02x\n", f,
*((char*) &f+3),*((char*) &f +2) , *((char*) &f+1), *((char*) &f+0));
}
The above code is run on a little-endian machine and hence the byte reversal. So, the answer would be
32840 = (1000000001001000) 2
So, in normalized representation (implicit 1), we have 15 positions to be shifted for exponent and IEEE using bias as 127,
we get exponent field = 127 + 15 = 142 = (10001110)2
Thus we get sign bit followed by 8 exponent bits followed by 23 mantissa bits (after removing the leading 1)
10.159 don't care conditions for the given minimized boolean expression to
hold top gateoverflow.in/19672
The boolean expression A`BE+BCDE+BC`D`E+A`B`D`E`+B`C`DE` can be simplified to BE+B`D`E`, if the don't care
conditions are:
(A) ABCDE+AB`CDE`
(B) ABCD+AB`CDE`+ABCD`E
(C) AB`CDE`+ABCDE+ABCD`E
(D) none
A`BE+BCDE+BC`D`E+A`B`D`E`+B`C`DE` = ∑m(0,2,4,9,11,13,15,18,31,25)
BE+B`D`E` = ∑m(0,4,9,11,16,20,25,29,31)
missing minterm are 16 20 19 which can't be achieved by any expression given in option so
option D none.
If half adders and full adders are implements using gates,then for the addition of two 17 bit numbers (using minimum gates)
the number of half adders and full adders required will be
a)0,17
b)16,1
c)1,16
d)8,8
Selected Answer
How many 32 K x 1 RAM chips are needed to provide a memory capacity of 256 K-bytes?
a)8
b)32
c)64
d)128
Selected Answer
= 26 = 64
Option C
a)10 flip-flops
b)12 flip-flops
c)8 flip-flops
d)6 flip-flops
Selected Answer
If we inplement half adder using mux we require 3 mux,2 for generating sum(xor) and 1 for carry
how they find the range of denormalized number exponent . what i know is that exponent in denormalized number is all
zeros . which will lead to zero . we use access 128 in ieee 754 single precision so how exponent - bias becomes 126...and
secondly what does actually denormalized means. in case of explicit implementation it is also normalized and there is no
leading 1 before the decimal point. ?
Selected Answer
IEEE 754 uses normalized representation by default. i.e., it adds an implicit 1 to the left of mantissa (before "."). But
normalization has a problem as it means, the smallest positive number that can be represented is
To allow smaller numbers than this we need to use denormalized representation. To incorporate this, all 0 exponent (and
non-zero mantissa) is taken for denormalized representation. That is, if all the exponent bits are 0s, there will be no
implied 1. Moreover normalized representation can no longer have all 0s as exponent- the smallest positive number in
normalized representation now becomes
Now, in denormalized representation, exponent is fixed- all 0's and we add a bias of "-126". Now, we have all 23 bits for
mantissa. The smallest positive number than can be represented becomes (the last mantissa bit is 1)
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
10.164 How many minterms are present in 8 input EXOR gate ? top gateoverflow.in/26487
Selected Answer
A : 1 min term
A Ex OR B Ex OR C = 4 min terms
10.164 K digits are required in base b for a number ,how many digits are
required in base x ? top gateoverflow.in/26621
Selected Answer
Let l be the required no. of bits in base x which gives the largest number as xl − 1
klog b
The size of the ROM required to build an 8-bit adder/ subtractor with mode control, carry input, carry output and two’s
complement overflow output is given as
(A) 2^16 × 8 (B) 2^18 × 10
(C) 2^16 × 10 (D) 2^18 × 8
Selected Answer
total input to the rom decoder will be (8+8 ( two 8 bit number ) +1( mode ) +1( carry in))
so total number of words out of decoder will be 2^18 . result will be 8 bit so 8 vertical lines +( 1 for carry ) +1 ( for
saying underflow) .
answer will be B.
https://www.google.co.in/search?q=8-bit+adder%2F+subtractor&oq=8-
bit+adder%2F+subtractor+&aqs=chrome..69i57.4118j0j7&sourceid=chrome&es_sm=93&ie=UTF-8#q=rom+required+8-
bit+adder%2F+subtractor
digital-logic
ok you want to prove it is not functionally complete . so it should be able to derive and and/or or not. first i want to
extract and /or from the exor expression by replacing only in terms of other so that the whole equation comes in one
variable only. but u can see u can't do it , whole equation ends in 0. like putting b =a , a.a'+a'.a=0. so i put b =1, then i
can derive not. at this point it can't be functionally complete ., but partially functionally complete because we always have
to take help from 1. now moving on to next step. now i wan to get and /or . so in tis equation a'b+ab'. try all the
combinations like . a=a', b=b, and a=a b=b', a=a', b=b'. you can see there is no way u can get and or. so not functionally
complete .
10.167 carry look ahead adder vs ripple carry adder top gateoverflow.in/26355
Selected Answer
S1: the point we use the carry look ahead adder is to do fast calculation. When carry are available at the same time.
Calculation is done in the same cycle. and result is obtained after one cycle .
s2: the cost is higher as a there is a need of extra hardware for like, AND OR gates in carrylookahead adder.
Option A is correct since for carry look ahead adder carry present at start so no need to wait , but in ripple
adder we wait for output at 1st half adder or full adder.
Edited:
Cost of carry look ahead adder is more b/c used two level and or gate ...(calculate Gi= Ai*B i and Pi= Ai exor
Bi) then start normal functioning .
This is positive edge triggered up counter so after two clocks output will be 6 ie 110 so ans is d
suppose you want to build a memory with 4 byte words and a capacity of 2^21 bits.what is type of decoder required if the
memory is built using 2K X 8 RAM chips?
Selected Answer
here u have to built a memory using some chips so first of all wht u should now is the ram implementation. here it is
so the type of decoder required will dependent on the number of rows . not number of columns . columns are for data
whenevr one row is selected the whole data on that row will be extracted by data lines . and that how each word size
matters. if your memory is byte addressable then 8 vertical lines will be there if itis one word where each word is of two
byte the it will be 2*8= 16 as we know every row should accomodate one word if the memory is word addressable else
one byte if byte addressable .
so leaving the chips required first of all take a look at what we have to make . given is 4 byte word memory . mens
memory is word addressable where each word is of 4 byte . so data lines required will be 4*8=32 . and total capacity is
2^21 bit so number of rows required will be equal to 2^21/2^4=2^16
now finally we have to make it using 2k *8 chip which mens 2^11 rows . so now dividing 2^16/2^11 is the actual no of
adress line required if i use these chips direct implementation will require 2^16 adress line .
evaluate (X ⊕ Y) ⊕ Y ?
isro digital-logic
Selected Answer
(X⊕Y)⊕Y=(XY'+XY')Y'+(XY+X'Y')Y
=XY'+XY
=X
(X⊕Y)⊕Y=X⊕(Y⊕Y)
=X⊕0
=X
digital-logic
D is answer
Someone please tell me the truth table for 4 variables, say (A,B,C,D). What all 16 possible input combinations will be?
Thank you in advance.
digital-logic
Selected Answer
Input combinations will be binary numbers from 0000-1111. For each of this 2 possible outputs- 0 or 1. So, 2^16 possible
boolean functions.
10.175 Find the minterms of the product of two functions top gateoverflow.in/17971
and f2=∑m(1,2,4,5)+d(0,7)
f=??
According to me F is AnD operation of f1 and f2 so in f minterm will be common min-term of both function.
then check the f1 dont care is present in minterm of f2 or not if yes then take it in(e.g. let 2 in f1 be 1 and 2 is in f2 so it
will be 1) similarly check for f2 vice versa. this is done because . 1 and Dn't care is a don't care because the value will now
depend on what i take the don't care to be . so we just take intersections of don't care with minterms of f2.
f1=∑m(0,1,5)+d(2,3,7)
f2=∑m(1,2,4,5)+d(0,7)
f=∑m(1,5)+d(0,2,7)
10.176 max no of boolean expression that can be formed for the function
f(x,y,z) satisfying the relation f(x',y,z') = f(x,yz) top gateoverflow.in/18173
f(x',y,z') = f(x,y,z) means y remains same and the for x z values the function does`nt have any effect .
so in kmap for 2 3 6 7 y is 1 . and the remaining 0 1 4 5 we put dontcare . so in the function 2 3 6 7 will be there but all these dont
care have 2 choices either its present or not present . 24 = 16 possibilities . ( i may be wrong :D )
10.177 minimum 4*16 line decoders required to realize 8*256 line decoders
are top gateoverflow.in/16141
Selected Answer
for 8*256 decoder 1 would required in first level and 16 in second level ....the best way to apprach this question is
starting from 2nd level see 256 output lines so 256/16 decoder now to select one of 16 decoder we neead one 4:16
decoder so ans is 1+16=17
A 3 bit ripple counter uses j k flip flops.if the propagation delay of each flipflop is 50 nsec,then the maximum clock frequency
that can be used in megahertz... please explain the soln
max clock frequency=1/3*50*10^-9 clock frequncy=1/t (for asychronous tt= n*propogation delay)
=6.67 MHz
digital-logic
bcz these asynchronous ips are active low hence option D is correct one.
If a 3 bit multiplicand is multiplied to a 2 bit multiplier, minimum number of two input AND, XOR, and OR gates, needed in
the design are respectively?
A) 16,14,1
B) 7, 3, 1
C) 10, 4, 1
D) 8, 4, 1
digital-logic
Selected Answer
let the three bit multiplicand be 111 and two bit multiplier be 11
1 1 1
* 1 1
1 1 1
1 0 1 0 1
TO ADD GREEN BITS WE NEED 1 HALF ADDER AND FOR YELLOW BIT WE NEED 1 FULL ADDER AND ONE MORE HALF
ADDER FOR LAST BIT
AS WE KNOW HALF ADDER NEEDS 1 XOR (FOR SUM) AND 1 AND GATE(FOR CARRY BIT)
FULL ADDER NEED 2 XOR (FOR SUM)AND 3 AND GATE AND 1 OR GATE(FOR CARRY BIT)
TO MINIMIZE WE CAN IMPLEMENT 1 FULL ADDER WITH 2 HALF ADDER + 1 OR GATE (2-XOR GATE+2-AND GATE+1-OR
GATE)
Selected Answer
Self complementing code is a code wherein sum of weights is 9. Except for D, all other options have sum of weights=9
and also find the 1's complement of the no according to given weightage then if it will stisfied then given weightage is self
complemantary code.
9's complement 2 is 7 for this if we represent 2 by weightage and take 1's complememnt then the no is
selfcomplememntry code
d) 641-3
10.182 the noninverting buffer have delay of 2 ns and 4ns both xor and all
wire have zero delay how many transition top gateoverflow.in/17579
Here, the value of p should be 24, not 23 as taken...also no reason is given for this assumption by the author (Navathe ).
Can anyone explain this ?
A number system uses 20 as the radix. The excess code that is necessary for its equivalent binary coded representation is ??
digital-logic
https://books.google.co.in/books?
id=wFNMpKd6_y8C&pg=PA173&lpg=PA173&dq=A+number+system+uses+20+as+the+radix.+The+excess+code+that+is+necessary+
10.184 the minimum number of two input NAND gate required to realize one
AND gate is (complemented inputs is not available). top gateoverflow.in/18423
options are
1. 1
2. 2
3. 3
4. 4
Answer is 2.
Actually I don't know how to find MUX equation. please provide answer with explanation.
Ans - D
10.186 when we realize a 64x1 mux using 4x1 muxes we have levels? gateoverflow.in/18902
top
options are:-
A) 2
B)3
C)4
D)5
Selected Answer
At level 1 we need 64/4 =16 4:1 MUX we will have 16 output at this level
At level 2 we need 16/4 = 4 4:1 MUX we will have 4 output at this level
At level 3 we need 4/4=1 4:1 MUX we will have 1 output at this level
10.187 A X:Y decoder can be constructed using how many A:B decoder with
enable? top gateoverflow.in/18903
options are :
A)Y/B
B)X/A
3)X/B
4)Y/A
Selected Answer
Here we follow the reverse process of MUX in finding the levels and deocder at each level
if ouput < B then we use 1 more level i.e. level 1 with one decoder
if output >B then keep on dividing with output and increasing the levels.
10.187 this is gate cs 2007 question about 4 bit counter. top gateoverflow.in/6226
my soln-10^30 = 2^x
actually 1030 -1 but its close to 10 30 so yes you are right , its greater than 90
digital-logic
Selected Answer
D1C1B1A1D0C0B0A0 = 0 0 1 0 1 0 0 1 geen data will enter in IC1 now read it in BCD format 1 0 1 0 0 = 1 4
14 will be converted into binary format by IC1 i.e Y5Y4Y3 Y2Y1=0 1 1 1 0 output of IC1 option B
10.190 If i consider XOR gate takes 0 delay i am getting ans as 16 , top gateoverflow.in/18487
digital-logic
I think so!
isro digital-logic
Selected Answer
If we ignore delay of exor gate then total delay is 16 . NOT and OR gate running independently but AND gate can't run
until NOT gate give output to AND gate.So NOT and AND are working sequencially . so (6+10) total delay.
the minimum decimal equivalent of the number 11C.0 is.. a)183 b)194 c)268 d)269
they have asked the minimum decimal number which will be obtained when base will be the smallest , and the smallest
base possible here is 13 , as c is 12 ( a base n number can only contain digits from 0 to (n-1))
more at
http://www.engineerclub.in/2014/09/ies-previous-year-solution-part-1.html
digital-logic
We have 2^4 = 16 total function, out of which we got 8 minterms(i.e 1) and the remaining will be 0. (maxterms).
Now by constructing function table we get only one boolean function possible as shown below:
Can somebody please prove A'+ AB' = A' + B' using both methods vann diagram and alegebric simplification.
digital-logic
A' + AB' will become TRUE if A' is true or if AB' is true. If A' is true we don't need to consider AB' and if A' is false, it means
A is true and hence we need to consider only B'.
A'+AB'
1.(A'+B')
A'+B'
10.195 After 3-clock pulses , what is the content of shift Register top gateoverflow.in/32833
I could not understand here both the outputs point to D3 bit . How to proceed in this scenario ?
digital-logic
minimum number of states required to detect n-bit sequence are ( for sequence detector)
log2n , 2 n , n-1 , n ??
n=log2 N bits,so the minimum number of states required to detect n bit sequence will be 2^n
10.197 a dynamic ram has refresh cycle of 32 bits per msec top gateoverflow.in/32954
a dynamic ram has refresh cycle of 32 times per msec. Each refresh operation requires100 nsec and a memory cycle
requires 250 nsec what percentage of memory's total operating time is required for refreshes
First we will find how many no cycle will be there in one memory operation-
then we can find cycle in 250 nsec (which is 1 memory cycle time) no of refresh cycle = (32*250)/10 6 cycle
Now we can find total time taken by refresh operation in 1 memory cycle
now find percentage of memory's total operating time is required for refreshes (100/250)*0.8 = 0.32%
10.198 A pulse train can be delayed by a finite number periods using of clock
top gateoverflow.in/32445
digital-logic
option (a) is correct because using shift register using D-flip flop we can delay serial input signal to appear at serial output
by keeping clock at low level for some finite amount of time.
ans-
Therefore answer is C.
The boolean expression f (x, y, z) in its canonical form for the decoder circuit shown below is
Π M(4, 6)
Σ m(0, 1, 2, 3, 5, 7)
Σ m(4, 6)
Π M(0, 1, 2, 3, 5)
Ans is ∑m(4,6)
Is it right???
Selected Answer
A digital system has clock generator that produces pulses at frequency of 80 MHz design circuit that provides clock with
cycle time of 50 ns
Selected Answer
1
−9
desired clock frequency = 50× 10 Hz = 20 MHz,
so we have to divide given clock frequency by 4 in order to achieve the desired clock frequency.
This can be done with the help of two edge triggered T flip flops as follows:
I am using -ve edge triggered flip flops here.
T input of both the flip flops is 1 .
Clock pulses from the given clock generator are passed to the first flip flop.
Output of first flip flop i.e. Q1 will change only on the -ve edges of given clock pulse, so it can be seen from the pulse plot that frequency of
Q1 will be half of that
of given clock pulse.
So Q1 will produce pulse of frequency 40 MHz.
Q1 is being fed to the clock input of second flip flop.
And the output of second flip flop i.e. Q2 will change only on -ve edges of Q1,so the frequency of pulse produced by Q2 will be half of the pulse produces by Q1
and quarter of the pulse produced by the given clock generator.
80
Using D flip flop 4 state counter at the Clock of 80MHz will produce the output.
T = 4*12.5 = 50ns
minimum number of ( 2*1) multiplexers required to realize the following function if inputs are available only in true form-
4,2,1,3 ??
3 variable function can be implemented with 4*1 MUX or 8*1 MUX. No. Of 2*1 mux reqd to implemet 4*1 is 3 And no. Of
2*1 reqd to implement 8*1 is 7. 7 isn't given in the options. So it shud be 3. Is it ? What's the answer ?
How many different BCD numbers can be stored in 12 switches? (Assume two position or on-off switches).
(a) 2^12 (b) 2^12-1 (c) 10^12 (d) 10^3
digital-logic
Selected Answer
By using 16 bit binary in BCD , how many switching functions can exist ?
Now , since this is BCD anything above 1001 is invalid. Considering 16 bits : 1001 1001 1001 1001
Above is number of possible combinations : 0 - 9999 There are 10^4 possible combinations. Number of switching functions :
2^(10^4)
I think 2^(10^4) is correct answer. Don't know why (10^4) is given. (It is size of truth table)
10.206 which of the following is termed as minimum error code top gateoverflow.in/17266
a)Binary code
b)Gray code
c)Excess 3 code
d)octal code
Selected Answer
b) Gray Code
aka :
reflected binary code
cyclic permutation code
digital-logic
Selected Answer
its base 15 means . the system will have 15 number - 0 to E. And 15 is represented as F . so it is asking the radix
complement of the number, now the radix complement can be written as dimnishd radix complement + 1.
digital-logic
Selected Answer
What are values of Q0 and Q1 after 4 clock cycles, if the initial values are 00 ?
(a) 11 (b) 01 (c) 10 (d) 00
Selected Answer
correct me if wrong!
q0q1
(initial) 00
(1 clock) 10
(2 clock ) 01
(3 clock ) 11
( 4 clock) 00
digital-logic
Selected Answer
Or, Another way is to convert them in decimal, then after doing all calculation, convert back to desired base.
Note: In base 4, we can only { 0, 1, 2, 3}, in any calculation(adding or multiplication) if get 4 or above. It need to convert
Convert into binary then add and again convert to 4 base with multiplication with 10
digital-logic
digital-logic
Selected Answer
2 points
1:- if circuit have odd number of NOT gate then it is "Astable Multivibrator"
2:- if circuit have even number of NOT gate then it is "Bistable Multivibrator"
digital-logic
No of columns = 4/2=2
5 .1 The D latch of Fig. 5.6 is constructed with four NAN D gates and an inverter. Consider the following three other ways for obtai ning a D latch . and in eac h case draw the logic diagra m and
verify the circu it operation;
(a) Use NOR gates for the SR latch part and AND gates for the other two. An inverter may be
needed .
(b) Use NOR gates for all four gates. Inverte rs may be needed .
(c) Usc four NAND gates only (without an inverte r). This can be done by con nect ing the output
of the upper gate in Fig. 5.6 (the gate that goe s to the SR latch) to the input of the lower gate
(instead of the inverter output)
digital-logic
Selected Answer
First we design RS latch and Flip-flop with NAND and NOR gates, and then convert it into D Flip-Flop, by using equation
¯
R = D and S = D
digital-logic
Selected Answer
Q2 Q1 Q0
← Initial/
0 0 0
Data input bit ↓
New Q0 = Data
New Q2= Q1 New Q1 =Q2 ⊕ Q0 1
Input bit
0 0 1 0
0 1 0 0
1 0 0 1
0 1 1 1
1 1 1 0
1 0 0 0
0 1 0 0
1 0 0 0
0 1 0 ← Final Q2Q1Q0
Answer is C
In question they are asking for table Y which is lsb in the compressed input. it is simple 4 to 2 encoder
you need the table
D3 D2 D1 D0 X Y V
0 0 0 0 x x 0
0 0 0 1 0 0 1
0 0 1 x 0 1 1
0 1 x x 1 0 1
1 x x x 1 1 1
D3 + D2'D1
Selected Answer
¯
¯
¯
¯
′ ′
A+C +D +B+D
=
As, variable are available both primed and Unprimed form. We are having 4 , 2-Input Nor Gates..
Given answer: D
Please explain
digital-logic
Selected Answer
This type of question are very simple. Just remember the following prints :
2 NOT gates always cancel each other, (0')'=0. So, output of XOR, 0 ⊕ A = A, First Input to OR.
AND gate with TTL is connected to +10V taken as 1 and open connection will be counted as 1, output of AND = 1,
Second Input to OR.
A+1 = 1
answer = option D
simulated circuit with open ends and using all gates from TTL(shown in blue) logic : Output is still positive, Though
presence of Input A effects the output. But it never goes negative/zero. that is shown by the glowing probe in figure 2.
is
Selected Answer
4 nand gate
(x'+y')(z+w) = (x'+y')z + (x'+y')w = (xy)'z + (xy)'w
make (xy)' as common nand gate input for z and w then there output to one more nand gate.
¯
¯ ¯
¯ ¯
((xy)z). ((xy)w)
= 8Tc = 8 ∗ 40 = 3.125Mhz
wx/yz 00 01 11 10
00 1
01 1 1 1
11 1
10 1 1 1 1
digital-logic
method (1)
RHS=(AB+A'B')(AC+A'C')=ABC+A'B'C'
SO, LHS!=RHS
method(2)
(A xnor
Ax-
ABC B)(A
nor(BC)
xnor C)
0001 1
0011 0
0101 0
0110 0
1000 0
1010 0
1100 0
1111 1
how many MOD -4 counters are needed to provide line that operates at 62.5 KHZ from a 16 MHZ crystal?
4,8,12,16
Selected Answer
I guess you meant multiplication and division by power of 2. For multiplication your question answers itself, as answer is
always an integer. For division, answer to your question is "yes"- it won't work. Because when we use shift instead of
division, compiler will just use shift instruction provided by the CPU (if it does). So, lets take Intel architecture and this is
what Intel manual says for SAR (Shift Arithmetic Right) Instruction.
"Using the SAR instruction to perform a division operation does not produce the same result as the IDIV instruction.
The quotient from the IDIV instruction is rounded toward zero, whereas the “quotient” of the SAR instruction is
rounded toward negative infinity. This difference is apparent only for negative numbers. For example, when the
IDIV instruction is used to divide -9 by 4, the result is -2 with a remainder of -1. If the SAR instruction is used to
shift -9 right by two bits, the result is -3 and the “remainder” is +3; however, the SAR instruction stores only the
most significant bit of the remainder (in the CF flag)"
So, for positive numbers, when we want only the quotient we can safely use shift in place of division by power of 2.
Otherwise we should not use shift.
Reference: http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-
developer-manual-325462.pdf
Given answer: D
I am not getting how to approach this question.
digital-logic
Selected Answer
F = A ′ B ′ C + A ′ BC ′ + AB ′ C ′ + ABC = (A ′ B ′ + AB). C + (A ′ B + AB ′ ). C ′
¯ ¯
= (A ⊕ B). C + (A ⊕ B). C = (A ⊕ B) ⊕ C
Now its dual (Dual is obtained by complementing the input variables and then by complementing the function)
= (A ⊕ B) ⊕ C
2.no two mutually exclusive term should be present(for three variable(0,7)both should not be present)
A-> minterms 3 and 4 both are present and are ME(sum is 7) so not a self dual function
so option D is correct..
In a 4-bit carry look ahead adder, the propagation delay of EX − OR gate is 20ns, AND and OR gates is 10ns. The sum and carry
output of full adder takes 20ns and 10ns respectively. The total propagation delay of the above adder in ns is__________.
Selected Answer
carry look ahead generator has inputs P(i) =A(i) EXOR B(i) , Gi = A(i) AND B(i) , delay max(20,10) = 20
digital-logic
Selected Answer
at t<t0
output of NOR gate is 1. and input Vi is 1 so input to Ex-or gate is 1,0 ..
final output ll be 1..
at t0<t<t1
input to NOR gate is 1 but still output or NOR gate is 1 (due to propagation delay). Input to Ex-OR gate is 1,1 and final
output ll b 0..
at t1<t<t3
input to NOR gate is 1 and here output of NOR gate is 0.
Input to Ex-OR gate is 0,1 but fiinal output ll b 0 (due to propagation delay of Ex- OR gate)..
at t>t3.
input to NOR gate is 1 and here output of NOR gate is 0.
Input to Ex-OR gate is 0,1 and fiinal output ll b 1..
Option A..
m assuming difference between two consecutive ti (i=0 to3) value is 10nsec..
The maximum number of boolean expressions that can be formed for the function f(x,y,z) satisfying the relation
f(x',y,z')=f(x,y,z) is
So 24=16
example: f(A,B,C,D)=A
Which of the following multiplier pattern of boothe algo gives better performance and how:
1..01111111110
2..1111100011111
3..011111011111
4..111111111000
While using the Booth algorithm, performance is good if the multiplier pattern is continuously of same type. it takes the
negative value of actual number with multiplier when it goes from 0 to 1 and takes the positive value if it is making the
moving from 1 to 0.
eg:
1) multiplying by 1
x *1 = x*2 -x
2) multiplying by 6 (110)
x* 6 = 8*x - 2*x
here it starts scanning from right most bit (it initialize the first bit to 0) and takes the negative of number when it
encounter 0 to 1 transition(-2*x) and takes the positive of number(8*x) when it goes from 1 to 0 (or end of bit).
Therefore, here options (1) and (4) give the better performance, because in both cases it has to take only once the
positive of the number and once the negative of the number.
10.231 What's the best way to approach this question in digital logic? gateoverflow.in/29474
top
Given answer: A
Please explain
digital-logic
Selected Answer
to select I0 line AB should be 00 and now C is connected to I0 so fro min term ABCD here ABC are 001 D can take o or 1
similarly for I1 we get AB as 01 and D 0 so 01C0 c can be 0 or 1 so 0110 and 0100 ie m4 and m6
So F=∑(m2,m3,m4,m6,m8,m10)
So ans is d.
according to me..
Q2 Q1 Q0
0 1 0(initial state)
0 1 0 (1 clock)
0 1 0 (2 clock)
0 1 0(3 clock)
0 1 0(4clock)
NAND gate is there receiving input AS 0(from q2 state),1(from clock) giving output as 1 to both the first and second flip
flop
now first flip flop give output as 0 and after that input going to second flip flop is the previous state ie q0 which is 0
making second flip flop disable, similarly for thrid flip flop initially q1 is 1 making flip flop enable therefore it will no toggle
as input is 0 therefore output will be zero..
p value will be 1
Samples of old matured wine were tested and their respective % of pure wine in each sample were as given in table.
Remaining constituent in each sample was water
If any two samples are mixed from above. Then on maximum, the number of distinct pairs of samples will never give desired
composition and more than 60% of wine is_______.
Find the sum of all the 4 digit numbers that can be formed with the digits 3,2,3,4.
Ans- 39996
Now 2 and 4 will occur at units tens hundred and thousand place 3 times
11.2 Where i can find the complete tutorials of general aptitude and discrete
mahematics top gateoverflow.in/171
General aptitude is a vast area but for GATE they ask only from a small section which is clearly mentioned in GATE
syllabus. Many people won't prepare for these but it is advisable to just read the sections mentioned in GATE syllabus from
a recommended book for aptitude such as Aggarwal.
Discrete Mathematics is an important area in GATE CSE. This you should definitely read from one of the recommended
books such as Kenneth H. Rosen.
a b
b a
+
a b
b a
−
Given =1
If a and c are positive integers, then how many ordered pairs are possible for (a, c), where: a + 4b2 + c ≤ 8?
A. 45
B. 28
C. 17
D. 18
combinatorics algebra
Ans will be 45
((a^2+b^2)/ab)/((a^2-b^2)/ab)=1
=>(a^2+b^2)/(a^2-b^2)=1
=>(a^2+b^2)=(a^2-b^2)
=>2b^2=0
=>b=0
a+c<=8
=>a=6 c=0,1,2
...............
mathematical-logic made-easy_test-series
mocktest
12.4 Number Series: What will be the next Number? top gateoverflow.in/43050
number-series
Selected Answer
Let Consider p is the position for which we are calculating the value. P starts from 1 and goes infinite.
Then It is using (((p^3)-2) + ((p^2)-1) + p) formula. This will give the result.
I think answer given by them is stupid. ( If anyone is allowed to seat anywhere, people will buy economy class & will want to
seat in First class :P
I think any option apart from first one does not even make sense :P
Option C implies all seats are non-first class. I guess that is a decent answer :) All other options do not even come close.
Here I do not agree with Answer given. I think first is more better approximation, second is not, because in paragraph we
are talking about TIME, and in ans they have marked it as Green They are talking about "PARTS of earth-> Locations"
A survey is conducted among 125 people of India. Among them 25 people have neither a valid visa nor a valid passport and
70 people have a valid visa.
(a) 30 (b) 40
(c) 70 (d) 50
(a) 30 (b) 40
(c) 55 (d) 50
easy venn-diagrams
Selected Answer
No of people who has either a valid visa or a valid passport or a valid visa and passport 125-25=100
And No. of people who doesnot have either a valid visa or a valid passport =25
In how many ways can 4 letters be selected from the letters of the 3 words "GATE MADE EASY"?
1. 70
2. 112
3. 113
4. 127
From a well shuffled deck of 52 cards, cards are dealt. The probability that the 13th card is the first king to be dealt is
______ × 10 −1
Q9 : I am getting 126
Selected Answer
3- A
3- E
all other letters 1 each.
3 A's - 7 C1 = 7.
The question asks to find ways of choosing letters- and not the number of possible words. Hence we are using
combination and not permutation.
48C
12 .4 37.38.39
52C
Q10. 13
= 49.50.51 = 0.4388.
Selected Answer
2
a+a = a+ b+c =a(1+a)
b+b2 = a+b+c =b(1+b)
2
c+c =a+ b +c=c(1+c)
So:
=(a+b+c)/(a+b+c)
=1
In 100 m race A beats B by 6 sec B beats C by 3 sec.If A beats C by 25m time taken by A to complete 100 m is
Selected Answer
Distance = 100m
25
Speed of C = 9 m/s
100
25
9
Time taken by C = = 36 sec
t + 9 = 36 sec
Four undergraduates are staying is a room. They agreed that older enjoys the more space. Manu is two months older than
Sravan, who is one month younger than Trideep. Pavan is one month older than Sravan. Who will enjoy more space in room?
Selected Answer
Manu>Trideep=Pavan>Sravan
12.13 Doubt rergarding one question's answer in GATE 2016 top gateoverflow.in/41615
This was one of the questions asked in GATE 2016 that which of these 4 words is odd one out:- mock, deride, praise, jeer.
Praise seems to be the obvious answer but at the GATE website, it is mentioned that mock is the answer. Can anyone
explain me why?
Selected Answer
Let Consider p is the position for which we are calculating the value. P starts from 1 and goes infinite.
Then It is using (((p^3)-p) + ((p^2)-p) +p) formula. This will give the result.
Answer 145
A. commit
B. to commit
C. committed
D. commiting
verbal-ability
Selected Answer
http://www.thefreedictionary.com/DARE
For GATE they usually ask from some GRE books- yes this is one part where they copy questions :P
Sorry, I'm not good in verbal ability to suggest you a good book. May be some others can.
Answer given is option B but whats wrong in saying this "all the information that you want " ?
According to me it should be like Many times, news has been published in the papers that the end of the world is certain if a
nuclear war breaks out.
ans is a
[D]. No error.
According to me the option A sound correct so then whats the issue with that ?
its (a)
correct sentence - while he was walking slowly in the park.
I've realized that Answering Verbal questions in GATE without any preparation will mostly lead to negative marks ! So trying
to improve if I could !
Syllabus for Verbal Ability: English grammar, sentence completion, verbal analogies, word groups,
It has bulk of marks. I'm looking to increase my couple of marks by preparing Verbal, If I can !
0. Have you prepared for it ? How you prepared for it, Please share your experience !
2. Whether GRE books are more relevant for GATE or CAT Books ? If you have prepared for this exams, using which exams
book will be better for GATE point of view ? Please give exact book name you are suggesting.
verbal-ability
http://www.amazon.in/Word-Power-Made-Norman-Lewis/dp/8183071007/ref=sr_1_1?
s=books&ie=UTF8&qid=1449024675&sr=1-1&keywords=word+power+made+easy
Let p,q,r,s,t be consecutive positive integers such that p+q+r is perfect square and p+q+r+s+t is perfect cube..find smallest
possible value of r
12.20 Please suggest book / notes / lectures for verbal ability. top gateoverflow.in/16021
verbal-ability
Three roomattes a,b,c decided to prepare food combinely for two months.So they buy cooking stuffs as needed and there
individual investments are 1200 , 1300, 1600 in 2 month(both of 31 days).After these they wanted to calculate individual
cost for food . what amount will be shared between them to make fair(equality in money) for this period
A and B will pay rs (4100/3)-1200 and (4100/3)-1300 to C as the total expenditure is 4100 and c has paid more than
4100/3.
8. Which of the following options is the closest in meaning to the sentence below? “As a woman, I have no country.” (A)
Women have no country. (B) Women are not citizens of any country. (C) Women’s solidarity knows no national boundaries.
(D) Women of all countries have equal legal rights.
Option C
It is a metaphorical statement.
Two varieties of rice are mixed together in the ratio 2:3. The cost price of each kg of second variety is Rs.5 more than the
cost price of each kg of first variety of rice. If the cost price of mixture is Rs.25, then find the cost price of first variety of
rice.
Selected Answer
total mixture=5x
now
2x *C + 3x *(C+5)=5x *25
x(2C+3C+15)=125x
5C=110
C=22
Option B
verbal-ability
Most of the passage is regarding the upward trend in global temperatures. So D will be good choice, I think.
Selected Answer
Its like we are adding 5 to all the odd position terms and multiplying by 2 all the even even terms.
Like:
0 is at position 1, means its an odd position => add 5
5 is at position 2, means its an even position => multiply number at this position by 2, and so on..
Verbal Ability : English Grammar, Sentence Completion, Verbal Analogies, Word Groups, Instructions, Critical Reasoning and Verbal Deduction.
verbal-ability
I think that is a difficult question to answer. Probably you can refer some GRE books- but that would be a bit too much for
GATE. Usually the verbal questions asked in GATE are just a bit low standard compared to CAT exams. So, if you are not
comfortable with verbal, you can prepare using CAT materials and avoiding tough ones.
numerical-ability ace-test-series
Selected Answer
Total cost for leasing after 4 years = ((1250 * 1.14 + 1250) * 1.14 + 1250 )*1.14 + 1250 = 6151.43 (assuming rent is
paid at end of a year). So, leasing is preferable.
A tiled floor of a room has dimensions m × m Sq.m. Dimensions of the tiles used are n × n Sq.m. All tiles used are green tiles except diagonal
tiles which are red.
After some years some green tiles are replaced by red tiles to form an alternate red and green tile pattern. How many green tiles are
removed? (m is not equal to n and total no. of tiles are odd)
C) (m 2 − 4mn − n2 )/2n2
algebra
Two cars start at the same time from Mumbai and pune and proceed towards each other at the rate of 60 km and 40 km per
hour, respectively.when they meet , it is found that one car has travelled 20 km more than the other. Find the distance
between Mumbai and pune
one having more speed with cover more distance in same time.
so, x = y + 20
60t = 40t + 20
t = 1hr
Number of labeled binary trees are there on vertices {1,2,3,4} that have only vertex 1 as leaf and every binary trees has 4
nodes are _______.
binary-tree
Selected Answer
We have 4 nodes out of which 1 is a leaf and there are no mode leaf nodes. So, we must have 4 levels with one node in
each. Each node in levels 2, 3 and 4 have two choices- either to be left child or right child. So, totally 2 × 2 × 2 = 8 ways.
Now, 2, 3, 4 can be permuted in any order in first 3 levels and each permutation gives a different binary tree. So, total
number of binary trees = 8 × 3! = 48.
Except root every node have 2 choices : 1. Left node 2. Right node
Total 4 nodes, so Number of possible combination for unlabeled tree are 2*2*2 = 8
10% of the voters did not cast their vote in an election between two candidates. 10% of the votes polled were found invalid.
The successful candidate got 54% of the valid votes and won by a majority of 1620 votes. The number of voters enrolled on
the voters list was:
a. 25000
b. 33000
c. 35000
d. 40000
Selected Answer
The sucessful candidate got 54% of valid votes and win by majority of 1620
So, lossing candidate got 46% of valid votes as it is two candidate election
8
100
× 0.81n = 1620
So, n = 25000
The shaded portion of figure shows the graph of which of the following?
a. x(y − 2x) ≥ 0
b. x(y − 2x) ≤ 0
1
( )
c. x y + 2 x ≥ 0
( )
d. x y − 2 x ≤ 0
cat2009
y = 2x
means y ≥ 2x or, y − 2x ≥ 0
And bounded by x ≥ 0
Here also, x(y − 2x) ≥ 0 (here product reverse the direction of inequalities)
y y
(
If f x + 8 , x − 8
) = xy, then f(m, n) + f(n, m) = 0
a. Only when m = n
b. Only when m ≠ n
c. Only when m = − n
d. For all m and n
y y
8 8
Let x + = m and x − =n
y y
8 8
As, f(x + , x − ) = xy
m+n
2
So,f(m, n) = × 4(m − n) = 2(m 2 − n2 )
Option D
In a certain zoo, there are 42 animals in one sector, 34 in the second sector and 20 in the third sector. Out of this, 24 graze in
sector one and also in sector two. 10 graze in sector two and sector three, 12 graze in sector one and sector three. These
figures also include four animals grazing in all the three sectors are now transported to another zoo, find the total number of
animals.
a. 38
b. 56
c. 54
d. None of the above.
Selected Answer
A = 42
B = 34
C = 20
A ∩ B = 24
B ∩ C = 10
A ∩ C = 12
A∩B∩C=4
A∪B∪C = A+B+C−A∩B−B∩C−A∩C+A∩B∩C
A ∪ B ∪ C = 42 + 34 + 20 − 24 − 10 − 12 + 4
= 54
1 1
m n m n
If mxm − nxn = 0, then what is the value of x +x + x −x in terms of xn ?
2mn
xn (n 2 −m2 )
a.
2mn
xn (n 2 +m2 )
b.
2mn
n 2 2
c. x (m −n )
2mn
xn (m2 +n 2 )
d.
cat2009 numerical-ability
Selected Answer
mxm − nxn = 0
xm n
n
So, x = m
1 1
xm xm
1
xm +xn
+
1
xm −xn
=
xn
( ) ( )
xn
+1
+
xn xn
−1
( )
1 1
1 n n
n m m
= x +1
+ −1
m 1 1
= xn
( n +m
+ n −m
)
2mn
n 2 2
= x (n −m )
ˉ
If log(0.57) = 1.756, then the value of
a. 0.902
ˉ
b. 2.146
c. 1.902
ˉ
d. 1.146
cat2009 numerical-ability
Selected Answer
1
2
= log(100) + log(0.57) + log(0.57)3 + log(0.57)
= 2 + 4.5log(0.57)
= 2 + 4.5( − 1 + 0.756)
= 0.902
permutation combinations
Selected Answer
Now, two 6's can come as 66x 6x6 or x66, and this counts to 5 + 5 + 4 = 14 numbers (for the last case, x can only be
from 1-4 and not 0)
Now, two 6's can come as 66x 6x6 or x66, and this counts to 5 + 5 + 5 = 15 numbers.
combinatorics numerical-ability
Selected Answer
you can see Here if number of 4 in unit place is odd then unit digit will be 4 and number of 4 in unit place
is even then unit digit will be 6.
Now
4*5*1=20
1793 317 491
Hence unit digit in ( 3474) *( 225 ) * ( 451 ) will be ZERO.
We are given a set X = {x1, x2, …, xn } where xi = 2i. A sample S (which is a subset of X) is drawn by selecting each xi
1
independently with probability Pi = 2 . The expected value of the smallest number in sample S is:
a) 1/n
b) 2
c) √ n
d) n
probability expectation
The area of the triangle in the plane formed by the vertices ( − 1, 0), (1, 0), (cosθ, sinθ) is
numerical-ability geometry
logarithms
Selected Answer
13.16 Logical Reasoning: Who among the following teaches Chemistry gateoverflow.in/9770
top
Eight people – A, B, C, D, E, F, G and H are sitting around a circular table facing the centre, but not necessarily in the same
order. All of them are at equidistant. Each one of them teaches different subjects viz., English, Hindi, Mathematics, Biology,
Psychology, Physics, Chemistry and Accounts, but not necessarily in the same order.
The person who teaches Accounts, sits third to the right of G. C is an immediate neighbour of G. The person who teaches
Mathematics sits second to the left of C. B sits third to the right of H. H teaches neither Accounts nor Mathematics. Only two
persons sit between C and the person who teaches Physics. A and F are immediate neighbours of each other. Neither A nor F
teaches Accounts. The person who teaches English sits second to the right of A. Two persons sit between D and the person
who teaches Hindi. D does not teach Accounts. The person who teaches Psychology is an immediate neighbour of the person
who teaches Accounts. The person who teaches Physics sits second to the left of A. One of the immediate neighbours of G
teaches Chemistry.
logical-reasoning
Selected Answer
A B C D E F G
We have eight people and eight seats around a round table, so a person has two neighbours. Just writing the given
conditions: '-' shows a place taken by a undecided person. (Accounts) means the person teaching Accounts.
1. G _ _ (Accounts)
2. G C or C G
3. (Maths) _ C
4. H _ _ B
5. H no Accounts no Maths
6. C _ _ (Physics) or (Physics) _ _ C
7. A F or F A - both not Accounts
8. A _ (English)
9. D _ _ (Hindi) or (Hindi) _ _ D D not Accounts
10. (Accounts) (Psychology) or (Psychology) (Accounts)
11. (Physics) _ A
12. G (Chemistry) or (Chemistry) G
First seeing Accounts- it is not taught by G or C or H or A or F or D. So either B or E. But seeing the conditions 1 and 4, B
cannot be Accounts as G != H. So, Accounts must be taught by E - condition 13.
So,
G _ _ E
E is teaching Accounts
So, E is teaching Accounts and AF cannot be between G and E. Also, an interesting condition is given in conditions 6 and
11 because it says either C _ _ _ _ A or A C. Now lets see the possibilities for placing H _ _ B by trying to place H in all
possible places.
Case 2: G _ H E _ B _ _ only place for A F is at the end and C is a neighbor of G. So, this case leads to G C H E D B A F
(again using C _ _ _ _ A).
So, there are 3 possibilities for Chemistry- H, C or B. So, answer must be None of these.
Answer : (2) H
13.17 Modular Arithmetic: What will be the in the units place of? top gateoverflow.in/17609
(
Q1) What is the units digit of 3911– 3211 ? )
(a) 1 (b) 5
(c) 7 (d) 8
(a) 0 (b) 2
(c) 3 (d) 7
modular-arithmetic
Selected Answer
In these type of questions, i.e. when you raise a number to some power, find the pattern of unit digit and then solve.
For 3911 : Unit digit of 39 is 9, and thus unit digits of its powers will be 9,1,9,1,... So 3911 ends in 9.
For 3211 : Unit digit of 32 is 2, and thus unit digits of its powers will be 2,4,8,6,2 (and then pattern continues). So 3211
ends in 8.
probability
Selected Answer
One side of the tossed coin is head. So, our sample space now has only two possible coins - HH and HT but both are not
equally probable.
In our sample space we can have 6 possible outcomes: (HT means Head turns up and Tail is on other side)
HH, HH, HT, TH, TT, TT all of which are equally probable.
Now, Head turns up means we now have only 3 events HH, HH and HT and only HT is favorable for the other side being
Tail. So, required probability is 1/3.
It will be equal to
(probability of getting head on the coin with head and tail.) / (probability of getting head in any coin)
=1/3
In any given year, the probability of an earthquake greater than Magnitude 6 occurring in the Garhwal Himalayas is 0.04.
The average time between successive occurrences of such earthquakes is ____ years.
aptitude probability
Selected Answer
0.04 × n = 1
1
0.04
n=
= 25
answer = 25 years
A bag contains 3 balls. Given that one of the balls is red and the other two balls can be either red or non-red..what is the
probability of picking up a red ball?
probability
Selected Answer
First let's see what are the possibilities for other two balls :
probability of Drawing a red ball here is 1 {As all balls become RED }
probability of occuring of this case is 1/4 {As other cases can be RN,NR,NN }
So, Total probability of Drawing a red ball for this case = 1/4 * 1
probability of Drawing a red ball here is 2/3 {As 2 balls are RED }
probability of occuring of this case is 2/4 {As other cases can be RR,NN }
So, Total probability of Drawing a red ball for this case = 2/4 * 2/3
probability of Drawing a red ball here is 1/3 {As one ball is RED }
probability of occuring of this case is 1/4 {As other cases can be RN,NR,RR }
So, Total probability of Drawing a red ball for this case = 1/4 * 1/3
10 men and their wives participate in a corporate mixed-doubles tennis championship. What is the probability that no couple
play in the second game?
A. 0.6222
B. 0.3111
C. 0.4285
D. 0.2777
probability
Selected Answer
Cases were no couples are there = 10 C2 * 8C2 (select 2 men from all 10 possibilities and select 2 women from all
possibilities excluding the 2 wives)
Ram and Ramesh appeared in an interview for two vacancies in the same department. The probability of Ram's selection is
1/6 and that of Ramesh is 1/8. What is the probability that only one of them will be selected?
(A) 47/48
(B) 1/4
(C) 13/48
(D) 35/48
probability
Must be B.
Because only one of the two conditions is supposed to hold, we add the two probabilities to get 1/4.
Edit :
When you solve by using
¯ ¯
P(Ram) + P(Ramesh) − P(Ram ∩ Ramesh) = P(Ram). [P(Ramesh) + P(Ramesh)] + P(Ramesh). [P(Ram) + P(Ram )] − P(Ram). P(Ramesh)
When you simplify these terms by opening the parenthesis, you will find that you are adding an extra P(Ram). P(Ramesh).
Hence, the incorrect answer.
Hope it helps.
A point P is randomly chosen in the line AB of length 2a. What is the probability that the area of the rectangle having sides
AP and PB will exceed a2 /2?
probability
Selected Answer
Let AP = x,
then PB = (2a − x).
Since point P can be anywhere between A & B, x belongs to [0, 2a], thus the total the length of total available range interval
for x = (2a − 0) = 2a.
Area of the rectangle having sides lengths equal to the length of AP & PB = x. (2a − x).
Length of interval range of x, in which x. (2a −x) >a 2 / 2
Length of total available range interval for x
Required Probability = .
_____________________________________________
Finding the interval for x in which (x. (2a − x)) > (a2 )/2.
x. (2a − x) > a2 /2
2ax − x2 > a2 )2
2ax − x2 − a2 > a2 /2 − a2
− x2 + 2ax − a2 > − a2 /2
x2 − 2ax + a2 < a2 /2
(x − a)2 < a2 /2
| x − a | < a/ √ 2 ------------------------- Inequality I
When x < a, − (x − a) < a/ √ 2
When x < a, (x − a) > − a/ √ 2
x > a − (a/ √ 2).
So when x belongs to [0, a], the range of x in which x. (2a − x) will be greater than a2 /2 would be (a − (a/√2), a].
Now, when x > a, from inequality I, (x − a) < a/ √ 2,
When x > a, x < a + (a/ √ 2).
So when x belongs to [a, 2a], the range of x in which x. (2a − x) will be greater than a2 /2 would be [a, a + (a/ √ 2)).
Hence, overall when x will belong to (a − (a/ √ 2), a] ∪ [a, a + (a/ √ 2)), that is, (a − (a/ √ 2), a + (a/ √ 2)), then (x. (2a − x)) will be greater
than a2 /2.
So length of favourable interval = ((a + (a/ √ 2)) − (a − (a/ √ 2))) = √2a. & the length of all available interval, i.e. the interval
[0, 2a] = 2a − 0 = 2a.
http://www.techtud.com/doubt/virtual-gate-2015-question-6
In the question u are required to calculate A's winning probability so it would be-->
Let probability that A throws sum 8 be P(A) (=5/36) and probability that B throws 7 be P(B) ( =6/36) in a single attempt
P(A)+ P(A')*P(B')*P(A)+P(A')*P(B')*P(A')*P(B')*P(A)+........ (it is simply either A throws 8 in first attempt or in third attempt and so on while B does not throws a 7)
therefore
=(5/36)*1/(1-155/216)
=(5/36)*(216/61)
=30/61
A. -6
B. 2
C. 6
D. 10
Selected Answer
3( − √ 3 + 1)3 + a( − √ 3 + 1)2 + b( − √ 3 + 1) + 12 = 0
3( − 3√ 3 + 9 − 3√ 3 + 1) + a(3 − 2√ 3 + 1) + b( − √ 3 + 1) + 12 = 0
a(3 − 2√ 3 + 1) + b( − √ 3 + 1) − 18√ 3 + 42 = 0
4a + b = − 42 [ by adding ]
2a + b = − 18 [ by subtracting]
a = − 12 and b = 6
q p l
a. √ p
+ √ q
+ √ n
=0
p q n
b. √ q
+ √ p
+ √ l
=0
q p n
c. √ p
+ √ q
+ √ l
=0
p q l
d. √ q
+ √ p
+ √ n
=0
α p
α+β p +q
so β = q -------(1)
β q
And α = p
α+β p +q
α
= p --------(2)
α+β α+β p +q p +q
α β p
× = × q
(p +q )2 (α+β)2
pq αβ
=
(p +q ) (α+β)
√pq √αβ
= -------------(3)
p q
√ √ q
+ p
p +q
√pq
=
(α+β)
√αβ
= [From (3)]
−n
b
√
n
b
==
= − √ b
p q n
so, √ √ q
+ p
= − √ b
p q n
√ √ √ q
+ p
+ b
=0
The resistance of a wire is proportional to its length and inversely proportional to the square of its radius. Two wires of the
same material have the same resistance and their radii are in the ratio 9:8. If the length of the first wire is 162cms, find the
length of the other.
a. 64cm
b. 120cm
c. 128cm
d. 132cm
Selected Answer
Resistance of a wire is directly proportional to its length and inversely proportional to square of its radius
l
2
So, Resistance, R ∝ r
l
r2
R = k , where k is some constant.
Say R1 , l1 , and r1 are Resistance, length and radius for first wire, similarly R2 , l2 , and r2 for second wire
r1
9
r2
Given, = 8 and l1 = 162cm
So, R1 = R2
l1 l2
r21 r22
k =k
r2
()
8
()
2 2
r1 9
l2 = l1 = 162 ×
128cm
In a Certain office,1/3 of the workers are women,1/2 of the women are married and 1/3 of the married women have
children. If 3/4 of the men are married and 2/3 of the married men have children. What part of the workers are without
children??
my answer is 11/18 but given to be correct is 5/18??help guys.. but please mention the complete procedure.
numerical-ability ratios
Selected Answer
Now married workers without children = married women without children + married men without children
Q.5
In the given figure, triangles ABC and PQR are right angled triangles with angle C and Q being right angles. QR is parallel to
AC and AB = 300 cm, PQ = 20 cm and QR = 100 cm. The length of side BC to the nearest integer is ___________ cm.
Selected Answer
Answer : 59 cm
PR2 = PQ 2 + QR2 .
⇒ PR = √1002 + 202,
⇒ PR = 102 cm ( after rounding off).
∠PQR = ∠BCA = 90 ∘ ,
Now since the above two pairs of angles in ΔPQR and ΔBCA are equal, the third pair of angles i.e. ∠QPR and ∠CBA will
also be equal to each other.
Using a property of similar triangles, ratio of corresponding sides of both the triangles will be same,
BC PQ
that is AB = PR ,
PQ×AB
PR
⇒ BC = ,
20×300
102
⇒ BC = = 58.82 cm.
13.30 Virtualgate: Row echelon form having more than 2 non-zero entries
Virtual Gate 2016 top gateoverflow.in/38665
1). If the row reduced form of a matrix has more than two non-zero entries in any row, then the corresponding system of
equations has inifinitely many solutions.
2). If the row reduced form of a matrix has more than two non-zero entries in any row. then the corresponding system of
equations either has infinitely many solutions or no solutions.
For infinite or no solutions, shouldn't the number of equations be less than number of variables? If we have more than 2 non
zero, then its good, because then we will have more number of equations? How is the answer C?
virtualgate matrices
Reduced row echelon form is used to find the nature of the solution set of the system.whether the solution is finite or infinite or single
A linear system is said to be consistent, if it has either one solution or infinitely many solutions. A system is inconsistent if it has no solutions.now first thing is
how do we determine whether the system of linear equation is consistent or inconsistent , well consider a system of equations where we have 'n' columns or
variables and 'm' numbers of rows or equations .In augmented matrix form if the right most column or the n+1 column is not a pivot or leading 1 ,we have a
consistent system,otherwise we have an inconsistent system ,statement below is a theorem
THEOREM:
A).A linear system is consistent if, and only if the rightmost column of the augmented matrix is not a
pivot column.
Once it is decided that the our system is consistent we have a to find the number of dependent and independent or free variables.Again all the variables
corresponding to the pivot columns are dependent variables and rest are free variables the system of equations below and its reduced echelon form shows the
dependent and independent variables.
[ ]
1 −1 0 0 3 6
0 0 1 0 −2 1
0 0 0 1 4 9
0 0 0 0 0 0
0 0 0 0 0 0
Here column 1, 3, 4 are pivots while columns 2, 5, 6 are not pivots or represent free variables.Here column 6 is not a pivot which shows that
system of equation is consistent
equipped with information about the system consistency and free variables .we are able to find the nature of solution. Again a theorem
THEOREM:
B). If a linear system is consistent, and if there are no free variables, there exists only 1 solution. If
there are free variables, the solution set contains infinitely many solutions.
In picture above r is the number of pivots or non zero rows and n is the number variables
According to the above theorems and explanations C can only be true iff instead of no solution it is one solution.This question has some discrepancies.
A
natural
number
n
is
such
that
120
≤
n
≤
240.
If
HCF
of
n
and
240
is
1,
how
many
values
of
n
are
possible?
Options:
24
32
36
40
aptitude virtualgate
Selected Answer
240 = 24 × 3 × 5
so we need to find the numbers, such that, 120 ≤ n ≤ 240 , and not divisible of 2 or 3 or 5
Total numbers such that 120 ≤ n ≤ 240 and not divisible by 2 or 3 or 5 = 121 − 89 = 32
13.32 Virtualgate: Virtual Gate 2016 set I Birthday problem top gateoverflow.in/38657
Q) Vivek and Rishabh just become friend with Suchita , and they want to know when her birthday is Suchita gives them a list
of 10 possible options?
June 17 June 18
July 14 July 16
Suchita then tells Vivek and Rishabh separately the month and the day of her birthday respectively
Vivek : I don't know when Suchita's birthday is, but I know that Rishabh does not know too.
Rishabh: At first Ididn't know when Suchita's birthday is, but i know now.
(A). May 16
(B). June 17
(C). July 16
virtualgate aptitude
Options:
128
138
338
388
virtualgate
Selected Answer
625 × 16 = 10000
i.e. anything which is multiple of 10000 will also be multiple of 625
8888…8 8888…8
100 times = 96 times × 10000 + 8888
88888888888888…8
So to find reminder of 100 times , just find Reminder when 8888 is divided by 625
4
5
Atul does half as much work as Anshu in of the time. If together they take 16 days to complete the work, how many days
shall Anshu take to do it?
A. 23
B. 25
C. 26
D. 30
numerical-ability work-time
Selected Answer
x
a
Time Anshu takes for x amount of work = .
4x 8x
5a
Speed of Atul = 8
5a 13a
13a
13a 1
--> Let Anshu takes x Days , than Atul takes (2*(4/5)x) = 8x/5 Days.
--> Together Atul and Anshu takes = 16 Days . So, Together 1 Day work = 1 / 16 .
how much coal will required for 8 engines each running 13 hours a day it is been given that 3 engines of former type
consume 4 engines of latter type ?
how much coal will required for 8 engines each running 13 hours a day
1 3
3
Will be 8 × 13 × × 4 = 26.
100
Find the least significant digit of 23 ×10
A. 2
B. 4
C. 6
D. 8
numerical-ability
Selected Answer
100
23 ×10
= 230…00
= 275×4 ×100 …0
The answer given above is correct. Least significant digit is 6. Here is a different approach.
24 = 16 , 28 = 256
Thus, any power of 2 which is multiple of 4 will have least significant digit as 6.
24 = 16
25 = 32
26 = 64
27 = 128
1)characters
2)Numbers
3) Image
4) Sound
5) none of these
Selected Answer
http://www.socialresearchmethods.net/kb/datatype.php
aptitude
Selected Answer
Caption
aptitude
Selected Answer
1. S, P, M and E are four persons, working on project efficiency of M is twice that of others and M
works only for half of the total days worked by E. M works 6 hours/day and E works 12
M work done by
aptitude
eff of M =2xperhr
numerical-ability
There are four persons wearing different colour shirts and four gift packs of colours, same as
those of the shirts. The number of ways in which the gifts, one each to a person, could be
given such that a gift does not go to a person of his shirt colour is
Selected Answer
It is a derangement problem
Answer is 9
top
ABCD is square eacg side measuring 4√2.P Q RS are mid points of side AB BC CD DA A circle is drawn inside quadrilateral by
joining PQRS touching all sides..Find area of circle
Selected Answer
QUESTION 8 : A bag contains 5 balls out of which some or maybe all are black. 2 balls are drawn from the bag and both are found to be black.
What is the probability that all balls in the bag are black?
As three balls are left in the bag, we first draw the third ball & check for its colour & so on.
p(b)=p(third)*p(fourth)*p(fifth)
=1/48
25. Suppose that someone starts with a chain letter. Each person who receives the letter is asked to send it on to 4 other
people. Some people do this, while some do not send any letter. How many people have seen the letter, including the first
person, if no one receives more than one letter and if the chain letter ends after there have been 100 people who read it but
did not send it out ? Also find how many people sent out the letter ?
(A) 122 & 22 (B) 111 & 11 (C) 133 & 33 (D) 144 & 44
combinatory
Selected Answer
Either a person sends to 4 people or he doesn't send it. So, let x be the number of persons who sends to 4 people. 100
people didn't send any letter. Except 1 (the initial person) all others (x + 100) must have a sender. So, we can write
x + 100 = 4x + 1 3x = 99x = 33
ans-c
from basic, consider one sender , he send to four other who only read
" three " they send to ten other receiver who only read
this form AP having comman difference 3, and a/q total number of reciever who only read is 100 that is our last term
so, 4+(n-1)*3=100
If x1 + x2 + x3 + x4 = 98 and x1 , x2 , x3 and x4 are odd numbers, calculate total number of solutions of the equation?
combinatory
Selected Answer
LET
X1=2a+1
X2=2b+1
X3=2c+1
X4=2d+1 .....................
13.47 A vessel is filled with liquid, 3 parts of which are water and 5 parts
syrup.... top gateoverflow.in/42211
A vessel is filled with liquid, 3 parts of which are water and 5 parts syrup. How much of the mixture must be drawn off and replaced with water so that the mixture
may be half water and half syrup?
1 1
A. B.
3 4
1 1
C. D.
5 7
Answer is C
Suppose the vessel initially contains 8 litres of liquid. Let x litres of this liquid be replaced with water.
3x
5x
5x + 24 = 40 - 5x
10x = 16
8
∴ x = ( 5 )
8 1 1
13.48 The sum of all integers from 1 to 1000 that are divisible by 2 or 5 but
not divisible by 4 equals top gateoverflow.in/41761
The sum of all integers from 1 to 1000 that are divisible by 2 or 5 but not divisible by 4 equals
1. 175000
2. 225500
3. 149500
4. 124000
Selected Answer
but numbers like 10,20,30...are divisible by both 2 & 5 so they will be counted twice so we need to subtract them..to get
the numbers that are only divisible by 5
that is multiples of 10
sum= 175000
so
d*y+280=3344 --------------(IV)
from eq (I)
a*y =766
from eq (II)
b*y =1915
from eq(III)
c= 7
from eq (IV)
d= 8
y (divisor) = 383
Remainder = 280
How many numbers without repeating the number or digit less than 1000 are divisible by 5 can be formed ?
numerical-ability
1)ending in 5=9
3)ending in 0=8
So total numbers=64+72+17+1=154
1. 327
2. 333
3. 334
4. 336
numerical-ability
All numbers b/w 000 to 999 which are divisible by 3. So, total 334 elements.
How many 4 digit no. can b formed wit digits 1, 2, 3,4,5 which r divisible by 4 and digits not repeated?
Answer is 24.
Last 2 digits should be divisible by 4 for the number to be divisible by 4.Last two digits should be 12 or 32 or 52 or 24 and
corresponding to these 4 possibilities we can have 3*2=6 numbers in the starting two digits.
Selected Answer
then group 173 and 183 and 163 and 193 in both the cases x+y gives 35 take 35 as common from the entire
expression the resultant expression within the bracket will be (16² - 16·19 + 19² + 17² - 17·18 + 18²)
the entire expression evaluates to be as even and hence the original expression is divisible by both 35 and 2
and hence by 70. So the resultant remainder is 0
13.53 8 litres are drawn from a cask full of wine and is then filled with
water.... top gateoverflow.in/42210
8 litres are drawn from a cask full of wine and is then filled with water. This operation is performed three more times. The ratio of the quantity of wine now left in cask
to that of water is 16 : 65. How much wine did the cask hold originally?
A. 18 litres B. 24 litres
C. 32 litres D. 42 litres
Answer is C
x(1 − x )4 16
x
= 81
8 2
x 4
(1 − ) = ( 3 )4
8 2
(1 − x ) = 3
x−8 2
( x )= 3
3x - 24 = 2x
x = 24
The traffic lights at three different road crossings change after every 50s,75s and 100s respectively.If they start changing
simultaneously at 10 am,after how much time will they change again simultaneously?(Ans:-5min)
So, 300 seconds is the least interval after which they will change simultaneously; and they will continue to change
simultaneously in the interval of multiples of 300 seconds(5 minutes).
13.54 The odds in favour, of standing first of three students Amit, Vikas and
Vivek appearing at an examination are 1:2.2: 5 and 1 :7. respectively. What
is the probability that either of them' will stand firs t (assume that a tie for
the first place is not possible) top gateoverflow.in/9388
aptitude
The odds (in favor) of an event or a proposition is the ratio of the probability that the event will happen to the probability that the event will not happen
So, required probability = P(First person standing first) + P(Second person standing first) + P(Third person standing first)
= (56 + 48 + 21)/168
= 125/168
To find the number of digits(not bits) in a number, say x, we need to find the ceiling of log base ten of x, that is
log10x .
Given log2 = 0.30103, it seems a bit incomplete as the base of logarithm is not mentioned.
However since 100.30103 ≈ 2, so it can be inferred that in log2 = 0.30103 the base of log should be 10.
( )
log10 264 = 64log102 = 64 × 0.30103 = 19.26592 = 20.
Selected Answer
7*1+1=8
8*2+2=18
18*3+3=57
57*4+4=232....
There is a rectangular Garden whose length and width are 60m X 20m.There is a walkway of uniform width around garden.
Area of walkway is 516m^2. Find width of walkway
1/2/3/4
Selected Answer
Area of the outer rectangle will be (60+2*x) * (20+2*x)....(As length and width will get increased by 2*x)
x2 + 40*x -129=0
So answer is 3
Natural numbers like 1, 3 = 1 + 2, 6 = 1 + 2 + 3 etc are referred to as triangular numbers. In other words, a triangular
number is a natural number which is equal to the sum of all the preceding natural numbers. How many triangular numbers
exist if a set of first 2100 natural numbers is taken?
ABC is a 3 digit number.The sum of its digits is 8.If each of BA and BC are 2 digit numbers such that BA=BC-2,then the
number of values "C" can take?
aptitude
BA=BC-2
i.e A=C-2
possibilities
2 2 4
1 4 3
3 0 5 also satisfies those two conditions but BA and BC won't be 2 digit numbers as B=is 0
aptitude
Selected Answer
2 x 1.5 =3
3 x 2 = 6
6 x 2.5 =15
15 x 3 = 45 <- ans
2*1.5 = 3
3*2 = 6
6*2.5 = 15
15*3 = 45
45 * 3.5 = 157.5
So 45
multiply the first number (2) by 1.5 then increasing the multiplier by 0.5 at each step.
2 x 1.5 = 3
3 x 2.0 = 6
6 x 2.5 = 15
15
x
3.0
=
45
45 x 3.5 = 157.5
157.5 x 4.0 = 630
Hence Answer is 45.
Hello folks, how to solve Log64/Log16 ( i.e. log 64 divided by log 16) what will be the value?
Thanks!
Selected Answer
Assuming base as 2
log2 64 log2 26
log2 16 log2 24
=
=
4
{using property: logaam = m
3
2
=
Also, you don't even need to assume the base 2 for log. Remember the following property of logarithms:
logxa
logxb
= logba
So,
logx64
logx16
= log1664
3
=
2
{ ∵ √163 = 163 / 2 = 64
Selected Answer
60 X + 18 Y = 25(X+Y)
=>35 X = 7 Y
Q.10
Given and Q = a,b,c are positive integers. What is the number of ordered triplets ( a, b, c) such
that a + 2b + c ≤ 40?
Selected Answer
P=a/c+a/b+1
or, P=(ab+ac+bc)/bc.................(i)
Q=b/a+b/c+1
or, Q=(ab+ac+bc)/ac....................(ii)
or, a=11b
if b=1 a=11
equation a + 2b + c ≤ 40
or, 11+2+c≤40
or,c≤27
So, C can get 27 values and for that 27 values we get 27 triplets
like(11,2,1),(11,2,2),...................(11,2,27)....................i
So,triplet (33,6,1).......................................................iii
27+14+1=42 triplets
Q.4
Three friends Mukesh, Rajesh and Chetan walk from point A to B which are the two ends of the diameter of a semi circular
park. Mukesh takes the shortest path along the diameter whereas Chetan takes the longest path which is along the
periphery and Rajesh walks along two straight lines AC and CB where C is a point on the periphery of the semi circular park
such that AC + CB is maximum possible length. If all three reach B simultaneously, then what is the ratio of speeds of
Mukesh, Rajesh and Chetan respectively?
2 : 2*root(2) : pi
2*root(2) : 2 : pi
root(2) * pi : pi : root(2)
pi : 2 * root(2) : 2
numerical-ability
Selected Answer
2: 2√ 2: π
13.65 Find the odd one from the following group: top gateoverflow.in/30238
(A) W,E,K,O
(B) I,Q,W,A
(C) F,N,T,X
(D) N,V,B,D
aptitude
Selected Answer
First letter [after 7 letters] Second letter [after 5 letters] Third letter [after 3 letters] Fourth letter
square and regular octagon has same perimeter..find ratio of area octagon to square...
Selected Answer
Let the lengths of the sides of square be b and the sides of octagon be a.
Given: 4b = 8a
b = 2a
(2acos(22.5 ∘ ) ) × (2acos(22.5 ∘ ) )
= 4a2 cos2 (22.5 ∘ )
1 − cos2x
(
= 2 × a2 1 + sin(45 ∘ ) )
Area of the triangle can be calculated as follows:
2×
2
(acos(22.5 ∘ ) × asin(22.5 ∘ ) )
a2 sin(45 ∘ )
= 2
{sin2x = 2sinxcosx
a2 sin(45 ∘ )
2
=
2a2 + 2a2 √ 2
= b2
2a2 + 2a2 √ 2
4a2
=
1 + √2
= 2
Three boxes labeled A, B and C have a total of 249 marbles. If 3 dozen marbles are transferred from box ‘ A’ to box ‘B’, box
‘B’ will have 5 times the number of marbles in box ‘ A’. Instead, if 21 marbles are transferred from box ‘ B’ to box ‘C’, the
number of marbles in box ‘B’ will be 1.5 times the number of marbles in box ‘ C’. How many marbles should be transferred
from box ‘A’ or ‘B’ so that the number of marbles in both ‘ A’ and ‘B’ is identical?
made-easy numerical-ability
x+y+z=249
y+36=5(x-36)
y-21=1.5(x+21)
129-k=69+k
2k=60
k=30
so ans is b
A man drives 25 km in city and then increases its speed by one fourth of its original and reaches its destination 40 mins
early..if he had done the same 10 km earlier it would have saved another 5 min...find total distance travelled by car?
Selected Answer
Let (x+25)Km is total distance , t hr is time to reach the destination with speed s km/h
so time = distance/time
(x+25)/s = t ---------------(i)
if after 25km he increase his speed by 1/4 of original ,i.e, with 1.25s km/h , he reach his destination 40 min early , i.e
40/60 hr early,i.e, he takes (t - 40/60) hrs
if after 15km he increase his speed by 1/4 of original ,i.e, with 1.25s km/h , he reach his destination 45 min early , i.e
45/60 hr early, i.e, he takes (t - 45/40) hrs
s = 24 km/h
x = 80 km
Q.10
Venkat earns Rs 18,00,000 per annum which is spent under various heads as under:
Food : 24%
Transportation and House rent : 19%
Clothing : 9%
Miscellaneous heads : 22%
Savings : 14%
Loan installment : Rs 18,000 per month.
If he cuts down his expenditure on food by 4.33% and his clothing expense is down by 4% and the entire saving thus
achieved is used to pay off his loan, then the increase in the monthly installment of loan that he can afford is Rs
______________ .
Current food expenditure are 24% of the annual income, after reducing it by 4.33%, it will become
(100 −4.33 )
( 24 × 100
) % = 22.9608%.
(100 −4 )
Current clothing expenses 9% of the annual income, after reducing it by 4%, it will become 9 ×
( 100
) % = 8.64.
Thus total annual savings achieved by chopping Food & Clothing expenses = ((24 − 22.9608) + (9 − 8.64))% of Rs 18, 00, 000.
= 25185.60 Rs
25185.60
12
So we can increase the monthly instalments by Rs or Rs 2098.8
A boy sells apples for 12 cents each and pears for 7 cents each.Suppose the boy collected
$3.21.How many apples and pears did he sell?
The monthly rainfall chart based on 50 years of rainfall in Agra is shown in the following figure. Which of the following are
true? (k percentile is the value such that k percent of the data fall below that value)
aptitude
Logically 5 percentile curve must always lie below 95 percentile which actually is the case here.
(I) ON AVERAGE, it rains more in July than in December : It is a direct conclusion from the "Average" curve on the
graph.
Since July lies above in Average curve than December, it implies that on average, July is more rainy than December.
So it must be true.
(II) EVERY YEAR, the amount of rainfall in August is more than that in January : The plot gives no information
about the rainfall during individual years, it is a combined plot of 50 years.
Out of 50 years, there are 2 -3 years when the rainfall may drop to a very minimal value (say 0 mm) in August & in the
same year it is also possible that 100 mm Rain falls in January.
Hence false.
Above two deductions are strong enough to answer this question, as only option B is consistent with the conclusions
derived so far.
(III) July rainfall can be estimated with better confidence than February rainfall : It can be observed that the
difference between 95 percentile plot and 5 percentile plot at July is smaller than that at February (thin shaped graph at
July & thick at February).
It shows that for 90% of the data, variance in rainfall at February is higher than variance in rainfall at July.
It means that in July most of the times(90%) the rainfalls are densely spread around average rainfall, but in Feb they are
sparsely spread around the average rainfall.
(IV) In August there is AT LEAST 500 mm of rainfall : This is false, as the plot does not provides any information
about the minimum & maximum rainfall in any Month.There might be no rainfall (0 mm) during August in a particular
year.
13.72 What is the cost of production in Rs per tonne for a daily production of
100 tonnes? top gateoverflow.in/30165
A foundry has a fixed daily cost of Rs 50,000 whenever it operates and a variable cost of Rs 800Q, where Q is the daily
production in tonnes. What is the cost of production in Rs per tonne for a daily production of 100 tonnes?
gate-aptitude aptitude
130000
this is a cost for 100 tonnes. So, per ton production cost = 100 = 1300
There are 1000 villages and 1000 salesmen. 1st salesman visits every village. 2nd salesman visits every 2nd village starting
from the second village. 3rd salesman visits every 3rd village starting from the third village. This process goes on till 1000th
salesman visits the 1000th village (i.e. last village). Which of the following villages is visited by maximum number of
salesman?
So a village which is visited by maximum number of salesman has largest number of multiples (between 1 and 1000).
We can find the required village by finding L.C.M. of first few numbers until it crosses 1000. We will stop when L.C.M. goes
beyond 1000. So required village will be largest L.C.M (or its multiple) of first few numbers which is just smaller than
1000.
L.C.M. of 1 is 1.
L.C.M. of 1,2 is 2.
L.C.M. of 1,2,3 is 6.
We can't go beyond 840 because L.C.M. of 1,2,3,4,5,6,7,8,9 is 2520 which is beyond 1000.
if we solve using finding factor method i think it should 720 because salesman only visit a village if it divides completely
that village number according to question.
2 i
∑∑
i j (1)
value of i and j must be initialized then only we can calcuate the result because iteration of inner loop depends upon the
outer loop.
A tank is filled by three pipes with uniform flow. The first two pipes operating simultaneously fill the tank in the same time
during which the tank is filled by the third pipe alone. The second pipe fills the tank 5 hours faster than the first pipe and 4
hours slower than the third pipe. The time required by the first pipe is:
A. 6 hours B. 10 hours
C. 15 hours D. 30 hours
numerical-ability
Selected Answer
Option c
=(2x+5)/(x2+5x) work
X-4= (x2+5x)/(2x+5)
By solving it x=10 hr
consider a stack A with 4 elements a,b,c,d with a being top of the stack . satck B is empty . an element popped out of stack
A printed imidiatly or pushed to stack B. an entry popped out of stck B can only be printed . in tis arrangement how many
numbers of possible permutation will be there to print output?
13.77 How can two angles be 90 degree in a right angled triangle ? top gateoverflow.in/14654
If the ratio of sine of angles of a triangle is 1:1: sqrt(2) then the ratio of square of its greatest
side to sum of the squares of other two sides is ...
I am not getting that if sin A=1 then A =90 as well as sin B =1 then B =90 , so how can it be possible , a bit confused in this
,plz clarify this ...
Selected Answer
Here just by looking, we can infer the three angles as 45, 45, 90 degrees (hence ratio of sine is 1:1: √ 2). It is a right
angled triangle, and so square of largest side is equal to sum of squares of other two sides, and so the ratio asked in
question is 1.
In general, you can find angles as follows : Given ratio of sine as 1:1: √ 2, let actual sine of angles be k, k, √ 2k.
So sin(A + B) = sin(180 − c)
k 1 − k2 +
√ √1 − k2 ∗ k = √2k
2 1 − k2 =
√ √2
4(1 − k2 ) = 2
1
√2
k=
1 1
√2 √2
So sine of angles are , , 1, hence angles are 45, 45, 90 degrees.
remainder=?
5625/7=?
5 mod 7 = 5
25 mod 7 = 4
125 mod 7 = 6
625 mod 7 = 2
3125 mod 7 = 3
15625 mod 7 = 1
125
5625 = 55 = 3125125
A man purchases 11 articles @ 10rs per article and sells 10 articles @11 rs per article.Find The Overall Loss or Gain% ?
a)23%
b)21%
c)26%
d)20%
answer is B option but i want explanation for this type of GA questions .Thanks
numerical-ability
Selected Answer
If we go by general questions like these, your question is slightly incorrect. It should be "11 articles at Rs. 10" (not per
article). Similarly "10 articles at Rs. 11" (not per article).
( ) 110
10
profit% =
( ) ∗ 100 = 21%
11
For your exact question, the answer is simple, profit on one article = Rs. (11-10) = Re. 1
In general, for these type of questions, find CP and SP of one item and find profit/loss accordingly.
1)If P+45 and P+136 are two perfect squares(P is integer) then how many value exist?
2)if n+50 and n+81 are two perfect squares fibd sum of digits of n
Selected Answer
P+45=x^2
=>P=x^2-45............i
P+136=y^2
=>P=y^2-136............ii
x^2-45=y^2-136
=>y^2-x^2=91
=>(y+x)(y-x)=13*7
So, y+x=13.............iii
and y-x=7...............iv
y=10, x=3
putting it in eqn. i
P=9-45=-36
So, 1 solution
Ans is 1)
Part 2
n+50=x^2
n+81=y^2
X^2-50=y^2-81
y^2-x^2=31
y=16 x=15
n=225-50=175
So sum of digits=9
hariharan is fond of shopping , he took an amount of more than 10 and less than 20 rs, with aform of 1rs coins and 20 paisa
coins ...when he come back he had as many 1rs nots as many 20paisa coins and as many 20paisa coin as he originally had
one rupiee notes . total was reduced by two third thus he spent ?
Let x is the number of 1Rs notes and y is the number of 20 paisa coins.
when he come back after shopping ,then he had, number of 1Rs notes is as many as 20 paisa coins he originally had, and
Number of 20 paisa coins is as many as 1Rs notes, he originally had .
so y + (0.20)x = 3 (x + 0.20y)
3y + 0.6x = x + 0.2y
0.4x = 2.8y
x = 7y ------(1)
Hariharan originally took the amount for the shopping was greater than 10Rs and less than 20Rs
It takes 30 min to empty a half full tank by draining it at constant rate. It is decided to simultaneously pump water into the
half full tank while draining it. What is the rate at which water should be pumped so that it gets full in 10 minutes?
numerical-ability
Selected Answer
it takes 30 min to do tank empty by draining when it is half filled , 2 distance, with rate Vd
x
2
x
30 2
Vd = or = 30Vd
(Vu − Vd ) × 10 = 2
Vu = 4Vd
Let d be Draining Rate, p be Pumping Rate and L be the capacity of the tank.
L
30 × d = 2
L
2
(10 × p) − (10 × d) =
10 ⋅ (p − d) = 30 ⋅ d
p−d=3⋅d
p=4⋅d
1 1 1 1 1
a b c d
If a, b, c, d and e are positive real numbers, then the minimum value of (a + b + c + d + e)( + + + + e ) is
1. 25
2. 5
3. 125
4. Cannot be determined.
Its answer is A) 25, when all a,b,c,d and e are=1, in all other cases It will be greater than that. Try Hit and trial and option
elimination
13.84 the number of bit strings of length 8 that will either start with 1 or end
with 00 is? top gateoverflow.in/15898
the number of bit strings of length 8 that will either start with 1 or end with 00 is?
string starting with 1 - 8 places 1 place fixed .7 places have 2 choices . 2^7=128
common strings will be there that have been counted twice are . starting with 1 and ending with 00. such number of
string will be .
total = 128+64-32=160
13.84 . The probability that two friends are born in the same month is_? (a)
1/6 (b) 1/12 (c) 1/144 (d) 1/24 top gateoverflow.in/15032
Selected Answer
Let us say that what is the probability that they are not born in same month?
A can be born in any of 12 months and B can be born in any of the remaining 11 months ⇒ Total possible cases = 12 x
11 = 132
⇒ The probability that they are not born in same month = 144
132 12 1
⇒ The probability that they are born in the same month 1 − 144 = 144 ⇒ 12
Alternatively,
Let the first friend be born in any of the 12 months. For the second friend we have 12 cases and only 1 is favorable. So,
1
probability = 12 .
B) 1/12
13.84 In order to maintain the price line , a trader allows a discount of 10%
on the marked price of goods in his shop . however ,he still makes a gross
profit of 17% on the cost price .Find the profit percent he would have made
on the selling price had he sold at the marked price ? top gateoverflow.in/14738
Selected Answer
gain% =17%
=17/100*100
gain=17
Sp-Cp=gain
sp-100=17
SP=17+100
SP=117
discount= 10% of MP
let MP be x
10/100x=1/10x
discount
=1/10x
SP=MP-discount
117=x-1x/10
10x/10 - 1x/10=117
9x/10=117
9x=117*10
x=1170/9
x=MP=130
MP-CP=difference between both
130-100= 30
difference/CP*100
30/100*100
30%
ans is 30% . let us suppose c.p.=100 so after discount he sold at 117 so that he gets 17% profit
x-x/10=117=>x=130
test-series numerical-ability
Selected Answer
Logic ->
Now compare two set of 3 coins each. Now if they are equal then throw them away & Compare remaining 2 coins with
each other. Then lighter one is correct.
In case if one set of 3 coins is lighter than other set, throw remaining 5 coins away.
Compare any two coins , if one of them is light that coin is defective. If both are equal coin we have not compared is light.
13.86 How much percent more than the cost price should a shopkeeper mark
his goods ... top gateoverflow.in/14737
How much percent more than the cost price should a shopkeeper mark his goods, so that after allowing a discount of 12.5 he
should have a gain of 5 on his outlay?
Selected Answer
Suppose cost price is Rs. 100, then since he wants 5% profit, he should sell it at Rs. 105, but Rs. 105 is after applying
12.5% discount.
So after giving discount on some Rs. x, he should have Rs. 105. i.e.
12.5x
So he should mark the goods at Rs. 120 i.e. 20% more than cost price.
Triangles ABC and CDE have a common vertex C with side AB of triangle ABC being parallel to side DE of triangle CDE. If
length of side AB = 2 cm and length of side DE = 7 cm and perpendicular distance between sides AB and DE is 7.2 cm, then
find the sum of areas of triangle ABC and triangle CDE.
aptitude
Selected Answer
Proof ∆ABC ≂∆CDE (alternate angle and vertical angle are same ,so using AA property both are similar) therefore,
Area ∆ABC/Area ∆CDE =(AB/DE)^2 =(2/7)^2 ,Now we know that Area ∆ABC = 1/2 *h1*AB and Area ∆CDE = 1/2
*h2*DE where h1 and h2 are height of triangle ABC and CDE respectively
4/49 =(h1*2)/(h2*7) --> h1/h2 =2/7 Now h1+h2 =7.2 we get h1 = 1.6 and h2= 5.6 and sum of both triangle area
=21.2
The linear operation L(x) is defined by the cross product L(x) = b × x, where b = [ 0 1 0 ]T and x = [ x1 x2 ]
x3 T are three
dimensional vectors. The 3 × 3 matrix M of this operation satisfies
[]
x1
L(x) = M x2
x3
(A) 0, + 1, − 1
(B) 1, − 1, 1
(C) i, − i, 1
(D) i, − i, 0
eigen-value engineering-mathematics
14.2 Equivalence Classes: Consider these statements, of which the first three
are premises and the fourth is a valid conclusion. top gateoverflow.in/43437
Question is how do we know that what we should assume before converting such a problem using quantifiers. As they they
assumed in this solution like P(x), Q(x), R(x), ....are some statements..
Let P(x), Q(x), R(x), and S(x) be the statements “x is a hummingbird,” “x is large,” “x lives on
honey,” and “x is richly colored,”.
in my solution if i assume something else other then these and i get some different ans , so that ans would be right or wrong
.
mathematical-logic equivalence-classes
14.3 First Order Logic: Write first order expression for the following top gateoverflow.in/19451
mathematical-logic first-order-logic
B(x) = x is a believer
RG(x) = x respects God
B(x) = x is a believer
L(y, x) = y loves x
R(x, y) = x respects y
Which of the following is a correct predicate logic statement for “Every Natural number has one successor” ?
first-order-logic
Selected Answer
14.5 First Order Logic: Write these graph properties as first order expression
(assume graph is undirected) top gateoverflow.in/19577
1. The given graph is a clique (there is edge between every pair of vertices)
2. Every vertex has degree at least two (there is minimum two edges starting from every vertex )
first-order-logic
Selected Answer
please tell how to approach this types of qs,this type of qs came many times in gate.I tried it by making table,but it is not
doable..so,help me.
mathematical-logic first-order-logic
Selected Answer
You can do that even without picking pen with the help of boolean algebra
Note: p → q = pˉ or q = pˉ + q
See Try to prove that the given option is not tautology by making T--->F i.e., Try to make LHS of Implication True and
RHS be False...
Opt a)
So if p is made true then r V s of LHS has to be true. ie. r or s has to be true to make LHS true. (so i take p to be true)
If s is made true then RHS also becomes true which we do not want as T-->T is True
if r is made true and since we had taken p as true as LHS then RHS also becomes true thus there is no scope that RHS
becomes False.thus it is tautology..
Now Opt b)
If q on LHS is made true then RHS becomes True which we do not want
Now Either r or s has to be true so if we take s true then LHS becomes true and consequently RHS becomes true. but now we
put r as true it becomes that T--->F so it is not tautology...
14.7 First Order Logic: First Order Logic Question: English to predicate gateoverflow.in/32926
top
2. Let S(x) be the predicate "x is a student," B(x) the predicate "x is a book, " and H(x,y) the predicate "x has y, " where the universe of discourse is the
universe, that is the set of all objects. Use quantifiers to express each of the following statements.
Answers:
will someone explain briefly ? I tried my best to dechiper in to predicate, But failed.
This type of questions are somewhat tricky...Okk let starts with statment...
See every statement and see the beginning phrase properly..if it statemts with
No focus on each question implication is used whenever there you have to ensure that there is no condition such that left
is true and rhs is false. and AND is used when both have to occur simultaneously...and note never assume anything out
of question...
Means there will not be any one who is student and will not have means if he is student he has to have book means if
Left(L) is true then that student have a book(Right Side ). Since there is "a book" means a single will do ur work. and
since u cannot assume so if he is not a student then he may or may not have book .Thus,implication..Since student is
main concern so x will be bound others..AND implies in right side that the object chosen y has be simultaneously a book
and student must possess it. and since "a book" so one book will do it so there exist.
Or it can be read as there exist one student who does not have any book..Means You have to check entire book list and
has to ensure that this student must not have any(simulatenously means he is student and check entire list that he does
not have book).
Or All student have some particular book.....and this particular book can be any so
x B(x). and simulatenously you have to check that every student must possess that book so AND.in RHS we have implication which means there should
be any student (Left=T) which do not have that book (Right=F)
I hope i m clear
mathematical-logic first-order-logic
∃x(P(x)->Q(x)) ->(∀xP(x)->∀xQ(x))
first-order-logic mathematical-logic
1.∃x(P(x)->Q(x)) ->(∀xP(x)->∀xQ(x))
LHS:∃x(P(x)->Q(x))== ∃x(~P(x)vQ(x))
∃x~P(x)v∃xQ(x)
~∀xP(x)v∃xQ(x)which is ∀xP(x)->∃x
Q(x); HENCE FALSE
2.∃xP(x)->∀x Q(x) ->∀x(P(x)->Q(x))
∀x(~P(x)v∀x Q(x)
∀x(P(x)->Q(x)):HENCE TRUE
How to approach the question where , 2 premises are given and conclusion is asked, what i know is that i can check whether
it will be a valid. ?
mathematical-logic first-order-logic
Selected Answer
You can not conclude here anything . This is fallacy of affirming the conclusion.
Now we have
R->F
We can not conlude anything here. As we are affirming conclusion here, but it does not derive anything.
So we can say from above Two statements, " there will be flood." Same statement given to else, Nothing more.
More Info->
p->q,q => This is fallacy of affirming the conclusion.You can not derive here.
Also this is called fallacy of converse. i.e. If you derive p, then it is because you are assuming q-> p, which is incorrect.
p->q,~p => Fallacy of denying the hypothesis, You can not derive anything here..
If you try to derive ~q, then you are saying that ~p->~q, which is incorrect. It is also called fallacy of inverse.
(there will be flood ) AND (it is not raining for long OR there will be flood )
List-I
List-II
Codes:
A B C D
(a) 1 2 3 4
(b) 3 2 1 4
(c) 1 3 2 4
(d) 3 1 2 4
a. a
b. b
c. c
d. d
Selected Answer
Apple(p): p is an apple.
1) For all x, y & z, if (x is an apple and y is an apple and z is an apple), then (either x is same as y or x is same as z or y is
same as z).It means we have at most 2 apples.
2) For all x & y if (x is an apple and y is an apple) then (either x is same as y or y is same as x).It means we have at most
1 apple. here x & y need not to apple always but "if" both of them are apples then they are same apples, it says that we
may or may not have apples but if we have then we can not have more than 1 apple.
3) There exists an x & y such that x is an apple and y is an apple and x & y are different apples and for every z if z is an
apple then either z is same as x or z is same as y.It means we have exactly 2 apples.
4) There exists an x such that x is an apple and for every y if y is an apple then x & y are same. It means we have exactly
1 apple.
2) A commutative group
3) Not a semigroup
4) Not a monoid
groups
Selected Answer
Its a monoid.
Closure, associativity, Identity are defined for Real numbers.But inverse is not defined as R can be zero also. So (R,*) is
neither Group nor Abelian(commutative), but Monoid.
14.13 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-22 top gateoverflow.in/42734
Write each of these statements in the form “if p, then q” in English. [Hint: Refer to the list of common ways to express
conditional statements.]
kenneth-rosen mathematical-logic
14.14 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-21 top gateoverflow.in/42732
For each of these sentences, state what the sentence means if the logical connective or is an inclusive or (that is, a
disjunction) versus an exclusive or. Which of these meanings of or do you think is intended?
A. To take discrete mathematics, you must have taken calculus or a course in computer science.
B. When you buy a new car fromAcme Motor Company, you get $2000 back in cash or a 2% car loan.
C. Dinner for two includes two items from column A orthree items from column B.
D. School is closed if more than 2 feet of snow falls or if the wind chill is below −100.
kenneth-rosen mathematical-logic
14.15 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-20 top gateoverflow.in/42731
For each of these sentences, determine whether an inclusive or, or an exclusive or, is intended. Explain your answer.
Selected Answer
Inclusive OR : A or B or Both
Exclusive OR : Either A or B but NOT both
14.16 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-23 top gateoverflow.in/42739
Write each of these statements in the form “if p, then q” in English. [Hint: Refer to the list of common ways to express
conditional statements.]
mathematical-logic kenneth-rosen
B) if it stays warm for a week , then the apple trees will bloom
C) if the Pistons beat the Lakers then they win the championship
F) If you drive more than 400 miles, then you will need to buy gasoline
G) if you bought your CD player less than 90 days ago , then only your guarantee is good
14.17 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-26 top gateoverflow.in/42742
A. For you to get an A in this course, it is necessary and sufficient that you learn how to solve discrete mathematics
problems.
B. If you read the newspaper every day, you will be informed, and conversely.
C. It rains if it is a weekend day, and it is a weekend day if it rains.
D. You can see the wizard only if the wizard is not in, and the wizard is not in only if you can see him.
Selected Answer
They are saying represent in "P if and only if Q" form. Actually double implications are commutative so "P if and only if Q"
is same as "Q if and only if P".
A. You get an A in this course if and only if you learn how to solve discrete mathematics problems.
B. You will be informed if and only if you read the newspaper every day.
C. It rains if and only it is a weekend day.
D. You can see the wizard if and only if he is not in.
14.18 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-28 top gateoverflow.in/42744
State the converse, contrapositive, and inverse of each of these conditional statements.
kenneth-rosen mathematical-logic
contrapositive, =If I will not stay at home then it not snows tonight.
inverse =If it not snows tonight, then I will not stay at home.
contrapositive, =it is not a sunny summer day whenever I did not go to the beach.
inverse =I did not go to the beach whenever it is not a sunny summer day.
14.19 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-29 top gateoverflow.in/42745
How many rows appear in a truth table for each of these compound propositions?
A. p → ¬p
B. (p ∨ ¬r) ∧ (q ∨ ¬s)
C. q ∨ p ∨ ¬s ∨ ¬r ∨ ¬t ∨ u
D. (p ∧ r ∧ t) ↔ (q ∧ t)
kenneth-rosen mathematical-logic
14.20 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-27 top gateoverflow.in/42743
State the converse, contrapositive, and inverse of each of these conditional statements.
mathematical-logic kenneth-rosen
14.21 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-19 top gateoverflow.in/42729
For each of these sentences, determine whether an inclusive or, or an exclusive or, is intended. Explain your answer.
Selected Answer
14.22 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-25 top gateoverflow.in/42741
A. If it is hot outside you buy an ice cream cone, and if you buy an ice cream cone it is hot outside.
B. For you to win the contest it is necessary and sufficient that you have the only winning ticket.
C. You get promoted only if you have connections, and you have connections only if you get promoted.
D. If you watch television your mind will decay, and conversely.
E. The trains run late on exactly those days when I take it.
kenneth-rosen mathematical-logic
B. You win the contest if and only if you have the only winning ticket
14.23 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-24 top gateoverflow.in/42740
Write each of these statements in the form “if p, then q” in English. [Hint: Refer to the list of common ways to express
conditional statements]
A. I will remember to send you the address only if you send me an e-mail message.
B. To be a citizen of this country, it is sufficient that you were born in the United States.
C. If you keep your textbook, it will be a useful reference in your future courses.
D. The Red Wings will win the Stanley Cup if their goalie plays well.
E. That you get the job implies that you had the best credentials.
F. The beach erodes whenever there is a storm.
G. It is necessary to have a valid password to log on to the server.
H. You will reach the summit unless you begin your climb too late.
kenneth-rosen mathematical-logic
14.24 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-15 top gateoverflow.in/42724
A. Berries are ripe along the trail, but grizzly bears have not been seen in the area.
B. Grizzly bears have not been seen in the area and hiking on the trail is safe, but berries are ripe along the trail.
C. If berries are ripe along the trail, hiking is safe if and only if grizzly bears have not been seen in the area.
D. It is not safe to hike on the trail, but grizzly bears have not been seen in the area and the berries along the trail are
ripe.
E. For hiking on the trail to be safe, it is necessary but not sufficient that berries not be ripe along the trail and for grizzly
bears not to have been seen in the area.
F. Hiking is not safe on the trail whenever grizzly bears have been seen in the area and berries are ripe along the trail.
kenneth-rosen mathematical-logic
14.25 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-6 top gateoverflow.in/42630
Suppose that SmartphoneA has 256 MB RAM and 32 GB ROM, and the resolution of its camera is 8 MP; Smartphone B has
288 MB RAM and 64 GB ROM, and the resolution of its camera is 4 MP; and Smartphone C has 128 MB RAM and 32 GB ROM,
and the resolution of its camera is 5 MP. Determine the truth value of each of these propositions.
mathematical-logic kenneth-rosen
A. Smartphone B has the most RAM of these three smartphones. = true as smartphone B is 288 Mb most of among three.
B. Smartphone C has more ROM or a higher resolution camera than Smartphone B. =False since smartphone B has more
rom and camera resolution.
C. Smartphone B has more RAM, more ROM, and a higher resolution camera than Smartphone A. = False since resolution
of Smartphone A has more than Smartphone B.
D. If Smartphone B has more RAM and more ROM than Smartphone C, then it also has a higher resolution camera. =
False because Camera of Smartphone c has more i.e. 5MP.
E. Smartphone A has more RAM than Smartphone B if and only if Smartphone B has more RAM than Smartphone A.=
False since smartphone B always have more RAM than A . then it Smartphone B cant have less than smartphone A.
14.26 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-7 top gateoverflow.in/42631
Suppose that during the most recent fiscal year, the annual revenue of Acme Computer was 138 billion dollars and its net
profit was 8 billion dollars, the annual revenue of Nadir Software was 87 billion dollars and its net profit was 5 billion dollars,
and the annual revenue of Quixote Media was 111 billion dollars and its net profit was 13 billion dollars. Determine the truth
value of each ofthese propositions for the most recent fiscal year.
kenneth-rosen mathematical-logic
A. Quixote Media had the largest annual revenue. = False since Acme Computer was 138 billion dollars.
B. Nadir Software had the lowest net profit and Acme Computer had the largest annual revenue.= True since Nadir
Software had the lowest net profit= 5bd lowest among three and Acme Computer was 138 billion dollars greatest among
three.
C. Acme Computer had the largest net profit or Quixote Media had the largest net profit. = False since Quixote Media net
profit was 13 billion dollars. one is true.
D. If Quixote Media had the smallest net profit, then Acme Computer had the largest annual revenue. true since Acme
Computer had the largest annual revenue = 138 true so p->q= q is true since Acme Computer had the largest annual
revenue = 138.
E. Nadir Software had the smallest net profit if and only if Acme Computer had the largest annual revenue. true b/c Nadir
Software had the smallest net profit = 5bd and Acme Computer had the largest annual revenue = 138 so both are true.
14.27 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-8 top gateoverflow.in/42636
1. ¬p
2. p ∨ q
3. p → q
4. p ∧ q
5. p ↔ q
6. ¬p → ¬q
7. ¬p ∧ ¬q
8. ¬p ∨ (p ∧ q)
kenneth-rosen mathematical-logic
Not (I bought a lottery ticket this week) = I not bought a lottery ticket this week..
Either I bought a lottery ticket this week or won the million dollar jackpot or both.
If i bought a lottery ticket this week then I won the million dollar jackpot.
I bought a lottery ticket this week and won the million dollar jackpot.
I bought a lottery ticket this week if and only if I won the million dollar jackpot.
IF i not bought a lottery ticket this week then i not won the million dollar jackpot.
I not bought a lottery ticket this week and/ as well as not won the million dollar jackpot .
Either I not bought a lottery ticket this week or I bought a lottery ticket this week and won the million dollar jackpot .
14.28 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-5 top gateoverflow.in/42629
A. Steve has more than 100 GB free disk space on his laptop.
B. Zach blocks e-mails and texts from Jennifer.
C. 7 · 11 · 13 = 999.
D. Diane rode her bicycle 100 miles on Sunday.
mathematical-logic kenneth-rosen
Selected Answer
A. Steve has less than or equal to 100 GB free disk space on his laptop.
B. Zach allows e-mails or texts from Jennifer.
C. 7 . 11 . 13 ≠ 999
D. Diane did not ride her bicycle 100 miles on Sunday.
14.29 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-4 top gateoverflow.in/42628
kenneth-rosen mathematical-logic
14.30 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-1 top gateoverflow.in/42591
Which of these sentences are propositions? What are the truth values of those that are propositions?
kenneth-rosen mathematical-logic
Selected Answer
So, Statement should be declarative, not command or request etc. For example If I say " New Delhi is capital of
India". Here I am declaring that New Delhi is Capital of India, Hence it is proposition. But the statement like " Please
give me a glass of water." or "Don't use Gate Overflow unless and until you have completed with your
chapters". Here one is request and second one is command hence they are not proposition. However we can say that
"Every proposition is a statement but every statement is not proposition".
14.31 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-2 top gateoverflow.in/42626
Which of these are propositions?What are the truth values of those that are propositions?
kenneth-rosen mathematical-logic
A. Do not pass go. => not a proposition. why? because its an order.
B. What is the time? => not a proposition. Why ? because its a question.
C. There are no black files is the main. => a proposition. why? It can have truth value either true or false.
D. 4+x=5 => Not a proposition. Why? because its truth value depends on 'x'.
E. The moon is made of green cheese. => a proposition. Why? because, Its truth value is false.
F. 2n > 100 => Not a proposition. Why? because, Its truth value depends on truth value depends on the value of
'n'.
14.32 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-3 top gateoverflow.in/42627
mathematical-logic kenneth-rosen
C. 2+1 ≠ 3
14.33 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-9 top gateoverflow.in/42717
Let p and q be the propositions “Swimming at the New Jersey shore is allowed” and “Sharks have been spotted near the
shore,” respectively. Express each of these compound propositions as an English sentence.
A. ¬q
B. p ∧ q
C. ¬p ∨ q
D. p → ¬q
E. ¬q → p
F. ¬p → ¬q
G. p ↔ ¬q
H. ¬p ∧ (p ∨ ¬q)
kenneth-rosen mathematical-logic
Swimming at the New Jersey shore is allowed and Sharks have been spotted near the shore.
if swimming at the New Jersey shore is allowed then Sharks have been spotted near the shore.
if swimming at the New Jersey shore is allowed then Sharks have not been spotted near the shore.
Sharks have not been spotted near the shore or Swimming at the New Jersey shore is allowed.
14.34 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-10 top gateoverflow.in/42719
Let p and q be the propositions “The election is decided” and “The votes have been counted,” respectively. Express each of
these compound propositions as an English sentence.
A. ¬p
B. p ∨ q
C. ¬p ∧ q
D. q → p
E. ¬q → ¬p
F. ¬p → ¬q
G. p ↔ q
H. ¬q ∨ (¬p ∧ q)
mathematical-logic kenneth-rosen
14.35 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-30 top gateoverflow.in/42746
How many rows appear in a truth table for each of these compound propositions?
kenneth-rosen mathematical-logic
14.36 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-16 top gateoverflow.in/42726
A. 2 + 2 = 4 if and only if 1 + 1 = 2.
B. 1 + 1 = 2 if and only if 2 + 3 = 4.
C. 1 + 1 = 3 if and only if monkeys can fly.
D. 0 > 1 if and only if 2 > 1
kenneth-rosen mathematical-logic
14.37 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-17 top gateoverflow.in/42727
A. If 1 + 1 = 2, then 2 + 2 = 5.
B. If 1 + 1 = 3, then 2 + 2 = 4.
C. If 1 + 1 = 3, then 2 + 2 = 5.
D. If monkeys can fly, then 1 + 1 = 3.
mathematical-logic kenneth-rosen
14.38 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-14 top gateoverflow.in/42723
A. You get an A in this class, but you do not do every exercise in this book.
B. You get an A on the final, you do every exercise in this book, and you get an A in this class.
C. To get an A in this class, it is necessary for you to get an A on the final.
D. You get an A on the final, but you don’t do every exercise in this book; nevertheless, you get an A in this class.
E. Getting an A on the final and doing every exercise in this book is sufficient for getting an A in this class.
F. You will get an A in this class if and only if you either do every exercise in this book or you get an A on the final.
kenneth-rosen mathematical-logic
14.39 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-13 top gateoverflow.in/42722
kenneth-rosen mathematical-logic
14.40 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-11 top gateoverflow.in/42720
mathematical-logic kenneth-rosen
A. P ∧ Q
B. P ∧ ~Q
C. ~P ∧ ~Q
D. P ⊕ Q
E. P -> Q
F. (P V Q) ∧ ( P -> Q)
G. P <-> Q
14.41 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-12 top gateoverflow.in/42721
A. p → q
B. ¬q ↔ r
C. q → ¬r
D. p ∨ q ∨ r
E. (p → ¬r) ∨ (q → ¬r)
F. (p ∧ q) ∨ (¬q ∧ r)
kenneth-rosen mathematical-logic
a. If you have the flu then you will miss the final examination.
b. You will pass the course if and only if you don't miss the final examination.
c. If you miss the final examination then you will not pass the course.
d. You have the flu or you miss the final examination or you pass the course.
e. if you have the flu then you will not pass that course or if you miss the final examination then you will not pass that course.
f. If you have the flu and you miss the final examination or you don't miss the final examination and pass the course.
14.42 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-18 top gateoverflow.in/42728
mathematical-logic kenneth-rosen
Selected Answer
14.43 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-32 top gateoverflow.in/42749
A. p → ¬p
B. p ↔ ¬p
C. p ⊕ (p ∨ q)
D. (p ∧ q) → (p ∨ q)
E. (q → ¬p) ↔ (p ↔ q)
F. (p ↔ q) ⊕ (p ↔ ¬q)
kenneth-rosen mathematical-logic
http://web.stanford.edu/class/cs103/tools/truth-table-tool/
14.44 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-43 top gateoverflow.in/42847
Find the bitwise OR, bitwise AND, and bitwise XOR of each of these pairs of bit strings.
kenneth-rosen mathematical-logic
14.45 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-44 top gateoverflow.in/42848
Selected Answer
14.46 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-42 top gateoverflow.in/42846
What is the value of x after each of these statements is encountered in a computer program, if x = 1 before the statement is
reached?
A. if x + 2 = 3 then x := x + 1
B. if (x + 1 = 3) OR (2x + 2 = 3) then x := x + 1
C. if (2x + 3 = 5) AND (3x + 4 = 7) then x := x + 1
D. if (x + 1 = 2) XOR (x + 2 = 3) then x := x + 1
E. if x < 2 then x := x + 1
mathematical-logic kenneth-rosen
Selected Answer
initailly
x=1
x=1
x=1
x=1
x=1
14.47 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-41 top gateoverflow.in/42844
Explain, without using a truth table, why (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) is true when at least one of p, q, and r is true and at least
one is false, but is false when all three variables have the same truth value.
Selected Answer
Now the statement is true only when both expressions in it are true.
(p ∨ q ∨ r)
This is certainly true when any one of the three p,q,r is true.
(¬p ∨ ¬q ∨ ¬r)
This is always true when any one of the p,q,r is false.
Thus combining above two, for the above statement to be true at least one of the p,q,r should be true and at least one
should be false.
QED
14.48 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-40 top gateoverflow.in/42843
Explain, without using a truth table, why(p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p) is true when p, q, and r have the same truth value and it is
false otherwise.
14.49 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-45 top gateoverflow.in/42849
Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that is a number between 0 and 1,
inclusive.A proposition with a truth value of 0 is false and one with a truth value of 1 is true. Truth values that are between 0
and 1 indicate varying degrees of truth. For instance, the truth value 0.8 can be assigned to the statement “Fred is happy,”
because Fred is happy most of the time, and the truth value 0.4 can be assigned to the statement “John is happy,” because
John is happy slightly less than half the time. Use these truthvalues to solve below Exercises.
1. The truth value of the negation of a proposition in fuzzy logic is 1 minus the truth value of the proposition. What are the
truth values of the statements “Fred is not happy” and “John is not happy?”
Since Fred is happy truth value is 0.8 it means that Fred is unhappy truth value become 0.2
John is happy truth value 0.4 it means that John is unhappy truth value becomes 0.6
14.50 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-31 top gateoverflow.in/42747
A. p ∧ ¬p
B. p ∨ ¬p
C. (p ∨ ¬q) → q
D. (p ∨ q) → (p ∧ q)
E. (p → q) ↔ (¬q → ¬p)
F. (p → q) → (q → p)
kenneth-rosen mathematical-logic
http://web.stanford.edu/class/cs103/tools/truth-table-tool/
14.51 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-50 top gateoverflow.in/42913
Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that is a number between 0 and 1,
inclusive.A proposition with a truth value of 0 is false and one with a truth value of 1 is true. Truth values that are between 0
and 1 indicate varying degrees of truth. For instance, the truth value 0.8 can be assigned to the statement “Fred is happy,”
because Fred is happy most of the time, and the truth value 0.4 can be assigned to the statement “John is happy,” because
John is happy slightly less than half the time. Use these truthvalues to solve below Exercises.
An ancient Sicilian legend says that the barber in a remote town who can be reached only by traveling a dangerous mountain
road shaves those people, and only those people, who do not shave themselves. Can there be such a barber?
14.52 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-49 top gateoverflow.in/42912
Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that is a number between 0 and 1,
inclusive.A proposition with a truth value of 0 is false and one with a truth value of 1 is true. Truth values that are between 0
and 1 indicate varying degrees of truth. For instance, the truth value 0.8 can be assigned to the statement “Fred is happy,”
because Fred is happy most of the time, and the truth value 0.4 can be assigned to the statement “John is happy,” because
John is happy slightly less than half the time. Use these truthvalues to solve below exercise.
The nth statement in a list of 100 statements is “Exactly n of the statements in this list are false.”
14.53 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-48 top gateoverflow.in/42911
Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that is a number between 0 and 1,
inclusive.A proposition with a truth value of 0 is false and one with a truth value of 1 is true. Truth values that are between 0
and 1 indicate varying degrees of truth. For instance, the truth value 0.8 can be assigned to the statement “Fred is happy,”
because Fred is happy most of the time, and the truth value 0.4 can be assigned to the statement “John is happy,” because
John is happy slightly less than half the time. Use these truthvalues to solve below exercise.
14.54 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-47 top gateoverflow.in/42910
Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that is a number between 0 and 1,
inclusive.A proposition with a truth value of 0 is false and one with a truth value of 1 is true. Truth values that are between 0
and 1 indicate varying degrees of truth. For instance, the truth value 0.8 can be assigned to the statement “Fred is happy,”
because Fred is happy most of the time, and the truth value 0.4 can be assigned to the statement “John is happy,” because
John is happy slightly less than half the time. Use these truthvalues to solve below exercise.
The truth value of the disjunction of two propositions in fuzzy logic is the maximum of the truth values of the two
propositions. What are the truth values of the statements “Fred is happy, or John is happy” and “Fred is not happy, or John
is not happy?”
14.55 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-39 top gateoverflow.in/42842
14.56 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-46 top gateoverflow.in/42909
Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that is a number between 0 and 1,
inclusive.A proposition with a truth value of 0 is false and one with a truth value of 1 is true. Truth values that are between 0
and 1 indicate varying degrees of truth. For instance, the truth value 0.8 can be assigned to the statement “Fred is happy,”
because Fred is happy most of the time, and the truth value 0.4 can be assigned to the statement “John is happy,” because
John is happy slightly less than half the time. Use these truthvalues to solve below exercise.
The truth value of the conjunction of two propositions in fuzzy logic is the minimum of the truth values of the two
propositions. What are the truth values of the statements “Fred and John are happy” and “Neither Fred nor John is happy?”
14.57 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-34 top gateoverflow.in/42836
A. p ⊕ p
B. p ⊕ ¬p
C. p ⊕ ¬q
D. ¬p ⊕ ¬q
E. (p ⊕ q) ∨ (p ⊕ ¬q)
F. (p ⊕ q) ∧ (p ⊕ ¬q)
mathematical-logic kenneth-rosen
14.58 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-33 top gateoverflow.in/42834
A. (p ∨ q) → (p ⊕ q)
B. (p ⊕ q) → (p ∧ q)
C. (p ∨ q) ⊕ (p ∧ q)
D. (p ↔ q) ⊕ (¬p ↔ q)
E. (p ↔ q) ⊕ (¬p ↔ ¬r)
F. (p ⊕ q) → (p ⊕ ¬q)
kenneth-rosen mathematical-logic
14.59 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-38 top gateoverflow.in/42841
kenneth-rosen mathematical-logic
14.60 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-35 top gateoverflow.in/42837
A. p → ¬q
B. ¬p ↔ q
C. (p → q) ∨ (¬p → q)
D. (p → q) ∧ (¬p → q)
E. (p ↔ q) ∨ (¬p ↔ q)
F. (¬p ↔ ¬q) ↔ (p ↔ q)
mathematical-logic kenneth-rosen
14.61 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-36 top gateoverflow.in/42839
A. (p ∨ q) ∨ r
B. (p ∨ q) ∧ r
C. (p ∧ q) ∨ r
D. (p ∧ q) ∧ r
E. (p ∨ q) ∧ ¬r
F. (p ∧ q) ∨ ¬r
kenneth-rosen mathematical-logic
14.62 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1 QueNo-37 top gateoverflow.in/42840
A. p → (¬q ∨ r)
B. ¬p → (q → r)
C. (p → q) ∨ (¬p → r)
D. (p → q) ∧ (¬p → r)
E. (p ↔ q) ∨ (¬q ↔ r)
F. (¬p ↔ ¬q) ↔ (q ↔ r)
mathematical-logic kenneth-rosen
mathematical-logic-virtualgate
Selected Answer
[p → (q ∨ r)] ∧ (~q)} → (p → r)
= ((p' + q + r)q')' + p' + r
= (p'q' + rq')' + p' + r
= (p + q)(r' + q) + p' + r
= pr' + pq + qr' + q + p' + r
=pr' + (pq + qr' +q) + p' + r = (pr' + p') + q(p + r' +1) + r
= p' +r' + q + r
=p' + q + (r + r')
= p' + q + T
= TAUTOLOGY
so rhs p->r is false if p is true and r is false (we assume RHS is false)
F->F is true
linear-algebra matrices
Selected Answer
so answer is 48
Reference https://www.physicsforums.com/threads/determinant-of-a-matrix-multiplied-by-a-scalar.194725/
[ ]
2 3 4
if A = 3 −1 2 then rank of the matrix (A − AT) is _____
−1 4 5
matrices
A die is thrown 3 times and sum of 3 number thrown is 15 . find the chance that first throw was a 4 ?
probability
Selected Answer
A bag contain 3R and 5 B balls and second bag contain 6R and 4B balls . A ball is drawn from each bag . find the probability
that both are (i)red and (2) black.?
probability
probability engineering-mathematics
Selected Answer
Probability of A winning :
Answer A.
Three people X,Y, and Z are contesting in an election and we assume that exactly one of them wins it. Suppose that X and Z
have the same chances of winning and Y has only half the chance of X or Z. The probability that either X or Y wins the
election is _____
probability
X + X + X/2 =1
so x= 2/5.
E(X+2Y)=p
EXY)=q
Vat(X-2Y+1)=r
find pq+r
random-variable
IF X,Y are independent than Cov(X,Y) = 0 . Here its ≠ 0 . So we they are dependent .
Therefore pq+r = 20
The continuous random variable X has pdf f(x)=x/2, 0<=x<=2. Two independent determinations of X are made. What is the
probability that both these determinations will be greater than one? If three independent determinations had been
made,what is the probability that exactly two of these are larger than one?
random-variable probability
1. Alice is telling the truth: This results in both Carlos and John being guilty. This is
a contradiction based on my assumption.
2. John is telling the truth: We can say that Diana did not do it because Carlos is lying, but that
means that Diana would be telling the truth. Since we are assuming it is in fact only John that is
telling the truth in this scenario, we have a contradiction.
3. Carlos is telling the truth. This results in both John and Diana being guilth. This is
acontradiction based on my assumption.
4. Diana is telling the truth. This means that John is the criminal.
1 votes -- Shivam Dwivedi ( 55 points)
share
From the GATE CSE site I got the list of recommended Video lectures to watch. In case of Discrete Mathematics, I have
downloaded the following NPTEL video playlist: https://www.youtube.com/playlist?list=PLbMVogVj5nJQ-
tIzyygzzLLxomzlbIiE4
I would like to know are they good? I mean if someone has already gone through this playlist (Since it is a new video series).
Is it worth the time? there are 41 videos. Discrete Maths course from ADuni has also been recommended and I am currently
downloading them and I will go through all the videos once I complete the first one.
Do NOt watch all videos first to last.. it may consume much time...
STRATEGY:
At first go through kenneth rosen
then solve exercise and see where you are getting stucked......for those parts refer to the videos .. That's it
mathematical-logic
---------------------------------------------
B(x) :- x is a baby.
I(x) :- x is illogical.
D(x):- x is despised.
I had made above logic from the arguments given...but I am not able get correct result.
I think 2 logic is not according to condition...we are given that M(x)->~D(x)....so how the statement can be made that....
Not despised ppl are all able to manage crocodile.????
mathematical-logic
Selected Answer
~S(x) ^[P(x) ^ Q(x) ==> S(x)] gives ~[P(x) ^ Q(x)] --- (5) Modus Tollens
So option b is valid.
conclusion: Q(x)
Please tell me the procedure to solve such a question not just Answer .I know the answer.
computer-networks engineering-mathematics
Selected Answer
(i) 7*11*711*777%13
=(77*90)%13
=(-1 * -1)%13
=1 Ans
Let
since jasmine becomes unhappy is samir is there so these 2 can not be invited together
3)kanti and samir not possible (as jasmine is not there which is a prerequisite for kanti)
This question made my head revolve 360 degree many times in the exam....:) :P
https://en.wikipedia.org/wiki/Hasse_diagram
and if for every subset of poset there exists a LUB and GLB it is a Lattice.
a) No one is perfect. == Not ( one is perfect) = ~ (∃x(px))= ∀x ~p(x)= Every one is imperfect.
b) Not everyone is perfect.== Not (everyone is perfect.)= ~( ∀x(px))=∃x ~p(x)= Atleast one is imperfect.
c) All your friends are perfect. == if there is a person who is your friend then he is perfect== ∀x( F(x)→P(x))
d) At least one of your friends is perfect. == There is a person who is your friend who is perfect.
∃x (F(x)∧P(x))
14.87 Express & form negation so that no negation is to the left of the
quantifier & express this negation in simple English top gateoverflow.in/14390
Express and form negation, so that no negation is to the left of the quantifier and express this negation in simple English.
“Every student in this class has taken exactly two math classes at this school.”
"There is someone in the class such that for every two different math course, these are not the two & only two
math courses this person has taken".
mathematical-logic
Selected Answer
( student
∀x : in class(x) ∃a∃b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∧ ∀c :
( isMathClass( c )
∧ c≠a
∧ c≠b
¬Taken(x, c)
)))
Reads: For every student x in class, there exist math classes a and b such that x has taken a, and x has taken b, and for
any other math class c (c ≠ a, c ≠ b), x has not taken c.
To negate it, we put an negation sign at the start of the equation, and push it in.
When we push negation sign inwards:
( student
¬∀x : in class(x) ∃a∃b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∧ ∀c :
( isMathClass( c )
∧ c≠a
∧ c≠b
¬Taken(x, c)
)))
Pushing the negation inwards, ¬∀x: (…) will become ∃x: ¬(…). Note that the negation moves inwards.
( student
∃x :¬ in class(x) ∃a∃b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∧ ∀c :
( isMathClass( c )
∧ c≠a
∧ c≠b
¬Taken(x, c)
)))
Now, we have to negate everything inside those big brackets!
So, we get:
( student
∃x : in class(x) ∧ ¬∃a∃b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∧ ∀c :
( isMathClass( c )
∧ c≠a
∧ c≠b
¬Taken(x, c)
)))
Now, we encounter ¬∃a∃b(…)
We push to negation inwards twice like this:
¬∃a∃b(…)
∀a¬∃b(…)
∀a∀b¬(…)
Overall, we get:
( student
∃x : in class(x) ∧ ∀a∀b :¬
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∧ ∀c :
( isMathClass( c )
∧ c≠a
∧ c≠b
¬Taken(x, c)
)))
Now we need to negate everything inside that second big brackets!
This time, we have a lot of ANDs.
So, we use the De-Morgan's law!
(
¬ abc x ≡ ) ¬ (( ) )
abc x ≡ ( )
¬ abc ∨ ¬x ≡ (abc) ¬x
We can use this cool thing to quickly negate all those ANDs we have in the inner big bracket!
( student
∃x : in class(x) ∧ ∀a∀b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ¬∀c :
( isMathClass( c )
∧ c≠a
∧ c≠b
¬Taken(x, c)
)))
Great, almost done!
Negating that ¬∀c (…) we will get ∃c ¬(…)
That is, we get:
( student
∃x : in class(x) ∧ ∀a∀b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∃c :¬
( isMathClass( c )
∧ c≠a
∧ c≠b
¬Taken(x, c)
)))
The last bracket now!
Remember what implications change to?
Implication (p q) changes to (p ∧ ¬q).
So, we get:
( student
∃x : in class(x) ∧ ∀a∀b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∃c :
( isMathClass( c )
∧ c≠a
∧ c≠b
∧ ¬¬Taken(x, c)
)))
Notice that we now have two NOTs (¬¬) in a row!
We know that ¬¬p ≡ p
So, we can use that to finally get:
( student
∃x : in class(x) ∧ ∀a∀b :
( isMathClass( a ) ∧ isMathClass( b )
∧ Taken( x ,a ) ∧ Taken( x ,b ) ∃c :
( isMathClass( c )
∧ c≠a
∧ c≠b
∧ Taken(x, c)
)))
Now, lets take a step back and try to read what we just got.
It reads:
There is someone (x) in the class, such that for every two different math classes (a, b) that x has taken, there is atleast one
more math class c that x has taken!
Selected Answer
C: There exists a person z and z is the mother of y and x is the father of z. - the ANSWER
what is the difference BETWEEN "IF" and "ONLY IF" when we translate an english sentence into a logical expression???
Selected Answer
A if B is B implies A
A only if B is A implies B
with an example.
With conjunction LHS becomes stronger. It means for every x, both P(x) and Q(x) are true. So, it becomes equivalent to
RHS.
With disjunction LHS becomes weak. It means for every x, either P(x) or Q(x) is true. But RHS means for every x P(x) is
true, or for every x, Q(x) is true. Imagine saying all students in a class are either boy or girl. But, this doesn't mean all
are boys or all are girls.
(P⋂Q⋂R') -> P and Q are true and R is False [exactly two are true]
(P⋂Q'⋂R) -> P and R are true and Q is False [exactly two are true]
(P'⋂Q⋂R) -> Q and R are true and P is False [exactly two are true]
The notation ∃!xP(x) denotes the proposition “there exists a unique x such that P(x) is true”.
Give the truth values of the following statements :
I. ∃!xP(x) → ∃xP(x)
II. ∃!x ¬P(x) → ¬∃xP(x)
mathematical-logic
Selected Answer
I: If there exists a unique x with P(x) true, then there exist an x with P(x) true. This is TRUE as exactly 1 is a subset of at
least one.
II: If there exists a unique x with P(x) false, then there does not exist an x with P(x) true. This is FALSE (contradiction) as
all except one x can are having P(x) true.
A. for all person x der exist a job y or (let another) job z is not same as job y then x shouldn't has job z.
Let y!= z and x dont have any job then also A returns true.
D is correct.
Selected Answer
"You cannot ride the roller coaster if you are under 4 feet unless you are older than 16 years old "
mathematical-logic
Selected Answer
a) You get A in final exam, but you don't do every exercise in this book, nevertheless you can get A in the class
b) Getting A on the final and doing every exercise in this book is sufficient for getting A in this class
c) you will get an A in this class if and only if you either do every exercise in this book or you can get A on the final ?
mathematical-logic
Selected Answer
for c ) r <---> (q or p )
Is it correct ?
14.97 write first order logic " everybody loves my baby but my my baby dnt
love everybody but only me" top gateoverflow.in/16892
How can you represent the famous poem line, in first order expression
"Everybody Loves My Baby, but My Baby Don't Love Nobody but Me"
How can you represent the famous poem line, in first order expression
"Everybody Loves My Baby, but My Baby Don't Love Nobody but Me"
It's not an easy question as we think about logic and of course not a big also.
"Everybody loves my baby but my baby loves nobody but me" implies "I am my baby." (Please read question 3-4
times).
Let’s try to apply the language of Logic and Propositions that we learned in Coaching Classes/Self
Study/B.Tech/M.Tech...etc.
"Everybody loves my baby, but my baby don’t love nobody but me".
Suppose that our universe has one relationship, LOVES and two distinguished individuals, ME and MYBABY.
For example, LOVES(ME, MYBABY) means “I love my baby” and ∃x ~LOVES(x,ME) means "not everybody loves
me."
Let the domain for x consist of all people.Translating the proposition “ Everybody loves my baby, but my baby don’t
love nobody but me" into symbolic logic, we have
must be true for all x. We can then substitute MYBABY for x to obtain
The truth of the first proposition LOVES(MYBABY,MYBABY) together with the left-to-right implication
LOVES(MYBABY,MYBABY)→MYBABY=ME , imply that MYBABY=ME.
We must therefore conclude that individuals referred to as “ me” and “My Baby” are one and the same person.
https://www.mail-archive.com/everything-list@googlegroups.com/msg46966.html
http://griceclub.blogspot.in/2010/06/everybody-loves-my-baby-but-my-baby.html
All crows are birds but not all birds are crows.
Selected Answer
14.101 I can't really understand the difference between the two statements :
a)for all x(C(x)->F(x)) b)there exists x(C(x)->F(x)) C(x)=x is a comedian
F(x)=x is funny top gateoverflow.in/11841
What you told are exactly correct. But "some" and "all" makes a lot of difference rt? We can say some people studying for
GATE get to IIT. But ALL people studying for GATE get to IIT is a lot different.
“Students who have taken calculus or computer science can take this class.” - is an example of inclusive or
And how do we know for sure which one is exclusive or inclusive or when the statements almost reads the same?
mathematical-logic
Selected Answer
14.103 How many solutions are there to the equation x+y+z=17 in positive
integers? top gateoverflow.in/7502
How many solutions are there to the equation x+y+z=17 in positive integers ?
A) 120 B)171 C)180 D)121
We have 17 and we want to distribute it to x, y and z such that each gets at least one. So, initially itself we take 3 and
give 1 each to x, y and z. So, now we have 14 left and have to divide this into 3. Let the 14 be as follows and we use | for
division.
X X X X X X X X X X X X X X
We need 2 | for dividing this into 3 parts. and with 2 |, our problem reduces to finding all the permutations of 14 + 2
items, where 14 and 2 of them are identical. So, our answer will be
16!/14!2! = 15 * 8 = 120
Consider that x=1, then it'll have 15 different solutions in positive integers. (1,1,15), (1,2,14) ........(1,15,1).
Similarly consider x=2, then it'll have 14 different solutions in positive integers.
= 120 solutions
14.104 How many solutions are there to the equation x+y+z=17 ?They are
non-negative integers top gateoverflow.in/7504
How many solutions are there to the equation x+y+z=17 ?They are non-negative integers
A) 120 B)171 C)180 D)121
Selected Answer
Ans (B)
mathematical-logic
Selected Answer
option C
a. P → P ∧ Q
b. P → Q ∧ V
c. (P → Q) ∧ (Q → R) → P → R
d. (P → Q) ↔ ( ∼ Q →∼ P)
mathematical-logic
Selected Answer
P → Q = ¬P ∨ Q
¬Q → ¬P = Q ∨ ¬P
Hence, D is correct.
((P → Q) ∧ (Q → R)) → (P → R)
This is a tautology.
now let's say that the third option is incorrect then we can have (p -> r) false even when the left hand side is
true.
but p -> r false means p = True and R = False. Now for the left hand side to be true Q has to be false and true
at the same time. Since (p -> q) demands q to be false whereas (q -> r) demands q to be true. which is never
possible hence that is also a tutology.
option c
Let L(x, y) be the statement "x loves y," where the domain for both x and y consists of all people in the world.
Use quantifiers to express:
Q->There is exactly one person whom everybody loves.
E-some || A-for all ||
Answer-> Ex ( AyL(y,x) ^ Az((Aw L(w,z))->z=x) )
Can anyone explain the answer and how to solve these questions
i mean how to analyze these questions??
Selected Answer
First of all we have only two quantifiers- exists and forall. So, first try to convert the given sentence into a sentence
containing those (its just English)
There is someone who is loved by everyone, and there is no one else who is loved by everyone
There is someone, x, who is loved by everyone, and if there is another one, y, who is loved by everyone else,
means x and y are the same person.
This can be translated into first order logic (first order logic is just propositional logic with ∃ and ∀)
Here actually in place of w, we can use y as the life of y expires immediately after ∀y(y,x) this. Using w instead of y is
strictly not needed.
You can also try to express " There is at most one person whom everybody loves"
Now, the translations I did is based on my knowledge about the expressive powers of first order logic. That is first order
logic can't be used for all statement forms- we first need to convert it into a suitable form. Luckily there are only a few
cases, which you should get experienced by solving previous year questions in this topic. You can see the below 3
questions and they should cover almost any type of question from this topic.
http://gateoverflow.in/256/gate1992_92-xv
http://gateoverflow.in/923/gate2003_33
http://gateoverflow.in/922/gate2003_32
14.109 Give the first order predicate calculus of the following statement.
“Some boys like every girl” top gateoverflow.in/5928
D) None of these
mathematical-logic
Selected Answer
Option D is correct.
B - Everything is a girl, and is either liked by some boy, or something is not a boy. (I know, sounds funny.)
C - Every girl is liked by some boy, or there is something which is not a boy.
mathematical-logic
Selected Answer
A contradiction means any assignment ot variables produces a 0. So, it can never be satisfied.
Coming to B option, it says Every satisfiable formula is not tautology. This is wrong as valid formula is both satisfiable as
well as tautology. If we change "every" to "some", B option becomes correct. Actually this sentence is not grammatically
correct and can also be interpreted as "Every satisfiable formula is not a tautology" meaning some satsfiable formula is
not tautology. In this case B option becomes TRUE.
14.110 Total onto function from a to b with cardinality 4 anf 3 respectively top
gateoverflow.in/7977
3! * S(4, 3) = 3! * 6 = 36
http://gateoverflow.in/5596/no-of-surjective-functions
http://www.math.uiuc.edu/~kostochk/math413/comb.pdf
If it is below Freezing then not snowing OR If it is NOT below Freezing then it is snowing..
= (P ----> Q') ^ ( P' ----> Q) // something like IF 'X' THEN 'Y' ELSE 'Z'
= (P' + Q') ^ (P + Q)
= PQ' + P'Q
= P ◎ Q. // P Ex - OR Q
Disjunction : A v B
Conjunction : ~(~(A) v ~(B))
Negation. : ~A.
NAND : ~(A) v ~(B)
NOR : ~(A v B)
A Ex - OR B = ~(A v ~B) v ~(~A v B)}
A Ex - NOR B : ~{~(A v ~B) v ~(~A v B)}
a. ∀x man (x) ∧ intelligent (x) → ∃y knowledge (y) ∧ have knowledge (x, y).
b. ∀x∃y man (x) ∧ intelligent (x) → knowledge (y) ∧ have knowledge (x, y)
c. ∀x, y man (x) ∧ intelligent (x) ∧ knowledge (y) → have knowledge (x, y)
d. None of the above.
Selected Answer
a is correct.
b is wrong due to implication having lower precedence than quantifiers. It will be evaluated as
(∀x∃yman(x) ∧ intelligent(x)) (knowledge(y) ∧ have knowledge(x, y)).
Here, for the RHS, there is no quantification for x or y, meaning it must be true for every x and y.
Ref: https://en.wikipedia.org/wiki/First-order_logic#Notational_conventions
barber?
if he is in trouble then der is a barber who save him but that saver barber is in trouble. i.e. no such barber exists.
mathematical-logic
Selected Answer
Let:
≡ q follows from p
≡p q
does gate syllabus include RECURRENCE EQUATION.!!! if it is ,could any one recommend me link for good material for the
same!!!
http://www.cise.ufl.edu/~sahni/dsaaj/enrich/c19/recur.pdf
Which predicate logic means, "There are at most two men in class"?
∀x∀y((Male(x) ∧ Male(y)) → (x = y ∨ y = x)
How do I know the meaning of the statements? I want to know the working steps.
mathematical-logic normal
Selected Answer
∀x∀y((Male(x) ∧ Male(y)) → (x = y ∨ y = x)
The second part of OR is redundant here as x = y is same as y = x. So, this basically means there cannot be no more than 1
man in the class (either 0 or 1 man is possible).
There are x and y such that both are men, and if there exist another man z, then x = z or y = z. This means there are
exactly two men in the class- no less no more.
For every x, y, z, if all are men, then all are the same. I guess z is redundant here and it should mean the same as in (1).
14.117 is conjunctive normal form part of gate 2016 syllaus top gateoverflow.in/36025
Selected Answer
YES. Digital Electronics have POS (Product of Sum) form, SOP (Sum of Product) form. They are the variation or we can
say other names of Conjunctive Normal Form or Disjunctive Normal Form. So they are in syllabus.
a + b->c means
(a + b)-> c or a + (b->c)?
let A be a diagonalizable matrix of order n*n .then which of the following is true?
Selected Answer
1. We need to show that ∃x ∀y P(x, y) → ∀y ∃x P(x, y) is a tautology i.e. whenever ∃x ∀y P(x, y) is true, ∀y ∃x P(x, y) is also true.
If ∃x ∀y P(x, y) is true, it means there exists an x = c (where c is an arbitrary constant), for which P(c,y) is true for all y, which in turn means
that for all y, there exists an x (the constant c), for which P(x,y) is true i.e. ∀y ∃x P(x, y) is true. Hence proved.
2. We need to show that ∃x (P(x) → Q(x)) and ∀x P(x) → ∃x Q(x) always have the same truth value.
L.H.S = ∃x (P(x) → Q(x)) ≡ ∃x (¬P(x) v Q(x)) ≡ ∃x (¬P(x)) v ∃x Q(x) ≡ ¬∀x P(x) v ∃x Q(x) ≡ ∀x P(x) → ∃x Q(x) = R.H.S.
3. False. ∀y ∃x P(x, y) being true means for every y, there is an x (possibly different x for different values of y we choose) such that P(x,y) is
true. It doesn't mean that there is a single x which makes P(x,y) true for every y.
∀x ∃y P(x, y) being true means for every x, there is a y (possibly different y for every x), which makes P(x,y) to true. This doesn't mean that
there is a single x, which makes P(x,y) for every possible y.
Option a
As complement
N∧(m∨p)= (N∧m)∨(N∧p)
And 0∨p= p
14.122 total ways of making a question paper with 12 binary questions top
gateoverflow.in/34779
if a test consist only 12 true false questions then total ways of making test with one answer to each question?
So,
=2*2*2*.....*2
=2^12
So,
=3*3*.......*3
=3^12
valid statement.
vs.
Tautology.
Selected Answer
Contingency-> atleast one row having 0 value and atleast one row having 1 value
Now,
Valid = Tautology
Unsatisfiable = Contradiction
Using above results u would be able to get solutions to all problems related to it ('and' and 'or' --> treat them as logical
connectives)
for eg.--
Is ϕ REFLEXIVE on R(ϕ->ϕ)?
I think it is.
Recall that a predicate logic statement is contingent if its truth value depends on the choice of the universe and on the
interpretations of the predicate symbol S and the constant symbol b involved.
Consider the following predicate logic statements in which b, x and y are elements of the universe U.
B?????????
In these question there are 3 statements followed by 4 conclusions numbered as (a), (b), (c) and (d). Assume the given 3
statements to be true even if they are at variance with commonly known facts.
Conclusions:
a. None follow.
b. Only C4 follows.
c. Only C1 follows.
d. Both C1 and C4 follows.
mathematical-logic verbal-ability
Selected Answer
Consider a set CLOUDS with RAINS, GIRLS and CARS it's subsets and all of them mutually disjoint. The given statements
are true here but none of the conclusions follow.
a) S∧R
b)S→R
c)S∨R
d)None.
Selected Answer
PV Q is equivalent to -P->Q
Q->S
apply transititvity
-P->S
using contrapositive
-S->P
and P->R(given)
-S->R
Selected Answer
Whenever you see this type of question then use this method to solve this.
5^3 = 125 //Divisible by 77 but return remainder 48, which is a huge number. Our objective is to get as less remainder as
possible.
5^4 = 625 // Divisible by 77, and remainder is 9. It is pretty less, then stop here.
= (9 * 9 * 9 * 5) %77
= (729 * 5) %77
= (36 * 5) % 77 // 729%77 = 36
= 180 % 77 = 26
Hence 26 will be the answer.
14.129 Assume the following predicate and constant symbols: top gateoverflow.in/3740
W(x,y): x wrote y
N(x): x is a novel
a: Amit h: Harshal
"Harshal wrote a novel which is longer than any of the Amit's novels"
mathematical-logic normal
Selected Answer
(A) For every book if there exists a shorter book, then harshal has written the shorter one and amit the longer one.
(B) Every book written by Harshal is longer than every book written by Amit.
(C) There exists an x such that if x is a novel written by Harshal, then all novels written by Amit are shorter than x.
(D) There exists an x such that x is a novel written by Harshal and all novels written by Amit are shorter than x.
if d probability dat an individual suffers a bad reaction frm injection of a serum is 0.001.determine the probability that out of
2000 indivisuals exactly 3 individuals suffer a bad reaction?
mean(lambda)=n*p =2
(e ^ -2) *2^3/3¦ =. 18
engineering-mathematics
Let S(x) be the predicate “x is a student,” F(x) the predicate“x is a faculty member,” and A(x, y) the predicate “x has asked y a question,” where the domain consists
of all people associated with your school. Use quantifiers to express each of these statements.
a) Some student has asked every faculty member a question.
b) There is a faculty member who has asked every other faculty member a question.
A(x,y) (here x is student,y is faculty member) student ask faculty member a question
So, at last we can say"Some student has asked every faculty member a question"
A(x,y) (here x is one faculty member,y is all faculty member) faculy member x ask faculty member y a question
So, we can say " There is a faculty member who has asked every other faculty member a question."
it can be visualised as
∀- For universal quantifier p->q condition exists which is same as conditional statement.
if p the antecedent is true q (consequent) should be true but if p is false it q could be anything, the implication would be
true. Same is the case in universal quantifier.
∃- For existential quantifier p^q condition exists.It is same as conjunction. There must exist atleast a condition where p
and q both should be true.
∀x∀yP(x,y)→∀x∀yP(y,x)
1.The above formula is not tautology as the formula will be seen as:
∀x∀y(P(x,y)→∀x∀yP(y,x))
--For every (x,y) if P(x,y) is true then for every (x,y) P(y,x) is true
Why it is not like:
(∀x∀y(P(x,y))→(∀x∀yP(y,x)))
How the above bracketing have been done. Is some rule of precedence used here, if yes then tell their order.
2.Will the same rule will be applied for below formula:
∀x∃yR(x,y)↔∃y∀xR(x,y)
>>>>>>> both are not same . because of the associativity the meaning changed, well u should wait for a better answer.
ans is a
when partition is
numerical-answers
Line segment AB is the major axis, & PQ is the minor axis of this ellipse.
Circles are special cases of ellipse, having length of major axis equal to that of minor axis.
None of eigen value is zero that means both A as well as A 2 + 3A are invertible.
How many non-isomorphic simple graph are there with 5 vertices and 3 edges?how to approach this qus....
graph-theory
I think 2
If a simple graph has 3 component and these component have 4,5,6 vertices ,then maximum number of edge present in
graph.
(a) 26
(b) 76
(c)30
(d)42
graph-theory
component 1 : 4c2 = 6
component 2 : 5c2 = 10
component 3 : 6c2 = 15
total = 6+10+15=31
set-theory&algebra
How do we find whether the group is finite or infinte in questions like below ?
If (G,*) is a group such that (a ∗ b)2 = (a ∗ a) ∗ (b ∗ b) for all a,b belonging to G, then G is
a) Finite group
b) Infinite group
c) Abelian group
set-theory&algebra
Selected Answer
Let a be an element of the group G. If there exists a positive integer n such that an = e, then a is said to have
Finite Order, and the smallest such positive integer is called the order of a, denoted by o(a). If there does not
exist a positive integer n such that an = e, then a is said to have Infinite Order.
There is no way to prove that the given group (G,*) is a finite group or not. Because It does not talk about the sets. I
have read this document. You can also read if you want to see that.
Now In the above question, The correct answer is C. The given group is an Abelien group. A group with Commutative
property is called Abelian group. Because we will get (a * b)^2 = (a * a) * (b * b), only when the group is commutative.
Like this:
(a * b)^2 = (a * b) * (a * b)
= (a * b) * (b * a) // Commutative property
= (a * a) * (b * b) // Associative Property
Hence the given group is Abelian group. Hence Option C is the correct answer.
∀x (( )
G(x) ∨ S(x) → P(x) )
Why not the following?
( ) ( )
∀x G(x) ∨ ∀x S(x) → P(x)
Although universal quantifier is not distributive over disjunction but in this case the ornament will belong to only 1 category,
so is there any with this?
mathematical-logic
Selected Answer
Here ∀x (( ) )
G(x) ∨ S(x) → P(x) : It implies that if an ornament is made of either gold or silver then it is precious.
( ) ( )
∀x G(x) ∨ ∀x S(x) → P(x)
First of all,you have made x of P(x) as free variable, so you should have out quantifier before P(x) also.
Now coming to your confusion,here it implies all ornaments made of gold or all ornaments made of silver are precious. So
here there are possibilities that some ornaments which are both gold and silver in your universe of discourse which is not
true from given context of question.
I hope it is clear.
six balls have to be placed in the squares such that each row has atleast one ball . no of ways of doing this is-
combinatory
Selected Answer
There are 8 cells and 6 balls to place, so we can do it in ( 6 ) . Now we need to remove two cases where toprow is left out
8
without balls and second where last row is left out. So then it becomes ( 6 ) - 2 = 26.
Selected Answer
Here bi-direction is necessary because if only uni-direction implication were there from Left to Right and consider if
number is even but prime ,so LHS becomes false so we can't say anything about RHS i.e whether number is two or
not.This is so because in implication,if LHS is false we can't say anything about RHS and whole implication becomes true
i.e F -> T or F is always true.
Hence we need both side implication to show that if given no. is both prime and even then it is only '2' ,and if given no. is
'2' then its even & prime both.
I am not sure but you can try my option and let me know if i m wrong....
See Question is saying No. Should be even as well as prime(even and prime) and if it is true then no.has to be 2 otherwise
formula sholud not exist....
P(x):No.is even
Q(x):No.is Prime
R(x):No. is 2
then
14.147 How to approach this type of Mathematical logic Question top gateoverflow.in/32667
The answer is option c. I want to know how to solve these type of questions and how other options are not the correct
answer.
mathematical-logic normal
In order to play basketball,10 childrens at playgorund divide themselves into two teams of 5 each.How many divisions are
possible?
combinatory
Selected Answer
15 Probability top
15.1 Bayes Theorem: Bayes Probability top gateoverflow.in/32923
probability bayes-theorem
Selected Answer
blue egg(40%)=40
red=60
8X/13=48
x=78
so P=78/100
Blue(40) Red(60)
empty 10 12
Pearl 30 48
Ans=30/40= 3/4
Selected Answer
Let P(E) = Probability of choosing 1Black & 1 Green balls from Urn.
P(E) = Select Urn1 & choose 1Black & 1 Green balls + Select Urn1 & choose 1Black & 1 Green balls +Select Urn1 &
choose 1Black & 1 Green balls
2
= (1/3)* 2C 1* C 1 / (
7C ) + (1/3)* 3C *4C / (9C ) +(1/3)* 2C *2C / (9C ) = 4/63 + 1/9 + 1/27 = 40/189
2 1 1 2 1 1 2
Now we have to find probability that balls chose were from Urn 'i'
i.e P(E i / E) = ?
Now
P(E1 / E) = P(E1 ∩ E)/P(E) = P(E1)* P(E / E1) / P(E) = (4/63) / (40/189) = 3/10 (Substituting values from above calculations)
P(E2 / E) = P(E2 ∩ E)/P(E) = P(E2)* P(E / E2) / P(E) = (1/9) / (40/189) = 21/40 (Substituting values from above calculations)
P(E3 / E) = P(E3 ∩ E)/P(E) = P(E3)* P(E / E3) / P(E) = (1/27) / (40/189) = 7/40 (Substituting values from above calculations)
125/216
91/216
117/216
9/216
binomial-theorem probability
P(Y)=1/6
=(5/6)^3
an unbiased coin is tossed infinite no of times.The probability that 4th head appear at 10th toss is
1) 0.067
2) 0.073
3) 0.082
4) 0.091
probability coin
Selected Answer
In previous 9 toss ,we have to take 6 tail and 3 head with probability
= (9*8*7)/(3*2)
=3*4*7 = 84
=21/256 =0.082
Let x be the number obtained from rolling a fair dice and you toss an unbiassed coin X times. What is the probablity that X=5
given that you have obtained 3 heads from X tosses?
conditional-probability
My Answer is 2/7.Given that 3 heads appeared it means the outcome of die roll is at least 3.Now if the out come of die roll
is 3, then ways of occurring 3 heads is 3C3, if 4 occurred in die roll then ways of occurring 3 heads is 4C3, similarly 5C3
and 6C3.so all possible ways in which 3 heads can appear is (3C3 + 4C3 + 5C3 + 6C3). The favourable outcome is when
die roll happens to be a 5 and 3 heads appear that is 5C3. So desired probability will be (5C3)/(3C3 + 4C3 + 5C3 + 6C3)
which gives 2/7.
A die is thrown 3 times and sum of 3 numbers thrown is 15. Find the chance that first thrown is 4 ?
probability conditional-probability
Selected Answer
1 / 6 ×2 ×1 / 36
10/ 216
=
= 2/10 = 1/5.
= 2/36 = 1/18.
Consider two independent random variables X and Y with identical distributions.The variables X and Y take blue 0, 1 and 2
with probabilities 1/2, 1/4 and 1/4 respectively. What is conditional probability P(X+Y=2/X-Y=0)???
Selected Answer
P(X = 0) = P(Y = 0) = 2
P(X = 1) = P(Y = 1) = 4
P(X = 2) = P(Y = 2) = 4
Let A = X + Y = 2
and B = X − Y = 0
X+Y=2 P(A∩B)
( )
P X−Y=0 = P(B)
1 1 1
P(A ∩ B) = 4 . 4 = 16
i.e. X = 0 or Y = 0
X = 1 or Y = 1
X = 2 or Y = 2
1 1 1 1 1 1
P(B) = 2 . 2 + 4 . 4 + 4 . 4
6
16
=
Now
1
16
6
X+Y=2 P(A∩B)
P ( ) X−Y=0
= P(B)
= 16
=6
15.8 Expectation: Estimate the expected number of integers with 1000 digits
that need to be selected at random to find a prime, if the probability a
number with 1000 digits is prime is approximately 1/2302. top gateoverflow.in/4628
Answer:2302
probability expectation
Selected Answer
We require expected value of sum of all X i to be 1. Linearity of expectation (refer link at bottom) says that expected value
of sum of a random variable is equal to the sum of the individual expectations.
We have X i = 1/2302 and that is the same for all i. (once we take a number that number can be repeated also and hence
events are independent)
=> ∑ (1/2302) = 1
http://www.cse.iitd.ac.in/~mohanty/col106/Resources/linearity_expectation.pdf
15.9 Expectation: then what is the expected number of games played in the
series top gateoverflow.in/41874
If two teams A and B play a best-of-five series, and if team A has a 1/4 chance of winning any game (and team B has 3/4
chance of winning any game), then what is the expected number of games played in the series. (Note that in a best-of-five
series, the teams play games until one team has won three games.)
expectation
You need to calculate the answer approx. as I have given the equation in terms of p and q with p=1/4 (A's Chance of
winning) and q=3/4 (B's chance of winning).
probability expectation
Selected Answer
The first 9 terms form an Arithemtico-geometric progression and we can find the sum using the formula given here:
https://en.wikipedia.org/wiki/Arithmetico-geometric_sequence
Or, we can sum them individually. Answer comes out to be 3.0928 and adding the last term gives 5.03
Out of 2000 families with 4 children each how many families would you expect to have atleast one BOY..?
probability expectation
Selected Answer
Assumption :
P ( Boy Child) = P ( Girl Child ) = 1/2
Solution :
= 1- 1/16
= 15/16
= 1875
A fair coin is tossed repeatedly till both head and tail appear atleast once. Average no of tosses required is ?
gate-ec-2014 expectation
Answer is 3
Let S be E(x)
S=2*1/2+4*1/4+8*1/4......
S=3
appearing on two fair dice when they are rolled ... top gateoverflow.in/4629
What is expected value of the sum of the numbers appearing on two fair dice when they are rolled given that the sum of
these numbers is at least nine. That is, what is E(X|A) where X is the sum of the numbers appearing on the two dice and A
is the event that X ≥ 9?
probability expectation
Selected Answer
Given sum is at least 9. So, the possible cases are (4, 5), (5, 4), (3, 6), (6, 3), (5, 5), (4, 6), (6, 4), (5, 6), (6, 5) (6, 6)
and all of these are equally likely.
= 10
My Understanding
Method 1 :
Independent events are events whose sample space of Happening will never overlaps
There for the there are 2 kings which are black in a deck so the above problem is NOT INDEPENDENT
Method 2
probability independent-events
Selected Answer
Method 2 is right.
As the both coins being used at Pune & Bangalore are fair,
P(Bh ∩ Ph).
But since the result of coin flip at on location is not going to affect the result at other location, they are independent.
but here it can be observed drom the diagram below that, these two events (Bh & Ph) are having overlapping sample
spaces:
Hence,
"Independent events are events whose sample space of happening never overlaps."
Disjoint sample spaces of the two events tells us that the events are mutually exclusive.
And if any two events are mutually exclusive then they are highly dependent because occurrence of any one event
immediately tells us the non occurrence of other event.
then A ∩ B = null.
but if both P(A) & P(B) are non zero then P(A) x P(B) will never be equal to 0.
So A & B are not independent, if they are mutually exclusive and both of them having non zero probabilities.
15.15 Made Easy_test Series: FST -10 q-65 madeeasy testseries top gateoverflow.in/38337
If it is quantized by a two bit quantizer such that all the levels are equiprobable then the mean square value of the output of
the quantizer is ______________ V.
density of the curve is same to the left as to the right(as in case of Normal distribution) it is symmetric distribution.
https://probabilityandstats.wordpress.com/2015/05/09/the-skewness-of-a-probability-distribution/
Let X be uniformly distributed on {0, 1, 2…32}. What is probability of choosing x ∈ X such that 3x + 12 ≅ 0 (mod 33)?
probability modular-arithmetic
Selected Answer
3x + 12 ≅ 0 (mod 33), where x ∈ {0, 1, 2…32}, can be written as following three equations:
3x + 12 = 33
3x + 12 = 66
3x + 12 = 99
So we have to calculate P x = 7 or x = 18 or x = 29 ,( )
which is same as P(x = 7) + P(x = 18) + P(x = 29).
Since random variable x is uniformly distributed over all of its 33 values, the value of P(x = 7) + P(x = 18) + P(x = 29) will be:
1 1 1
33 33 33
+ +
Hence
(
P x ∣ 3x + 12 ≅ 0 (mod 33) )
= P(x = 7) + P(x = 18) + P(x = 29)
1
= 11
numbers which satisfy condition 3x+12congurent 0(mod33) & which are in {0,1,2,,,,,32} are {7,18,29}
Probability = 3/33 = 1/11
What is the chance that a leap year selected at random will contain 52 Sundays?
a. 1
b. 3/7
c. 1/7
d. 2/7
Selected Answer
The question asks for "contain 52 Sundays" which means at least 52 Sunday. Any year whether leap or not will contain
365
7
= 52 Sundays. So, our answer is
1.
Now, suppose the question is exactly 52 Sundays- meaning 53 Sundays is not favorable:
So, we have 52 Sundays for sure and have 2 extra days. As per question we dont want the 2 of them to be Sundays. We
have 7 choices for the 2 days
All of these are equally likely (random choice of leap year) and 5 among these are favorable. So, our required probability
will be
5
7
.
15.19 Probability: why is it true that 3 events are pairwise independent but
not as a whole ? top gateoverflow.in/26815
Let a ball be drawn from a bag containing 4 balls ,numbered 1 to 4 and events are defined like :
E={1,2 }
F={1,3}
G={1,4}
now these 3 events are pairwise independent but as a whole P(E∩F ∩G) ≠ P(E)*P(F)*P(G)
why is this so and why even they are pairwise independent since ball no 1 is common so if I take two events say E and F
then if E occurs and I had drawn ball 1 so then will it not affect the probability of event F since now for event F to be
happening we will be left with ball 3 only so then why are these even pairwise independent ?
probability
See this
http://gateoverflow.in/33561/how-to-identify-an-independent-event#a33570
15.20 Probability: How to prove that none of the three events are
independent ? top gateoverflow.in/26837
If I have 3 events A,B and C such that all 3 are independent , then how to prove that P(A' ∩ B' ∩ C') is also independent , for
this
=1-[P(A)+P(B)+P(C) -P(A)P(B)-P(A)P(C)-P(A')P(B)P(C) ]
=1 -[P(A)+P(C)+P(A')P(B)-P(A)P(C)-P(A')P(B)P(C) ]
=1-[P(A)+P(A')P(C)-P(A')P(B) -P(A')P(B)P(C) ]
=P(A')P(C') +P(A')P(B)+P(A')P(B)P(C)
Now after this I am unable to get the actual result which I should be getting for proving that even this (A' ∩ B' ∩ C') is also an
independent event , so plz clarify this .
probability
hence P(A'nB'nC')=P(A)'P(B)'P(C)'.
15.21 Probability: How to find probability from given sample space ? gateoverflow.in/26921
top
In answering on a multiple choice test, a student either know the answer or guesses. Let p be the probability that the students knows the answer and 1-p
be the probability that the student guesses. Assume that a student who guesses at the answer will be correct with probability 1/m, where m is the number
of multiple choice alternatives. what is the probability that he answers the question correctly ?
My confusion is that in the question P(K)=p but shouldn't it be 1/3 since we have 2 mutually exclusive events here
probability
"If the student guesses then he does not know the answer & if the student knows the answer then he is not going to
guess."
So yes P(K) and P(G) are mutually exclusive events, since only one of them can happen at a time.
But given P(K) and P(G) are mutually exclusive events, the only fact you can guarantee here is
You can not infer the exact values of P(K) and P(G) from their mutual exclusiveness.
A ∪ B = 1 and A ∩ B = 0.
From (A ∪ B) = A + B + (A ∩ B)
Clearly we can not conclude from this equation that what will be the individual values of A & B.
But one thing about which you are sure is if you know the cardinality of A(say the cardinality of A is x), then you can find
the cardinality of B(it will be (1 − x)), and vice versa.
Similarly here with the given information about P(K) and P(G) you can only say that
P(K) + P(G) = 1
Which shows that events K and G are totally exhaustive, that is the student MUST attempt the question no matter whether
his answers is correct or incorrect but he can not leave it unattempted.
In your conventions,
P(KC) = p,
P(KC ) +P(GC )
A group consists of equal no of men and women .of this grp 20% of men and 50% of women are unemployed .If a person is
selected at random from this group ,the probability of the selected person being employed is ____________
P(E)=P(M∩ E) +P(W∩ E) where U and E are for employed and unemployed ,Now P(M)=P(W)=1/2
so we get
probability
P(employed)=1-P(not employed)
P(not employed)=0.5*0.5+0.5*0.2=0.35
A fair coin is tossed n times .find probability of difference between head and tails is n-3
probability easy
for n= even n-3 is odd and difference between head and tail will be always even
for n= odd n-3 is even and difference between head and tail will always odd
so probability=0
15.24 Probability: Probability:You are given a deck of fifty two cards which
have printed on them a pair of symbols top gateoverflow.in/27919
You are given a deck of fifty two cards which have printed on them a pair of symbols: an integer between 1 and 13, followed by one of the letters “S,” “H,” “D,” or
“C,” There are 4 × 13 = 52 such possible combinations, and you may assume that you have one of each type, handed to you face down.
(a) Suppose the cards are randomly distributed and you turn them over one at a time. What is the average cost (i.e. number of cards turned over) of finding the card
[11,H]?
(b) Suppose you know that the first thirteen cards have one of the letters “H” or “D” on them, but otherwise all cards are randomly distributed. Now what is the
average cost of finding [11,H]?
probability algorithms
(b)If first 13 cards have H in all then avg. turn will be 13+1/2=7
if first 13 cards have D in all then avg. turn will be 39+1/2 =20
15.25 Probability: How to find probability of getting two heads from a set of
fair and unfair coins ? top gateoverflow.in/26923
I have 4 fair and 3 unfair coins ,now I am chosing 2 coins what is the probability of getting 2 heads ,Now I am confused
while calculating P(FU) i.e. probability that I chose 1st fair coin and then chose 2nd coin as unfair coin
According to me P(FU)= P(F)*P(F/U) = 4/7 * 3/ 6 since after I chose a fair coin , then will have remaining 6 choices , so
what's the issue in this , then using total probability I can calculate
P(HH)=P(FF∩HH) +P(FU∩HH)+P(UU∩HH)
P(FF)=2/7 ,P(UU)= 1/7 other things are also stated ,only issue is with this P(FU ) , even it could be P(UF) but what's the
issue since both would be same only .
probability
then 4C2/7C2[(0.5)(0.5)]+3C2/7C2[(Ph)(Ph)]+(4C1*3C1)/7C2[(0.5)*(Ph)]
A bag contain 4 white and 5 black balls and another bag contain 3 white and 4 black balls . A ball is taken out from the first
bag and without seeing its colour is put in second bag .A ball is taken out from the latter . Find the probability that ball
drawn is white ?
probability
Selected Answer
Select a Black Ball from BAG A and put it into BAG B. Now select a white Ball from BAG B. (5C1/9C1)*(3C1/8C1) = 15/72
Select a White Ball from BAG A and put it into BAG B. Now select a white Ball from BAG B. (4C1/9C1)*(4C1/8C1) = 16/72
a fair coin is tossed 10 times ,wt is the probability that head will come up in first two toss of coin??
probability
Selected Answer
"a fair coin is tossed 10 times ,wt is the probability that head will come up in first two toss of coin "
A pair of dice is rolled again and again till a total of 5 or 7 is obtained. The chance that a total of 5 comes before a total of 7
is
probability
Selected Answer
Prob of 5 = 4/36 = 1/9 Prob of 7 = 6/36 = 1/6 Prob of 5 and 7 will not occur = 1 - (1/9 + 1/6) = 13/18
= (1/9)/(5/18)
= 2/5 (ans)
It is known that screws produced by a certain company will be defective with probability 0.01 independently of each other.
The company sells the screws in package of 10 and offers a replacement guarantee that at most 1 of the 10 screws is
defective. What proportion of packages sold must the company replace?
probability
The probability that a screw is defective (screwed :P) is 0.01, independently. Thus, probability of a screw not being
defective is (1 − 0.01) = 0.99
The company offers a guarantee that in any pack of 10, at most one is defective. That means, if there are more than one
defective screws in your pack, the company will replace it.
The probability that there is more than one defective piece in a pack of 10 screws can be calculated as:
P ( more than
one defective ) = 1− ((
P zero
defective ) (
+ P one
defective ))
(10 × 0.01 × 0.99 ) 9
choose 1 screw out of 10
(( )
0.01 = P(1 defective screw )
≈ 1 − 0.99573
P ( more than
one defective ) ≈ 0.00427
Packet will be returned if at-least 2 defective screws are found in the packet.
since probability of being defective does not depend on the other : This case can be solved by Binomial Distribution with
n = 10
checking a screw in the packet (check for it being defective) is a trial and we have a total of n = 10 such trials. each trial is
independent of the other.
where, p = probability of success(here, which is being defective, coz we have defined x like that) = 0.01
so,
and
which imply
A coin is tossed untill a Head appears or the Tail appear 4 time in succession . Find the probability distribution of number of
tosses ?
probability
P(x=1)=1/2 (p(H))
P(x=2)=1/4 p(TH)
P(x=3)=1/8 p(TTH)
P(x=4)=1/8 p(TTTH,TTTT)
∑p(x)=1
out of 2n+1 tickets consecutively numbered 3 are drawn at random . Find the probability that number on them are in AP ?
probability
Selected Answer
General way
The total number of combination (2n+1C3)
If 1 is slected total number of combination n
If 2 is slected total number of combination n-1
If 3 is slected total number of combination n-1
.
.
.
If (2n-2) is selected total number of combination 1( i.e. 2n-1 2n 2n+1)
If (2n-2) is selected total number of combination 1( i.e. 2n-2 2n-1 2n)
(n −1 ) (n −1 +1 )
2
So total number of combination = n+ n-1 + n-1 + n-2 + n-2+ ..............+ 1 + 1 = n + ∗2
So probability = n^2/(2n+1C3)
from a well shuffled pack of 52 cards. Three cards are drawn at random. Find the probability of drawing an ace, a king and a
jack,
a) 16/5525
b) 16/625
probability
Selected Answer
52
3
Number of ways of choosing 3 cards from a pack of 52 cards is = ( ) =22100
64 16
22100 5525
So the probability of drawing an Ace, a King and a Jack = =
Two cards are drawn from a well shuffled pack of 52 cards without replacement . What is probability one is red queen and
other king is of black colour ?
probability
Selected Answer
Now Select one Queen out of two Red Queen i.e. 2C1 ways
Select one Black King out of Two Black King i.e. 2C1 ways.
Sample Space = 52 C2
52 cards are equally given to 4 players a,b,c,d. a and b have together total 8 spades among them. Find probability that c
has 3 spades out of remaining 5.
In this ques , sample space reduces to 44 cards , so is the answer 5C3 * 39C10 /44C13 Correct ?
probability
Selected Answer
21C
10 --> to have other 10 non-spades
So probability is
5C 21C
3. 10
26C
13
answer = option C
but why?
probability engineering-mathematics
Selected Answer
By replacement we mean the same coupon once remove can be put back into the set.
For 9 to be the largest of the seven coupons the selected coupons must be between 1 and 9
so 9^7 possibilities. But this way it is also possible that 9 isnt selected even once. So out of 9^7 we need to remove all
those cases where 9 isnt present, which means the numbers are selected only between 1 and 8.
The probability of event A occurring is 0.5 and of B occurring is 0.3. If A and B are mutually exclusive events then the
probability of neither A nor B occurring is___
Solution : 0.2
P(A' UNION B' ) = 1- P(A UNION B)
1-0.8
= 0.2
My Solution : 1
= 1 - 0 ( mutually exclusive )
=1
probability
"neither A nor B" means "A doesn't occur AND B also doesn't occur".
ie P(A' INTERSECTION B')
=P(A UNION B)'
=1- P(A UNION B)
=1-(P(A)+P(B))
= 1-0.8 =0.2
What you have taken "P(A' UNION B' )" is "A doesn't occur OR B doesn't occur".
A police man fires four bullet on a dacoit . The probability that dacoit will be killed by one bullet is 0.6 .what is prob that
dacoit is still alive ?
probability
Selected Answer
0.4x0.4x0.4x0.4
From a well shuffled deck of 52 cards, cards are dealt. The probability that the 13 th card is the first king to be dealt is
____________ × 10–1.
probability
n(E)= ( 12 ) ∗ 4 (first 12 card are non king i.e. 12 out of 48 and 13th is 1 out of 4 kings)
52
n(S)= ( 13 )
=0.43885=4.3885 *10 −1
A and B throwing unbiased dice alternatively.Whoever throws a number >= 5 first wins. If A throws the dice first then
probability of B's winning the game is _______.
probability
Let ~a denote the probability that player A does not throw >=5 and a denote the probability that player A throws >=5.
Consider similar notation for player B as well.
Any player wins if he gets 5 or 6. Probability of getting 5 or 6 is 2/6 = 1/3. Probability of not getting 5 or 6 = 2/3
15.40 Probability: Two cards are drawn together from a pack of 52 cards.
The probability that one is spade and other is king is ? top gateoverflow.in/39093
I did it from conditional probability , first case when we pick one spade first and then pick king next
so it is equal to ,probability of picking up a spade*probability of picking a king given that we have already picked up a spade so it is equal to 13/52 * 1/51
And then probability of picking up a king and a spade =probability of picking up a king *probability of picking up a spade given that we have already picked up a king
which is equal to 4/52 * 12/ 51
probability
Selected Answer
13 spades
{(12c1 * 1c1)(both the cards from spade) +(13c1 * 3c1)(king from another sets)} / 52c2
One (King (not spade)) other is Spade + One( king spade ) One more for Spade
probability
If A and B are 2 independents events such that P(A' ⋂ B) = 2/15 and P (A⋂B') = 1/6 . find P (B)
probability
Selected Answer
From a lot containing 25 items , 5 are defective and 4 are chosen at random . Let X be the numbers of defective found
.Obtain the probability distribution of X if item are choosen without replacement ?
probability
15.44 Probability: What is the chance that a leap year selected at random
will contain 52 Sundays? top gateoverflow.in/42317
What is the chance that a leap year selected at random will contain 52 Sundays?
probability
Selected Answer
so 366/7=52.29 which means 52 complete weaks so 52*7=364 days so last 2 days are remainingit can be
p(52 sunday)=all pair expect those having sunday bcz we want 52 sunday/TOTAL PAIR
so ans is 5/7
In a leap or non leap year you any ways have 52 week . so 52 week will cover will 52 sundays so prob 1 ;
Bdw for the above answer : if they would have asked 53 sundays in a non leap year it would have been 2/7
probability
Selected Answer
1
6
should be the correct answer.
Three numbers are chosen at random without replacement from {1, 2, 3, . . . . . , 10}. What is the probability that minimum of the
chosen numbers is 3 or their maximum is 7?
11
a. 30
11
b. 40
1
c. 7
1
d. 8
probability engineering-mathematics
Selected Answer
= 7C2/10 C3
For this 3 is already taken with no choice and for remaining 7C2 is total number of ways to choose 2 numbers more than 3
(i.e. 4,5,6,7,...10) from given set.
= 6C2/10 C3
For this 7 is already taken with no choice and for remaining 6C2 is total number of ways to choose 2 numbers less than 7
(i.e. 0,1,2,.....6) from given set.
= 3C1/10 C3
For this 3 & 7 is already taken with no choice and for remaining 3C1 is total number of ways to choose 1 number more
than 3 and less than 7 (i.e. 4,5,6) from given set.
Now the probability that minimum is 3 or maximum is 7 among chosen 3 numbers i.e. P(A ⋃ B) .
= (21 + 15 - 3) / 120
= 33/120
= 11/40
favourable events from which we need to choose two more when 3 minimum is already chosen = {4, 5, 6, 7, 8, 9, 10}
similarly, favourable events from which we need to choose two more when 7 maximum is already chosen = {1, 2, 3, 4, 5,
6}
7 6 3
(2 ) + (2 ) − (1 )
10
required probability =
(3)
21 + 15 − 3
120
=
33
= 120
11
40
=
probability engineering-mathematics
Since the balls are put back with replacement, the probability will not change.
P(G) - probability for green ball | P(B) - probability for blue ball
M wins the game if either he draws in the first turn, or he draws a blue and N also draws a blue and then he draws a green
in his turn. Thus, we will get a series like this :
Using the above values, we put in the series and we get the relation.
=x (x+y)/x 2+2xy+y2-y2
=x+y/x+2y
x+y/x+2y=2/3
x=y
so ans is b
From a pack of 52 cards , 4 cards are drawn . Find the probability that they are the 4 honours of same suit ?
probability
If 6 out of 10 people have their birthday in the 4 months of the year between February and May inclusive,then What is the
probability is the next person has also his or her birthday in this 4 months?
probability
So probability is 4/12*1/4=1/12
Three cards are drawn with replaacement from a well shuffled back of cards . Find the prob that cards drawn are King queen
and jack ?
probability
here also same scenerio P(KING n QUEEN n JACK)=P(king).p(queen).p(jack). bt here also card order is matter means
J,Q,K can be arranged in 6 ways
For the three events A, B, and C, P (exactly one of the events A or B occurs) = P (exactly one of the two events B or C
occurs) = P(exactly one of the events C or A occurs) = p and P (all the three events occur simultaneously) = p2 , where
1
0 < p < 2 . Then the probability of at least one of the three events A, B and C occuring is
probability
Selected Answer
Similarly,
Also, P(A ∩ B ∩ C) = p2 .
¯
We want P(A ∪ B ∪ C)
3p
Two aeroplanes I and II bomb a target in succession. The probability of I and II scoring a hit correctly are 0.3 and 0.2
respectively. The second plane will bomb only if the first misses the target.The probability that the target is hit by the
second plane ?
probability
Probability that the target is hit by the second plane means Target Hit and that bcoz of plane 2.
E1 and E2 are events in a probability space satisfying the following constraints p(E1)= p(E2);p(E1U E2) = 1; E1 & E2 are
independent then p(E1)=
probability
Given P(E1 U E2) = 1, P(E1) = P(E2), P(E1 intersection E2) = P(E2) * P(E2) (since E1 & E2 are independent).
Now by using inclusion exclusion principle, P(E1 U E2) = P(E1) + P(E2) - P(E1 intersection E2).
Let P(E1) = a, then P(E2) = a, and P(E1 intersection E2) = a * a. Putting all these values along with P(E1 U E2) = 1, leads
to a quadratic equation a^2 - 2a + 1.
Suppose that the probability that x is in a list of n distinct integers is 2/3 and that it is equally likely that x equals any
element in the list. Find the average number of comparisons used by the linear search algorithm to find x or to determine
that it is not in the list.
probability
Selected Answer
(
Expected number of comparisons = ∑ni=1 number of comparison till ith entry × probability of getting the number at ith entry + 3 . n )
1
Since it is equally likely that x is any element in the list, probability that x is element i is 3n
So,
2 n n +1 n 2n +1
( )
Expected number of comparisons = ∑ni=1 i. 3n +3 = 3 +3 = 3
Now, there is a catch here. We have counted one comparison for one element in the linear list. But if we count the loop
exit condition and the final found or not check also as in the algorithm give here
http://www.programmingsimplified.com/c/source-code/c-program-linear-search, we get 2i + 1 comparisons for a successful
check at ith position and 2n + 2 comparisons if x is not in the list. This would give
2 (2n +2 ) 2.(n . (n +1 ) +n ) 2n +2 2n +4 2n +2 4n +6
(
Expected number of comparisons = ∑ni=1 (2i + 1). 3n
) + 3
= 3n
+ 3
= 3
+ 3
= 3
probability
Selected Answer
In the favorable case we have (n-1) choices for each of the m balls and the total number of choices for each ball is m. So,
probability
= [(n-1)/n]m
[Here first bin is fixed. Had it been any one bin being empty, answer would have been multiplied by nC1]
probability
Favourable outcomes: The point should be nearer to center than from circumference, it means the point could be
anywhere within the radius r/2, = pie* (r/2)^2. Total possible outcomes: The point could be anywhere within the radius
r;=pie* r^2. Thus probability = area(r/2)/area(r) = 1/4.
It is known that a bus will arrive at random at a certain location sometime between 3:00 P.M. and 3:30 P.M. A man decides
that he will go at random to this location between these two times and will wait at most 5 minutes for the bus. If he misses
it, he will take the subway. What is the probability that he will take the subway?
probability
Selected Answer
the white area is our desire outcome and the total area is total outcome .
(0.5*25*25+30*30*0.5)/30*30=0.8472
The bus and man can arrive in any time between 3:00 and 3:30.
Probability of man arriving before 3:25 = 5/6 as each 5 minute interval is equally possible for his arrival.
Probability of man arriving before 3:25 and catching the bus = 5/6 * 1/6 = 5/36 (as the probability for bus to come in any
non-overlapping 5 minute interval- 0-5, 1-6... is 1/6 as probability for bus arrival must be 1/6 for every consecutive 5
minutes out of 30 minutes).
Probability of man coming after 3:25 and catching the bus = 1/6 * 1/6 *x = x/36, where x is the probability that man
comes first. Since both man and bus are equally likely to come first, x = 1/2, giving required probability = 1/72.
So, Probability that man catches the bus = 5/36 + 1/72 = 11/72.
A player in the Powerball lottery picks five different integers between 1 and 59, inclusive, and a sixth integer between 1 and
39, which may duplicate one of the earlier five integers. The player wins the jackpot if the first five numbers picked match
the first five number drawn and the sixth number matches the sixth number drawn.
probability combinatory
15.58 Probability: Suppose the probability that x is the ith element in a list of
n distinct integers is i/[n(n + 1)]. top gateoverflow.in/4633
Suppose the probability that x is the ith element in a list of n distinct integers is i/[n(n + 1)]. Find the average number of
comparisons used by the linear search algorithm to find x or to determine that it is not in the list.
probability
Selected Answer
Expected number of comparisons = sum((number of comparison till i th entry) * probability of getting the number at i th
entry) + n. probability that x is not in the list.
i 1
i n i2 n 2n +1 n n . (n +1 ) . (2n +1 ) 5n +1
= ∑ni=1 n . (n +1 ) . i + 2 = ∑ni=1 n . (n +1 ) + 2
= 6
+ 2
∵ ∑ni=1 i2 = 6
= 6
Now, there is a catch here. We have counted one comparison for one element in the linear list. But if we count the loop
exit condition and the final found or not check also as in the algorithm give
h e r e http://www.programmingsimplified.com/c/source-code/c-program-linear-search, we get 2i + 1 comparisons for a
successful check at ith position and 2n + 2 comparisons if x is not in the list. This would give
i 2n +2 2i 2 +i 2n +1 1 5n +4 1 10n +11
probability
February 29 occurs only in leap years. Years divisible by 4, but not by 100, are always leap years. Years divisible by 100, but
not by 400, are not leap years, but years divisible by 400 are leap years.
a) What probability distribution for birthdays should be used to reflect how often February 29 occurs?
b) Using the probability distribution from part (a), what is the probability that in a group of n people at least two have the
same birthday?
probability
Selected Answer
(a) We need to find the probability that a birthday comes on February 29. Consider a 400 year period- as leap year cycle
repeats every 400 years. Number of leap years in this = 400/4 - 4 + 1 = 97. So,
In these days February 29 repeats 97 times. So, probability of birthday on February 29 = 97 / 146097
= 1 - (probability that every birthdays are distinct with 1 birthday being feb 29) - (probability that every birthdays are
distinct with none being on February 29)
= 1 - ((365 * 364 * ... 365 - n + 2)/365 n) n (400/146097)n-1 (97/146097) - ((365 * 364 * ... 365 - n +
1)/365n) (400/146097)n
(In the second term, we are picking distinct days and probability of a birthday falling on each such day is 400/146097 for
any day other than feb 29 and 97/146097 for feb29) (n is used since birthday of any of the n person can come on feb 29)
A box contains 10 screws, 3 of which are defective.Two screws are drawn at random with replacement.The probability that
none of the two screws is defective will be
probability
Answer is 10240/C(52,5)
My approch:
2*(4)^5/C(52,5)
probability
1 2 3 4 5 6 7 8 9 10 J Q K Ace(1)
15.62 Probability: A pair of dice is rolled again and again till a total of 5 or 7
is obtained. The chance that a total of 5 comes before a total of 7 is?? gateoverflow.in/1116
top
probability
Selected Answer
(I ignored the reverse cases like (4,1) for (1,4) as this happens for both 5 and 7 and hence won't affect the probability)
(We can ignore all other cases, as questions asks for probability of sum = 5 compared to sum = 7)
1/9 is the probability of sum of 5 and 1/6 is the probability of sum of 7. Probability that neither happens = 26/36 =
13/18.
1/9 2
S = (1 − (13/18) = 5
15.63 Probability: If two squares are chosen at random on a chess board the
probability that they have a side in common is? top gateoverflow.in/1115
a) 1/9
b) 2/7
c) 1/18
d) none
probability
Selected Answer
In each row we have 7 pairs of squares having a common side. So, totally 8*7 = 56 such squares horizontally. Similarly,
we get 56 such squares vertically. So, total number of favorable cases = 56+56=112.
Required probability = 112/64 C2
= 112*2/(64*63)
= 1/18
In 64 squares,
4 at-corner squares, each has only 2 options to select from so 4*2C1
6*4 = 24 side squares, each has only 3 options to select from so 24*3C1
6*6 = 36 inner squares , each has 4 options to select from so 36*4C1
So.
15.64 Probability: A man visits a couple who have 2 children. one of the
children, a boy, comes into the room. top gateoverflow.in/782
A man visits a couple who have 2 children. one of the children, a boy, comes into the room. find the probability p that the
(a)1/3
(b)2/3
(c)1/2
(d)3/4
probability normal
Selected Answer
Since, it's given that the first one is a boy, the second event is independent of the first and the probability is 1/2.(The sample space contains only the events
concerning the second child ({G, B}) . Had the question been "what's the probability of both the children coming to the room being boys given that one is
surely a boy", then the sample space will contain BB, BG and GB and probability would be 1/3)
15.64 Probability: Find the smallest number of people you need to choose at
random so that the probability that at least two of them were both born on
April 1 exceeds 1/2. top gateoverflow.in/4604
probability
Selected Answer
At least 2 out of n people born on April 1 means either all n are not born on April 1 or exactly 1 born on April 1.
where P(Y) is the probability that none are born on April 1 and P(Z) is the probability that exactly 1 is born on April 1
P(3) = 0.016
P(50) = 0.24
P(120) = 0.517
P(119) = 0.514
P(115) = 0.502
P(114) = 0.497
probability
15.65 Probability: 19. a) What is the probability that two people chosen at
random were born during the same month of the year? top gateoverflow.in/4603
19.
a) What is the probability that two people chosen at random were born during the same month of the year?
b) What is the probability that in a group of n people chosen at random, there are at least two born in the same month of
the year?
c) How many people chosen at random are needed to make the probability greater than 1/2 that there are at least two
people born in the same month of the year?
probability
Selected Answer
(a). Let the first person's birth month be x. Now, the second person must born in the same month (1/12 probability) to
satisfy the given condition as both their births are independent events. So, required probability is 1/12 .
We have n persons and required to find if at least two of them have same birth month. So, we find the probability of none
of them have same birth month and subtract this from 1. (n <= 12 as when n = 13, surely two persons will have same
birthmonth as per pigeonhole principle)
P(X') = 12 * 11 * .. (12-n+1) / 12 n (As the first person has 12 months to choose from, second person has 11, and so on)
= 12 Pn / 12n
P(X) = 1 - P(X')
(c)
Suppose that the length of the phone calls in minutes is an exponential random variable with parameter λ = 1/10.
If someone arrives immediately ahead of you at a public telephone booth, find the probability of that you will have to wait
probability random-variable
0 if x< 0
The cumulative distributive function F(a) of an exponential random variable is given by
F(a) = P(x≤a) = ∫ 0a λe-λx dx = 1- e -λ*a
a) P(x>10) = 1- P(x<10)
= 1- (1- F(10))
= 1 - (1- e-λ*10) = e -1 = 0.368
15.67 Random Variable: You are asked to open one door. There is a large
prize behind one of the three doors and the other two doors are losers. top
gateoverflow.in/4619
You are asked to open one door. There is a large prize behind one of the three doors and the other two doors are losers.
After you select a door, Monty Hall opens one of the two doors you did not select that he knows is a losing door, selecting at
random if both are losing doors. Monty asks you whether you would like to switch doors. Suppose that the three doors in the
puzzle are labeled 1, 2, and 3. Let W be the random variable whose value is the number of the winning door; assume that
p(W = k) = 1/3 for k = 1, 2, 3. Let M denote the random variable whose value is the number of the door that Monty opens.
Suppose you choose door i.
probability random-variable
Selected Answer
(a) 1/3 as one out of 3 is the favourable case and all are equally likely
(b)
P(M=1|W=1, i = 1) = 0
P(M=2|W=1, i = 1) = 0.5
P(M=3|W=1, i = 1) = 0.5
P(M=1|W=2, i = 1) = 0
P(M=2|W=2, i = 1) = 0
P(M=3|W=2, i = 1) = 1
P(M=1|W=3, i = 1) = 0
P(M=2|W=3, i = 1) = 1
P(M=3|W=3, i = 1) = 0
(c)
P(W=1|M=2) = 2/3 (i = 3 implied by distinct values, and i=3 with probability 1/3 and Monty never selects the winning
one making the other one's probability to win 2/3)
P(W=1|M=3) = 2/3 (i = 2)
P(W=2|M=1) = 2/3 (i = 3)
P(W=2|M=3) = 2/3 (i = 1)
P(W=3|M=1) = 2/3 (i = 2)
P(W=3|M=2) = 2/3 (i = 1)
(d). The probability of my selection winning is 1/3 and probability of the remaining door winning is 2/3 => so, if I believe
in probability I should change the doors.
http://faculty.washington.edu/tamre/BayesTheorem.pdf
D).yes the door should be changed as the probability of winning after switching the doors is 66.66%.Here it goes how? If
the prize is behind Door 1, Monty will open either Door 2 or Door 3 to reveal an empty door. You switch to the other of
Door 2 or Door 3, and in either case you switched to a door with nothing behind it (remember, the car is behind Door 1).
If the car is behind Door 2, Monty will open Door 3. This is because he always opens a door which has nothing behind it,
and he can't open Door 1 because that was your original choice. So the only door you can switch to is Door 2, which is the
door with the car behind it.'You win!' If the car is behind Door 3, Monty will open Door 2. This is because he always opens
a door which has nothing behind it.and he can't open Door 1 because that was your original choice. So the only door you
can switch to is Door 3, which again is the door with the car behind it. Ding! You win!So out of three you win two times so
probability is 66.66%.
f ) Show that
g) Show that E(I j,k ) = 1/2.
h) Use parts (f) and (g) to show that E(I ) = n(n − 1)/4.
i) Conclude from parts (b), (d), and (h) that the average number of comparisons used to sort n integers is .
probability random-variable
Let X∈{0,1} and Y∈{0,1} be two random variables if P(X=0) =p and P(Y=0)=q then P(X+Y>=1) is equal to
1)pq+(1-p)(1-q)
2)pq
3)p(1-q)
4)1-pq
Selected Answer
X∈{0,1} Y∈{0,1}
= 1- P(X=0,Y=0)
=1- {P(X=0).P(Y=0)}
=1-pq
random-variable
P(x>1)=1-p(x<1)
value of k as 3/14
P(1)=3/14*11/6
=11/28
P(x>1)=1-11/28=17/28
X is uniformly distributed random variable that takes values between 0 and 1.The value of E(X^3) will be
random-variable expectation
a=0 b=1
1/b-a=1
Ans is 1/4
Consider two independent random variables X and Y having probability density functions uniform in the interval [ − 1, 1]. The
probability that X2 + Y2 > 1 is
1. π/4
2. 1 − π/4
3. π/2 − 1
4. Probability that X2 + Y2 < 0.5
5. None of the above.
probability random-variable
Selected Answer
x1 x2 x3 are three independent random variables distributed uniformly on [0,1].Find probability that P(X1 is largest )
random-variable probability
probability is 1/3..
Solution:- there are 6 cases P(x1>x2>x3), P(x1>x3>x2), P(x2>x1>x3), P(x2>x3>x1), P(x3>x2>x1), P(x3>x1>x2).
All cases are equally likely and hence P(x1) being largest is P(x1>x2>x3) or P(x1>x3>x2).
Let x1 x2 x3 be three independent and identically distribuyed random variables with uniform distrbution on (0,1) find
probability p(x1+x2<=x3)
probability random-variable
X1+X2<=X3
X1+X3<=X2
X2+X3<=X1
X2+X1>=X3
X2+X3>=X1
X3+X1>=X2
Q) Let x be normal variable with mean 8 and standard deviation 4 then p(X ≤ 5) is
statistics
This is the normal distribution curve for this mean and standard deviation μ=8 and σ=4
Since the area under the curve from μ-3σ(-4 here) to μ(8) is 0.5 hence P(x≤5) will be even smaller but will not be zero.
Hence option A is correct.
if today is not Monday, Then I have read Don Quixote" What is the probability of given proposition having truth value "True",
If chances that I be telling truth about reading Don Quixote are 10%.
Your Answer: 0.775
Accepted answer is between: 0.22 and 0.23
probability testbook
a)(n2-1)/12
b)(n+1)/6
c)(n-1)(2n+1)/3
d)n(n-1)
variance
Selected Answer
= ((1-μ)2+(2-μ)2+...+(n-μ)2)/n
= (n+1)(n-1)/12
= (n 2-1) / 12
consider the first 10 positive integers . If we multiply each number by -1 and then add 1 to each number , the variance of
the numbers so obtained is
1) 6.5
2) 8.25
3) 3.87
4) 2.87
variance
Selected Answer
σ= ∑10
i =1
n
= ∑10
i =1
n
− μ2 = 10
− ( − 4.5)2 = 6 .10
(
− 20.25 ∵ Sum of squares of first n natural numbers = 6
) = 28.5 − 20.25
The mean of 100 observation is 50 and there standard deviation is 5. The sum of all squares of all the observation is
1) 50000
2) 250000
3) 252500
4) 25500
variance
Selected Answer
σ= Σni=1 n
= Σni=1 n − Σni=1 n + μ2 = Σni=1 n − 2μ2 + μ2 = Σni=1 n − μ2
Two Squares are chosen at random on a chess board then what is the probability that they have a side in common ??
Selected Answer
is it 1/18 ?
First understand for one head if first flip is head then stop but if first flip is tail then we have wasted one flip n we have to
compute x
x=1/2(1+x)+1/2(1)
X=2
If the first flip is tails, we have wasted one flip,but if we get heads on the first flip, we still have to think about what will
come next:
we get a tail,we have wasted one more flip but if we get head then stop.
=6
15.81 A fair coin is tossed 100 times. The Probability of getting 50 heads is
close to one of the following numbers: a) 0.001 b)0.1 c)0.3 d)0.4 top gateoverflow.in/5129
Selected Answer
A computer program selects an integer in the set {k : 1 ≤ k ≤ 10,00,000} at random and prints out the result. This process
is repeated 1 million times. What is the probability that the value k = 1 appears in the printout atleast once ?
Probability that the value k=1 appears at least once= nC1 (1/1 million)* (1-1/1million)^(n-1) + nC2 (1/1 million)^2 *(1-
1/1 million)^(n-2) +..................
OR
Probability=1- (No. of times 1 doesn't appear/Total no. of times process is repeated)^Total no. of times process is
repeated
=1 - (999999/1000000)^1000000
=0.632121
This fraction might seem too tedious to calculate so you may just shorten the question like finding out probability if
process is repeated 1000 times. then also the probability comes out nearly 0.632.
Moreover, you may just look at the options and eliminate the options.
A class of the first year B.Tech students is composed of four batches A,B,C and D, each consisting of 30 students. It is found
that the sessional marks of students in Engineering Drawing in batch C have mean 6.6 and deviation 2.3. The mean and
standard deviation of the marks for the entire class are 5.5 and 4.2 respectively. It is decided by the course instructor to
normalized the marks of the students of all batches to have the same mean and standard deviation as that of the entire
class. Due to this, the marks of a student in batch C are changed from 8.5 to
a) 6.0 b) 7.0 c) 8.0 d) 9.0
Mean of 30 marks must be reduced from 6.6 to 5.5 while SD must increase from 2.3 to 4.2.
Multiplying each number by n changes SD by n (Since SD = ∑i(xi − μ)2 ). So, we can make the SD change from 2.3 to 4.2
by multiplying each term by 4.2/2.3. This will also change the mean from 6.6 to 12.05.
∑ixi
Now, subtracting a constant from each term makes the mean reduce by that same constant. (since μ = n ). So, to reduce
the mean from 12.05 to 5.5 we should subtract 6.55 from each term. (Subtracting a constant from each term won't affect
the standard deviation as mean and each term change by the same amount and hence also won't change).
So, our given value 8.5 becomes 8.5 * 4.2 / 2.3 = 15.52 for adjusting SD, and then becomes 15.52 - 6.55 = 8.97 when
adjusted for mean.
Q1 ) With Replacement
Q2 ) Without Replacement
What is the probability that they are of different colors . Find answer in two questions
Q1]
Probability of getting red in first draw, P(R) = 26/52 = 1/2
Probability of Getting black in second draw, P(B) = 26/52 = 1/2
probability of getting different color = P(R) * P(B/R) + P(B) * P(R/B)
1 1 1 1
= 2 × 2 + 2 × 2
1
= 2
Q2]
= 52 × 51 + 52 × 51
= 0.509
a) 1 b) 3 c) 2 d) 1/sqrt(3)
Selected Answer
Answer: p + (n − 1)p(1 − p)
2 friends Alice and bob have found an unfair coin ,it has 72% chance of coming up heads .Alice and bob play a game with
this coin ,If coin comes up with head and then tails,Alice wins and if its in the reverse way then bob wins .And if neither of
the two things happen then the game restarts and continues until there is a winner ,what is the probability that bob wins ?
Selected Answer
P(H)=0.72 P(T)=0.28
=x1(1+y1+y1*y1+...)
=x1(1/(1-y1))
=0.2016(1/(1-0.5968))
=0.5
A fair coin is tossed until one of 2 sides occurs twice in a row . Probability that the number of toses required is even is
Selected Answer
Assume that there are 6 color letters L1,L2,L3,L4,L5,L6 are to be placed in same color envelop E1,E2,E3,E4,E5,E6 (one letter
for each envelop). What is the number of possibilities to place every letter in wrong color envelop?
a) 260
b) 265
c) 270
d) 275
Derangement of 6 people :)
Answer is 265
http://mathworld.wolfram.com/Derangement.html
Success will be in nth try i.e. n-1 Unsuccessful try must be there.
P(Success in nth try) = (1-1/n)(1-1/n)(1-1/n).........n times * 1/n =((n-1)/n) n-1 *1/n
15.92 Suppose that X 1 and X 2 are independent Bernoulli trials each with
probability 1/2, and let X 3 = (X 1 + X 2 ) mod 2. a) Show that X 1 , X 2 ,
and X 3 are pairwise independent, but X 3 and X 1 + X 2 are not
independent. top gateoverflow.in/4632
15.93 What is the expected number of bins that remain empty when m balls
are distributed into n bins uniformly at random? top gateoverflow.in/4636
P(Xi) = [(n-1)/n]m
E(Xi) = 1 * [(n-1)/n]m
Now, we require the expectation of ∑ X i which is equal to the summation of their individual expectation as per linearity of
expectation.
= n [(n-1)/n]m
http://www.cse.iitd.ac.in/~mohanty/col106/Resources/linearity_expectation.pdf
15.95 Let X n be the random variable that equals the number of tails minus
the number of heads when n fair coins are flipped. a) What is the expected
value of X n ? b) What is the variance of X n ? top gateoverflow.in/4631
Answers:
a) 0
b) n
15.95 Find the probability that the first child of a family with five children is
a boy or that the last two children of the family are girls, for the condition
that the probability of boy is 0.51 ? top gateoverflow.in/12601
This is my approach .
the probability of 1 st child is boy and the probability of last two child is girl (51*49*49/100 3) .
so the probability of 1 st child is boy or the probability of last two child is girl = (51/100) + (49/100) 2 - (51*49*49/1003)
= 0.6276
a man appeared for a job interview in companies A,B,C,D . the probability of getting job in A,B,C,D are 0.6,0.5,0.5 and 0.7
. the probability that the candidate will get the job is ?
Selected Answer
Given the probability of getting job in A,B,C,D are 0.6,0.5,0.5 and 0.7
probability that the candidate will get the no job= 0.4 * 0.5 * 0.5 * 0.3 = 0.03
probability that the candidate will get the job = 1 - probability that the candidate will get the no job
=( 1 - 0.03 ) = 0.97
A and B play game in whic they toss coin 3 times.The one obtaining heads first wins the game.If A tosses coin first and if
total value of stake is Rs 20.How much should be contributed by B in order that game is fair?
I think A flips 3 time if loose then B flips three time and it continues till anyone wins.
First, calculate the probability that A does not win on his first turn. That is simply the probability that a coin flipped three
times turns up no 'heads'.
That probability is (1/2)^3 = 1/8. So, that means A has a 7/8 chance of winning on his first turn.
Assuming A doesn't win (which happens 1/8 of the time), B then flips three times.
The probability that B doesn't win these three flips is again 1/8, so the probability of B winning on his first turn (if B gets a
first turn) is 7/8,
But B only gets a first turn 1/8(if A loose first turn) of the time.
So the actual probability of B winning on his first turn is: 1/8 * 7/8 = 7/64.
The A's second turn, with the probability of winning 7/8 again, if A gets a second turn.
But the probability of getting to A's second turn is 1/8 * 1/8 = (1/8)^2. So the total probability of A winning on his second
turn is (1/8)^2 * 7/8 = 7/512.
The pattern repeats. The total probability of B winning on his second turn is (1/8)^3 * 7/8 = 7/4096.
The total probability of A winning on his third turn is (1/8)^4 * 7/8 = 7/32768.
final probability that A wins the game, we get an infinite series, which evaluates to:
Probability that A wins = 7/8 + 7/8*(1/8)^2* + 7/8*(1/8)^4 + 7/8*(1/8)^6 + ...
Probability that A wins = 7/8 * (1 + (1/8)^2* + (1/8)^4 + (1/8)^6 + ...)
Probability that A wins = 7/8 * (64/63)
Probability that A wins = 8/9
So, A wins the game with a probability of 8/9. We can then deduce that B wins the game with a probability of 1/9.
For a fair game, B must put of 1/9 of the stakes, or:
B's stakes = 1/9 * 20
B's stakes = 2.222
Manish has to travel from A to D changing buses at stops B and C enroute.The maximum waiting time at either stop can be
8 minutes each,but any time of waiting upto 8 minutes is equally likely at both places.He can afford upto 13 minutes of
waiting time if he is to arrive at D on time,What is probability Manish will arrive late at D?
Given that, at both the stations B & C, any waiting time up to 8 minute is equally likely.
Now the problem can be thought as "Choosing any point P randomly on real number line between 0 to 16(inclusive), what
is the probability that the point will lie between 13 to 16."
Point P will represent our total waiting time, clearly all points will be equally likely since they will be equidistant from each
other.
The Probability that P > 13 = length of line segment between 13 and 16 / length of line segment between 0 and 16
Hence the probability that total waiting time is greater than 13 minutes = (16 - 13) / (16 - 0) = 3/16
Manish will arrive late at D if he will spend more than 13 minutes in waiting.
India plays two matches each with West Indies and Australia. In any match, the probabili es of India ge ng, points 0, 1 and 2 are 0.45, 0.05 and 0.50
respectively. Assuming that the outcomes are independent, the probability of India getting at least 7 points is
Since there are 4 matches to be played. India can get a maximum of 8 points(2 points in each match).
Probability of getting exactly 7 points = P(Getting 2 points each of 3 matches and getting 1 point in one match)
= ( 4 ) (0.5) 4 (0.05)0=0.0625
P(india gets at least 7 points) =P(Getting exactly 7 points) + P(Probability of getting Exactly 8 points)
= 0.025 + 0.0625
=0.0875
15.99 A roulette wheel with 38 numbers is spun. What is the probability that
in five spins the wheel never lands on either 0 or 00? What is the probability
that the wheel lands on one of the first six integers on one spin, but does
not land on any of them on the next spin? top gateoverflow.in/14074
A roulette contains numbers 0, 00, 1,2..., 36. So for first question, every time, we have 36 choices out of 38. So
36
P= ()
38
5
.
6 32
In second case, P = 38 ∗ 38
15.100 How can a event be neither independent nor dependent nor mutually
exclusive ? top gateoverflow.in/26812
If I am rolling two dices and following 3 events are defined such that
Now since this inequality doesn't hold true so these are not independent events , so then why are these not dependent events as well since
Now P(E2 / E1) =1/ 36 since there will be only 1 favourable case (4,2) ,Now even this inequality doesn't hold true , and
even E1 ∩ E2!=0 so they are not even mutually exclusive so to which category do these events belong to ?
Selected Answer
Suppose you got 6 on the first throw then the sum of two dices is never going to be 6, since the sum will be at least 7
.Thus we can see that they are dependent.
The out come of of the first throw will surely contribute to the sum of two dice throws, so they are not independent.
E2
1 1
It will be 6 instead of 36 .
E2
P[ E1 ] means GIVEN THAT 4 has already been occurred in the first throw, what is the chance of getting a sum of 6.
Since occurrence of 4 in the first throw is given to us we will not consider the probability of occurrence of 4 in the first
throw.We already have 4 & we need a 2 to make the sum 6, hence we will only consider the probability of getting 2 in the
1
E2 1
So P[ E1 ] = 6
Also P[E1] = 6
E2 1 1 1
E1 6 6 36
this will give P[E1] × P[ ]= × = .
1
36
The probability of getting a 4 in the first throw and getting sum 6 is P[E1 ∩ E2] = , as you have described.
E2
And yes they are not mutually exclusive, since both of the events can occur simultaneously.
However if I change E1 to "Getting 6 on the first die." and E2 remains same then E1 and E2 will be mutually exclusive since
happening of any one of them will imply not happening of the other.
15.101 Explain what is wrong with the statement that in the Monty Hall
Three-Door Puzzle the probability that the prize is behind the first door you
select and the probability that the prize is behind the other of the two doors
that Monty does not open are both 1/2, because there are two doors left. top
gateoverflow.in/14013
the number of bit strings of length 8 that will either start with 1 or end with 00 is?
the statement is wrong . first for all the other i just explain the puzzle . the puzzle just says that there is a show in which a
candidate have to choose a door out of 3 doors. one door contain the gift let it be car and others to be goat . the host of
the show know which door contain a gift. after choosing the one door . the host not directly open the door but open one of
the remaining two door with a goat .and then the user is again given a choice to either stick to the earlier door or he can
now choose the second door.
the statement is wrong as there is equally likely probability of gift behind any door. so the probability will be 1/3 for each
door. and the probability of gift behind the door you have selected is 1/3 and the probability of gift behind the 2 doors
monty have not opened yet will be 2/3.
the answer end here . but for real life situation i u sometime get to that show somehow . the trick to win is alays change
the door . after monty opens the door with a goat . as your winning changes are still 1/3 if u stick to your door . but the
other set changes were 2/3 but now as there is only one door left in that set he probability is still 2/3 so good to go with
more probability.
1)Among 10000 random digits find probability P that digit 3 appears at most 950 times.(area under normal between Z=0
and Z=1.67 is 0..4525)
2)A die is tossed 180 times .using normal distribution find probability that face 4 willnturn up atleat 35 times..(area under
normal curve between Z=0 and z=1 is 0.3413)
1) n = 104
1
this area equals in value with the area between -1.67 and 0
+ the area outside -1.67 and +1.67, both separated areas shown below are EQUAL, due to symmetry in bell curve.
1 −2 ×0.4525
2
is given as = = 0.0475
An airplane knows that 5 percent of the people making reservations on a certain flight will not show up. Consequently, their
policy is to sell 52 tickets for a flight that can hold only 50 passengers. What is the probability that there will be a seat
available for every passenger who shows up?
Selected Answer
( )
= 1 − 0.9551 × 0.05 × 52C1 + 0.9552 = 0.74
1.Probability of getting total of atleast once in three tosses of pair of fair dice is
d)99/216
2.How many dice must be thrown so that there is better than even chances of getting 6
For certain binary communication channel probability transmitted 0 is received as o is 0.95 and probability that transmitted 1
is received as transmiited 1 is 0.9 If probability 0 is transmiited is 0.4 find probality that 1 was transmitted given 1 was
received?
Selected Answer
P(1T) = 0.6
A sequence of independent trails consisting consists flipping of a coin having probability p of coming up of heads is
continually performed until either a head occurs or a tital of n flips is made. Let X denote the no of time the coin is
flipped.then P(X=n) is
A)(1-p)^n
B)p(1-p)^(n-1)
C)(1-p)^(n-1)
D)np(1-p)^(n-1)
So after n trials there could Success in the nth trial: in that case P(x=n)=(1-P)^n-1p
So P(X=n)= Succes+faliure=(1-p)^n-1.
Suppose a system contains certain type of component whose lifetime is T .Random variable T is modelled by exponential
distribution with mean time to failure is b=5 .Probability that given component installed on system is still working after 8
years is
In above problem if 5 of these components are installed in different systems.What is probability that atleast 2 components
are still functioning at end of 8 years?
Selected Answer
Cumulative distribution function of exponential distribution is given by F(x) = 1 − e −λx, where λ is the rate of occurrence of
event. (https://en.wikipedia.org/wiki/Exponential_distribution#Cumulative_distribution_function )
Here mean time of failure is 5 years i.e. rate parameter λ is 1/5 = 0.2.
(a) Probability of component working even after 8 years is 1 − F(8) = 1 − (1 − e −0.2∗ 8 ) = e −1.6 ≈ 0.20
(b) Probability that at least 2 systems are working = 1 - (prob of no system working + prob of 1 system working)
Let probability of a system working after 8 years is p, which is 0.20 as calculated earlier.
So required probability is
5 5
In a lottery there are 200 prizes of Rs 5 ,20 prizes of Rs 25 and 5 prizes of Rs 100.Assuming 10000 prizes tickets are to be
issued and sold what is the fair price to pay for ticket?
Selected Answer
Here fair price means on an average, you should not lose anything. So if you buy a ticket for Rs. x, and win Rs. 5, then
you gain net Rs. 5 − x. This gain should not be negative i.e. it has to be at least 0.
200 20 5
You win net Rs. 5 − x with probability 10000 , win Rs. 25 − x with probability 10000 , win Rs. 100 − x with probability 10000 , and
9775
10000
win Rs. −x with probability .
Last case occurs when you don't win any ticket and lose your Rs. x.
Hence x = 0.2
If 20% of bolts produced by machine are defective determine probability that out of 4 bolts choosen number of defective
bolts is less than 2
1)27/64
2)81/256
3)27/256
4)512/625
Selected Answer
20 1
Probability that less than 2 items are defective = Prob(no item is defective) + Prob(1 item is defective). Hence required
probability is
4 1 4 4 1 4 512
P= ( )(0
)( )
5 0 5 4
+ ( )(
1
)( )
5 1 5 3
=
625
15.110 Suppose that 100 people enter a contest and that different winners
are selected at random for first, second, and third prizes. What is the
probability that Michelle wins one of these prizes if she is one of the
contestants? top gateoverflow.in/13998
Selected Answer
100
Total number of ways in which any 3 random people can be chosen from 100 is ( 3 ).
Now in our favourable cases, Michelle wins the prize, so in all favourable cases, Mitchelle is one of the 3 persons in the set
99
which is chosen for winning. Now other 2 persons can be chosen in ( 2 ) ways, so probability is
99
99 ∗ 98
(2) 2
100 100 ∗ 99 ∗ 98
3
( ) 6
P= = = 0.03
15.110 What is the probability that Abby, Barry, and Sylvia win the first,
second, and third prizes, respectively, in a drawing if 200 people enter a
contest and a) no one can win more than one prize. b) winning more than
one prize is allowed top gateoverflow.in/13997
Selected Answer
P(Barry winning second prize) = 199 , as Abby can't win more than one prize.
1 1 1
(b) Now total probability = 200 ∗ 200 ∗ 200 , because everyone can win any number of prizes.
A bin contains two red balls and one white ball. The probability of picking the balls is equally likely. Two balls are taken
without replacement. What is the probability of getting two red balls.
probability 1/3 . (if you one after another then also the probability is going to be same , 2C11C1/ 3C12C1
Consider a set A = {1, 2, 3, …….., 1000}. How many members of A shall be divisible by
3 or by 5 or by both 3 and 5 ?
(A) 533 (B) 599
(C) 467 (D) 66
Selected Answer
(A U B ) = (A) + (B) - (A ∩ B)
A U B = 333+200-66=533-66=467
If f(x) is normal distribution with mean 8 and std deviation 1 value of f(x) for x=10 is
1)0.05
2)0.14
3)0.25
4)0.73
f(x)=0.0540.
There is an urn having r red balls, b blue balls and w white balls. There is atleast two balls are there of each color. We are
taking two balls from the urn without replacement. What is the probability that the second ball selected is red. Express in
terms of r, b and w
Selected Answer
P (RR) + P(!R R)
= r/(r+b+w) * (r-1)/(r+b+w-1)
Then x bar(mean for x values) and y bar(mean for y values) are respectively
Q-2 Regression equations are x=4-0.2y and y=7-0.8x then value of correlation coefficient is
Q.1 Point of intersection of two regression lines is , so if we solve the two equations given, we get (2,3) as
intersection point, which is .
So r = -0.4
var(3X+5)
⇒3var(X) + var(5)
⇒3*1/λ2 + 0 as var(constant)=0;var(X)=1/λ 2
⇒3/λ 2
so option B
'X' is playing a dice game in which a dice is rolled 5 times.If a number turns up exactly 3 times then the game
is won.'X' has thrown the dice 2 times and got number 4 both times.What is the probability that 'X' will win the
game?
a) 1/216
b) 75/216
c) 80/216
d) 90/216
Selected Answer
First case:
1 5 5 5 1 5 5 5 1
= ( 6
∗6 ∗6 )(
+ 6
∗6 ∗6 )(
+ 6
∗6 ∗6 )
75
= 216
Second Case:
5 1 1 5
= 6 ∗ 6 ∗ 6 = 216
75 5 80
two independent random variables X and Y are uniformly distributed in[-1,1] probability that max(X,Y) is less than 1/2
1)3/4
2) 9/16
3)1/4
4)2/3
Area of ABCD=3/2*3/2
=9/4
car arrives at service station acc to poisson distribution with mean rate of 5 hrs.service time per car is exponential with
mean of 10 minutes.at steady state average waiting time in queue is
1)10 min
2)20 min
3)25 min
4) 50 min
A problem in mechanics is given to 3 students A,B,C whose chances of slogging it are 1/2,1/3,1/4 respectively. The
probability that the problem will be solved is..
problem will be solved only when any one of them solve it all any two of them solve them or all of them solve them. the
approach to this type of question is . if u find in the first go that there are lot of case u have to cover like. here a can solve
, or b , or c, or a and c , or b and c, or c and a or all of them . a b c. then it will be easy to go with the 1- ( probability
approach) . The problem will be solved can be written as . 1- ( no one can solve )
all will be independent events as the problem solving capability of one does not depend on other.
15.120 What is the probability that a five-card poker hand contains the ace of
hearts? top gateoverflow.in/13980
51C
4 5
52C
There is only one ace of hearts. So, required probability = 5
= 52
(ace is assumed to be picked and we need to pick any 4 from remaining 51)
15.120 What is the probability that a five-card poker hand does not contain
the queen of hearts? top gateoverflow.in/13981
51C
5 47
52C
There is only 1 queen of heart. So, required probability = 5
= 52 .
A die is rolled 3 times. The probability that the exact one ODD number turns up among the 3 outcomes is..
(1,4,2),(1,4,4),(1,4,6),(3,4,2),(3,4,4),(3,4,6),(5,4,2).(5,4,4),(5,4,6),
(1,6,2),(1,6,4),(1,6,6),(3,6,2),(3,6,4),(3,6,6),(5,6,2).(5,6,4),(5,6,6),
So, probability=(3*27)/6^3=1/8
Means
A+B+C=1
0.25(B) 0.625(C)
If there are n stations and each station can send data with probability n ,Now if at any instant of time there should be
exactly one station which should transmit data then for finding the probability for this why can't I do p/np =1/n
since favourable case will be p since only 1 station will transmit and out of total cases to be np , what is wrong in this
approach ?
if a station want to successfully transmit this is the probability 1/n . it is not the maximum probability but this is true. it
can also be seen as Nc1 * p* (1-p)^(n-1). which is also equal to 1/n .
Selected Answer
P(even) = 2/3
P(odd) = 1/3
Now, sum is odd if either {even, odd} or {odd , even} occur on dices respectively , which gives
= 4/9
since you have mentioned that μ = 102 and σ = 27 the points 90 and 102 translate to -0.444 and 0 in standard normal
distribution x − μ/σ. To find the probability of the region between 90 and 102 (ie -0.44 and 0 in SND), F(0)=
1/(1 + exp( − 1.7255 ∗ 0))-F(-0.444)=1/(1 + exp( − 1.7255 ∗ ( − .44)(.44)0.12))
=0.5-0.339
=.16.
The shaded region shows the required region. but here Z is -0.444 and by symmetry we can have it on the other side too.
I thought answer would be (C). Because, inner 'f' is outputting values 8, 9, 3, 1, 2. So, outer 'f' should take these values for
final output. But as these values are not in its domain [S], so that should be undefined.. Right?
set-theory&algebra ace-test-series
You are correct. C is correct answer, but because of same explanation, B should also be correct answer.
gof(x) = g(f(x))
On computing f(x), it gives output that belongs to the set T. This output serves as input of g(x). But the valid domain set
for g(x) is S, while it is receiving its input in domain T, hence we say that gof(x) is not defined too.
Given/Know :
¯
⟨B, ∨ , ⋅ , , 0, 1⟩ is a Boolean Algebra, and for any 3 of its arbitrary elements a, b, c in B the following postulates are satisfied:
It is not expected that one should provide a complete answer to all parts of the question. Whatever one can
supply to support its answer is welcomed.
R1 ⊕ R2
16.4 Equivalence Classes: Which of these relations on the set of all functions
from Z to Z are equivalence relations? top gateoverflow.in/42202
Which of these relations on the set of all functions from Z to Z are equivalence relations?
In this question, what does it mean by f(1) = g(1) and f(1) - g(1)? And how it satisfies all the conditions (Symmetric,
Transitive and Reflexive) of equivalence relation. Actually I cannot able to analyze when the relations defined on set of
function. If anyone describe a bit it would helpful.
f has one element ,say i.e. 1 . Two function (f and g) merging in one element . Relation will be (1,1)
f has 2 elements , say i.e. 1,2 .But relation is (1,1) or (2,2) , but may not both
distance between same element of f to g is 1 . But distance between g to f is -ve , which is not possible. So, it is not even
symmetric
Which of these collections of subsets are partitions of the set of bit strings of length 8?
(a) the set of bit strings that end with 00, the set of bit strings that end with 01, the set of bit strings that end with 10, and
the set of bit strings that end with 11.
(b) the set of bit strings that end with 111, the set of bit strings that end with 011, and the set of bit strings that end with
00
Answer: a is a partition
Confusion is, why b is not a partition. We know that, the elements of different partition must be unique and union of all
partition should be equal to the set itself. I can't find any overlapping elements between different partition of (b) and if there
is any, then why not in (a).
Selected Answer
In option (a) they are saying set of bit string end with 00, 01, 10, 11 .Option (a) is definitely partition of 8 bit string.
Becouse they are disjoint as well as union of all subsets givesAll bit string of length 8.
In option (b) they are saying set of bit string ends with 111, 011 , 00 . Yes these are disjoint but combination of all (i.e.
Union) is not same as Statement (all 8 bit string). So it is not partition.
functions
Selected Answer
False :
f(E) = {5, 6, 7, 8}
f(E ∩ F) = {7, 8}
Alternatively
f(E ∩ F) ⊆ f(E) as intersection never adds any new element to a set and a function should have a mapping for all elements in
domain.
Combining both,
⊆ becomes = only when f is one-one - when the mappings are unique for each element.
functions
Selected Answer
gof is surjective (onto) meaning - codomain = range. So, gof maps every element in C which is its codomain set. Since gof
is surjective g must be surjective. Now g is an injection meaning it maps one-one. Thus, g becomes bijection.
g being bijective means, for every element in B there is a corresponding unique element in C and vice-versa. gof maps to
every element in C. So, it must be the case that f maps to every element in B- otherwise the corresponding element in C
won't be mapped to by g. Hence, f must be surjective.
If f: X → Y and a, b ⊆ X, then
f(a ∩ b) is equal to
A. f(a)– f(b)
B. f(a) ∩ f(b)
C. a proper subset of f(a) ∩ f(b)
D. f(b)– f(a)
set-theory&algebra functions
The only requirement to answer the above question is to know the definition of function- a relation becomes a function if
every element in domain is mapped to some element in co-domain and no element is mapped to more than one element.
Now, we have a, b ⊆ X. Their intersection can be even empty set. So, lets try out options:
Lets take a case where a ∩ b = ϕ. Now, f(a ∩ b) = ϕ, but f(a) ∩ f(b) can be non empty. So, option B can be false.
Option C is always true provided "proper subset" is replaced by "subset". This is because no element in domain of a
function can be mapped to more than one element. And the subset needn't be "proper" as for a one-one mapping, we get
f(a ∩ b) = f(a) ∩ f(b).
The number of surjective functions defined from A to B where |A| = 5, |B| = 4, is _______
set-theory&algebra functions
Selected Answer
We have 4 elements in set B and 5 elements in set A and surjection means every element in B must be mapped to. So,
this problem reduces to distributing 5 distinct elements (r = 5) among 4 distinct bins (n = 4) such that no bin is empty,
which is given by n! S(r, n), where S(r, n) is Stirling's number of 2nd kind. So, here we need S(5, 4).
1 1
1 3 1
1 7 6 1
1 15 25 10 1
http://www.cse.iitm.ac.in/~theory/tcslab/mfcs98page/mfcshtml/notes1/partset.html
2) surjection
3) Bijection
ans 240
If F and G are Boolean functions of degree n. Then, which of the following is true ?
(A) F ≤ F + G and F G ≤ F
(B) G ≤ F + G and F G ≥ G
(C) F ≥ F + G and F G ≤ F
(D) G ≥ F + G and F G ≤ F
functions
Selected Answer
G= (4 boolean function)
so answer is B
Let f: A → B and g: B → C denote two functions. Consider the following two statements:
S1 : If both f and g are injections then the composition function gof : A → C is an injection.
S2 : If the function gof : A → C is surjection and g is an injection then the function f is a surjection.
a) S 1 only
b) S2 only
c) S 1 and S 2
d) None of these
Suppose that f is a function from A to B.We define the function Sf from P(A) to P(B) by the rule Sf(X) = f(X) for each subset X of
A. Similarly, we define the function Sf−1 from P(B) to P(A) by the rule Sf−1 (Y) = f −1 (Y) for each subset Y of B.
Q. Suppose that f is a function from the set A to the set B. Prove that
a) if f is one-to-one, then Sf is a one-to-one function from P(A) to P(B).
b) if f is onto function, then Sf is an onto function from P(A) to P(B).
c) if f is onto function, then Sf−1 is a one-to-one function from P(B) to P(A).
functions
16.13 Generators: What are the generators for the group G having
multiplication modulo 6 as an operation? top gateoverflow.in/20639
What are the generators for the group G={1,2,3,4,5,6} having multiplication modulo 6 as an operation?
0 is not in G
If in a Group there is atleast one generator present then we can say Group is cyclic.
A Group(G,*) is called a cyclic group if there exist an element a∈G such that every element of G can be
written as an for some integer n.Then a is called generating element or generator.
Before check Group is cyclic Group or not we have to check given set is Group or not.
⊗6 1 2 3 4 5 6
1 1 2 3 4 5 0
2 2 4 0 2 4 0
3 3 0 3 0 3 0
4 4 2 0 4 2 0
5 5 4 3 2 1 0
6 0 0 0 0 0 0
Here elements 2,3,4 and 6 doesn't have inverse that is necessary to make a Group.
1.Closure Property
2.Associativity
3.Identity
4.Inverse
By 1st property
Ans given is d.
a) [ ] 0
1
1
0
b)
[ 1
−1
−1
1 ]
c)
[ −1
1 −1
1
]
[ ]
1 1
2
−2
d) 1 1
−2 2
set-theory&algebra group
Selected Answer
Answer is D.
16.16 Groups: Which of the following statements is/are true? top gateoverflow.in/30728
set-theory&algebra groups
Selected Answer
S1: It is False
16.17 Groups: Firstly, What is identity element for this group? top gateoverflow.in/20581
A = {0, 1, 2, 3, 4, 5, 6, …23}
a ∗ b = (a + b) mod 24
How many proper subgroups does the group G(A, ∗ ) have?
groups
Selected Answer
According to Lagrange's theorem, the order of the subgroup divides the order of the group.
In order to find the number of proper subgroups, we need to find the proper divisors of 24
24 = 23 × 31
No of proper divisors = 4 × 2 − 2 = 6
Please explain following example in Detail, I'm not able to understand this explanation.
set-theory&algebra groups
Let G be a finite group. If A and B are subgroups of G with orders 4 and 5 respectively, then | A ∩ B | = ______.
set-theory&algebra groups
Selected Answer
Now, common element between A and B must have same order. Only common order possible is 1..
Now find no of elements with order 1. Order 1 is special element and we call as identity element. In any group at most
and exactly 1 identity element exist.
Alternative methods
Method 1:
Intersection property of two sub group of a group, states that A∩B is a subgroup of A as well as B. Now, using Lagrange's
theorem (order of subgroup must divide order of group), |A∩B| must divide |A| as well as |B|. Only common divisor for 4
and 5 is 1. So, |A∩B| = 1.
ref@http://math.stackexchange.com/questions/1364274/let-g-be-finite-group-if-
a-b-le-g-with-orders-4-5-respectively-then-a
@http://www.quora.com/Let-G-be-finite-group-if-A-and-B-are-subgroups-of-G-with-orders-4-and-5-respectively-then-A-
%E2%88%A9-B
hasse-diagram
16.21 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-5 top gateoverflow.in/42919
Translate the given statement into propositional logic using the propositions provided.
You are eligible to be President of the U.S.A. only if you are at least 35 years old, were born in the U.S.A, or at the time of
your birth both of your parents were citizens, and you have lived at least 14 years in the country.
Express your answer in terms of
e: “You are eligible to be President of the U.S.A.,”
a: “You are at least 35 years old,”
b: “You were born in the U.S.A,” p: “At the time of your birth, both of your parents where citizens,”
and r: “You have lived at least 14 years in the U.S.A.”
1.Above 35 year
so it is (a ^(b v p) ^r)--->e
16.22 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-6 top gateoverflow.in/42920
Translate the given statement into propositional logic using the propositions provided.
You can upgrade your operating system only if you have a 32-bit processor running at 1 GHz or faster, at least 1 GB RAM,
and 16 GB free hard disk space, or a 64-bit processor running at 2 GHz or faster, at least 2 GB RAM, and at least 32 GB free
hard disk space. Express you answer in terms of
u: “You can upgrade your operating system,”
b32: “You have a 32-bit processor,”
b64:“You have a 64-bit processor,” g1: “Your processor runs at 1 GHz or faster,”
u ((b 32 ⋀ g 1 ⋀ r 1 ⋀ h 16 ) ⋁ (b 64 ⋀ g 2 ⋀ r 2 ⋀ h 32 ))
16.23 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-15 gateoverflow.in/42944
top
Each inhabitant of a remote village always tells the truth or always lies. A villager will give only a “Yes” or a “No” response to
a question a tourist asks. Suppose you are a tourist visiting this area and come to a fork in the road. One branch leads to
the ruins you want to visit; the other branch leads deep into the jungle. A villager is standing at the fork in the road. What
one question can you ask the villager to determine which branch to take?
Selected Answer
The answer is apparently: " If I were to ask you whether the right branch leads to the ruins, would you answer
yes?"
Explanation:
For the sake of simplicity suppose the left branch leads to the ruins whereas the right one leads you lost deep into the
jungle.
Case 1. The villager is a liar: in this case, since he knows the right branch leads to the jungle then he'd say it leads to the
ruins, but he won't tell you NOW this, so his answer here is NO.
Case 2. The villager tells the truth: he will answer NO again, 'cause he knows the right branch takes you to the jungle and
he will let you k now that.
From the above, it's clear you must choose THE other branch if the answer is NO.
16.24 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-3 top gateoverflow.in/42917
Translate the given statement into propositional logic using the propositions provided.
You can graduate only if you have completed the requirements of your major and you do not owe money to the university
and you do not have an overdue library book. Express your answer in terms of
g: “You can graduate,”
m: “You owe money to the university,”
r: “You have completed the requirements of your major,”
and b: “You have an overdue library book.”
no overdue of book=∿b
so
(r ^ (∿m )^ (∿b))---->g
16.25 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-1 top gateoverflow.in/42914
Translate the given statement into propositional logic using the propositions provided.
You cannot edit a protected Wikipedia entry unless you are an administrator.
Express your answer in terms of e: “You can edit a protected Wikipedia entry”
and a: “You are an administrator.”
"If there is a rain then I will not go to college unless there is holiday."
P: There is a rain
R : There is a Holiday.
So comes to your problem, Give statement is " You cannot edit a protected Wikipedia entry unless you are an
administrator".
a -> e.
16.26 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-2 top gateoverflow.in/42915
Translate the given statement into propositional logic using the propositions provided.
You can see the movie only if you are over 18 years old or you have the permission of a parent. Express your answer in
terms of
m: “You can see the movie,”
e: “You are over 18 years old,”
and p: “You have the permission of a parent.”
Selected Answer
m (e⋁ p)
16.27 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-7 top gateoverflow.in/42921
Express these system specifications using the propositions p “The message is scanned for viruses” and q “The message was
sent from an unknown system” together with logical connectives (including negations).
a. “The message is scanned for viruses whenever the message was sent from an unknown system.”
b. “The message was sent from an unknown system but it was not scanned for viruses.”
c. “It is necessary to scan the message for viruses whenever it was sent from an unknown system.”
d. “When a message is not sent from an unknown system it is not scanned for viruses.”
kenneth-rosen set-theory&algebra
a. “The message is scanned for viruses whenever the message was sent from an unknown system.” = Q->P (whenever ==
if)
b. “The message was sent from an unknown system but it was not scanned for viruses.”= (Q ∧ ~P) ( but == and)
c. “It is necessary to scan the message for viruses whenever it was sent from an unknown system.” = (Q ->P)
d. “When a message is not sent from an unknown system it is not scanned for viruses.” =(~Q -> ~P)
16.28 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-4 top gateoverflow.in/42918
Translate the given statement into propositional logic using the propositions provided.
To use the wireless network in the airport you must pay the daily fee unless you are a subscriber to the service. Express your
answer in terms of
16.29 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-12 gateoverflow.in/42927
top
Are these system specifications consistent? “If the file system is not locked, then new messages will be queued. If the file
system is not locked, then the system is functioning normally, and conversely. If new messages are not queued, then they
will be sent to the message buffer. If the file system is not locked, then new messages will be sent to the message buffer.
New messages will not be sent to the message buffer.”
This system is consistent. We use L,Q,N, and B to stand for the basic propositions here, “The filesystem is locked,” “New messages will be queued,” “The system is functioning
normally,” and “Newmessages will be sent to the message buffer,” respectively. Then the given specifications are ¬L?Q,¬L?N, ¬Q?B, ¬L?B, and ¬B. If we want consistency,
then we had better have B false in order that¬B be true. This requires that both L and Q be true, by the two conditional statements that have B falsein order that ¬B be true
16.30 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-14 gateoverflow.in/42943
top
What Boolean search would you use to look for Web pages about hiking in West Virginia? What if you wanted to find Web
What Boolean search would you use to look for Web pages about hiking in West Virginia?
Answer: ("Hiking") AND ("West Virginia") : This will return all the webpages which have Keyword "Hiking" and "West
Virginia" both.
What if you wanted to find Web pages about hiking in Virginia, but not in West Virginia?
Answer: (("Hiking") AND ("Virginia")) AND (NOT(("Hiking") AND ("West Virginia"))) : This will return all the
webpages which contain "Hiking" and "Virginia", but it will neglect all the webpages which have "hiking" and "west
Virginia".
If you want to see that how its working then look at this.
16.31 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-11 gateoverflow.in/42926
top
Are these system specifications consistent? “The router can send packets to the edge system only if it supports the new
address space. For the router to support the new address space it is necessary that the latest software release be installed.
The router can send packets to the edge system if the latest software release is installed, The router does not support the
new address space.”
Consistent means that, "If All the propositional formula in the system can be true simultaneously then that
system is called Consistent."
1) The router can send packets to the edge system only if it supports the new address space, ( Q --> P)
2) For the router to support the new address space it is necessary that the latest software release be installed. ( R-->Q )
3) The router can send packets to the edge system if the latest software release is installed. ( R-->P)
4) The router does not support the new address space. ( ~Q).
Here Take (Q = F) and (R = F), All the Formula will be True. Hence This system is Consistent.
16.32 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-13 gateoverflow.in/42929
top
What Boolean search would you use to look for Web pages about beaches in New Jersey? What if you wanted to find Web
pages about beaches on the isle of Jersey (in the English Channel)?
16.33 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-10 gateoverflow.in/42924
top
Are these system specifications consistent? “Whenever the system software is being upgraded, users cannot access the file
system. If users can access the file system, then they can save new files. If users cannot save new files, then the system
software is not being upgraded.”
Now,
a) “Whenever the system software is being upgraded, users cannot access the file system.”
u→¬a
b) “If users can access the file system, then they can save new files.”
a→s
c) “If users cannot save new files, then the system software is not being upgraded.”
¬s→¬u
Yes, for example making u false, a false, and s true makes it consistent.
16.34 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-9 top gateoverflow.in/42923
Are these system specifications consistent? “The system is in multi-user state if and only if it is operating normally. If the
system is operating normally, the kernel is functioning. The kernel is not functioning or the system is in interrupt mode. If
the system is not in multiuser state, then it is in interrupt mode. The system is not in interrupt mode.
Consider,
Now,
In (5), We have to take S = F, then and only then we get (5) as True.
In (3), We have taken S = F, then we have to take ( R = F) then and only then we will get (3) as True.
In(4), Since S = F, then we have to take ( P = T), then and only then we will get (4) as True.
In(2), Since R = F, then we have to take (Q = F), then and only then we will get (2) as True.
In(1), we have P = T and Q = F, which can never generate a true value, (1) will be false.
16.35 Kenneth Rosen: Kenneth Rosen Edition7 Ch-1 Ex-1.2 QueNo-8 top gateoverflow.in/42922
Express these system specifications using the propositions p “The user enters a valid password,” q “Access is granted,” and r
“The user has paid the subscription fee” and logical connectives (including negations).
a. “The user has paid the subscription fee, but does not enter a valid password.”
b. “Access is granted whenever the user has paid the subscription fee and enters a valid password.”
c. “Access is denied if the user has not paid the subscription fee.”
d. “If the user has not entered a valid password but has paid the subscription fee, then access is granted.”
kenneth-rosen set-theory&algebra
Selected Answer
a) r ⋀~p
b)(r⋀p)q
c) ~r ~q
d) (~p ⋀r) q
set-theory&algebra lattice
Selected Answer
2 is correct answer. fig 2, b and c have {f,g} as upperbound. but for the graph to be a lattice it should have a least upper
bound. Since b and c have two upper bounds they cannot have a least upper bound<which is always unique for a pair for
vertices>. In other words we cannot say which one is least one out of the pair {f,g}. therefore it is not a join
semilattice(every pair of element should have a least upper bound). henceforth it is also not a lattice
lattice
A Hasse diagram uniquely determines the relations in a partially ordered set, so two isomorphic Hasse diagrams represent two isomorphic posets,
provided that they are isomorphic as directed graphs.
set-theory&algebra lattice
Selected Answer
A lattice must be first a poset i.e. it should be reflexive , anti-symmetric and transitive.
16.38 Lattice: What are the complement pairs for the following lattice? top
gateoverflow.in/20512
set-theory&algebra lattice
Selected Answer
Meet(4,3) -> 1
Join(4,3) ->12
There is another pair here -> Upper & Lower bounds are also compliments of each other.
Meet(1,12)->1
Join(1,12) ->12
no b is not correct....
for relation to be symmetric and antisymetric only self pairs are allowed
so d is ans
or, equivalently,
So in option (b) (aRb) with a ≠ b and (bRa) is also holding,Thats why its not antisymmetric.
Ref : https://en.wikipedia.org/wiki/Antisymmetric_relation
16.40 Partial Order: Which relations are partial orders? top gateoverflow.in/38606
Argument: R2 is straight away eliminated. For R3, to satisfy Antisymmetric relation.. Say -2 and +2 satisfy it then +2 and -2
should not satisfy. But its not the case. Answer is given as C. Am I so blind that I couldn't figure out my mistake?
partial-order
Selected Answer
The least num of computers required to connect 8 computers to 4 printers to guarantee 4 comp can direct]ly access 4
printer is _____
16
17
19
20
21
pigeonhole
16.43 Relations: Let R be the relation on the set of all colorings of the 2 × 2
checkerboard where each of the four squares is colored either red or blue top
gateoverflow.in/4725
Let R be the relation on the set of all colorings of the 2 × 2 checkerboard where each of the four squares is colored
either red or blue so that (C 1 , C 2 ), where C 1 and C 2 are 2 × 2 checkerboards with each of their four squares colored
blue or red, belongs to R if and only if C 2 can be obtained from C 1 either by rotating the checkerboard or by rotating it and
then reflecting it.
set-theory&algebra relations
set-theory&algebra relations
For relation to be symmetric if (m,n) belong to R then (n,m) also belongs to R ie m is factor of n and n is factor of m this
is possible only when m=n this relation is antisymmetric for eg(2,4) belongs to R but (4,2) does not belong to r so ans is
d
set-theory&algebra relations
FALSE.
If relations R1 and R2 are irreflexive, then the relations R1 U R2, R1 ⋂ R2, R1 -1 are also Irreflexive.
Determine whether the relation R on the set of all Web pages is reflexive, symmetric, antisymmetric, and/or transitive,
where (a, b) ∈ R if and only if
a) everyone who has visited Web page a has also visited Web page b.
b) there are no common links found on both Web page a and Web page b.
c) there is at least one common link on Web page a and Web page b.
d) a is taller than b.
I have the knowledge about the reflexive, symmetric, anti-symmetric, and transitive also I can able to solve the problems
when the relations are defined in ordered pairs. But can't able to visualize this kind of relations.
set-theory&algebra relations
Selected Answer
1. a is taller than b. Looks like A>=B now it is reflexive , antisymmetric ,and transitive.
10=10 so reflexive.
2. a and b were born on the same day. Looks like A=B now it is reflexive, symmetric, transitive , anitisymmetric.
Let A = {1,2,3 }
R= {(1,1)(2,2)(3,2)(1,2)(2,3)}
S= {(1,1)(2,2)(3,3)(2,3)(3,2)}
Which of the following ARE correct Justify Each Option ( for my understanding )
set-theory&algebra relations
Selected Answer
R is not anti symmetric as it have (2,3)and {3,2} .R intersection S not equivalence--->as it is not reflexive(as {3,3}
missing.
Solve.
a) Show that satisfies the recurrence relation and the initial condition p(0) = 1.
b) Find the number of different equivalence relations on a set with n elements, where n is a positive integer not exceeding
10
set-theory&algebra relations
(a) n = 1
(b) n = 2
(c) n= 3
Answer has not been given. How do I calculate number of transitive relations?
For n = 2, If (a, b)εR and (b, a)εR the (a, a)εR and (b, b)εR. But how can we calculate this?
Selected Answer
(a) take only self loops (not necessarily all at a time). 4 options.
(b) There are two interconnecting lines.for Transitive relation select any edge (but not both). For each line case (a) occurs. So 2*2 2 = 8
(c) select all self loops all interconnecting edges i.e. whole relation. 1 relation.
https://en.wikipedia.org/wiki/Transitive_relation?wprov=sfla1
16.50 Sets: Find the dual of boolean algebra expresion S dual: top gateoverflow.in/5265
S: (a^b) = a if a<=b
a) S* :(a^b)=a if a<=b
b) S* :(aVb)=a if a<=b
c) S* :(a^b)=a if a>=b
d) S* :(aVb)=a if a>=b
sets set-theory&algebra
16.51 Sets: how many subsets does P(A) have if A is null set? top gateoverflow.in/18518
let A={} or phi be null set.it has 0 elements and 1 subset that is itself.
P(A) represents power set of A.how many elements and subsets does P(A) has? i think P(A)={ {} } has 1 element ie {}..now P(A) should have 2 subsets.. {} null set
and P(A)(itself ie set containing null set) so P(A) should have 1 element and 2 subsets..at lot of places ans is given as 1 subset so please clarify?
sets set-theory&algebra
Selected Answer
Yes, you are right Anurag, P(A) has exactly two subsets.
This implies the set P(A) = {∅} has exactly two subsets, namely ∅ and P(A)(= {∅}) itself.
I just want to know how the value in the answers come like 2^n2 and 2^n^2-1 etc. Please make it clear.
we can derive it through the defination of antisymmetric. if (x,y) and (y,x) exist x=y.
total number of choices for them is 2^n ( i.e. n elemets have 2 choices either has to come or do not appear.)
because either the lower diagonal should come or the upper diagonal elements or non of them comes.
16.52 Sets: number of equivalence relation possible with N element of set? top
gateoverflow.in/16891
sets relations
Selected Answer
1 2
2 3 5
5 7 10 15
See https://en.wikipedia.org/wiki/Bell_number
16.53 Sets: Determine the cardinality of the following set top gateoverflow.in/14162
set-theory&algebra sets
Selected Answer
Smallest value of x = 8 = 1
17
Largest value of x = 2 = 8
and x is an integer so between 0.125 to 8.5 there are 8 integers {1,2,3,4,5,6,7,8} so x can be any of these. so cardinality
of the set is 8
16.54 Sets: Set Theory & Algebra: how many ordered pairs top gateoverflow.in/28322
Let n(A) denotes the number of elements in set A. If n(A) = p and n(B) = q, then how many ordered pairs (a, b) are there with
a ∈ A and b ∈ B?
(a) p2
(b) p × q
(c) p + q
(d) 2pq
set-theory&algebra sets
Selected Answer
|{(a,b)}| = p*q
No of ordered pairs will be pq ( every element of A can be combine with every element of q)
(a)∑m
k=0 √k
(b)∑m
k=0 √ k3
Is there any quick way to find the formula for complex expression?
http://ramanujan.sirinudi.org/Volumes/published/ram09.pdf
16.56 Summation: What are the values of the sum? top gateoverflow.in/41904
if we have ∑nj=1 1 then the answer will be n. But what happens if this a set?
set-theory&algebra summation
S = {1,2,3,4,5.......n }
Sum = 0;
while ( j in S)
Sum = Sum +1
j = j + 1
Return Sum ;
Answer will be 4.
sets theory
set-theory&algebra
set-theory&algebra
In given relation R
16.60 Let s(w) denote the set of all the letters top gateoverflow.in/35712
Let s(w) denote the set of all the letters in w where w is an English word. Let us denote set equality, subset and union
relations by =, ⊂ and ⋃ respectively.
Which of the following is NOT true?
(a) s(ten) ⊂ s(twenty) (b) s(stored) = s(sorted)
(c) s(sixty) ⊂ (s(six) ⋃ s(twenty) (d) None of these
set-theory&algebra
If R1 and R2 are two assymteric relations ,so assymetric relations are closed under intersection operation as well as set-
difference operation,Now
R1 - R2 =R1∩ R2 C
Now when both set-difference and intersection operation are closed then why is this complement operation not closed from
this definition .Also R1∩R2C ⊆ R1 or R2 C
And assymetric relations are closed under subset operation as well so then why is set complementation operation not closed
?
a) R1 ∪ R2.
b) R1 ∩ R2.
c) R1 − R2.
d) R2 − R1.
e) R1 ⊕ R2.
set-theory&algebra
Selected Answer
2/2(2)+3/2(3)+4/2(4) +.......
Selected Answer
2 3 4
2 3 4
S = 2 + 2 + 2 + − − −
1 2 3 4
2 23 24 25
∗ S = + + + − − −
Perform Substraction,
1 2 1 1 1
2 2 3 4 5
∗S= 2 + 2 + 2 + 2 + − − − − −
1 2 1 / 23
2 22 1 −1 / 2
∗S= +
1 2 1 / 23
2 22
∗S= + 1/2
1 2 1
2 2 2
∗S= 2 + 2
1 3
2 22
∗S=
3 3
2
S=2∗ 2 = 2
Note: for any such series having AP and GP in it this procedure will work.
16.63 Please suggest me a good books for discrete maths to solve more and
more problem. top gateoverflow.in/42355
Selected Answer
If you want to learn the theory as well, then Discrete Mathematics by Kenneth Rosen is good..
For problems...
First, solve all Previous GATE/TIFR Questions from GATEOverflow Book..
http://www.gatecse.in/gate-overflow-book-previous-gatenon-previous-gate-questions-answers/
If you want even more problems, you can go for "Schuam Series".. But solve only those topics relevant to GATE..
16.63 Why set of all functions f: (N->{0,1}) is uncountably infinite? top gateoverflow.in/36654
engineering-mathematics set-theory&algebra
e.g.
function is a subset of cross product (some restircions but lets forget this
http://cs.stackexchange.com/questions/51319/number-of-finite-strings-over-a-countably-infinite-alphabet
16.63 the binary relation S=∅ on set A={1,2,3} is transitive and symmetric top
gateoverflow.in/40929
Selected Answer
Defintion of transitive relation.. here X is a set and a,b and c are elements of X
Extra:
But the given relation is not reflexive...
in a reflexive relation, for every element a of set X, aRa.
but here we donot have 1R1 and 2R2 and 3R3.
So, the given relation S=ϕ is not reflexive
bell number.
16.64 Set Theory and Algebra : Let L be a lattice and let a and b be the
elements of L such that a≤b top gateoverflow.in/42045
Let L be a lattice and let a and b be the elements of L such that a≤b. The interval [a,b] is defined as the set of all x€L such
that a≤X≤b. Prove that [a,b] is a sublattice of L.
Source- Discrete Mathematical Structures- 3rd Edition-Kolman Page Number 257 question Number 7
set-theory&algebra
this f(x) function is injective as it gives distinct values in B for each element of A. but it is not surjective because f(x)'s
range is between ( -0.5 to 0.5 ) only .
16.66 How to Find inverse of this: (z,*) is a group with a*b=a+b+1 then
inverse of a is? top gateoverflow.in/39113
engineering-mathematics set-theory&algebra
Selected Answer
Identity Element = I
a*I = I*a = a
a=a+I+1
I = -1
Inverse of a is a-1
a*a-1 = I
a + a-1 + 1 = -1
a-1 = -( a+2 )
which contains the partial order <= is (a) n! (b) n+2 (c) n (d) 1 top gateoverflow.in/4284
GATE_1997_Discrete_Maths_Set Theory
set-theory&algebra
http://gateoverflow.in/2257/gate1997_6-1
16.68 On a set of n elements, how many relations are there that are both
irreflexive and antisymmetric? top gateoverflow.in/3123
On a set of n elements, how many relations are there that are both irreflexive and antisymmetric?
set-theory&algebra
Selected Answer
A relation consists of set of ordered pairs (a, b). Here a can be chosen in n ways and similarly b can be chosen in n ways.
So, totally n2 possible ordered pairs are possible for a relation. Now each of these ordered pair can either be present in the
relation or not- 2 possibilities for each of the n2 pair. So, total number of possible relations =
2
2 n .( )
Now, for a relation R to be reflexive, ordered pairs {(a, a) ∣ a ∈ S}, must be present in R. i.e.; the relation set R must have n
ordered pairs fixed. So, number of ordered pairs possible is n2 − n and hence total number of reflexive relations is equal to
2
(
2 n −n . )
Number of irreflexive relations is same as number of reflexive relations. In reflexive relations we always included n ordered
pairs for {(a, a) ∣ a ∈ S}, while in irreflexive relation we always omit those n ordered pairs. So, the number of ordered pairs
to choose for the relation is the same for both reflexive as well as irreflexive relations which is
2
(
2 n −n . )
A relation becomes symmetric, if for ordered pair (a, b) in R, ordered pair (b, a) is also present in R. So, here, the total
number of ordered pairs possible is reduced from
n + n + … + n to
n (n +1 )
2
n+n−1+n−2+…+1= .
2 ( 2
).
A relation becomes anti-symmetric if for the ordered pairs (a, b) and (b, a) in R, a = b. i.e., the pairs (a, b) and (b, a) cannot be
For the n pairs (a, a) in R, they can be either present in relation or absent. So, 2 possibilities for each giving 2n possible
relations.
Number of pairs (a, b) in R such that a ≠ b equals number of ways of selecting 2 numbers from n without repetition, equals
n (n −1 )
2
Now, for each of these pairs (a, b), there are 3 possibilities-
2n ×3 ( 2
).
Finally, coming to your question, number of relations that are both irreflexive and anti-symmetric which will be same as
the number of relations that are both reflexive and antisymmetric is
n (n − 1 )
3 ( 2
).
We just have to always exclude n pairs being considered for (a, a) while calculating the possible relations for anti-symmetric
case.
Let R be a non-empty relation on a collection of sets defined by ARB if and only if A∩B=ϕ
(a) R is reflexive and transitive (b) R is symmetric and not transitive
(c) R is an equivalence relation (d) R is not reflexive and not symmetric
set-theory&algebra
a) unique solution b ∗ a −1
b) unique solution a −1 ∗ b
c) unique solution a −1 ∗ b −1
d) many solutions
set-theory&algebra
Selected Answer
In a group
1] there exist a unique identity element of Group i.e G. lets call it ' e '
2] the inverse of any element in G is unique. We generally represent inverse of a element 'a' as a −1
x*a*a −1 = b * a −1
x* e = b * a −1
x = b * a −1
∵ there always exit only unique inverse of any element in Group so solution to this equation is also unique.
Ref : https://en.wikipedia.org/wiki/Group_(mathematics)#Uniqueness_of_identity_element_and_inverses
Let A={x|x∈R and x!=2} and B={x|x∈R and x!=1} define f:A->B and g:B->A by
Yes it will be option A because its a property composition of two function are not commutative.
Functions f and g fail to commute if for some x, g(f(x))≠f(g(x)). Take any f such that f(x)≠x for some x. Now
g(f(x)) can be chosen independently of g(x), and in particular it can be some element other than f(g(x)).
for example let x=2 in fog = -2 but in gof we cant even take 2 coz A={x|x∈R and x!=2}
so fog≠gof
Selected Answer
y= f(x) = 1 + kx
y−1
x= f −1 (y) = k
x−1
k = 1 + kx
x − 1 = k(1 + kx)
( )
x k2 − 1 + (k + 1) = 0
(
(k + 1) x(k − 1) + 1 = 0 )
Thus,
{
−1 or,
k= x−1
x
1)(A-B)-C=A-(C-B)
2)A-(B∪C)=(A-B)∩(A-C)
3)A-(B-C)=(A-B)-(A-C)
4)A∆(B∪C)=(A∆B)∪(A∆C)
1) is false.
2) is true.
3) is false.
4) is false.
Answer 1,3,4 !
If A and B are subsets of set X={1,2,3........100} and A∆B denotes set of all elements of X which belong to exactly one of A
or B.Then total no of subsets of X such that A∆B ={2,4,6.....100}is
a)2^50
2)2^51
3)2^100
4)2^25
Selected Answer
2^100. Each of the odd elements of X have 2 choices, either they can be in both A & B or they can't be in both A & B, so
2^50 choices for them. Each of the even elements of the set can either be in A or be in B, so 2^50 choices for them. Thus
overall 2^100 choices
According to the question A Δ B should contain all even number of elements which in set notation can be written as :
(A − B ) ⋃ (B − A ) = {2,4,6,........100}
Now Both set A and B either should contain any of the odd elements {1,3,5,......99} or with will not contain any of the
odd elements ie it has each of 50 odd elements have two chances either to be placed in both A and B or to be placed
outside of both A and B which can be done in 2 50 ways .
Answer option C .
A set S has 5 elements .How many ways we can choose subset P and Q of S so that P∩Q=∅
Selected Answer
But it can’t join both set P & set Q, since P & Q shares no common elements.
P intersection Q will be null even if both P & Q are null, so no need to treat this case differently and it will one of those 35
choices.
16.77 How to find the sum of sqrt of first n natural numbers ? top gateoverflow.in/18604
When searching for the key value 60 in a binary search tree, nodes containing the key values 10, 20, 40, 50, 70, 80, 90 are
traversed, not necessarily in the order given. How many different orders are possible in which these key values can occur on the
search path from the root node containing the value 60?
http://ramanujan.sirinudi.org/Volumes/published/ram09.pdf
16.77 prove that y=cos2x+6 is not a one one and onto function. top gateoverflow.in/9780
Proving whether a function is one one or onto is totally dependent on the domain and codomain of the function. I assume
that domain and codomain are the set of all Real numbers.
Now consider x= 0° & 180 °, you will get the same y value =>Hence function is not one one
Therefore, there will be many values in codomain set, for which there is not any preimage in the domain set. Hence
function is not onto function.
please give me adetail solution.basically I am getting confused how to determine onto function or not for a polynomial.please
answer me as early as possible..
set-theory&algebra
Selected Answer
f(x) = x3 − 3x2 + 5x − 10
f ′ (x) = 3x2 − 6x + 5
Now, a polynomial is bijective (one-one and onto) if and only if its derivative never changes sign.
Here, the derivative is 3x2 − 6x + 5, for any x, this is positive. So, f is one-one and onto.
√36−60
6
f ′ (x) =0 x=6± , hence no real roots.
16.79 which of the following statements about a group are true? top gateoverflow.in/19380
1.If a group has an odd number of elements then there exists no element which is inverse of itself. 2.If a group contains even no of elements then there
exists only one element which is inverse of itself.
I am confused that if I have odd no of elements then in that case I will have one identity element and then I will be left with even no of elements,which
can be paired up so then I will be left with atleast one element which is inverse of itself so then in the case where the group has even no of elements then
can't we argue in the similar fashion .
answering what i think your doubt might be is.if i have odd elements and one will be identity element. so odd-1 = even
now we know that if we have order as even then there will be a element who will be inverse of itself. so odd also should
have a element which is inverse of itself. well it is not true because in this case u want to count the identity element twice.
the case of even also considers identity element which u have already considered it .
if u have odd elements then then remove identity element because identity element is inverse of itself.
so left with even number of elements which can be paired such that no element will remain.
but if i have even number of elements then . removing identity will make it odd number of elements now if i pair them up.
one element will definitely will be there which will don't have a inverse now we know since it is a group every element
should have a inverse.
I am not getting here that what is a and b are these elements of the set or two subsets of X ?
I want to know the best way through which we can find transitive closures of any relation ? Please let me know.
You can check Relations chapter in Keneth Rosen, Relations chapter, where you can find Closures topic. There is method
for finding transitive closure using Matrix Multiplication.
16.82 If R = ((1, 1), (3, 1), (2, 3), (4, 2)), then which of the following
represents R2, where R2 is R composite R? top gateoverflow.in/17920
If R = ((1, 1), (3, 1), (2, 3), (4, 2)), then which of the following represents R2, where R2 is R
composite R?
(a) ((1,1), (3, 1), (2, 3), (4, 2))
(b) ((1, 1), (9, 1), (4, 9), (16, 4))
(c) ((1, 1), (2, 1), (4, 3), (3, 1))
how to solve.
set-theory&algebra
RoR=R2=((1, 1), (3, 1), (2, 3), (4, 2))((1, 1), (3, 1), (2, 3), (4, 2))
take first set (1,1) then take second element of this subset check in the other set R is there any starting with 1 if
yes then take its second element and make a subset in R2 similarly check for all.
so answer will be D
Complex numbers are not comparable nless in a+ib c+id it is mentioned whether a<c etc.But if they are not
comparable,then how can one say c1 <=c2 implies c2<=c1 do not exist.(Since it is a poset ,anti symmetricity should hold)
set-theory&algebra
Where are you quoting it from ? I think here "<=" is general symbol for an ordering relation, not "less than equal"
relation.
16.84 Can you please help me understand Antisymmetric relation top gateoverflow.in/12665
Hi ,
I am stuck with Antisymmetric relations. I know the formal definition . If A = {a,b} , If aRb ^ bRa both true then a=b for all
a,b belongs to A.
Now , while the formal definition is ok , for practical purpose I found out that diagonal elements and / or half of the diagonal
elements are anti-symmetric.
A={a,b,c}
so , relations
{ (a,a),(b,b),(c,c)} is anti-symmetric.
{(a,b),(a,c),(b,c)} or {(b,a),(c,a),(c,b)} is anti-symmetric ( as one half of the diagonal ).
{(a,b),(b,c),(c,c)} is also anti-symmetric ( one half of diagonal and (c,c) is diagonal element )
set-theory&algebra
Selected Answer
See,
AntiSymmetric means that if aRb->bRa then a=b.Precisely if aRb exists then bRa should not exist.
Asymmetric is something which is both AntiSymmetric and irreflexive at the same time.
(A = {a,b} , If aRb ^ bRa both true then a=b for all a,b belongs to A) .
but this is not anti-symmetric {(a,b) , (b)} it`s violating the anti-symmetric properties .
As a simple example, the divisibility order on the natural numbers is an antisymmetric relation .
where R=real no
N =natural no
Z=integer
Selected Answer
identity element is the element in the set which when operated by a number with the operation given produces the same
element as result example
now in your question only (N,+) doesn't have an identity element rest have 1 as the identity element.
PS: 0 can be part of N or not and there is no agreement on this. See here.
Selected Answer
closed- what that means for every two elements from the set A when operated by the given operation give an output
which belongs to the same set A. In your question both are closed because you take any two elements and operate you
will get an element in the set.
Example:
(N,*) 5 * 2 = 10
(Z,*) -3 * 0 = 0
set-theory&algebra
Reflexive relations -> Self loops must exists. For All a, (a,a) belongs to relation. Other elements may or may not be
present
In Diagonal Relation -> Other than diagonal elements all other elements must be 0, i.e. For all a, For all b, if a!= b, (a,b)
does not belong to relation. Diagonal elements may or may not be present.
Selected Answer
A totally ordered set means, for every two elements of the set a and b, either a ≤ b or b ≤ a, and thus a ≤ b if and only if
a ∧ b = a (meet operation) and a ∨ b = b (join operation).
A lattice (L, ∨ , ∧ ) is distributive if the following identity holds for all x, y, and z in L:
x ∧ (y ∨ z) = (x ∧ y) ∨ (x ∧ z)
LHS = x ∧ (y ∨ z).
For a totally ordered set, this will return x, iff order of x is ≤ either y or z. Otherwise it will return the larger of y and z.
The same thing is applicable for RHS also making LHS = RHS for a totally ordered set.
If group order is divisible by P 2 where P is prime then group is Non Cyclic Abelian Group.
here, 27 is 32*3 so it is not cyclic ..
let f and g be two functions f :A->B and g: B->C g0f :A->C is surjection g is injection then f is
1)injection
2) surjection
3)bijection
4)none
Selected Answer
Given that gof is onto it implies that A as a whole must be able to access all the elements of C. Also A can not access C
directly, A can only access C via B. So indirectly B must have access to all the elements in C i.e. g must be onto. Now
since g is already into and it must be onto in order to make gof onto so g is bijective. Now since g is bijective so there is a
one to one correspondence between B and C.Hence in order to access C completely from A, we must have access to all the
elements of B from A which is making f a surjective function. Please let me know, am I correct sir?
set-theory&algebra
Selected Answer
∅ is subset of every set that is why it is called Trivial SubSet of any set.
so ∅ ⊆ {∅} and ∅ ∊ {∅}.
Selected Answer
This is the Example of lattice which is Distributive Lattice but not Complemented Lattice.
In Distributive Lattice complement of element an element if exists is Unique i.e. each element has at most
one complement.
This Example satisfy the condition of Distributive Lattice but fails the condition of Complemented Lattice
because element 6 have no complement.
2. No, it is not True.Distributive Lattice might be bounded but Complemented should be bounded.
This is Unbounded Lattice and distributive too because here every element has at most one complement.it is
not complemented Lattice because first, it is unbounded and second Here complement of every element is
not present.
a≠y a≠b
if Lattice contains
a
sub
lattice which is isomorphic to one of these two then we can say Lattice is not distributive and
otherwise it is distributive.it doesn't matter Lattice bounded or not.There is no relation between Bounded Lattice
and Distributive Lattice.
Selected Answer
1. Go to X and not Y.
2. Go to Y and not X.
3. Go to neither X nor Y.
we need to count unordered pairs- (X = {1, 2}, Y = {3, 4}) and (X = {3, 4}, Y = {1, 2}) should not be counted separate.
We can see that every pair X, Y have two orders except (X = ∅, Y = ∅). So, to count the no. of unordered pairs we can do
81 − 1
2
+ 1 = 41.
answer = 41
http://math.stackexchange.com/questions/1223425/total-number-of-unordered-pairs-of-disjoint-subsets-of-s
16.93 If G is an infinite cyclic group then which of the following is not true?
top gateoverflow.in/5669
b) G is isomorphic to (Z,+).
ans is A:
because cyclic group is a group generate dby a single element, which is generator g. applying repeatedly group operations
to this g or its inverse we can get all the eements of group.
B & C are propertie of infinite cyclic group, which are always true.
From a group of 10 doctors, how many ways a committee of 5 can be formed so that atleast one of Dr A and Dr B will be
included.
set-theory&algebra
Assuming Dr. A and Dr.B are the two special doctors in the group ,at least one of them must be included.
Required no. of groups = Total possible groups of 5 doctors - Groups in which none of Dr.A and Dr. B were selected
= 10 C5 - 8 C3 = 196
16.94 If f is one-one and g is onto.Then what can we say about gof? top gateoverflow.in/6236
It is closed
The set G = {0, 1, 2, 3, 4, 5} under addition modulo 6 is a group. Which all subgroups of order 2 and 3 are possible?
set-theory&algebra
Selected Answer
(0,3)
(0,2,4)
set-theory&algebra
set-theory&algebra
set-theory&algebra
http://gateoverflow.in/33339/group-theory
answer is A.
engineering-mathematics set-theory&algebra
Selected Answer
look if a graph is not complete then chromatic no is dmax.means higest degree of that graph.
(n-1)
A relation is said to be antisymmetric if (a,b) belong to R and (b,a) belong to R implies a=b...
No, reflexive means if (a,b) belongs to R, (a,a) and (b,a) should also be in R.
Anti-symmetric actually says symmetry should not be there. i.e., if (a,b), and (b,a) shouldn't be present together unless a
= b.
(Z- , >=)
whereZ- is the negative integers
is this woset expalin.? and also tell the least element.??
set-theory&algebra
Two numbers are such that their HCF is 16 and their sum is 144. How many such pairs of numbers are possible?
Selected Answer
16x + 16y=144
x+y=9
(1,8), (2,7), (4,5), (7,2), (8,1) pairs (Co primes of 9 , so that HCF remains 16)
The product of the two numbers is 576 and their HCF is 4. How many such pairs of numbers are possible?
HCF is 4.
4x * 4y = 576
xy = 36
[Note: We need co primes from the possible factors of 36. only bcoz HCF is fixed, nothing can be common except that.]
4)none
Selected Answer
Two Subgroup can't be disjoint. Reason is, to hold Group property each subgroup has to have Identity element. So each
Subgroup must contains Identity element.
How many zeroes does the product of all factors (including itself) of 100 end in ?
http://puzzles.nigelcoldwell.co.uk/nineteen.htm
http://www.geeksforgeeks.org/count-trailing-zeroes-factorial-number/
Find the sum of the perimeters of all the rectangles with integral sides whose area is 216 sq. units.
A function f: {0, 1}n → {0, 1} is called symmetric if for every x1 , x2 , . . . . , xn ∈ {0, 1} and every permutation σ of {1, 2, . . . , n}, we have
( ) ( )
f x1 , x2 , . . . , xn = f xσ(1 ) , xσ(2 ) , . . . . xσ(n ) .
a. 2n +1
b. 2n
c. 22n /n!
d. 22n
e. n!
normal set-theory&algebra
Selected Answer
First we need to find different number of inputs for f given that permutations are equivalent.
Now given two binary string x, y: x is a permutation of y iff x has same number of ones and zeros as y.
So the total number of different inputs is n+1 ( namely input with zero 0's, one 0's ... n 0's)
For each of these inputs we can have either 1 or 0 as output, so two choices.
2×2×2×…×2
Therefore, number of choices is n +1 times .
So the total number of such symmetric functions is 2n +1 .
16.110 Set Theory and Algebra: Which of the following is NOT true? top gateoverflow.in/28381
Let s(w) denote the set of all the letters in w where w is an English word. Let us denote set equality, subset and union
relations by =, ⊂ and ⋃ respectively. Which of the following is NOT true?
set-theory&algebra
Selected Answer
(a) { t, e, n } ⊂ { t, w, e, n, t, y } //TRUE
(b) { s, t, o, r, e, d } = { s, o, r, t, e, d } //TRUE
(c) { s, i, x, t, y } ⊂ { s, i, x, t, w, e, n, t, y } //TRUE
16.111 If X and Y are two sets, then X⋂(Y⋃X) C equals top gateoverflow.in/28324
My attempt:
X = {1,2,3} Y = {3,4,5}
(Y⋃X) = {1,2,3,4,5}
X⋂(Y⋃X) = {1,2,3}
set-theory&algebra
Selected Answer
16.112 Suppose the element a,b in a group satisfies aba-1=b2 for b<>e top
gateoverflow.in/28108
set-theory&algebra engineering-mathematics
Selected Answer
(aba-1)=b2
(aba-1)2=b4
(aba-1)(aba-1)=b4
ab(aa-1)ba-1=b4
ab 2a-1=b4
a(aba-1)a-1=b4
a2ba -2=b4
(a2ba -2)2=b8
a2b2a-2=b8
a2(aba-1)a-2=b8
a3ba -3=b8
a3b2a-3=b16
a3(aba-1)a-3=b16
a4ba -4=b16
a4b2a-4=b32
a4(aba-1)a-4=b32
a5ba -5=b32
= a 5ba -5
made-easy test-series
Selected Answer
how it is equivalent???pls give your solve.I am clearly seeing that it is not even reflexive. x<=4,y<=4 ..
and x+y<=5
17 Combinatory top
17.1 Combinatory: total number of 5 digit pallindrome???? top gateoverflow.in/17022
Reading and writing of variables is atomic, but the evaluation of an expression is not atomic.
The set of possible values of variable x at the end of the execution of the program is:
A. {4}
B. {8}
C. {4, 7, 10}
D. {4, 7, 8, 10}
E. {4, 7, 8}
mathematical-logic -combinatory
Answer should be 9*10*10 = 900. Out of the five digits, most significant three digits you can choose by your own and
remaining two digits will be fixed, based upon the choices you made. Now first digit must be a non zero digit other wise
the number will become a four digit number so, nine choices for the most significant digit, ten ten choices for second and
third digits respectively, which will give 9*10*10 choices.
Given answer: A
Please explain
engineering-mathematics combinations
Selected Answer
Required Probability
[]
1
[ ]
1 31 3 1 1 3 3 1 3 1 1
2 2 6
P = P(2) + P(¬3 ∧ ¬5 ∧ ¬2). P(2) + P(¬3 ∧ ¬5 ∧ ¬2). P(¬3 ∧ ¬5 ∧ ¬2). P(2)… = 6 + 6 6 + 6 6
+ … = 6 1 + 6 + 6 + … = 6 1− = 6.2 = 3.
17.4 Combinations: Counting number of functions which are neither 1-1 nor
onto top gateoverflow.in/33128
Let A = {1, 2, 3, 4}. Number of functions possible on A which are neither 1 − 1 nor on-to is _________.
combinations engineering-mathematics
Selected Answer
232 (Ans)
|A| }
from A → B are |B|
∵ 1 has 4 choices
3 has 2 choices
I believe that in place of last C(8,3) it should be C(7,3) because 3 people have been already chosen before that. Please check
whether I am correct or not.
combinations engineering-mathematics
Selected Answer
12600
How many bit strings contain exactly eight 0s and 10 1s if every 0 must be immediately followed by a 1?
Selected Answer
the bit strings must consist of eight 01 substrings and two 1s. Thus, there
are ten total positions and choosing the two positions for the 1s determines the string.
There are
10C2=45 such strings
17.6 Combinations: how many among the first 100,000 positive int contain
exactly one of each 3,4 and 5 in their decimal representation ? top gateoverflow.in/11001
combinations permutation
for the second case I did 5C2*4C2*1C1 , Again this can be permuted in 3! ways ,Now on adding these two cases I am
getting answer as 480 , what's wrong in this approach ?
combinations
Selected Answer
Answer is 150
U made the cases correct , but in calculation u made some error, Let's examine -
17.8 Combinations: In how many ways this can be done? top gateoverflow.in/30998
An entrepreneur needs to assign 5 different tasks to 3 of his employees. If every employee is assigned at least 1 task, how
many ways can entrepreneur assign these tasks?
My Attempt: Though the question seems quite simple, it got me confusing because of answer mismatch.
Initially assigning 1-1 task to all gives C(5,3) * 3! Then the remaining 2 tasks can be assigned in 3(all rem tasks to 1
person) + 3(one-one task to each)... So this will give, C(5,3)*3!*(3+3) = 360 ways
In the solution, they have stated that its like onto function and directly applied number of onto functions formula to get
correct answer as 150.
What is wrong with my approach and moreover I will be thankful if somebody suggests a combinatorial method for this qstn
rather than using function defination as they did. Thanks in advance !
Selected Answer
In your approach you did not accounted for permutation of last two tasks if both were assigned to different people.
So in case your approach was correct the answer the answer would be 5C3*3!*(3 + (3*2!)).
But your method is counting same things more than once in different ways,
For example let set of tasks be {a, b, c, d, e} & set of employees be {x, y, z}, & consider following 2 cases:
Case - 1
a --> x
b --> y
c --> z,
Case - 2
b --> y
c --> z
d --> x
It can be observed that assigning tasks in rounds (as we did here assigned 3 tasks in round one & remaining 2 in round
two) will not work we should assign all at once.
This can be done correctly by breaking set of tasks into 3 partitions & assigning each partition to one employee.
1) Partition of type 3, 1, 1 : Choose any 3 elements & put them in one partition. 5C3*1*1 = 10 partitions of this type.
2) Partitions of type 2, 2, 1 : Choose any 2 elements & put them in one partition, then choose 2 out of remaining 3
elements & put them into second partition, remaining one element will go to third partition without any choice. ((5C2)*
(3C2)*1)/2 = 15 possible partitions of this type.We divided by two because all partitions of type 2, 2, 1 will be counted
twice.
For example : suppose a partition {a, b}, {c, d} {e}, this will be produced in two ways, first choose {a, b} using 5C2 &
{c, d} using 3C2 and another way choose {c, d} using 5C2 & {a, b} using 3C2.So we divided by 2.
17.8 Combinations: how many distinct 4-digits integers one can make from
the digits 1,3,3,7,7,8 ? Is there and method or we have to go by
enumerating the possibilites ? top gateoverflow.in/11002
combinations permutation
17.9 Combinations: Counting number of functions which are neither 1-1 nor
onto top gateoverflow.in/33129
Given explaination:
combinations engineering-mathematics
Selected Answer
Look,the number of one to one function a set to itself is basically permutation on this set.let a set has n element,no one to
one function to itself is,n!.cause,first element has choice of n,next has n-1,next to next has n-2......thus... (n).(n-
1)......1= n!.
Now here the set has 4 elements,so the no of one to one functions are 4!.
Ref:http://math.stackexchange.com/questions/366146/a-one-to-one-function-from-a-finite-set-to-itself-is-onto-how-to-
prove-by-indu
And basically both one to one and onto functions to the set itself are permutation of the elements of that set.
Now the number of one to one or onto functions are 4! + 4! -4! = 4!.
I think that number of 5 elements subsets with 7 should be C(n-1, 4) instead of C(n,4) as we have already fixed 7 so
number of elements left will be n-1. Please check
engineering-mathematics combinations
Selected Answer
20 (Ans)
set cardinality = n
4 = (n-1)C4
n! (n −1 ) !
4 ∗ (n −5 ) ! ∗ 5 ! (n −5 ) ! ∗ 4 !
=> =
Problem: In how many ways can 2n seats in a congress be divided among 3 parties so that the coalition of any 2 parties will ensure them of majority?
Answer: Total number of ways in which the seats can be distributed among parties such that any 2 of them combined and form a govt. is -
C(2n+2, 2) - 3 C(n+2, 2) +3
I cannot understand why we have to add 3 with the final expression. This question is similar to this except the problem considering even number of seats.
Selected Answer
No. of ways to divide 2n seats among 3 parties = no. of ways in which we can distribute 2n identical balls into 3 distinct
bins
= 2n +2 C2 .
Now, we have to ensure that selecting any two party will get no. of seats more than the other. So, we can take the
complement case where no party gets the majority of seats. Here, we have 2n seats and to ensure no majority one party
needs n seats. So, remaining n seats we can distribute among 3 parties in n +2 C2 ways and the n seats can go to any one
among the 3 party and thus we get 3 × n +2 C2 ways.
But we over counted above. This happens when n seats go to say party A and n remaining seats go to party B. This case
will be repeated when initial n seats go to party B and remaining n to party A and similarly for B and C too. So, AB-BA, AC-
CA, BC-CB, 3 cases are counted extra. Excluding these our final answer will be
2n +2 C − 3 × n +2 C2 + 3.
2
O.....O|O......O|....
this was general distribution without condition ...now to follow condition ..i will give N balls already to any one basket ...
now i have N balls left ..that can be distributed in same way as did with 2N balls....N+2C2 *3 ..as i could put those first N
balls in any basket ....now in this procedure ....i have counted ..O|O| ....twice ...how ..lets give N already to 1 basket
..and then to 2 ..and this will happen when N will be given already to 2nd basket first ..so need to add ...3 ..."HERE 3 are
not special cases ...these are just overcounted ways ",,,,thats why its correct
we have to choose five chocolates,say, C1, C2, C3, C4 and C5. Now for C1 we can choose among three kinds of chocolates. Since the supply of chocolates is infinite, for C2, again we Can
choose among three kinds of chocolates. Similarly for each of C3, C4, C5, we have three options. So total number of choices =3^5=243.
Now if we have a case like CCCCP and PCCCC , so then these cases are counted distinct but they should be same , so then how to proceed from here ?
combinations
C |F |P
*** |** | HERE it means 3 CADBOURY ....2FIVE STAR and 0 PERKS ...same like that u can
divide 5 stars in any partitions .SO 7C2 is the answer ....and by formula too ..(5+3-1)C(3-1)
permutation combinaton
12!/(3!*2!*2!*5!)
=166320
So option B is correct.
How many ways are there for a horse race with 4 horses to finish if ties are possible?(any number of horses may tie)
combinatorics engineering-mathematics
Selected Answer
2. Two Horses tie: Number of ways to choose 2 horses from four horses 4C2 = 4*3/2 = 6, Now we can consider these 2
horses as one horse since they tie for position, Number of outcome of race with 3 horses is 3!. So total number of
outcomes becomes 6*3!
3. Three horses tie: (Number of ways to select 3 horses) * (number of outcomes for 2 horse race without tie) = (4C3)*2!
= 8
Four horses are competing in race , and any no. of ties are possible.
I II III IV
st place} => # ways = 4C4 = 1
4 { Here all 4 finishing in I
1 3
# ways = 4C1 * 3C3 = 4
1 2 1
# ways = 4C1 * 3C2 * 1C1 = 12
1 1 2
# ways = 4C1 * 3C1 * 2C2 = 12
1 1 1 1
# ways = 4C1 * 3C1 * 2C1 * 1C1 = 24
Total # ways = 1 + 4 + 6 + 12 + 4 + 12 + 12 + 24
= 75 ways..
combinatorics
Is it
100C0x^200+100C1x^198+100C2x^196+100C3x^194+.............................+1
In how many ways 5 blue pens and 6 black pens can be distributed to 6 children?
a)97020
b)116424
c)8008
d)672
combinatorics
x1 + x2 + x3 + x4 + x6 = 5 and x1 + x2 + x3 + x4 + x6 = 6
The number of ways 16 identical objects can be distributed among 4 persons such that each person gets atleast 2 objects is
______.
combinatorics engineering-mathematics
Selected Answer
I used this formula:- the number of ways of distributing r similar balls into n numbered boxes C(n-1+r,r)
by the way above formula also belong to the number of non-negative integral solutions to X1+X2+X3+...+X n =r
now move to question:- 16 identical object distributed among 4 person and each person gets atleast 2(minimum 2)
So (2+X1)+(2+X2)+(2+X3)+(2+X4)=16
X1+X2+X3+X4=8
So C(4-1+8,8)=C(11,8)=165
hope ans is correct :)
17.18 Combinatorics: How many 4 digit integers are there with digit 6
appearing exactly once top gateoverflow.in/33427
How many 4 digit integers are there with digit 6 appearing exactly once .
6_ _ _ 9 *8*7
_ 6 _ _ 9* 8 * 7
_ _ 6 _ 9*9*7
_ _ _ 6 9*9*8
combinatorics
Selected Answer
6_ _ _ = 9*9*9
_ 6 _ _ = 8*9*9
_ _ 6 _ = 8*9*9
_ _ _6 = 8*9*9
Suppose if we have
combinatorics
Selected Answer
Now see in what order we choose doesn't matter, i can choose 1 english movie out of the 6 first and then 1 malayalam
movie out of 8 or 1 malayalam movie first and then choose english, both are same order doesnot matter.
Incases where order doesnt matter, it is COMBINATION, in case where order matters it is PERMUTATION.
So in this question, case 1 + case 2 + case 3 i.e 6C1 x 8C1 + 6C1 x 10C1 + 10C1 x 8C1 = 188
Method 1 :
Total no of ways of choosing 2 movies - no of ways of choosing 2 movies from same language
Method 2:
= no. of ways of choosing[ (1 english movies & 1 hindi ) or (1 Malayalam movies & 1 hindi) or (1 english movies & 1
Malayalam)
The least number of cables required to connect 8 computers to 4 printers to guarantee that 4 computers can directly access
4 different printers.
I assumed this was simple bipartite graph k(8,4) , 32 connections.That seems to be wrong.
combinatorics
Selected Answer
Since each 4 comp need direct connected with each printer.... so 16 connection + now remaining 4 computer, each connected to 4
different printers, so 4 connections=20 connections.
c1-> p1,p2,p3,p4
c2-> p1,p2,p3,p4
c3-> p1,p2,p3,p4
c4-> p1,p2,p3,p4
c5->p1
c6->p2
c7->p3
c8->p4
Now, any pick of 4 computers will have a direct connection to all the 4 printers.
How many solution exist for x+y+z=10 with 1<=x<4 1<=y<=7 and z>1
combinatorics
Ans will be 18
.......................
y=2 , z=6
.......................
y=2, z=5
............................
An entrepreneur needs to assign 5 different tasks to three of his employees. If every employee is assigned atleast 1 task,
how many ways can the entrepreneur assign those tasks to his employees?
As every employee is given at least 1 task, we assign them 3 out of 5 tasks. We are left with 2 tasks, name them A and B.
Now, we have to assign these 2 tasks: A and B, to 3 employees : E1, E2 and E3.
Each task can be assigned to any of the 3 employees, we don't care if an employee gets both of these 2 tasks, or gets
none of these 2, because we have already assigned 1 task to each employee and we can assign the remaining 2 tasks in
any way we wish.
So, each task can be assigned to any of 3 employees. 2 tasks can be assiged in 3*3=9 ways.
How many functions are there from the set {1, 2, . . . , n}, where n is a positive integer, to the set {0, 1}
a) that assign 1 to exactly one of the positive integers less than n?
counting functions
Selected Answer
The domain set has n elements and co-domain set has 2 elements. So, each of the n elements from domain has 2 choices
in the function and thus we get 2n total functions.
Now, we are given a condition that exactly 1 positive integer less than n maps to 1. So, all others less than n must map to
0. We can find this number in n −1 C1 ways (all the mappings for these n − 1 elements are fixed) and n can be mapped to
either 0 or 1, thus we get 2.(n − 1) possible functions.
How many bit strings of length 10 contain either five consecutive 0s or five consecutive 1s?
counting
Selected Answer
Let T(n) denote the number of but strings of length n containing 5 consecutive 0's.
So, no. of bit strings of length n not containing 5 consecutive 0's = T(n) ′ = 2n − T(n)
Now, we can form a recurrence relation for Tn . We can for a bit string of length n containing 5 consecutive 0's in two ways:
1. from a bit string of length n − 1, containing 5 consecutive 0's by adding either 0 or 1 at end.
2. from a bit string of length n − 6, not containing 5 consecutive 0's by adding 100000 at end.
These two covers any possible bit strings containing 5 consecutive 0's. In the second case we needed "100000" and not
"00000" as "00000" would cause strings already considered in 1.
We get,
The number of bit strings having 5 consecutive 1's must also be 112.
Now, we need to find the number of bit strings of length 10 containing 00000 as well as 11111. There are only 2
possibilities:
1111100000 and
0000011111
Thus no. of bit strings of length 10, having either five consecutive 0's or 5 consecutive 1's = 112 + 112 - 2 = 222
How many bit strings of length eight contain either three consecutive 0s or four consecutive 1s?
combinatory counting
Selected Answer
Let T(n) denote the number of but strings of length n containing 3 consecutive 0's.
So, no. of bit strings of length n not containing 3 consecutive 0's = T(n) ′ = 2n − T(n)
Now, we can form a recurrence relation for Tn . We can for a bit string of length n containing 3 consecutive 0's in two ways:
1. from a bit string of length n − 1, containing 3 consecutive 0's by adding either 0 or 1 at end.
2. from a bit string of length n − 4, not containing 3 consecutive 0's by adding 1000 at end.
These two covers any possible bit strings containing 3 consecutive 0's. In the second case we needed "1000" and not
"000" as "000" would cause strings already considered in 1.
We get,
Now, let M(n) denote the number of bit string having 4 consecutive 1's. We get
Now, we need to find the number of bit strings of length 8 containing 1111 as well as 000. We get the following 4 and
their 4 reverse strings.
11110001
11110000
01111000
11111000
Thus no. of bit strings of length 8 having either three consecutive 0's or 4 consecutive 1's = 107 + 48 - 8 = 147
combinatory counting
Selected Answer
= n(n+1)/2 + 1 // n is no of characters in string, as we have 1 sub-strings of length n, 2 of length n-1, ... n sub-
strings of length 1.
= 8*9/2 +1 = 36 + 1
= 37
Every String has at least 2 substring one is NULL string and 2nd is the given string itself, Which are called Trivial
substring....remaining possible substring called Non-trivial substrings.
So answer is C. 2
combinatory generating-functions
Selected Answer
In multinomial expansion of (1+x^5+x^9)^100, every term will be of form: C(100 ; m, n, p) * (1^m) * ((x^5)^n)
* ((x^9)^p), where m + n + p =100.
So, for the coefficient of x^23, (5*n + 9*p) should be equal to 23. There is only 1 pair exist for this condition to hold i.e
(1,2).
So, (m, n, p) will be (97, 1, 2). Now, put these values in the term for x^23.
C(100; 97, 1, 2) = 100!/(97! * 1! * 2!) = 485100. This will be the coefficient of x^23.
17.27 Permutation: No. of ways in which 2n white and 2n black balls can be
arranged such that no consecutive n white balls are together top gateoverflow.in/41638
The number of ways in which 2n white and 2n black balls can be arranged such that no consecutive n white balls are together,
is
A. 2n +1 C2 + 4n C2n
B. 2n +1 C2 − 2n +1 C1 . 3n Cn ( − 1)n + 4n C2n
C. 2n +1 C2 + ( − 1)n . 2n +1 C1 . 3n Cn + 4n C2n
D. 2n +1 C2 + ( − 1)n . 3n Cn . 2n +1 C1
combinatory permutation
Without any restriction we have a permutation of 4n objects where 2n each are identical. So, 4n C2n .
Now we have to subtract the cases where n white balls are consecutive. We can choose the starting position for these n
balls in 3n + 1 ways. Remaining 3n balls would give 3n Cn . So, our answer should be
4n C − (3n + 1)3n Cn .
2n
But this counts repeatedly the n consecutive case- waiting for correct solution.
17.28 Permutation: Different possible integer solutions for the given function
top gateoverflow.in/35600
How many integer solutions exist for the given equation x + y + z = 15 subject to the constraint that 0 ≤ x, y, z ≤ 10?
I tried the brute force method and listed the possible solution sets for the above equation, given the variable constraints as
follows :
[]
2 3 10
2 4 9
2 5 8
3 6 6
3 4 8
3 5 7
4 5 6
4 7 4
4 10 1
4 11 0
6 7 2
6 8 1
6 9 0
5 9 1
5 10 0
7 8 0
Here, each row will denote the possible values for the three variables. I tried to eliminate any duplicate values, and listed
only the unique combinations of integer values. Then, the number of possible solutions should be one of the permutations of
the above values only, right? So, that should be 16 * 6 = 96 possible solutions. The answer given was 3666, derived using
Generating functions. Please explain.
permutation normal
Selected Answer
This problem can be reduced to balls in bins problem. x, y and z are 3 distinct bins and we have 15 identical balls to fill
them. Now, the problem reduces to all the possible permutations of 15 + (3-1) (3-1 separations split 15 items to 3 bins)
items, with 15 identical balls and another 2 identical separations. So,
17!
15!2!
= 136.
So, let x = 11, now we have y + z = 4, which has 5 possible cases (calculated as above). Similarly for y = 11 and z = 11 we get
5 more cases each totaling 15 cases.
Similarly for 12, 13, 14, 15 we get 3.4, 3.3, , 3.2, 3.1 cases totaling 15 + 12 + 9 + 6 + 3 = 45 possible cases.
If there are 9 students in a class and each team contain 3 students then how many number of ways 9 students can be
partitioned into 3 teams?
permutation
Selected Answer
To make #1 group having 9C3 ways and #2 group having 6C3 ways and last #3 group have 1 way to make a group
with remain students.
With ordered group total ways are 9C3 * 6C3 * 3C3.
But for unordered group 9C3 * 6C3 * 3C3 divided by 3!.
In how many ways can 2n + 1 seats in a congress be divided among 3 parties so that coalition of any 2 parties will ensure
them majority?
permutation counting
Selected Answer
This problem corresponds to the problem of non negative integral solutions to the equation
The solution will be n −1 +rCr having n = 3 and r = 2n + 1. This comes as 2n +3 C2n +1 which further reduces to 2n +3 C2 = A. (say).
EDIT :
The constraint the the coalition of 2 parties must form a govt can be dealt with as follows-
We have to also ensure that govt must be formed by coalition so we have to eliminate the case where a single party gets
a majority i.e. n + 1 votes. That corresponds to non negative integral solutions to the eqn
P1 + P2 + P3 = n
Selected Answer
Ans : (B)
Hence this problem is identical to distributing 8 balls among x1,x2,x3,x4 such that each will get alt least one ball
x1+x2+x3+x4=8
so we get 4+4-1C4=35
option b
in how many ways 10 identical blue marbles and 5 identical green marbles be arranged in a row so that no two green
marbles are together??
combinatory permutation
Selected Answer
First we place the 10 blue balls in 1 way because they are all identical :
__B1__ B2__B3__B4__B5__B6__B7__B8__B9__B10__
Since no 2 green balls are together only place we have is to place the green balls in between blue balls . There are 11
available places to place the green balls : Therefore we can select any 5 places as 11C5 . Then we arrange the 5 balls in 1
way because they are identical .
17.33 Permutation: How many ways are there to choose a dozen donuts from
20 varieties top gateoverflow.in/4579
How many ways are there to choose a dozen donuts from 20 varieties
counting permutation
Selected Answer
a) Here a dozen items must come from a single variety. And we have 20 varieties possible. H ence the no of ways of
selecting a dozen of same variety donut = 20.
b) For this part lets find out no of ways in which the 12 donuts can be chosen from 20 varieties
x1 + x2 + … + x20 = 12
No ways of solving this is (20+12−1 ) C19 = 141, 120, 525 (Explained at end). In the question they have asked that there are at
least 2 varieties of donuts. Hence we need to negate the ans of part a(i.e, the no of ways in which the same variety can
be chosen ) from the total no of ways of choosing the donuts = 141, 120, 525 − 20 = 141, 120, 505
c) It is given that at least 6 donuts of blueberry variety should be there. Here we can assume that 6 donuts are already
chosen. Hence now the solution is (20+6 −1 ) C19( ie., no ways of solving x1 + x2 + … + x20 = 6) = 177, 100.
d) Here the condition is no more than 6 blue berry are selected. To solve this find the no of ways in which at least 7 blue
berry will be chosen an in part c which is (20+5 −1 ) C19 = 42505. Now negate this from total no of possibilities to get the
required ans = 141, 120, 525 − 42, 505 = 141, 078, 021.
So, this problem is equivalent to dividing 12 identical balls into 20 distinct bins without any further restrictions. So, lets
use | for the separation between bins and 0 for the balls. For example the below configuration shows all 12 balls in the
first bin.
0 0 0 0 0 0 0 0 0 0 0 0 | | | | | | | | | | | | | | | | | | |
So, now our required answer will be all possible permutations of the above. We have 12 balls and (20-1) separations.
Further 12 balls are identical and 19 separations are also identical (bins are distinct but separations are identical as two
separations together means a bin in empty and their order doesn't matter). So, no. of possible permutations
(12+19) !
= 12!19! = 31C19.
Ref: http://www.cse.iitm.ac.in/~theory/tcslab/mfcs98page/mfcshtml/notes1/thperset.html
How many 4-permutations of the positive integers not exceeding 100 contain three consecutive integers k, k + 1, k + 2, in
the correct order
a) where these consecutive integers can perhaps be separated by other integers in the permutation?
combinatory permutation
Selected Answer
a) In this part the permutation 5,6,32,7, for example, is to be counted. since it contains the consecutive
numbers 5, 6, and 7 in their correct order (even though separated by the 32). In order to specify such a
4-permutation, we first need to choose the 3 consecutive integers. They can be anything from {I, 2, 3} to
{98, 99, 100}; thus there are 98 possibilities. Next we need to decide which slot is to contain a number not
in this set; there are 4 possibilities. Finally, we need to decide which of the 97 other positive integers not
exceeding 100 is to fill this slot, and there are of course 97 choices. Thus our first attempt at an answer gives
us, by the product rule, 98· 4 . 97.
Unfortunately, this answer is not correct, because we have counted some 4-permutations more than once.
Consider the 4-permutation 4. 5. 6. 7, for example. We cannot tell whether it arose from choosing 4, 5, and 6
as the consecutive numbers, or from choosing 5, 6, and 7. (These are the only two ways it could have arisen.)
In fact, every 4-permutation consisting of 4 consecutive numbers. in order, has been double counted. Therefore
to correct our count, we need to subtract the number of such 4-permutations. Clearly there are 97 of them
(they can begin with any number from 1 to 97). Further thought shows that every other 4-permutation in our
collection arises in a unique way (in other words, there is a unique subsequence of three consecutive integers).
Thus our final answer is 98·4·97 - 97 = 37.927.
b) In this part we are insisting that the consecutive numbers be consecutive in the 4-permutation as well.
The analysis in part (a) works here, except that there are only 2 places to put the fourth number-in slot 1
or in slot 4. Therefore the answer is 98·2·97 - 97 = 18,915.
Prove that at a party where there are at least two people, there are two people who know the same number of other people
there.
Selected Answer
http://math.stackexchange.com/questions/445487/prove-that-at-a-party-with-at-least-two-people-there-are-two-people-
who-know-th
Assume that in a group of six people, each pair of individuals consists of two friends or two enemies. Show that there are
either three mutual friends or three mutual enemies in the group.
let the group be labeled as A;B;C;D;E and F. Consider now the person labeled as
A. The remaining five people can be grouped into friends or enemies of A. Of the five other people
(other than A), there are either three or more who are friends of A, or three or more than are enemies
of A. Indeed, when a set of 5 objects (persons) is divided into two groups (friends or enemies) there
are at least d5=2e = 3 elements in one of these groups. Consider first the group of friends of A. Call
them B;C or D. If any of these three individuals are friends, then these two and A form the group
of three mutual friends. Otherwise, B, C and D form a set of three mutual enemies. The proof in the
case of three enemies of A proceeds in a similar manner.
During a month with 30 days, a baseball team plays at least one game a day, but no more than 45 games. Show that there
must be a period of some number of consecutive days during which the team must play exactly 14 games
Selected Answer
Let a1 be the number of games played until day 1, and so on, ai be the no games played until i.
Consider a sequence like a1 , a2 , …a30 where 1 ≤ ai ≤ 45, ∀ai.
Add 14 to each elements of the sequence we get a new sequence a1 + 14, a2 + 14, …a30 + 14 where 15 ≤ ai + 14 ≤ 59, ∀ai.
Now we have two sequences
1. a1 , a2 , …, a30 and
2. a1 + 14, a2 + 14, …, a30 + 14
So according to pigeon hole principle there must be at least two elements taking a same value ≤ 59 i.e., ai = aj + 14 for
some i and j.
There for there exists at least a period such as aj to ai, in which 14 matches are played.
Show that there are at least six people in California (population: 37 million) with the same three initials who were born on
the same day of the year (but not necessarily in the same year). Assume that everyone has three initials.
Selected Answer
Show that in a group of 10 people (where any two people are either friends or enemies), there are either three mutual
friends or four mutual enemies, and there are either three mutual enemies or four mutual friends.
Selected Answer
Take a single person A out of the 10 people. The remaining 9 people has to be either friends or enemy with A. Therefore
acc to pigeon hole principle there atleast⎾9/2⏋(i.e., 5) friends or enemy of A. Lets assume that A has five friends.Now, if
at least two of these are friends then there are three mutual friends if not then there are five mutual enemies(which also
implies that there are four mutual enemies). similarly we can prove that there are either three mutual enemies or four
mutual friends by assuming A has 5 enemies.
Show that in a group of five people (where any two people are either friends or enemies), there are not necessarily three
mutual friends or three mutual enemies.
Selected Answer
https://www.google.co.in/url?
sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB4QFjAAahUKEwiGsbLmwODGAhXDW44KHYbdD5A&url=http%3A%
3-2-06.pdf&ei=NBaoVYbHBsO3uQSGu7-ACQ&usg=AFQjCNGVQAfyFu-
7NoEMpP0RK9QhCv2Sfg&sig2=PggJgcHYJoK3003ypov3Pg
17.40 Placement Questions: In how many ways a rook can go from SouthEast
to northwest corner of 8×8 chess board if travels only upwards or left? top
gateoverflow.in/42390
Selected Answer
To go to from (0,0) (consider, southeast corner) to (8,8) (consider northwest corner) we need to take 7 Up turn and 7
right turn. It means that its a forming a string like UUUUUUURRRRRRR (Whatever the way you go, you have to take 7 Up
and 7 right to reach (8,8)). Now our job is it find the how many permutation can be formed from this string. Which is a
very simple task.
Total Number of permutation will be : ( factorial(14) / (factorial(7) * factorial(7))). Which is equivalent to 14C7.
I think the ans should be C, but the given answer is A. Anyone can explain please?
engineering-mathematics probability
Now, it is given among 3 pair of throws only one pair will show 10
Now, that pair we can choose among any one of (5,5),(4,6),(6,4)= so 3C 1 ways (say (a,b) =3C1)
Now for other two pairs ( say (c,d) , (e,f) ) we cannot choose among that previous three pairs
For 2 " " " " " " " 1,2,3,4,5,6 = 6 choice.................ii
For 3 " " " " " " " 1,2,3,4,5,6 = 6 choice..................iii
For 4 " " " " " " " 1,2,3,4,5 = 5 choice.....................iv
For 5 " " " " " " " 1,2,3,4,6 = 5 choice......................v
For 6 " " " " " " " 1,2,3,5,6 = 5 choice.....................vi
=121 / 576
A parking lot has 16 spaces in a row. Twelve cars arrive, each of which requires one parking space, and their drivers chose
spaces at random from among the available spaces. Auntie Em then arrives in her SUV, which requires 2 adjacent spaces.
What is the probability that she is able to park?
11 4 81 17
probability
Selected Answer
12 cars will take 12 places and we are left with 4 places. So, we need to find the probability that at least 2 of them are
adjacent. This will be equal to 1 - Probability that none of them are adjacent.
C C C C C C C C C C C C V V V V taking 16 places.
If we want no two V's to be adjacent, we must place the V's around the 12 C's in 13 places- 12 after each C and 1 before
the first C. i.e.; we have 13 C4 ways where no vacant places are adjacent.
top
In a round-robin tournament with m players, every two players play one game in which one player wins and the other loses.
We want to find conditions on positive integers m and k with k < m such that it is possible for the outcomes of the
tournament to have the property that for every set of k players, there is a player who beats every member in this set. So
that we can use probabilistic reasoning to draw conclusions about round-robin tournaments, we assume that when two
players compete it is equally likely that either player wins the game and we assume that the outcomes of different games
are independent. Let E be the event that for every set S with k players, where k is a positive integer less than m, there is a
player who has beaten all k players in S.
a) Show that where F j is the event that there is no player who beats all k players from the
j th set in a list of the mk sets of k players.
b) Show that the probability of Fj is (1−2 −k ) m−k
c) Conclude from parts (a) and (b) that C(m,k)(1−2 −k ) m−k and, therefore, that there must
be a tournament with the described property if C(m,k)(1−2 −k ) m−k <1
d) Use part (c) to find values of m such that there is a tournament with m players such that for every set S
of two players, there is a player who has beaten both players in S. Repeat for sets of three players.
combinatory probability
This is not a gate oriented qus.however the things that are asked to be proved can be remembered to answer mcq
1. Find recurrence relation for ternary string of length n that do not contain two consecutive zeros or two consecutive 1s?
2. Find recurrence relation for ternary string that contain either two consecutive or two consecutive 1s?
3. Find recurrence relation for no of ternary strings of length n that do not contain two consecutive symbols same?
4. Find recurrence relation for ternary strings of length n that contain two consecutive symbols same?
combinatory recurrence
1. Let an be the no. of ternary strings not containing "00" or "11" of length n. Let a0 be the no. of ternary strings not
n
containing "00" or "11" of length n and ending in '0' and similarly we define a1 and a2 . So,
n n
an = a0 + a1 + a2
n n n
(
= a1 + a2
n− 1 n− 1 ) (
+ a0 + a2
n− 1 n− 1
+ a0 + a1 + a2
n− 1 n− 1 n− 1 ) ( )
(
= 2. a0 + a1 + a2
n− 1 n− 1 n− 1
+ a2
n− 1 )
= 2.an −1 + an −2 .
For initial condition, a1 = 3, a2 = 7.(All two length strings except 11 and 00).
bn = 3n − an .
bn = 3n − 2.an −1 − an −2
(
= 3n − 2. 3n −1 − bn −1 − 3n −2 + bn −2)
[ ]
= 3n −2 32 − 2.3 − 1 + 2.bn −1 + bn −2
(
= 2. 3n −2 + bn −1 + bn −2 )
Initial condition, b1 = 0, b2 = 2.
an = a0n + a1 + a2
n n
= a1 + a2 + a0 + a2 + a0 + a1
n− 1 n− 1 n− 1 n− 1 n− 1 n− 1
= 2.an −1 .
Initial condition a1 = 3, a2 = 6.
4.
bn = 3n − an
bn = 3n − 2.an −1
(
= 3n − 2. 3n −1 − bn −1 . )
Initial condition b1 = 0, b2 = 3.
an = an-1 + n , n>=1
a0=2
Find a 100... ?
Solution
T(n) = T(n-1)+n
and back substitute
T(n)= T(n-k) + nk
putting n-k = 0
T(n) = 2+ n* n
So T(100) = 2+100*100
recurrence algorithms
Selected Answer
t(n)=t(n-1)+n
=t(n-2)+n+n-1
=t(n-3)+n+n-1+n-2
=t(n-k)+n+n-1+n-2+.....1
k=n
=t(0)+n(n+1)/2
=2+100(101)/2
=5052
a0 =2
a1=a0+1 =2+1
a2=a1+2=2+1+2
a3=a2+3=2+1+2+3
a4=a3+4=2+1+2+3+4
a100=2+1+2+3+ .........+100
=2+5050=5052
an = 5an / 3 + 7, a1 = 5
recurrence
Selected Answer
( )
T(n) = 5 ⋅ T n/31 + 7
( ( )
= 5 × 5 ⋅ T n/32 + 7 + 7 )
( )
= 52 ⋅ T n/32 + 51 ⋅ 7 + 7
( ( )
= 52 × 5 ⋅ T n/33 + 7 + 51 + 7 )
( )
= 53 ⋅ T n/33 + 52 ⋅ 7 + 51 ⋅ 7 + 7
⋮
k−1
∑
( )
= 5k ⋅ T n/3k + 7 ⋅ i =0 5i
(log 3 n ) −1
∑
T(n) = 5log3 n ⋅ T(1) + 7 ⋅ i =0 5i
51 + (log3 n −1 ) − 1
= 5log3 n ⋅ T(1) + 7 ×
( 5−1
)
It is given that T(1) = 5, hence, we get:
T(n) =
4
(
⋅ (4 ⋅ 5 + 7) ⋅ 5log3 n − 7 )
1
=
4
(
⋅ 27 ⋅ nlog3 5 − 7 )
1
⪅
4
(
⋅ 27 ⋅ n1.465 − 7 )
recurrence-eqation engineering-mathematics
As other than the recursion function , any function of K is not added , this equation is equivalent to T(k) = 3T(k-1) + 1 ,
T(0) = 1
Using repeated substitution we can observe that T(k) = 1 + 3^1 + 3^2 ... + 3^k .
17.47 Suppose that S is a set with n elements. How many ordered pairs (A,
B) are there such that A and B are subsets of S with A ⊆ B? top gateoverflow.in/4580
Selected Answer
A set with n elements has 2 n subsets. Now, from the given set we can have
n subsets and a subset of subset will be a subset of a set)
nCn subsets of size n (which will have 2
....
So, total number of ordered pairs satisfying the subset order will be
= (x + 1) n where x = 2,
= 3n
5 member commities are to be formed out of 10 people. The names are written in chits of paper and put into 6 boxes.
Atleast _______ chits go into the same box.
5 member commities are to be formed out of 10 people. The names are written in chits of paper and put into 6 boxes.
Atleast _______ chits go into the same box.
Selected Answer
Find the sum of all four digit numbers that can be formed by the digits {0,1,2,3,4}?
a)183450
b)259980
c)266640
d)6600
combinatory
Selected Answer
Now expected value of first digit in any given no. = (1 +2 +3 +4)/4 = 5/2
= sum of all five expected digits = E[1st digit] + 4* E[other digit except 1st] = 5/2 + 4*E[other digit except 1st]
Hence ,4*E[other digit except 1st] = 10 - 5/2 = 15/2 => E[other digit except 1st] = 15/8
Now since there are 96 numbers, Hence total sum = 96*[5/2 *10 3 + 15/8 * 10 2 + 15/8 * 10 1 + 15/8 * 10 0] = 259980
Method 2:
First let us assume number can start with '0' also. Total no of such no : 5*4*3*2 =120.
Frequency of each digit at unit or tens or hundred or thousand place = 120/5 = 24.
In this sum ,we have included those no's also which starts with '0'.so we have to deduct those sum.
Hence frequency of each digit {1,2,3,4} at unit ,tens ,hundred place = 24/4 =6
Selected Answer
X a X a X a X a X b X b X b X d X d X e X
Required no.of ways = no.of arranging 4 a's , 3b's ,2 d's and 1 e's and then selecting 3 places out of 11 places and
putting 3 c's there.
2) Here required no of ways = Total no of ways of arranging 13 letters - No of ways in which all 3 c's are together(i.e
consider all 3 c's as one unit ,thus arrange 11 letters and finally arrange 3 c's among themselves
17.53 Suppose that when an enzyme that breaks RNA chains after each G
link is applied to a 12-link chain top gateoverflow.in/4582
Suppose that when an enzyme that breaks RNA chains after each G link is applied to a 12-link chain, the fragments obtained
are G, CCG, AAAG, and UCCG, and when an enzyme that breaks RNA chains after each C or U link is applied, the fragments
obtained are C, C, C, C, GGU, and GAAAG. Can you determine the entire 12-link RNA chain from these two sets of
fragments? If so, what is this RNA chain?
combinatory
Couldn't understand the method they have used to find the answer. Please explain
combinatory
Selected Answer
find number of 7 digit number with sum of digits equal to 11 and formed using digits 1 ,2 ,3
Selected Answer
We have to arrange 8 a's, 3 b's, 4 c's and 5 d's.. i.e Permutation to find possible number of answer keys that are
possible= 20! but the all a's are identical, b's are identical , c's are identical and d's are identical, therefore Answer is =
20!/(8! . 3! . 4! . 5!)= 3491888400
17.56 total possible 4 digit numbers from given 6 digits top gateoverflow.in/34777
total possible 4 digit numbers from 2,3,5,6,7,9 without repetition? total numbers possible less than 500?
combinatory
=2* 20 * 6
= 120
17.56 In how many ways 5 blue pens and 6 black pens can be distributed to
6 children? top gateoverflow.in/36291
http://gateoverflow.in/3286/gate2008-it_25
Similar question
17.57 How many cards must be chosen from a standard deck of 52 cards to
guarantee that there are at least two cards of the same kind? top gateoverflow.in/4577
Selected Answer
yes. 5 should be the answer. 14 would be the answer for "at least 2 cards of different kind".
how many ways are there to arrange 6 girls and 15 boys in a circle such that there are atleast two boys between two
adjacent girls?
combinatory
For every girl there are 2 boys one at left and other at right. so for 6 girls, 12 boys can be chosen in 15P12 ways.Now
every girl and 2 boys are considered as group remaining 3 boys(15-12 boys) are also consider as groups.so we have total
9 group in total and this can be arrange in circular in (9-1)!=8!ways. Number of permutation satisfy the conditions equals
15P12*8!
17.59 There are six runners in the 100-yard dash. How many ways are there
for three medals to be awarded if ties are possible? top gateoverflow.in/4508
There are six runners in the 100-yard dash. How many ways are there for three medals to be awarded if ties are possible?
(The runner or runners who finish with the fastest time receive gold medals, the runner or runners who finish with exactly
one runner ahead receive silver medals, and the runner or runners who finish with exactly two runners ahead receive bronze
medals.)
combinatory
Selected Answer
How many ways are there for 3 TYPES of medals? (no ties)
Any of the 6 runners can finish 1st
Any of the remaining 5 runners can finish 2nd
Any of the remaining 4 runners can finish 3rd
6 * 5 * 4 = = 120
How many ways are there for 3 TYPES of medals? (ties possible)
top
what is Hockey Stick Identity means and Where it is used in Practical Application?
Also Prove Suitable Explanation of the combinatorial argument.
Consider a sequence of 10 A's and 8 B's placed in a Row. By a run we mean one or more letters of the same type placed side
by side. Here is a arrangement of 10 A's and 8 B's which contains 4 runs of A and 4 runs of B:
AAA BB A BBB AA B AAAA BB
In how many ways can 10 A's and 8 B's be arranged in a row so that there are 4 runs of A and 4 runs of B.
a) 2*(9c3)(7c3)
b) (9c3)(7c3)
c) (10c4)(8c4)
d) (10c5)(8c5)
C) (10c4)(8c4)
17.61 What are the number of ways to colour a rainbow with 7 colours
provided no two adjacent stripes has the same colour? top gateoverflow.in/43790
so you can have RGB or RGR --Look no 2 adj layers have same colours .
17.62 The English alphabet contains 21 consonants and five vowels. How
many strings of six lowercase letters of the English alphabet contain a)
exactly one vowel? b) exactly two vowels? c) at least one vowel? d) at least
two vowels? top gateoverflow.in/4503
a) 122,523,030
b) 72,930,375
c) 223,149,655
d) 100,626,625
And I used the following approach to each option but answers don't match.
a) C(5,1)*C(21,5)*6!
b) C(5,2)*C(21,4)*6!
c) P(26,6)-P(21,6)
d) [C(5,2)*C(21,4)+C(5,3)*C(21,3)+C(5,4)*C(21,2)+C(5,5)*C(21,1)]*6!
Please check.
Selected Answer
(a) Six letters with one vowel. We can place the vowel in any of the 6 positions in 5 * 6 ways and the remaining 5
positions can be filled in in 215 ways by the consonants as they can be repeated also. So, total number of words possible
= 215 * 5 * 6 = 122,523,030
@Sahil-gupta All your answers are correct if letters were not allowed to be repeated.
17.62 How many ways are there for a horse race with four horses to finish if
ties are possible? [Note: Any number of the four horses may tie.) top gateoverflow.in/4505
Selected Answer
Result can be like this: A, B, C, D are horses and 1-4 are the final positions.
1 2 3 4 - 4! = 24 ways
1 2 3 3 - 4!/2! = 12 ways
1 2 2 3 - 4!/2! = 12 ways
1 2 2 2 - 4!/3! = 4 ways
1 1 2 3 - 12 ways
1 1 2 2 - 4!/2!2! = 6 ways
1 1 1 2 - 4 ways
1 1 1 1 - 1 way
17.64 How many bit strings with length not exceeding n, where n is a
positive integer, consist entirely of 1's ? top gateoverflow.in/41036
why do we count here empty string also , it has no 1's , so what's the reason for counting this ?
Selected Answer
Empty string does not violate the given condition. But usually we don't count that when we count the no. of strings. To
avoid confusion they usually say non-empty string.
How many 4 digit even number are possible with each digit distinct ?
engineering-mathematics
Selected Answer
17.65 How many strings of length 10 over the alphabet {a, b, c} have either
exactly three a's or exactly four b's? top gateoverflow.in/4576
Selected Answer
Case 1: Exactly 3 a's: We fill 3 places with 3 a's in 3C3 * 10C3 ways. Now, remaining 7 places can be filled using b or c in
27 ways.
Case 2: Exactly 4 b's: We fill 4 places with 4 b's in 4C4 * 10C4 ways. Remaining 6 places can be filled using a or c in
26 ways.
So, number of strings possible = Case 1 + Case 2 - Case 3 = 10C3 * 128 + 10C4 * 64 - 4200 = 24,600
Selected Answer
Answer is 26 4
A, B are two 8-bit numbers such that A+B < 2^8. The number of possible combinations of A and B are
Selected Answer
2,0 2,1
3,0
A class is composed of 2 brothers and 6 other boys. In how many ways can all the boys be
seated at a round table so that the two brothers are not seated together?
a. 3000
b.3600
c. 2050
d. 2600
4320
17.69 33. How many different strings can be made from the letters in
ORONO, using some or all of the letters? top gateoverflow.in/4575
Selected Answer
1 letters: = O,R,N(=3)
2 letters: = OO,OR,ON,NR(1+2+2+2=7)
3 Letters: = OOO,OOR,OON,ORN(1+3+3+6 = 13)
4 Letters : OOOR,OOON,OORN (4+4+4!/2! = 8 + 12 = 20)
5 Letters: = OOORN(5!/3! = 120/6 = 20)
So Total words = 3 + 7 + 13 + 20 + 20 = 63
The number of ways in which 6 rings can be worn on the four fingers of one hand is:
a. 360
b. 4^6
c. 6C4
d. 6^4
Selected Answer
Ans B) option, you can put one ring in any of 4 fingers so it becomes 4*4*4*4*4*4.
17.71 How many cards must be chosen from a standard deck of 52 cards to
guarantee that there are at least two cards of each of two different kinds? top
gateoverflow.in/4578
The answer given is 17.
Selected Answer
I guess question is "at least two cards each of two different kinds".
We can only have 13 cards of one kind. So, in the worst case we pick these 13 cards all of same kind. Now, if we pick the
next card of a different kind, we can do like this only 3 more times- as there are only 4 different kinds. The fourth time we
do, we must repeat a kind. So, 13+4 = 17 is the answer.
Selected Answer
You can see the below problems. Also see this link:
http://www.cse.iitm.ac.in/~theory/tcslab/mfcs98page/mfcshtml/notes1/thperset.html
http://gateoverflow.in/tag/combinatory
17.72 From 2,3,4,4,5,how many numbers can be formed such that even digits
are at odd places ? top gateoverflow.in/26144
Now I have 2 even positions and 2 odd positions and I have 3 even numbers 2 ,4 ,4 and 2 odd numbers so one odd position will be occupied by an even number but
then even no can't be at odd position so then how to approach this question ?
Selected Answer
17.73 Find out the recurrence relation for the given problem top gateoverflow.in/20381
If an is number of ternary sequences of length n with even number of 0's, then the recurrence relation for an is?
engineering-mathematics combinatory
= 2 × an −1 + (3n −1 − an −1 )
= an −1 + 3n −1
The last symbol that is nth symbol may be 1 or 2 and this wont effect the even no of zeros which will also be present in the
string of size an −1 . Therefore twice of an −1 is used.
Now, if the nth symbol is 0 we can count all strings with "odd" number of 0's of length n − 1 which is given by
an′ −1 = 3n −1 − an −1 .
Let a0 = 1
a1 = 2 because {1, 2} have 0 no of zeros which are valid.
a2 = a1 + 31 = 5 the possible 2 length string with even no of zeros {00,11,12,21,22}
a3 = a2 + 32 = 14
a4 = a3 + 33 = 41
a5 = a4 + 34 = 122
a6 = a5 + 35 = 365
a7 = a6 + 36 = 1094
a8 = a7 + 36 = 3281.
All balloons are identical, and we're distributing it among 4 children, it is clearly a case of combination with repetition.
The given constraint is that each of the child receives at least 2 balloons. Mathematically we can write:
c1 + c2 + c3 + c4 = 10, where ci ≥ 2
From, ci ≥ 2 ci − 2 ≥ 0
Let, ci − 2 = bi ≥ 0
b1 + b2 + b3 + b4 = 2, where bi ≥ 0
So, the answer to the question is the number of solutions possible for the above equation, which is
4+2−1 5
( 2
) = ( 2 ) = 10
1 votes -- Sujit Kumar Muduli ( 169 points)
17.74 how many ways 10 persons can be divided into 5 teams of 2 each ? top
gateoverflow.in/26165
10!
5
We can also do as 2 = 113400
Now, if the teams are unlabeled, we have to divide the answer by 5! = 120 as each of the permutation is the same.
113400
120
So, required answer = = 945.
Notice that teams here do not have separate identities. They are just teams (so obviously you cannot distinguish among
two teams). So, if you include Boy1, Boy2 in one team then do not include them in any other team because they both are
already counted as a team (doesn't matter which team). So whatever permuatations you make, if the sequence aleady
has X,X,boy1,boy2,X,X,X,X,X,X then no need to include boy1,boy2,X,X,X,X,X,X,X,X again. 10!/(2! 2! 2! 2! 2! * 5!) = 945
ways
17.75 From the word ASSASSINATION ,now in how many ways can we form
4 letter word from it ? top gateoverflow.in/26200
My confusion is how to deal with the case when I have 2 same and 2 different ,now since I have 3A's ,4 S so why can't I chose 2A's like 3C2 , what 's the problem
in this ?
Selected Answer
A S S A S S I N A T I O N
AAAS
AAAS
AAAS
as we have given importance to the position of each 'A' but in a word when they come together, the words are the same.
3 A's
4 S's
2 I
2 N
4!
4C 2 !.2 !
2. = 36
1 (only SSSS)
Every Sunday, Bill makes lunches for Carolyn. Lunch consists of a sandwich, a fruit, and a desert. Sandwich is either ham
and cheese, peanut butter and jelly, egg salad, or tuna fish. Fruit is either an apple, an orange, or a coconut. Desert is either
pretzels, a brownie, or an apple pie.
(a) How many different lunches can Bill make for Carolyn?
(b) If Carolyn does not like to have egg salad with apple pie, or tuna fish with an apple, then how many lunches can Bill
make for Carolyn.
combinatory
Selected Answer
basically this is a simple one. there are four choices for sandwich , 3 for fruit and 3 for desert, so he can choose anything
for the lunch.
part one
4c1*3c1*3c1=4*3*3=36
second part.
now this all combination contains all the combinations like . sandwich - egg salad , desert -apple pie. Now she does not
like this combination . so all such combinations will be 3, because i can arrange this pair with every fruit one by one. as
there are 3 fruits . 3 pairs will be there. similarly for second case i can choose the fruit in 3 ways . so total combination we
don't have to include is 3+3=6
17.77 how many ways can we form a team of 2 men and 2 women such that
no couple is a part of team ? top gateoverflow.in/26213
There are 10 couples at party .In this question I have only doubt that if I chose 2 husbands first ,now for wives remaining
choice will be 8 so it will be 10C2 *8C2 ,Now I could have done it other way around like first chosing 2 wives and then
removing their corresponding husbands so again no of ways in which team can be formed is 10C2*8C2 ,now why can't we
add these two cases ?
Find the number of ways of forming a committee of 9 people drawn from 3 different parties so that no party has absolute
majority in committee?
Selected Answer
In an experiment 4 different colored dice are thrown simultaneously and numbers are added find number of distinct
experiments such that total is 18?
6 5 2 5 12
6 4 4 4 4
5 5 4 4 6
5 5 5 3 4
Total 80
This method is brute force method and its highly prone to careless mistake.
For ans verification you can write a simple programe(https://ideone.com/E9Vym3)
2)How many integers in set{,2,3,---1,00,000} contains exactlu one 3 one 4 one 5 in their decimal representation?
9 9 9 combination = 9*9*9
8 9 9 9 combination = 8*9*9
therefore total combination with exactly one 6= 3*8*9*9 + 9*9*9 = 2673 i guess its the answer
The given word is MATHEMATICS which can be arranged in different ways by taking some or all the letters used in the word.
the number of words that can be formed by taking 4 letters at a time out of the letters of the given word.
combinatory
Selected Answer
There are 8 distinct letters: M-A-T-H-E-I-C-S. 3 letters M, A, and T are represented twice (double letter). Selected 4
letters can have following 3 patterns:
1. abcd - all 4 letters are different: 8P4=1680 (choosing 4 distinct letters out of 8, when order matters) or 8C4∗4!=1680
(choosing 4 distinct letters out of 8 when order does not matter and multiplying by 4! to get different arrangement of
these 4 distinct letters);
2. aabb - from 4 letters 2 are the same and other 2 are also the same: 3C2∗4!2!2!=18 - 3C2 choosing which two double
letter will provide two letters (out of 3 double letter - MAT), multiplying by 4!2!2! to get different arrangements (for
example MMAA can be arranged in 4!2!2! # of ways);
3. aabc - from 4 letters 2 are the same and other 2 are different: 3C1∗7C2∗4!2!=756 - 3C1 choosing which letter will
proved with 2 letters (out of 3 double letter - MAT), 7C2 choosing third and fourth letters out of 7 distinct letters left and
multiplying by 4!2! to get different arrangements (for example MMIC can be arranged in 4!2! # of ways).
1680+18+756=2454
A computer net network consists of 6 computers.Each computer is directly connected to 0 or more computers.Based on
pegion hole principle which one of the following is true?
1) There is atleast 5 computer in the network that is directly connected to same no of other computers
2) There is atleast 4 computer in the network that is directly connected to same no of other computers
3) There is atleast 3 computer in the network that is directly connected to same no of other computers
4) There is atleast 2 computer in the network that is directly connected to same no of other computers
Selected Answer
It would be better to view this computer network as a simple undirected graph of 6 vertices, where degree of each vertex
is greater than or equal to zero.
In this graph we have to find out at least how many vertices must have same degree.
Degree of a vertex can be any one element from the set D = {0, 1, 2, 3, 4, 5} (since number of vertices are 6 in the
graph & the graph is simple so multiple edges & self loops are not allowed & thus each vertex can have a maximum of 5
degree).
Now if we are assigning a DISTINCT DEGREE to each of the 6 vertices then, we have to assign a distict element of D to
each of the nodes & 0, 1, 2, 3, 4, 5 will be assigned to six nodes.
But we know that sum of degree of all the vertices of a graph must be an even number.
Also it can be observed that this ODD DEGREE PROBLEM can be solved by replacing any of assigned odd degree {1, 3, 5}
with any of the even degrees {0, 2, 4} then this problem can be solved, & such a graph will be a valid graph.
For example choose degrees (0, 1, 2, 3, 4, 4) or (0, 1, 2, 2, 4, 5) or (0, 0, 2, 3, 4, 5) and so on, sum of degrees in all this
case will be even.
Thus we have tried our best to assign as much distinct degree as possible to the six vertices along with keeping the
graph valid, & found that at least 2 of the vertices MUST have a common degree.
Moreover we can also guarantee that the repeating degree must even, it can’t be odd.
How many binary sequences of length 10 are possible with exactly 4 zeros and no two zeros are consecutive?
Its given exactly 4 zero it means we have 6 1's which can be arranged in any order therefore 1! (since all 1 are identical)
1 1 1 1 1 1 since no two 0 should be consecutive we have total 7 space between each 1 we can place one 0
so select 7 places for 4 0's(all 0 are identical so we use the combination rather than permutation for arrangement) = 7C4
How many 5 digit number are possible so that in each of these number every digit is greater than digit on its right?
first lets take number from 1 to 9 then we can select any 5 numbers in 9C5 ways but we can arrange them only in one
way.
now including 0 we can place it at only last position since at any other position it would not satisfy the condition.
Suppose 10 persons are in canteen whoch offers coffee,tea,pepsi How many ways they can order their drinks as a group if
each persin wants one of the 3 drinks ?
Selected Answer
We have to divide 10 persons into 3 groups (corresponding to three drinks) such that a group may be empty. This is stars
and bars problem Theorem 2(https://en.wikipedia.org/wiki/Stars_and_bars_%28combinatorics%29), and solution is given
10+3 −1 12
by ( 3 −1 ) ( 2 ) = 66 ways.
=
1)x1+x2+x3+x4+x5<=10<br />
2)x1+x2+x3+x4+x5<10
Selected Answer
1. Any solution of the equation can be seen as partitioning 10 (or less) indistinguishible objects into 5 groups
(corresponding to x1,x2,x3,x4,x5), where each group may be empty (because solution is non-negative integer).
n +k−1
17.87 How many possible outcomes are there when 5 similar dices are rolled
? top gateoverflow.in/28201
In this question If I consider first total no of outcomes as 6^5 , then I divided it be 6C5 *5! since there are 5 similar dices so
the outcome (1 2 3 4 5 ) will be similar to (5 4 3 2 1) .
Selected Answer
6C 6C 5C 6C 4C 6C 5C 6C 5C 6C 5C
5 1. 3 2. 1 1. 2 1. 1 1. 1
5 different outcomes + only 1 outcome appearing twice + 2 outcomes appearing twice + one outcome appearing thrice + one outcome appearing thrice and 1 outcome appearing twice + one item appearing 4 tim
for every dice we have 6 possibility which are independent of any other dice, Hence total possible outcomes if 5 similar dices are rolled, given
that each outcome for a dice is equally likely is given by : 65
Suppose that a computer science laboratory has 15 workstations and 10 servers. A cable can be used to directly connect a
workstation to a server. For each server, only one direct connection to that server can be active at any time. We want to
guarantee that at any time any set of 10 or fewer workstations can simultaneously access different servers via direct
connections. Although we could do this by connecting every workstation directly to every server (using 150 connections),
what is the minimum number of direct connections needed to achieve this goal? Please explain the answer with explanation.
combinatory
Selected Answer
What we have to guarantee is at any point up to 10 workstations must be directly connected to servers. And we have 15
workstations in total.
free we must guarantee a connection to each of them. So, this means for the remaining 5 workstations we need 5 ⨯ 10 =
50 direct connections. So, minimum, 10 + 50 = 60 direct connections are required.
combinatory
Selected Answer
Solution: B
This problem is a special case of permutiation called Dearrangement. where the permutation dose have any element occur
in their original place.
so D(n)=265 ,
dearrangement(n) =
therefore , D(6) =
ref@ http://math.stackexchange.com/questions/83380/i-have-a-problem-understanding-the-proof-of-rencontres-
numbers-derangements/83472#83472
How many function are there from the set{1,2,3,........n} where n is positive integer ,to the set {0,1}.
a) 0 is mapped to both 1 & n. Hence for remaining (n-2) elements, we have two choices {0,1} for mapping of each
element.
b) Here in this case, '1' is assigned to exactly one integer less than 'n' i.e any one of '1' to 'n-1'. So for remaining (n-1)
element ,we have only one choice of mapping all of them to '0'
17.91 How many seven digits number are there such that Digits are distinct
integers taken from {1, 2, ..., 9} and Digits 5 and 6 do not appear together
(consecutively) top gateoverflow.in/10011
Selected Answer
Case 1: 5 and 6 appear together. Here, it can be 56 or 65. So, 2 ways and remaining we have 5 digits to chose from 7 and
6! ways (5 digits plus 56 or 65) to arrange them. This gives 2! * 7C5 * 6! = 42 * 720
17.91 How many ternary strings of length 4 have exactly one 1? top gateoverflow.in/7500
Selected Answer
4 * 23 = 32
Of length 4, one we take for 1. Remaining 3 characters can be filled with 2 symbols in 2 3 = 8 ways. Now, the one can be
placed in 4 ways between the 3 characters giving 4 * 8 = 32 strings.
combinatory
Selected Answer
Subwords means letters must be consecutive as in the word. Since, the given word has 13 letters we can have
13 subwords of 1 letter
12 subwords of 2 letters
11 subwords of 3 letters
....
1 subword of 13 letters
No two consecutive letters are repeating in the given word. But there are 3 A's, and 2 I's. So, 3 subwords of length 1 are
counted extra. So, total number of distinct subwords = 91 - 3 = 88.
17.92 Suppose that when an enzyme that breaks RNA chains after each G
link is applied to a 12-link chain top gateoverflow.in/4583
Suppose that when an enzyme that breaks RNA chains after each G link is applied to a 12-link chain, the fragments obtained
are AC, UG, and ACG and when an enzyme that breaks RNA chains after each C or U link is applied, the fragments obtained
are U, GAC, and GAC. Can you determine the entire RNA chain from these two sets of fragments? If so, what is this RNA
chain?
combinatory
Find number of ways of selecting a commitee of 10 members out of 6 men and 7 women of which atleast 4 women are
included.
combinatory
Selected Answer
=35+126+105+20 =286
17.94 how many distinct question paper can be set with 10 questions which
have four choices and there is only one correct answer per questions. gateoverflow.in/11014
top
how many distinct question paper can be set with 10 questions which have four choices and there is only one correct answer
per questions.
10!*4^10
. A, B are two 8-bit numbers such that A+B < 28 . The number of possible combinations of A and B
Base is 2
Selected Answer
How many ways are there to seat six people around circular table where two seatings are considered same when everyone
has same two neighbors without regard to whether they are left or right neighbors?
An entrepreneur needs to assign 5 different tasks to three of his employees. If every employee is assigned atleast one task,
how many ways can the entrepreneur assign those tasks to his employees?
jobs are 5 and persons are 3. so first i can choose 3 jobs out of 5 in 5c3 ways because it is given that atleast one should
be assigned . and now these jobs can also be arranged in 3! ways . and after that 2 jobs are remaining and 1 can be
choose in 2c1 ways and can be assigned in 3 ways . and similarly last job can be assigned in 3 ways . so i think answer
should be
A mint prepares metallic calendars specifying months , dates and days in the form of monthly sheets (one plate for each
month ) . how many type of feburary calendars should be prepare to serve all the possibilities in the future year ?
combinatory
Selected Answer
1) First day of the Feb will have 7 choices from the set {Mon, Tue, Wed, Thu, Fri, Sat, Sun}.
2) Total number of days in the month will have 2 choices from the set {28, 29}.
We can enumerate all the 14 possibilities using an ordered pair (x, y) where x represents the first day of that particular
February month and y represents total number days in that particular February month.
For Example:
(Mon, 28) represents a Feb month whose first day (i.e. 1 Feb) is Monday, & the month has total 28 days.
The month of February has either 28 days (non-Leap Year) or 29 days(Leap Year).Thus there are 2 possibility for the
number of days in February. Also the first day of the month can be any of the 7 days In a week.
For a game in which 2 partners oppose 2 other partners, six men are available. If every possible pair must play against every
other pair, the number of games to be played is
45 is correct.
Steps :
2) Now, suppose we have 4 players {A,B,C,D} & we have to form two teams of 2.
17.100 How many integers are there between 1 and 10^6 such that sum of
digits is 12 ? top gateoverflow.in/29381
Selected Answer
Finding 12 as sum of digits between the numbers 1 and 1,000,000 is like finding coefficient of x^12 between 1 and 999,999 (as the digits of course of
1,000,000 don't sum up to 12).
Now all the numbers a1+a2+a3+a4+a5+a6 (number of digits in 999,999) should be between 0 and 9.
=17C5 - 6. 7C5
=6188 - 126
=6062
17.100 How many ways 10 persons can be divided into 5 teams of 2 each top
gateoverflow.in/33438
Selected Answer
Notice that teams here do not have separate identities. They are just teams (so obviously you cannot distinguish among
two teams). So, if you include Boy1, Boy2 in one team then do not include them in any other team because they both are
already counted as a team (doesn't matter which team).
So whatever permuatations you make, if the sequence aleady has X,X,boy1,boy2,X,X,X,X,X,X then no need to include
boy1,boy2,X,X,X,X,X,X,X,X again.
S1 ) In any simple graph with more than one vertex, there must exist at-least 2 vetices of the same degree
S2 ) A graph with 13 vertices, 31 edges, 3 vertices of degree 5 and 7 vertices of degree 4 does not exist.
s1 is true
15+28+3x=62
x=19/3
so d is ans
x=
18.2 Ace Test Series: Minimum edges in graph so that it is not connected top
gateoverflow.in/37527
I think the explanation is for edges for which graph is always connected.
graph-theory ace-test-series
Selected Answer
if we want to disconnect graph then do one thing just partition original graph in two portion with 1 and n-1 nodes
respectively.
now find number of edges in each component.
(A). When a recurrence relation has a cyclic dependency, it is impossible to use that recurrence relation (unmodified) in a
correct dynamic program.
(B). Given a connected graph G(V, E) if a vertex v ϵ V is visited during level K of a breadth first search from source vertex s
\epsilon V, then every path from s to v has length at most k
Argument: I dont have much idea about A, but it seems to be true. For B, with BFS tree we get the shortest path possible
from source vertex. So, every other possible path should have the length of atleast 'k'. Given wording is 'atmost'. So, B
should be wrong.
Given answer is D.
What is the minimum number of colors needed to color a graph with five vertices. The graph contain a cycle also
graph-theory graph-coloring
Selected Answer
If you say minimum then it should be 2 ( a cyclic graph with even vertices required 2 colours and for odd 3 ) and we can
form a cyclic graph with 4 vertices and 5th vertex will connect any one of that cyclic vertices with one edge (of course :D )
. peace
if there is cycle of 4 verticces then 2 colour required if there is cycle of 5 vertices then 3 colors are required
18.5 Graph Isomorphism: Given no of vertex & edges how to find no of Non
Assume that ‘e’ is the number of edges and n is the number of vertices. The number of non-isomorphic graphs possible with
n-vertices such that graph is 3-regular graph and e = 2n – 3 are ______.
------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------
No of Edges = 9
From here on, Given no of vertex & edges how to find no of Non Isomorphic graphs possible ? , this is real question ! Is there
any algorithm for this ?
graph-theory graph-isomorphism
3n= 2e
as we know e = 2n – 3
equat both
3n/2 = 2n -4
n= 6 // no. of vertex
so using 6 vertex and 9 edges with every vertex has tree degree only two graph possible. one is k3,3
graph-isomorphism
1. Same no of edges
2. Same no of vertices
Matching it means that no 2 edges are adjacent simply a vertex with degree 1
In the above graph if we start with G we have 2 edges for G In matching we consider 1 edge since if both are considered
we get degree of G as 2 so if we consider G-A edge then node 2 is alone and has degree 0 it makes graph to be not
matched so we consider G-2 edge , A-0 edge T has edges with 0 and 1 since A-0 edge is present if we consider 0 then
degree of 0 is 2 so we don't consider
Given explanation:
In the above explanation, it is written that matching number is 4 but I am getting matching number as 3 for this
graph(choosing edges 1-2, 3-4 and 6-7). Please check where I am going wrong
graph-theory graph-matching
Let us start with 2 then we get (2-1),(3-8),(4-7),(5-6) these edges are matching so the matched number is 4
Is there a way to find no of perfect matchings in a complete graph K n where n could be either even or odd..?
graph-matching
Selected Answer
if n is odd then perfect matching 0. because in perfect matching degree of each vertex must be 1, which is not possible if
n is odd.
For Kn
what is the sufficient condition so that we say given graph is planar or not???
graph-planarity
(A) G1 (B) G2 (C) G3 (D) G4
In this question planar drawings( no 2 edges intersect) for G2, G3 and G4 exists, thats why answer should be G1
But I couldn't find any subgraph homoemorphic to K5 in G1 as a graph is non planar iff it contains a subgraph homoemorphic
to K5 or K 3,3...
graph-theory graph-planarity
18.12 Haming Distance: Haming Distance and Chromatic Number top gateoverflow.in/38185
Consider the undirected graph G defined as follows. The vertices are bit string of length 5. We have an edge between vertex
“a” and vertex “b” iff “a” and “b” differ only in one bit possible (i.e., hamming distance1). What is the ratio of chromatic
number of G to the diameter of G?
Selected Answer
ACTUALLY IT IS A N CUBE...
vertex of n cube=n;
degree of n cube=n;
edges of n cube=n*2^(n-1)
chromatic number=2(ALWAYS)
hence chromatic number of the graph=2
the solution to the recurrence relation T(n)= T(n-1) +n, T(0)=2 is..
recurrence
Selected Answer
T(n)=T(n-1)+n
T(n-1)=T(n-2)+n-1
T(n)=T(n-2)+n-1+n
T(n)=T(n-k)+(n-k+1)+.........n-k+n
Put n=k
T(n)=T(0)+1+2..........+n
T(n)=2+n(n+1)/2
So T(n)=O(n^2)
for the recurrence relation a n=6an-1-9an-2 + F n , what will be the particular solution
if case 1; F n = 3 n 5n+1
case 2; F n = 2 n 5n+1
recurrence
18.15 Which of the following is true regarding minimum cut edges for a pair
of vertices in a graph? top gateoverflow.in/30713
Let G be an undirected graph. For a pair (x,y) of distinct vertices of G, let mincut(x,y) be the least number of edges that
should be deleted from G so that the resulting graph has no x-y path. Let a,b,c be three vertices in G such that mincut(a,b)
<= mincut(b,c) <= mincut(c,a). Consider the following possibilities.
tifr2016
The answer is d. Consider a path a->c->b , then mincut(a,b) >= min(mincut(b,c),mincut(a,c)) . So if considering this
condition to be always true , option i and iii violate the conditions.
graph-theory
Selected Answer
this is just an example of bipirated graph. . one set contains printer and one contain 8 computers. no edge can be
between the same set. as it is said to guarentee atleast 4 access different printers. so take one computer connect with all
printer . 4 cables. now take one more , and connect with 4 . similarly connect 4 computer with all the 4 printers. 4*4 = 16
cables are consumed and we have satisfied the condition. now just connect remaining 4 computer with the minimum no of
connection i.e 1 .which will lead to 4 . so 16+4 =20 .
c: V → { 1, 2, ...,k) such that for every edge {u,v) ∈ E we have c(u) ≠ c(v).
1. G is |V| colorable.
graph-theory
2- If graph is 2 colourable then it is bipirated graph . and a graph is bipirated if and only if every cycle is of even length in
it.
3- the condition is not give same colour to adjacent vertexes. so if it has a degree k then u need k+1 colour. one for itself
and other need k. so try this u can easily say that this is the upper limit.
4- yes. check for bipirated graph. or every cycle is of even lenght or not. from point 2
5-if a graph has a cycle graph in itself . suppose it has cn ( cycle graph with 3 vertices. i.e a triangle ) then it requires
18.18 How to find no of paths of length 2 in the below graph ? top gateoverflow.in/28489
graph-theory
There are only 3 possible paths of length 2, which passes through vertex v1. they are
v4 v1 v2
v3 v1 v2
v4 v1 v3
This can be done by selecting two of the adjacent vertices of v1 , hence C(3,2)
this can be solved using adjacency matrix . and i also can't get the logic. still i have an hard way.
make the adjacency lets call it a . now . A2 means it is stating all paths of from length 2 from any vertex i to vertex j .
where i is the any row and j is any column No need to solve full just solve half. as the other half will be stating the same
thing. and don't consider the diagonal. now count . it will give 19..
18.19 how to draw the graph for this problem?? top gateoverflow.in/27507
how many numbers of edges if the degree of sequence is 5,2,2,2,2,1.... how can we draw the graph for this problem???
no of edge = 7
18.19 how to cheak given grpah is complet bipertee graph top gateoverflow.in/27505
18.21 how to find path of length 3 in below graph including V5 ? top gateoverflow.in/31790
Since the path should pass through v5 I am assuming we only include the path in which v5 can be intermediate vertex.
And path visited in reverse order is not counted as distinct.
Let us consider that vertex v5 is in position 2. Actually it doesn't matter whether vertex v2 is in position 2 or 3 because v2 comes at position 3 in reverse order.
_ v5 _ _
We have v1 v5 _ _
For third vertex we can have 3 choices. In this case we can have v2, v3 or v4 as third vertex
When we have v2 as third vertex we have only one choice that is v3.
When we have v3 as third vertex we have 2 choices that is v2 or v4.
When we have v4 as third vertex we have only one choice that is v3
For all the four choices for the first vertex we can have total of 16 choices.
graph-theory
This is a combinatory qs basically. There are 5 vertices ,in which V5 is fixed,cause it must remain in the path. Now for
path of length 3,we need 4 vertices. V5 is already fixed,so we are left with 3 more vertices,which can be chosen from out
of 4 vertices.so the no of paths are 4C3 = 4.
Kuratowski's second graph is not planar then why it dont contradict for following inequality for checking planarity :
e<=3n-6
=>(e=9)<=3*(n=6)-6
K3,3 has 6 vertices and 9 edges, and it is true that 9 ≤ (3 × 6) - 6 = 12. So we cannot use this Corollary to prove that
K3,3 is non-planar. We have another Corollary
Let G be a connected planar simple graph with n vertices and e edges, and no triangles. Then e ≤ 2n - 4.
For graph G with f faces, it follows from the handshaking lemma for planar graph that 2e ≥ 3r because the degree of each
2
For graph G with f faces, it follows from the handshaking lemma for planar graphs that 2e ≥ 4r (because the degree of
1
Q1. Assume that G is a simple graph of 20 edges, 6 vertices of degree 4 and other nodes have degrees more than 5, then
the maximum no of vertices of G is______
Q2. all thread must wait whenever any critical section is occupied----how this is false?
Selected Answer
=>xy=40-24
=>x=2
Say, for Reader-Writer, More than one reader is allowed in critical section at the same time.
1. the line graph L(k5) is a regular graph of degree_______ and edges ________
graph-theory
You can have the adjacency matrix of the line graph of the K5 regular graph by considering the edges as the columns and
the rows. You will have to fill the matrix from the graph then, with an entry in a cell a ij if edge e i and e j are adjacent to
each other in the K5 graph. You will observe that every row (or column) will have exactly six entry, so we can say that the
degree of the graph is 6. Also, since this is an undirected graph, so every vertex ( or the edge pair ) will be counted twice,
one time for filling up the entry for edge ei and other time for filling up the entry for e j. Now, since every row (or column)
have six entry and there are ten rows (or columns) and every actual vertex (of the K5 regular graph) is counted twice, we
have : (6 * 10) / 2 = 30 edges.
How many different isomorphisms are there from one cycle on n-vertices to another cycle on n-vertices.
Selected Answer
Must be 2n.
We can map first vertex of first graph with any of the n vertices of the second graph, so there are n ways. But after
choosing that vertex, we may traverse either in clockwise or counter-clockwise direction. So, we have 2 ways to choose
the direction. After choosing the vertex and direction, the remaining vertices of the cycle will be mapped automatically.
=> n>=(e+6)/3
graph-theory
18
Subgraph of a graph is a graph whose vertex set is a subset of vertex set of the graph and edge set is a subset of the
edge set of the graph
Adding these up : 18
graph-theory
So now ,to make it disconnected you only need to remove only two more edges..
18.28 The number of colors needed to edge color a simple graph with
maximum degree Δ is? top gateoverflow.in/38675
The number of colors needed to edge color a simple graph with maximum degree Δ is?
Selected Answer
edge colouring can be anything between maximum degree or maximum degree -1 depending on the instance of the
graph/.
This question is related to Graph Colouring . In Graph colouring , No adjacent nodes ( 2 nodes connected by a edges )
must not have some colour . So here if they say when a degree of a node ( say A ) is n , it mean A is attached to n nodes
by an edges .
Say if a degree of a node B is 3 then it is adjacent to node D E F ( D E f may or may not be adjacent . But that is not our
concern for now ) by an edge connecting them . So we know that no 2 adjacent nodes will have single colour .
so if i give node b =red colour Node D = blue colur node E = balck Node F = purple So if you see for since node b has
degree 3 . To do proper graph colouring technique , we need have 4 colours so that no adjacent nodes have same colour .
So by stating above example I can conclude that in general if a node has a degree n , then it adajcent to n nodes . And so
for a proper graph colouring you need to colour with n+1 colours .
https://en.wikipedia.org/wiki/Vizing%27s_theorem
Assume G is connected planar graph that has 14 vertices and 20 regions . All interior regions are bounded by a cycle of
length 3(i.e. 3 edges). The no of edges bounded the interior region is ?
R=E-V+2
Total no of edges:
E=20+14-2=32
Thus, 19*3+1*x=64,x=7
Given answer is 2, I think it should be 3: F,A, and G are articulation points. Please check
graph-theory engineering-mathematics
Selected Answer
Given explanation:
engineering-mathematics graph-theory
Selected Answer
1st one :for any graph with n vertices maxdegree of vertex is n-1
2nd one:
engineering-mathematics aptitude
18.33 How many strongly connected component are there in the above graph
top gateoverflow.in/32839
How many strongly connected components are there in the above graph?
graph-theory
Selected Answer
Answer is 5. A directed graph is strongly connected if there is a path between all pair of vertices.
A-B-F-C
H so totally 5
18.33 What is Maximal Independent Set (MIS) ? How to calulate size of it ? top
gateoverflow.in/33938
Selected Answer
https://www.youtube.com/watch?v=03PUwWef2Dg
graph-theory engineering-mathematics
Selected Answer
connected planar graph with no cycle of length less than 4 means that no circuit of length 3 .so we have theorem in this
case:e<=2n-4
where n=15 given put and get the answer.
e<=30-4
e<=26
so 26 edges needed in connected planar graph(CPG)
graph-theory
Selected Answer
In a connected planner graph with v vertices e edges r regions or faces and min. Degree of region =k (no c ycle of length
less than 4 means no region can have degree less than 4)
1 v-e+r=2
2 k.r≤2e
3 e ≤ k(v-2)/(k-2)
e ≤ 2v-4
e<=2v --4
so e<=2*15-4
e<=26
How many non isomorphic directed simple graph are there with n vertices?
graph-theory
Consider n vertices V1,V2......Vn.Assume edge between any two vertices is say edge slot.So for each edge slot between
two vertices say V1 and V2,we have following 3 choices of putting edge
1)V1->V2 or V2-> V1
2)V1->V2 & V2->V1 since graph is directed,we can put two edges between two vertices.
3)No edge.
So for each edge slot between two vertices say V1 and V2,we have following 4 choices of putting edge
1)V1->V2
2)V2-> V1 since vertices are labelled,V1->V2 & V2->V1would give different results.
3)V1->V2 & V2->V1 since graph is directed,we can put two edges between two vertices.
4)No edge.
Please verify it as i have considered only total graphs but i am not able to filter-out isomorphic graphs.
if G and G* are isomorphic graphs , then no of connected components of G* if G has connected components, are
For two graphs to be isomorphic (same) they must have the following properties:
Number of distinct graphs with p vertices and q edges ( p not equal to q) is always equal to
a) p
b) q
c)min(p,q)
d)max (p,q)
e) none of this
graph-theory
Selected Answer
I think, None of this should be answer for this question. total no of distinct graphs will be
p(p-1)/2 C q
a) 1/8
b) 1
c) 7
d) 8
approach?
if itsAnswer option C) 7
There will be c(8,3) = 56 cycles.Probability of existence of a particular cycle is 1/2*1/2*1/2 =1/8.So no of cycles =
1/8*56 = 7.
Ans c
Total ways=56*1=56
http://mathoverflow.net/questions/124116/maximum-number-of-edges-in-a-planar-graph
18.41 What is the no of ways to divide 'n' nodes into three graphs g1,g2 and
g3? top gateoverflow.in/7497
b)join
c)change
d)update
The three graph will be 3 connected components of some disconnected graph with n nodes.Now The no of possible way
will be no of possible solution of the equation g1+g2+g3=n.
Selected Answer
Does not fit in all cases -> Use https://en.wikipedia.org/wiki/Kirchhoff's_theorem this theorem
3 vertices = 3 (3-2) =3
If I have any complete graph given then what is the approach to be followed up for calculating the number of paths of length
n because for large value of n ,computation would be tricky ,so how to proceed with such questions.
M = Adjacency Matrix
MN = M x M x M ...n times.
I just wanted to confirm that if I have a disconnected graph ,then I can call it planar .so for a graph to be planar do I need to
check whether it is connected or disconnected.
planar graph need not to be connected .... this should follow only condition is no edge must cross each other
they will specify for connected planar graph in question.
graph-theory
Selected Answer
Every element in an equivalent partition is related to each other- so the subgraph of an equivalent partition must be
complete. So, for each partition we get a clique and all these cliques are mutually disconnected.
18.45 Consider the following set : {1,2,3,.....n}. Now consider all possible
subset. Two subset S1 and S2 are having edge between them only if their
intersection has two common elements. top gateoverflow.in/5286
Consider the following set : {1,2,3,.....n}. Now consider all possible subset. Two subset S1 and S2 are having edge between
them only if their intersection has two common elements.
Find:
a) Number of isolated vertices.
b) Number of components
c) Highest degree possible.
Answers:
a) n+1
b) n+2
c) 3*2n-3
graph-theory combinatory
Suppose there is a graph with self loop on vertices, has multiple edges and has loops. Then what would be eccentricity of a
vertex containing self loop? Also what would be the eccentricity of vertex in a cycle( i.e if a cycle contains that vertex)..and
eccentricity of a vertex in multiple edges(multiple edge start or end at that vertex)...?
So total 8 graphs
See , a perfect matching, every vertex of the graph is incident to exactly one edge of the matching. A perfect matching is therefore a matching of a graph containing edges, the largest
possible, meaning perfect matchings are only possible on graphs with an even number of vertices. A perfect matching is sometimes called a complete matching or 1-factor.
The nine perfect matchings of the cubical graph are illustrated above.
Note that rather confusingly, the class of graphs known as perfect graphs are distinct from the class of graphs with perfect
matchings.
a) m= 1
b) n=1
c) both a) and b)
d) none
Plz explain........................
It is used for this question only actually whenever m=n the complete bipartite graph is regular. here they want to just test
the concept whether we know this or not and how patiently we go through all options.
Ans is a)
I dont think that they are. here we have G2 we have 3 cycle of degree 2 and in G1 we have only two.
In a simple undirected graph with n vertices what is maximum no of edges that you can have keeping the graph
disconnected?
A) nC2 -1
B) nC2
C) n-1C2
D n-1C2 - 1
Selected Answer
Since we have to find a disconnected graph with maximum number of edges with n vertices. Therefore our disconnected
graph will have only two partions because as number of partition increases number of edges will decrease.
Now assume that First partition has x vertices and second partition has (n-x) vertices.
b) A circuit may have repeated vertices other than its end points
Ans is none....but as per me a) is F as closed path don't have distinct vertices (initial and final vertices are same).....
"has distinct vertices" I guess number of distinct vertices or "all distinct" should be mentioned here,
The no of vertices in a graph containing 21 edges, 3 vertices of degree 4 and other vertices of degree 3 are:
a) 10
b) 13
c) 11
d) None
Let no of vertices=n
4*3+(n-3)*3= 42
n=13
Selected Answer
13 is correct answer by the logic you have produced. Be confident, sometimes given answers are not correct!!
(2)For any two edges e and e' in G , L(G) has an edge between v(e) and v(e'), if and only if e and e' are incident with the
same vertex in G
(A) P only
(B) P and R
(C) R only
(D) P,Q,S
i think
(A) P only
because by taking a simple graph of 4 vertices(i.e planar graph)(take a 2 regular graph) and we can some to know it's
planar : option C eliminated ,
but tree for tree is not possible as it seems to be a cycle : option D eliminated.
a)2
b)3
c)4
d) 5
graph-theory
Selected Answer
obviously in complete graph der is an edge which connect every pair of vertices..
https://en.wikipedia.org/wiki/Cayley's_formula
Then set each of tree node to be root, in each tree there are n ways to choose the root
Selected Answer
http://www.personal.kent.edu/~rmuhamma/GraphTheory/MyGraphTheory/eulerGraph.htm
Find Maximum and Minimum no of edges in a graph G with n vertices if G has 3 component with 2 non acyclic and 1 acyclic
component?
18.58 The number of distinct simple graphs with up to three nodes are gateoverflow.in/285
top
A)15
B)10
C)7
D)9
graph-theory normal
Selected Answer
Now there can be 0 edges, 1 edge, 2 edges or 3 edges in a 3 node simple graph.
4+2+1=7
A graph is an ordered pair (V,E). So, given a set V, graph will be different if E is different. Lets see how many different E
we can get when |V| = 3.
Now, the question asks for |V| upto 3. So, we have to consider |V| = 2 and |V| = 1 also. When |V| = 2, we can have |E|
= 1 or 0, so 2 possibilities. For |V| = 1, |E| can be only 0 and hence only one possibility. So, total number of possibilities
is
4+2+1=7
here they said upto three three nodes means we have |V|=1, or |V|=2, or |V|=3
1. Exactly 4
2. At least 4
3. Atmost 4
4. None
if only degree 3 and 1 allowed then answer should be EXACTLY 4 otherwise ATLEAST 4.
why is the edge connectivity less than or equal to minimal degree of the vertex , since if we remove the no of edges equal to the minimum degree then the graph will become disconnected so
then why is it that we put a less than or equal to condition on edge connectivity ?
see Edge connectivity is minimum number of edges removed in order to disconnect a graph. now we have to delete
minimum number of edges then try for those vertices which is associated with minimum number of edges i.e. degree of
that vertex should be minimum.
Note : a bridge in graph results edge connectivity to 1, which is less than minimum degree of any vertex.
18.61 How many nonisomorphic simple graphs are there with n vertices,
when n is a) 2? b) 3? c) 4? top gateoverflow.in/19594
I am unable to get this logic since in both of these algorithms we need to have a record of future requirement of the
processes so then why is it that resource allocation graph algorithm is more efficient ?
18.61 How many subgraphs with at least one vertex does K3 have? top gateoverflow.in/19070
graph-theory
3 subgraph as consider single - vertices ( question does not mention about distinct so we will consider all cases )
3 subgraph consider 2 vertices
1 subgraph consider 3 vertices
3 subgraph consider 2 vertices, one edge
3 subgraph consider 3 vertices, 2 edges
3 subgraph consider 3 vertices, 1 edge
1 subgraph consider 3 vertices, 3 edges
So, total 17
Therefore there are 7 subgraphs possible in case of unlabeled vertex in k3 having atleast one vertex.
How many edges are there in a forest of t-trees containing a total of n vertices ?
Selected Answer
In each tree we have k-1 edges for k vertices. So, for t trees with total n vertices (all trees are disconnected in a forest)
we would have n-t edges.
A graph G have 9 vertices and two components. What is the maximum number of edges possible in this graph?
graph-theory
Selected Answer
so by splitting it 1 vertex in one component and in other 8 vertices in other component we can have max edges .
Can anyone explain a connected planar graph with n vertices and e edges has e-n+2 regions??
graph-theory
Selected Answer
http://www.ics.uci.edu/~eppstein/junkyard/euler/
http://www.personal.kent.edu/~rmuhamma/GraphTheory/MyGraphTheory/planarity.htm
A certain tree has two vertices of degree 4, one vertex of degree 3 and one vertex of
degree 2. If the other vertices have degree 1, how many vertices are there in the graph ?
(A) 5 (B) n – 3
(C) 20 (D) 11
Selected Answer
Ans:(D)
so if there are n vertices in tree then tree contains exactly n-1 edges
(2*4)+(1*3)+(1*2)+(p*1)=2(p+4-1)
7 var occurs in a loop of computer programm.The variable nd step during which they must be stored are
t: step 1 through 6;u:step2;:steps 2 through 4 ;w:step 1 ,3 and 5;x:step 1 and 6;y:step3 through 6; nd z:step 4 nd 5. How
many different index registers are needed to store these variables during execution?
steps variables
1 t x w
2 t u v
3 t v w y
4 t v y z
5 t w y z
6 t x y
t v w y x z u
6 5 5 5 4 4 2
c1 c2 c3 c4 c2 c4 c3
18.67 How many edges are there in a forest with v vertices and k
components? top gateoverflow.in/18112
How many edges are there in a forest with v vertices and k components?
a)(v+1) - k
b)(v+1)/2 - k
c)v - k
d)v + k
No of Edges = v-k
Vertices are labeled as 1,2,3,......n. Now for each path 1st vertex will be 1 and the last vertex will be n.So the remaining
n-2( labeled 2,3,....n-1) vertcies could be internal vertices of the path.
Now the number of choices of the internal vertices these could be the number of subsets of the set(2,3,....n-1).
The degree sequence of a simple graph is the sequence of the degrees of the nodes in the graph in decreasing order. Which of the
following sequences can not be the degree sequence of any graph?
I. 7, 6, 5, 4, 4, 3, 2, 1
II. 6, 6, 6, 6, 3, 3, 2, 2
III. 7, 6, 6, 4, 4, 3, 2, 2
IV. 8, 7, 7, 6, 4, 2, 1, 1
Selected Answer
http://coddicted.com/the-havel-hakimi-algorithm/
complex-number
Selected Answer
Given equation is
950 = 398(a2 + b2 )
(a2 + b2 ) = 9
The possible set of eigen values of a 4 ∗ 4 skew symmetric; orthogonal real matrix is
A). ±i
B), ( ± i, ± 1)
C). ±1
D). (0, ± i)
To solve this question, we use two properties of eigen value of skew-symmetrical matrix of order 'n'
1) If n=odd,eigen value is 0.
In A = (a ij)nxn where aij = 1 ∀ i,j then number of different independent Eigen Vectors of A are _________ .
(a) 1
(b) n-1
(c) 2
(d) n
Answer will be 2
others are 0
So no. of different independent eigen vector also be 2 ( one for real no, other for 0)
A) what are the eigen values of Orthogonal matrix ? Describe general properties.
B) what are the Eigen value of skew-symmetric matrix ? Describe general properties.
C) Are there any speciality in Eigen values of Symmetric, Hermitian, Skew- Hermitian, Unitary . If there , describe them also.
( )
3
2
respectively?
A.
( )
1
1
−1
0
B. ( )
0.5
0
0.5
0
C.
( )
−1
1
0
1
D.
( )
−1
1
1
0
[ ]
The linear operation L(x) is defined by the cross product L(x) = b × x, where b = [010]T and x = x1 x2 x3 T are three dimensional
vectors. The 3 × 3 matrix M of this operation satisfies
[]
x1
L(x) = M x2
x3
a. 0, + 1, − 1
b. 1, − 1, 1
c. i, − i, 1
d. i, − i, 0
L(x) = b x X = [x3 0 -x1] T (Using definition of Cross Prod. from wikipedia ;) See comment below for details )
Exchange the top and bottom rows, place sign, nullify middle row.
[0 0 1
0 0 0
-1 0 0]
TRUE/FALSE :
1. if V1 and V2 are eigenvectors that correspond to the distinct eigenvalues then they are linearly independent.
2. if V1 and V2 are linearly independent eigenvectors then they correspond to distinct eigen values.
linear-algebra eigen-value
[ ]
2 −2 1
−1 3 −1
2 −4 3
Skipping the calculation step of eigen values. Eigenvalues are λ1 = 1,λ2 = 1,λ3 = 6,
Eigen vector you will get in terms of two linearly independent variable, I have taken k1 and k2 and the vector will be,
[] [ ]
2 −1
Now you will see that these two vectors 1 & 0 corresponding to one eigen value,λ1 = 1.
0 1
[]
2
Checking for 1 ,
0
[ ][]
2−1 −2 1 2
−1 3−1 − 1 * 1
2 −4 3−1 0
[ ][]
1 −2 1 2
= − 1 2 − 1 * 1
2 −4 2 0
[ ]
2 ∗ 1 + ( − 2) ∗ 1 + 1 ∗ 0
= ( − 1) ∗ 2 + 2 ∗ 1 + ( − 1) ∗ 0
2 ∗ 2 + ( − 4) ∗ 1 + 2 ∗ 0
[]
0
= 0
0
[]
−1
Checking for 0 ,
1
[ ][ ]
2−1 −2 1 −1
−1 3−1 −1 * 0
2 −4 3−1 1
[ ][ ]
1 −2 1 −1
= − 1 2 − 1 * 0
2 −4 2 1
[ ]
1 ∗ ( − 1) + ( − 2) ∗ 0 + 1 ∗ 1
= ( − 1) ∗ ( − 1) + 2 ∗ 0 + ( − 1) ∗ 1
2 ∗ ( − 1) + ( − 4) ∗ 0 + 2 ∗ 1
[]
0
= 0
0
[] [ ]
2 −1
C1* 1 +C2* 0 =0
0 1
The above equation are only possible for C1 = C2 = 0, So both vectors are linearly independent as well.
So its not always the case that if V1 and V2 are two linearly independent eigen vectors then they correspond to distinct eigen values.
[ ]
2 7 10
Eigenvalue of matrix A , 5 2 25 is −9.33
1 6 5
other eigenvalue is
1) 18.33
2) −18.33
3) 18.33 − 9.33i
4) 18.33 + 9.33i
engineering-mathematics eigen-value
Selected Answer
2+2+5 = -9.33+X+Y
or, -9.33.X.Y=0
or, X.Y=0
Q).Let A be a real n ∗ n matrix ,then which of the following statements are true?
I). A is orthogonal iff the row vectors form an orthgonal set of vectors in R4 .
II). A is orthogonal iff the columns vectors form an orthogonal set of vectors in R4 .
(A) Only I
(B) Only II
Selected Answer
Here R represents real number space and 4 represents the dimensionality (number of coordinates to represent a point in space) of the real
Dimensions
Each vertex of a cube is represented by 3 coordinates x, y, z . Since there are 3 coordinates to represent each point on a cube so the cube is
in three dimensional space. In case of this question there will be 4 coordinates to represent a point
Orthogonal Matrices:
1. Each column has norm one, and each row has norm one.
2. Each column is orthogonal to every other column, and each row is orthogonal to every other row
Since there are no numerical values for a matrix given so your answer is simply C
19.10 Eigen Vector: Count linearly independent eigen vectors top gateoverflow.in/38609
Answer should be A. But they gave D. Their Explanation: Corresponding to each distinct eigen value, we have atleast one
independent eigen vector.
Selected Answer
It is not true that when u have distinct eigen values then u will have that much linearly independent vectors , take a 2*2
identity matrix , it has same eigen values but it has 2 different linearly independent vectors (1,0) and (0,1) .
How many linearly independent vectors we will have also depends on the rank of matrix , so if u have 2 distinct eigen
values then there may be a case that u have repeated similar values which may be producing distinct linearly independent
vectors ,therefore , u can only say that it will have atleast 2 distinct linearly independent vectors, option A is not always
right .
Take A =
1 0 0
0 2 1
0 1 2
has eigenvalues 1 , 1 and 3.
The eigenvector for lambda=3 is [0 1 1] , and the repeated eigen value
lambda=1 has linearly independent eigen vectors [1 0 0] and [0 -1 1].
19.11 Eigen Vector: Eigen vectors of linear equation defined by cross product
top gateoverflow.in/38908
( )4
6
3
3
What is the sum of all the elements of the L and U matrices as obtained in the L U decomposition?
a. 16
b. 10
c. 9
d. 6
geek-mock-2016 lu-decomposition
Selected Answer
Answer is 9
[ ] [
4
6
3
3
=
l11
l21
0
l22 ][ u11
0
u12
u22 ] We get following equations :l11 ∗ u11 + 0 ∗ 0 = 4l11 ∗ u12 + 0 ∗ u22 = 3l21 ∗ u11 + l22 ∗ 0 = 6l21 ∗ u12 + l22 ∗ u22 = 3After solvi
What is the value of determinant of adjoint( A). What I am not getting in this is that since AA −1 = In .Now if I take determinant on both sides I will get
∣A ∣∣ A −1 ∣= In = 1 ,now ∣A −1 ∣= 1/ ∣ A∣ ,then ∣A −1 ∣=∣ AdjointA ∣ / ∣ A∣. By substituting the above value I get ∣AdjA ∣= 1. What is wrong in this statement ? since value of
det(adj(A)) = det(A)n −1
matrices linear-algebra
Selected Answer
A A -1 = I n
A (adj A) = |A| I n
| A (adj A) | = | |A| I n |
==>We know that if A be an n-rowed square matrix and ' k' be any scalar then
| K A | = K n |A|
Now
| A | | adj A| = | A | n | In |
| A | | adj A| = | A | n
| adj A| = | A |n-1
19.13 Matrices: why row rank of a matrix is equal to column rank of the
matrix ? top gateoverflow.in/15574
matrices linear-algebra
if k row of a matrix with n row is linearly independent then we say the rank of a matrix is k.
we know that if we take the transpose of a matrix the rank does nt changes so by taking the transpose row rank remains
k =>so column rank is also k.(as now row and column is interchanged in the new matrix).
in simple word,by interchanging the row and column the linear dependency is not going to change.
Let A = [ ]
P
R
Q
Q
. If P, Q, R and S are symmetric , What can you say about A?
matrices
A is not Symmetric.
a) I
b) -I
c) 0
d) A
matrices linear-algebra
Question does not have any notion of existing of inverse or related to rank. Therefore considering Zero matrix as A would
satisfy all the constraints.
top
matrices linear-algebra
top
[ ]
2
4
2
9
I proceeded by making it a upper triangular matrix and then using the negetives of the multipliers to get the lower triangular
matrix.
When I used to negative of the multiplier ,i.e. 2 to get the lower triangular matrix,
[ ]
1
2
0
1
.
But the product of L and U is not coming out to be equal to the orig matrix. What am I doing wrong ?
linear-algebra matrices
process is correct and even the product of L and U matrix is coming out as the original matrix. Calculate once again
properly.
Let A=L.U
L= [ 1
L21
0
1 ]
U=
[ U11
0
U12
U22 ]
From here lower and upper matrix can be evaluated.
19.18 Matrices: A is an upper triangular with all diagonal entries zero, then
I+A is top gateoverflow.in/15458
linear-algebra matrices
Selected Answer
A is an upper triangular matrix with diagonal elements zero. If we add I i.e. identity matrix to A then it will become an
upper triangular matrix with all diagonal entries are 1.
That means all eigenvalues A + I are non zero (eigenvalues of triangular matrix is nothing but diagonal elements), so
determinant will never be zero and matrix will be invertible for sure.
how to solve??
matrices linear-algebra
Selected Answer
linear-algebra matrices
option B
(p-1qp)n=p-1qnp how??
matrices linear-algebra
Selected Answer
(p-1qp)n=p-1qnp
= p-1 q I n q p ∵ AA-1 = In
= p-1 q q p
= p-1 q2 p
Similarly you can check and assure yourself with other values of n.
So (p-1qp)n=p-1qnp
PS : One of the most important use of matrix diagonalization is calculating higher powers of a square matrix.
Ref
: http://www.maths.lse.ac.uk/personal/martin/fme4a.pdf and https://en.wikipedia.org/wiki/Diagonalizable_matrix#An_application
19.22 Matrices: Let Mn×n be the set of all n-square symmetric matrices and
the characteristics polynomial of each A∈Mn×n is... top gateoverflow.in/15457
linear-algebra matrices
Selected Answer
This question is wrong, it could be a typo mistake. First I will explain why this question is wrong and then I will correct the
question and explain the solution. Just so you know, trace of a matrix is the sum of the diagonal elements of a matrix,
and also the sum of eigen values of that matrix.
Here Matrix M is a symmetric matrix with characteristic equation as given in the question. For a characteristic equation we
know that coefficient of tn-1 is the trace of Matrix (check eqn (6) of this link). Here in question the coefficient of tn-1 is
0, which means trace of M is 0 (Tr(M) = 0).
Now coefficient of tn-2 can be represented as (Tr(M)2 - Tr(M2))/2 = -Tr(M2)/2 (as Tr(M) = 0) (check eqn(17) in this
class note. Look for eqn c 2 = ... ).
Coefficient of tn-2 given in question is 1, that means Tr(M2) = -2, but it could never be negative for a symmetric matrix.
The reason for Tr(M2) to be non-negative can be explained in different ways. One way is as follows:
A symmetric matrix A has all real eigen values, and eigen values of A2 is the square of eigen values of A , hence trace
of A2 is sum of squares of real numbers, which makes it non-negative. Hence such a matrix doesn't exist.
Now jumping into main question. The dimension of the matrix. All square matrices of size n can be considered as a linear
space of dimension n2, as every element corresponds to a matrix with that element 1 and all others 0. We could also think
dimension as the freedom of filling this matrix. We can we fill whole of n2 with no restrictions. But in this question we have
two restrictions:
1) Matrix should be symmetric.
2) Matrix should have trace 0.
So for symmetric matrix, while filling one side of diagonal (say upper triangle), corresponding elements in the other side is
already determined. Which makes it (n2 - n)/2. Diagonals can be anything so dimension is updated with +n. But now to
have trace 0, last element in the diagonal has to be the -1 times sum of rest of elements in the diagonal, making the
updation +(n-1). So the dimension at the end is:
(n2-n)/2 +n-1 = (n-1)(n+2)/2. which is option (c)
matrices linear-algebra
Selected Answer
number-series
Selected Answer
S= 25/16
How the following fact applies to determinants (I came across it while solving problems):
Consider A is a n × n matrix, the elements of which are real (or complex) polynomials in x. If r rows of the
determinant become identical when x = a, then the determinant has a factor of order < r.
Can I know how logically connected is collapsing of rows of matrix (into one row) with order of its factors.
Elements of A are polynomial in X, so the determinant(A)(let's say f(x)) would also be polynomial in x.
Now consider the case when r=2 and x=a, so it'll produce the two identical rows in A and determinant of A would be 0.
(Let's assume that ith and jth rows are identical with x=a, so if we replace the ith row with ith row -jth row, determinant
would be same. But now new ith row would be zero with x=a, it states that (x-a) is one of the factor of ith row)
and to generalize this you can say that, (x-a) r-1 would be factor of f(x).
PS: It's a bit tricky when r>2, but if you are not convinced I can prove that also.
19.26 which of the statements are true for a 5*5 matrix whose all entries are
1 ? top gateoverflow.in/37477
1. A is not diagonalizable
2.The minimal polynomial and the characteristic polynomial of A are not equal
If A and B are real symmetric matrices of size n*n. Then, which one of the following is true?
a) AA^t = I
b) A = A^-1
c) AB =BA
d) (AB)^t = BA
engineering-mathematics linear-algebra
Selected Answer
Correct option is D.
19.28 which of the statements are true for a 5*5 matrix whose all entries are
1 ? top gateoverflow.in/37476
1. A is not diagonalizable
2.The minimal polynomial and the characteristic polynomial of A are not equal
Let A be a 4 × 4 matrix with real entries such that -1, 1, 2, -2 are its eigen values. If B = A 4 - 5A2 + 5I where I denotes 4 ×
4 identity matrix, then which of the following is correct? (det(X) represents determinant of X)
(A) det(A + B) = 0
(B) det(B) = 1
(C) trace of A + B is 4
19.29 A be a n-squared matrix with integer entries and B=A +12I then how
to conclude that B inverse exists ? top gateoverflow.in/37484
for Inverse there is one and only condition that determinant exist and it should be NON ZERO ..
19.30 The product of the non zero eigen values of the matrix is: top gateoverflow.in/5139
Matrix:
Is there any way shorter, than solving traditionally(lambda subtraction from diagonal)?
http://gateoverflow.in/2013/gate2014-2_47?show=7485#a7485
19.31 A set of r vectors with r < n elements are always Linearly Independent
How? top gateoverflow.in/39184
if V1 and V2 are 4-dimensional subspaces of a 6-dimensional vector space V, then the smallest possible dimension of
Intersection of V1 and V2 is ?
A huge bag contains chocolates of 6 different types, say A, B, C, D, E, and F.Two people, say Ramesh &
Suresh, were asked to pick 4 different types of chocolates from the bag.
Assume that the bag is never gonna run out of chocolates of a particular type.
The answer to this new question is 2 as they have to pick 8 chocolates in total & they have only 6 varieties.
For example,
Suppose Ramesh picks 4 chocolates of types A, B, C and D & Suresh picks 2 chocolates of type E and F.
Now Suresh has to pick 2 more chocolate which should not be of types E and F as he already has chocolates of type E and
F, so the remaining 2 chocolates of Suresh must be of any two types from the set {A, B, C, D}.
but since Ramesh already have chocolates of types A, B, C and D, hence both of them will have at least two types in
common.
Now suppose if both of them picked up chocolates of type A, B, D & F, in this case, then they will have all four types in
common but having four types in common might not be the case always.
Analogies:
PS: Any Space and its subspaces are similar entities, however in the analogy above they may appear quite different as
Space was analogous to a bag & its subspaces were analogous to people.I did this to keep the things simple.If it is
troubling you then you can assume that Ramesh & Suresh contain a bag & they are trying to fill them up with 4 different
types of chocolates from the original bag.
n . (n +1 )
2
Just output .
I was solving problems on deciding whether the given system of linear equations with three unknowns have trivial unique
solution, non trivial unique solution, non trivial infinite solutions or no solution, determinant of the coefficient matrix.
I did understood most facts from the video and put it in the table but not quite sure about the things in red color, since I
have guessed it from my observations and from reading text books:
Q1. Need confirmation about if slope is different then it means that the coefficient matrix is always non singular and if slope
is same then it means that the coefficient matrix is alwayssingular.
Q2. (3rd row, 2nd column) If the slope is different and same y intercept then, whether system is inconsistent or whether
such system cannot exist only?
Q3. If system is in the form Ax = b (b is non zero) i.e. non-homogeneous, does it implies equations always have different y
intercepts and vice versa and also if it is in the for Ax = 0i.e. homogeneous, does it implies equations always have same y
intercepts and vice-versa?
The video explains the system with two unknowns. I was trying to prepare similar for table with three unknowns. But not
able to comprehend similar things for three unknown variable systems. More importantly above table doesnt
talk anything about triviality of the solutions, but there are some facts that dictates triviality of the solutions as
below which I want to incorporate in above table.
3. A homogeneous system is assured of having nontrivial solutions—namely, whenever the system involves more
unknowns than equations.
Also while reading from many sources I found below facts, which I believe are correct (correct me if they are not):
Q1. However I found that these two tables do not map well. The red cells corresponding to Ax = 0 in above table do not map
with the corresponding ones in the first table
Q2. Also am not able to decide on the facts in red font in above table.:
You are basically intrepeting Row picture for system of linear Equation, which is a line for two variables , and a planne for
3 variablers, and much more complex for higher variable...... So a column picture/explanation becomes much more
handy.....
In your second table, All your answer depends on actually A matrix , cofficient matricx, if A is singular square matrix, then
there will always be unqiue solution and Non trival solution offcourse ( Ofccourse plays a role here!!!)
No soution imples inconsisent solution ... I think U need to get the mainig of follwing terminology right :-
1) Non-trival Solution
19.36 How to find how many linearly independent eigen vectors are possible
of a matrix? top gateoverflow.in/39404
How to find how many linearly independent eigen vectors are possible of a matrix?
Selected Answer
To find out the no of linearly independent vectors , first find the rank of the matrix , so no of linearly independent
vectors=n-r where n is the no of unknowns and r is the rank of the matrix .
Now for calculating the value of unknowns u should first try converting the matrix to echelon form and then try calculating
the unknowns.
since ,nullity =order of matrix -rank of matrix ....yes we can defined like that..
19.38 In a m*n order Matrix, How many submatrices are possible? top gateoverflow.in/39092
Selected Answer
To form a Sub-matrix , we have a choice for each row & column - to take or not to take.
But we have to exclude matrix having 0 rows & 0 columns - which can be formed when we delete all rows OR All
Columns , which correspond to 2m + 2n - 1 ways.
a) ax + bcy = 0
b) ax^2 + cy = 21
d) xy + ax >= 20
engineering-mathematics linear-algebra
19.40 A set of r vectors with r > n elements are always Linearly Dependent
How? top gateoverflow.in/39185
Let r = No. of Vectors and n = No. of elements in each vector A set of r vectors with r > n elements are always Linearly
Dependent, Can anyone please explain How?
Consider
Now in your case r > n . Such types of systems where number of rows or equations are greater than the number of
columns or variables are known as OVER-DETERMINED system.
In general over determined system are inconsistent and have NO solutions.however there are some cases where solution
exist
the system of equations have linearly dependent equations e.g. y = x + 1 is linearly dependent to 2y = 2x + 2 so if such
equations exists then after removing linearly dependent equations the number of equations becomes less then the
number of variables we have infinite solutions.
Next if after removing linearly dependent equations the number of equations is equal to the number of number of
variables we have exactly one solution.
So the only cases where the statement in your question is true , is when the system of equations (vectors) have linearly
dependent equations
X - y - z = 0
x + y + z = 46
x - 2y +z = 16
-x - y + 2z = -7
a) no solution
linear-algebra
19.42 Consider the series Xn+1 = Xn / 2 + 98 Xn, X0 = 0.5 obtained from the
Newton-Raphson method. The series converges to top gateoverflow.in/7159
options:
A)1.5 B)
sqrt(2)
C)1.6
D)1.4
Consider the series xn+1=xn/2+9/8xn,x0=0.5 obtained from the Newton-Raphson method. The series converges to
(A) 1.5 (B) √ 2(C) 1.6 (D) 1.4
Sol : Let us see which function's root is found using given series. We know that, according to Newton-Raphson method,
xn+1=xn−f(xn)/f′(xn)
xn+1=xn/2+9/8xn=xn−xn/2+9/8xn=xn−(4xn^2−9)/8xn
So clearly f(x)=4x^2−9. We know its roots are ±3/2=±1.5, but if we start from x0=0.5, according to equation, we cannot
get negative value at any time, so answer is 1.5 i.e. option (A) is correct.
linear-algebra
Selected Answer
adj (A)
| A|
A −1 =
| A | ⋅ A −1 = adj(A)
| A | ⋅ I = adj(A) ⋅ A
| A | n = | adj(A) | ⋅ | A |
| adj(A) | = | A | n −1
If I have 3 sets of vectors X=(1,0,0) , Y= (0,1,0) and Z=(0,0,1) then these all form a linearly independent set of vectors ,so K(X)+P(Y)+Q(Z) =0 , so we get
K=P=Q=0 , but my confusion is what is the no of independent solutions in this , since rank of matrix formed from these vectors will be 3 and according to
the formula No of independent solutions =no of unknowns- rank of matrix , we get no of independent solutions =0 , so how can it be 0 here ?
Selected Answer
A set of vectors is said to be linearly dependent if one of the vectors in the set can be defined as a linear combination of the other vectors.
K1X1+K2X2+K3X3=0
X1 = - K2/K1 X2 - K3/K1 X3
and If no vector in the set can be written in this way, then the vectors are said to be
linearly independent.
implies K1=K2=K3=0
Given
i.e. K1=K2=K3=0
Here Rank =3
= 3-3 =0
19.45 If rank of a matrix is n-1 then how is it that adjoint of matrix is not
equal to zero ? top gateoverflow.in/20968
Clearly |A|=0 ,so A*adj A=0 now since A is not null therefore Adj A can be anything , is may or may not be null so how can we say directly that adj A is not equal to 0
If the Rank of matrix A is n-1 then there is atleast one minor present of order n-1 of the matrix A is not equal to
zero.Therefore the matrix Adj A will be a non zero matrix and thus the Rank of the matrix Adj A will be greater than
zero.
Now
and we know
If the Rank of matrix A is n-1 then there is atleast one minor present of order n-1 of the matrix A is not equal to zero.
If the rank of a matrix is equal to the rank of augmented matrix then we get a unique solution , Now my ques is that I
applied a different row transformation and got the values to be x=7/3 , y=-1/3 and z=7 for a set of equations :
But some other answer is given for this ques so that means they must have applied some other row transformation so how
can it be unique ?
Yes , You can apply Different row or column transformation on a given equations, but this will not effect the
answer .
From equation-3 we get --> z = 2x + y --(3') (putting this value in equation-1 and 2 we get).
Answer --> x = 1 , y = 3 , z = 5 .
19.47 For what value of a, if any, will the following system of equations in x,
y and z have a solution? top gateoverflow.in/15503
For what value of a, if any, will the following system of equations in x, y and z have a
solution?
2x + 3y = 4, x + y + z = 4, x + 2y – z = a
(a) Any real number (b) 0
(c) 1 (d) There is no such value
linear-algebra
2x + 3y = 4 ........................(1)
x + y + z = 4 .....................(2)
x + 2y – z = a ...................(3)
1. |X| = 0 and | Y | ≠ 0
2. |X| ≠ 0 and | Y | = 0
3. |X| = 0 and | Y | = 0
4. |X| ≠ 0 and | Y | ≠ 0
0option C
0 0 0 0 0 0
in first and 2nd case matrix is diagonalizable .....as there are two distinct eigen values
but it is not possible both diagonalizable and nilpotent at the same time
Selected Answer
Answer - A
For a function to be continuous at a point the value at that point and the values of LHL ( LEFT HAND LIMIT ) AND RHL (
RIGHT HAND LIMIT) must be same.Here at x=1, F(x)=0
at x=1 - f(x)= 1
1)(A+B)(A-B)=A^2-B^2
2)(AB)^n=A^n B^n
3)AB^n=B^n A
4)A=I or B=I
AB = BA
AB^n = ABBBBBBBBBB........ //n times B
= (AB)BBBBBBBB........
= BABBBBBBBBBB....... // replace AB by BA
AB^n = B^nA
If diagonal matrix is commutative with every matrix of same order then it is necessarily
1)scalar matrix
2)unit matrix
3)symmetric matrix
4)zero matrix
Scalar..
even Identity & Null are also true but these are just a condition of Scalar matrix where K = 1 and 0 respectively ..
Selected Answer
19.54 If a matrix is non-zero then is it possible that Adj A is zero matrix ? top
gateoverflow.in/21005
For this matrix although A is non-zero but adjoint matrix is zero , so is it true that Adj of a matrix need not be always non-
zero for a non-zero matrix ?
Selected Answer
[ ]
1 1 1
A= 1 1 1
1 1 1
B=
[ ]1
3
2
4
Hence,
Adj
of
a
non
zero
matrix
need
not
be
non-zero
or
Zero
always.
if the matrix A (3∗3) has 3 distinct eigen values then the no.of linearly independent eigen vectors for A=
a)1
b)2
c)3
d)infinite
α1 x1 + α2 x2 + α3 x3 = 0 ⇒ α1 = α2 = α3 = 0
So we have
α1 x1 + α2 x2 + α3 x3 = 0 --- (1)
α2 β21(Ax2 ) + α3 β31(Ax3 ) = 0
α3 β31(e3 − e2 )x3 = 0
In fact, we can show this for any dimension, thus having n distinct eigenvalues implies n eigenvectors are linearly
independent.
Note : We can't have more than 3 linearly independent eigenvectors because 4th eigenvector must correspond to any one
of eigenvalue e1 , e2 , e3 , and thus it becomes linearly dependent on any one of x1 , x2 , x3 .
Let D denote the determinant of n*n matrix. If any line of the determinant is passed over m parallel lines which is true?
c) Data insufficient
d) none
Plz explain...
while solving linear equations, there comes a case where rank < number of varibles,
engineering-mathematics linear-algebra
Selected Answer
Also you ll hv to put x=k and get y value corresponding to it so 1 linearly independent soln ie x and y linearly dependent
on x)
In homogeneous,
unique soln not possible (coz fr solving n vars we need n linearly independent equations)
coz n-r vars cannot be solved uniquely u hv to assign sm consts k, l.. Note k, l are not linearly dependent (no of such vars
is n-r)
. For other vars u ll get values in terms of l and k eg k+l, l/2 etc.(these are linearly dependent on k, l)
Here answer is B.
Selected Answer
Option B is correct.
Now, it's Eigen Values are 0, -1, -1 . We have to find Eigen Vector for λ = -1
let , z = t , y = s => x = 2t
What is the Difference Between Minimal polynomials and characteristic polynomials ? With some example ?
linear-algebra engineering-mathematics
Please refer to my explanation,i tried to make it short and simple as far as possible,though this topic contains lot of
things..
19.60 is there any short cut to find the determinant of the matrix top gateoverflow.in/9803
1 0 0 0 0 2
0 1 0 0 2 0
0 0 1 2 0 0
0 0 2 1 0 0
0 2 0 0 1 0
2 0 0 0 0 1
use LU decomposition method .... then this will convert the matrix into a lower triangular matrix. whose determinant
(which is also the determinant of original matrix) can be calculated by multiplying the all diagonal elements of the matrix.
d sin2 x
lim
x→a dx x
a. 0
b. 2
c. 1
1
d. 2
e. None of the above
A=
[ ]
1
1
1
1
|A| = | |
1
1
1
1
=0
19.62 Is it true that if eigen value exists then we will always have a non-zero
linearly independent vector ? top gateoverflow.in/25154
For a 3*3 identity matrix , we have eigen value as 1 but there is no linearly independent vector for it since if they are 3 unknowns then we shall have x=y=z=0 so then how is it true that
whenever we have an eigen value existing then we have a non-zero linearly independent vector for it ?
1)0
2)2
3)4
4) 8
Selected Answer
x+2y+kz=1 ..............(i)
2x+ky+8z=3 ...............(ii)
Now if k=4
Ans k=4
x1 + x2 + x3 = 6
3x1 + x2 + 2x3 = 14
engineering-mathematics
Selected Answer
X2 will be 1
X3=2, X1=3
x1+x2+x3=6 or,2x1+2x2+2x3=12.............(i)
2x1+2x2+3x3=14.....................(ii)
( )
−4 −1 −1 −1
−1 2 −1 0
Find the Determinant of .
−1 −1 3 −1
−1 0 −1 3
20 Calculus top
20.1 Complex Number: How to solve below equation ? top gateoverflow.in/27025
(1 −i √3 )30
The value of (1 +i )
60
(i = √−1 ) is ______.
A. 1
B. 0
C. -1
D. 2
calculus complex-number
Selected Answer
(1 −i √3 )30 (1 −2i √3 −3 )15 ( −2 −2i √3 )15 ( −2 )15 (1 +i √3 )15 ( −1 )15 (2 )15 (1 +i √3 )15 (1 +3i √3 −9 −3i √3 )5 ( −8 )5
(1 +i )60 (1 +2i −1 )30 (2i )30 (2i )30 ( −1 ) (2 )30 2 15 15
= = = = = = 2 = −1
integration calculus
Selected Answer
ans 8
cos(x) − log(1 + x) − 1 + x
lim
x→0 sin2 x =?
calculus limits
Selected Answer
Answer is 0.
−1 x
2cos (x) 2sin xcos x
= limx→0 + =0
20.4 Limits: Please find the value of this limit top gateoverflow.in/17179
1 1
2 2
1 − (y2 + y) − (2y + 1)
Am I wrong ?
limits
It can be applied only when the problem has the form ∞ or 0 . This question is clearly not in that form. (it is in the form
∞ − ∞)
Multiply the numerator and denominator by y + (y2 + y)1 / 2 and simplify it, and you will get the answer.
lim
x→0 + logx = −∞
limits
Selected Answer
limx→a f(x) = L means that f(x) can be made as close to L as desired, by making x close enough (but not equal) to a.
limx→a + f(x) = L means that f(x) can be made as close to L as desired, by making x close enough (but not equal) to a
from the right side on the number line.
limx→a + f(x) = − ∞ means that f(x) can be made as largely negative as desired, by making x close enough (but not
equal) to a from the right side of the number line.
To Prove: For any given number M, there exists a value of x sufficiently close to 0, such that the value logx is smaller
(more largely negative) than −M. That is,
logx < − M
elog x < e −M
x < e −M
Since e −M > 0 for any M ∈ R, we can choose our x such that 0 < x < e −M.
Thus, we have shown that no matter how largely negative − M is, logx can be made more negative than − M by
making x sufficiently close to 0 + .
calculus limits
Selected Answer
x2 x −x
limx→0 1 −cos x
x2 xlog 2 +2 x −1
0 +sin x
limx→0
( )
1 1
x2 sin2 x
limx→0 −
calculus limits
Selected Answer
sin2 x−x2
( ) ( )
1 1
x2 sin2 x x2sin2 x
limx→0 − = limx→0
limx→0
( )x2sin2 x
= limx→0
( ) x4
sin2 x−x2
( ) ( ) ( )
2sin xcos x−2x sin 2x−2x
x4 4x3 4x3
limx→0 = limx→0 = limx→0
( ) ( ) ( )
sin 2x−2x 2cos 2x−2 1 −cos 2x
4x3 12x2 12x2
limx→0 = limx→0 = limx→0 − 2
2sin2 x
( )
−1
12x2
= limx→0 − 2 = 3
limx→0 sin x ()
(a) 1
(b) 0
calculus limits
Selected Answer
LHL = limx→0 − sin(1/x) put x → 0 − h then ,LHL= limh →0 sin( − 1/h) = limh →0 − sin(1/h) it gives negative value [-1 to 1]
(c) option
lt x--->0 {sin(1/x)/(1/X)}*(1/x)
blue term give 1 when after that we will apply limit to(1/x)
so lt x-->0(1/x)
a) - 1, -2 b) 1, 2
c) -1,2 d) 1,-2
calculus limits
Selected Answer
limx->0 (asin2x + b log(cosx))/x4 = 1/2 [0/0 form] ,applying L'Hospital rule ,we get
= > limx->0 (2a*sinx*cosx - (b /cosx)*sinx)/ 4x 3 = 1/2 => lim x->0 (a*sin2x - b*tanx)/ 4x 3 = 1/2 [0/0 form],
For above limit to exist,Numerator must be zero so that we get [0/0 form] & we can further proceed.
limx->0 (b*cos2x - b*sec2x) / 12x 2 = 1/2 [0/0 form], applying L'Hospital rule again ,we get,
= > limx->0 b*(-2sin2x - 2secx*secx.tanx) / 24x = 1/2 => lim x->0 2b*[-sin2x - (1+tan 2x)tanx] / 24x = 1/2
limx->0 2b*[-2cos2x - (sec2x+3tan2x*sec2x)] / 24 = 1/2 = > 2b[-2 -1] / 24 = 1/2 => -6b/24 = 1/2 => b = -2
-4a-b=6
1 1 1
[
limn →∞ (1 +n ) + (2 +n ) + − − − − − + (n +n ) ]
a) log2 b) 2
c) 2 d) Π/4
limits
which can be further splitted as log2 and log n now apply the limit and we have the ans as log2
x2sin () x
sin x
Value of limx→0 is
limits
Selected Answer
()
sin x
1 () x
()
limx→ 0 sin y
x
x2sin y
sin x limy→ ∞
x
sin x limx→ 0 1
limx→0 = = = 0( ∵ siny ≤ 1, y → ∞).
lim
3
x→1 −
√x + 1 ln(x + 1)
(A) 1
(B) 0
(C) 2
limits
lim lim
3 3
x→1 −
√x + 1ln(x + 1) = h →0 √1 − h + 1ln(1 − h + 1)
3
= √2ln(2)
x+4
limx→∞ x+3
( ) x+1
calculus limits
Selected Answer
We know that lim f(x) g(x) = lim e g(x)[f(x) -1] if f(x)->1 and g(x) -> ∞ .Actually this is applicable in [1 ∞ form]
Hence we have,
limx ->∞ [(x + 4)/(x + 3) ] x+1 = limx ->∞ e (x+1)[ (x+4)/(x+3) - 1] since for x->∞ (x+4)/(x+3) ->1 & x+1 -> ∞ . Hence [1∞ form]
= limx ->∞ e (x+1)[ (x+4-x-3)/(x+3)] = limx ->∞ e (x+1)[ 1/(x+3)] = e 1 since for x->∞ ,(x+1)/(x+3) -> 1
= e
lim
θ→π / 2 (1 − 5cotθ)tan θ
A. e5
B. e −5
C. e1 / 5
D. e −1 / 5
limits
Selected Answer
lim
Let y = θ→π / 2 (1 − 5cotθ)tan θ
Take log.
lim
(
logy = log θ→π / 2 (1 − 5cotθ)tan θ )
lim
(
= θ→π / 2 log(1 − 5cotθ)tan θ ) { log of lim = lim of log
provided the limit exists.
lim
= θ→π / 2 tanθ ⋅ log(1 − 5cotθ) {log (x ) = y ⋅ logx
y
Now, since tan(π/2) = ∞ and log(1 − 5cotπ/2) = 0, we have a ∞ ⋅ 0 form. We need to convert this to a 0/0 form to apply the
L'Hôpital's rule.
log(1 − 5cotθ)
lim
cotθ
logy = θ→π / 2
−5 ⋅ ( − csc2 θ)
lim
(1 − 5cotθ)( − csc2 θ)
= θ→π / 2 {L'Hôpital's rule
−5
lim
= θ→π / 2 1 − 5cotθ
logy = − 5
y = e −5
whenever u have to calculate a limit like Limit x-->a f(x)= 1 and limit x-->a g(x)=infinity , and if u have to calculate limit x--
g(x) , so it actually reduces to 1 infinity form
>af(x)
x2 +5x+3
2
limx→∞ x +x+2
( ) x
limits calculus
Selected Answer
Ans is e^4
limx - > ∞ [(x2+5x+3)/(x2+x+2)]x = limx - > ∞ e x[(x^2 +5x+3)/(x^2+x+2) -1] = limx - > ∞ e x[(4x+1)/(x^2+x+2)] = limx->∞
(4x^2 +1)/(x^2+x+2) = e 4 (since x-> ∞, taking only highest power in both numerator and denominator.
e
1
ln x
limx→0 + x
limits calculus
Selected Answer
Let y = limx→0 + x1 / ln x
lny = 1
y = e1
= limx->o+ (e(lnx/lnx) = limx->o+ (e(1/x)/(1/x) [applying L'hospital rule since power was in ∞/∞ form]
= e1 = e
1 −cos θ
limθ→0 θsin θ
calculus limits
Selected Answer
limit =1/2.
=limx->0 sinx/(sinx+xcosx)
=limx->0 ((sinx/x)*x)/[((sinx/x)*x)+xcosx]
=limx->0 x/(x+xcosx)
=1/1+1
=1/2
sin x ∘
limx→0 x
calculus limits
Selected Answer
∴ x ∘ = πx/180
ex −esin x
limx→0 x−sin x
calculus limits
Selected Answer
(ex −1 ) − (esin x −1 )
x−sin x
limx→0
[( ) ] [( ) ]
ex − 1 esin x − 1 )
x sin x
x − sin x
x−sin x
= limx→0
[( ) ] [( ) ]
ex − 1 esin x − 1 )
x sin x
limx→ 0 x − limsin x→ 0 sin x
x−sin x
= limx→0
(x−sin x)
= limx→0 (x−sin x) = 1
ex − sinx ex −sin x − 1
Given x →0
lim
x − sinx
lim
= x →0 esin x ⋅
[ x − sinx
]
ex −sin x − 1
lim lim
So x →0 esin x × x →0 x − sinx =1×1=1
ey − 1
lim
y
Above we have used y →0 = 1, Bcz above when x → 0
Then (x − sinx) → 0
π
limx→ 4 (tanx)tan 2x
calculus limits
Selected Answer
lim
π
lim
x→ 4 (tanx)tan (2x) = x→π / 4 etan 2xln (tan x)
Now,
sin 2xsec2 x
tan x
sin 2xln (tan x) 0 +2cos 2x.ln tan x 2
( )
π π π
cos 2x 0 −2sin 2x
limx→ 4 tan(2x)ln(tanx) = limx→ 4 form = limx→ 4 (L'Hospital's rule) = −2 = − 1
So,
1
lim
u → −1 eu = e , where u = tan(2x)ln(tanx)
limit= e ^-1/2
20.21 Limits: How to solve this using logarithms on both sides? top gateoverflow.in/39015
[(1-1/n)^n]^2
lim x->inf(1-1/x)^x=e^-1
using this
(e^-1)^2=e^-2
1
x
What is limx→0 (1 − x) ? Also please explain the result?
calculus limits
Selected Answer
1
x
limx→0 (1 − x)
1
x
= limx→0 eln (1 −x)
ln (1 − x)
x
= limx→0 e
ln (1 − x)
x
= e limx→ 0 ∵ e is a constant
This limit is 0 form and we can apply L'Hôpital's rule which gives limit
1
−1
=e = e −1 .
20.23 Limits: How to find this type of limits ? Pls do tell me how to proceed
Solution
sinx
1
(logx)
= limx− >0
cosx
−1 1
(logx)2
∗x
= limx− >0 ( using LH rule )
limits
so y=e^0=1
20.24 Limits: How to solve this integration? Virtual Gate top gateoverflow.in/39034
Selected Answer
option B
let x+1=z now when x-> -1 then z->0 so we can re write it in this way lim z->0 ln z /z^-3 its an indeterminate form we
can apply LH rule
lim z->0 3z
=0
( )
a x +b x x
2
limx→0
calculus limits
Selected Answer
Answer = ab
1
( )
a x +b x x
2
Let y = limx→0
( )
a x +b x x
2
logy = limx→0 log
ax + bx
2
log
x
= limx→0
1
x x
logy = limx→0 a +b . axloga + bxlogb ( )
1
= 2 . (loga + logb)
= log√ ab
So, y = √ab.
1 votes -- shreshtha5 ( 1227 points)
now we calculate forlim x→0 ((ax + bx)/2) − 1) ∗ 1/x which is 0/0 form now we apply l hospital rule that gives
π
limx→ 2 (sinx)tan x
calculus limits
Selected Answer
cos x
limx→ 2 sinxtan x = limx→ 2 etan x.ln (sin x) e limx→ 2 tan x.ln (sin x) = e limx→ 2
π
cos x
( 0
form, applying L'Hospital's rule )=e π
limx→ 2 − sin x
= e0 = 1
6 x −2 x −3 x +1
x2
limx→0
calculus limits
Selected Answer
(6 x −2 x −3 x +1 ) [ (2.3)x −2 x −3 x +1 ] [ (3 x −1 ) (2 x −1 ) ] 3 x −1 2 x −1
x2 x2 x2 x
limx→0 = limx→0 = limx→0 = limx→0 × limx→0 x = ln3. ln2.
xx −1
limx→0 x
calculus limits
Selected Answer
xx −1 0
x
limx→0 (00 = 1 and this is of 0 form)
d
dx
(x ) x
1
limx→0
limx→0 dx
(x ) = lim
x x
x→0 x (1 + lnx) = 1.(1 + ln0) = 1 + ln0 = ln0Hence, undefined
sin x
limx→∞ x
calculus limits
Selected Answer
sin x
1 x +2 x +3 x + … +n x −n
x
limx→0
calculus limits
Selected Answer
n −n 0
if we put limit value in given equation then it gives 0 = 0 which is indeterminate form so we apply l'hopital's rule which
gives
limx→∞ 4x + 5x (
1/x
)
calculus limits
Selected Answer
1
4 1
(( ))
1
x
∞
limx→∞(4x + 5x) = limx→∞ 5x ( 5 )x + 1
x
= limx→∞5 × () (the term inside () ranges between 1 and 2) = 5 × ()0 = 5 × 1 = 5
very easy
lt->inf (4^x+5^x)^1/x
ans will be 5
since 4/5 will give <1 no. and its to the power inf will results 0
calculus limits
Selected Answer
xm
x
We have limx→∞xme −x = limx→∞ e
Now we can apply L'Hopital's rule here i.e. differentiate numerator and denominator, we get
xm mxm− 1
ex x
limx→∞ = limx→∞ e
So answer is 0.
Caption
For finding the interval in which given function is increasing or decreasing ,there is no need to calculate maxima or
minima.
Just differentiate the function and find roots of f'(x), and then check where sign of f(x) is positive or negative.
for x ∈ (-∞,-3] ∪ [2 ,∞) , f'(x) >= 0 ,hence slope of function is increasing in this interval.Hence f(x) is increasing.
maxima-minima calculus
Selected Answer
Absolute minimum of f(x) is the minimum possible value that f(x) can ever attain.
Since a square root never spits out a −ve value, the minimum value that f(x) can attain is 0.
( )
Now to make f(x) = 0, 36 − 4x2 must be equal to 0.
( )
On solving 36 − 4x2 = 0, we get x = 3 & x = − 3.
f(x)=√(36-4x 2)
=2 √(9-x2)
So, 9-x 2 =0
x=3,-3
What is the least value of the function f(x) = 2x2 − 8x − 3 in the interval [0, 5]?
A. −15
B. 7
C. −11
D. −3
isro2013 maxima-minima
Selected Answer
Answer -11
f(x) = 2x 2 -8x -3
f'(x)=4x-8
Answer is -11
in case of 0 it is -3
sin t
t
At t = 0, the function f(t) = has
(A) a minimum
(B) a discontinuity
(D) a maximum
maxima-minima
Selected Answer
sint cost 0
lim lim
t →0 t t →0 1 0
= ;using L'Hospital's Rule for form
=1
sin x
x
visually we can see clearly for the plot y =
function is not defined at x=0 so, this means we are talking about the point which is not in the function domain hence, we
cannot say anything about it.
20.36 e sin x
e cos x
Maxima Minima: What is the maximum value of where x is a real
number? top gateoverflow.in/27705
calculus maxima-minima
Selected Answer
esin x
ecos x
can be written as esin x−cos x.
e is a famous irrational constant that is used as base of natural logarithms, and its approximate value is 2.7183, (which is of
course greater than 1).
So now we just have to maximize (sinx − cosx) to find the maximum value of given expression.
Clearly sinx and cosx are differentiable functions, hence their difference (sinx − cosx) is also differentiable.
Solution of the equation dx (sinx − cosx) = 0 will give us the points where sinx − cosx will attain its maximum value.
tanx = − 1
3π 1 3π −1
sin
( ) 4
=
√2
and cos
( )
4
=
√2
.
20.37 Mocktest: What will be the minimum value within a given range?
GATEFORUM_MOCKS top gateoverflow.in/38373
Which of the following is the right Procedure to get the minimum for f(x)?
Procedure 1: This is a closed interval, so we will have to calculate the value including and between [0,π/2].
To get critical points we do f'(x)=0. But here on f'(x) we get: -e-x-sin(x)=0, ie, there are no critical point and derivative
exists everywhere? So we will calculate the points where derivatives will be 0. Exponential will never be zero, so consider sin,
it will be zero only at point nπ/2.(here n=1)
Procedure 2: If f'(x)<0, then it is minimum at that point. Here we are getting f'(x)<0 for [0,π/2] and inbetween points. So
are we supposed to substitute each value in f(x) from options to check which gives the minimum?
To find maxima or minima we need to equation differential to zero but the differential is never satisfied by any value in
[0,pi/2] so we only need to check if slope is positive or negative to find the maxima , it is always negative in [0,pi/2] so
the value at pi/2 is the minimum.
20.38 Parabola: Volume generated by parabola about line [Gate 94] top gateoverflow.in/34714
The volume generated by revolving the area bounded by parabola y^2 = 8x and the line x = 2 about y-axis is....
A) 128π/5
B) 5/128π
C) 127/5π
D) None
EDIT: Following is the area we have to revolve. And answer is given as (A). And kindly explain the methodology to solve
such volumetric qstns if you get the answer. Thanx in advance :)
Selected Answer
20.39 Study Resources: Which book is best for calculus? top gateoverflow.in/30147
Between Higher engineering mathematics and Gilbert Strang which one is more appropriate for GATE?
study-resources
(A) a > 0
(B) a < 0
(C) a ≥ 0
(D) a ≤ 0
Selected Answer
f'(x)=a
so a>0
20.41 Virtualgate: For the function e^-x the linear approximation at aroung
x=2 is? Virtual Gate top gateoverflow.in/39026
Selected Answer
=f(2)+f '(2)(x-2)
f(x)=e^-2
put values
e^-2 -e^-2(x-2)
e^-2[1-x+2]
e^-2[3-x]
calculus
Selected Answer
number of element in B = 1
number of element in A = 8
let B = {3}
A = { 1,2,3,4,5,6,7}
One One Functions From B ----> A are :
1. {(3,1)}
2. {(3,2)}
3. {(3,3)}
4. {(3,4)}
5. {(3,5)}
6. {(3,6)}
7. {(3,8)}
8. {(3,8)}
top
xα −1
∫10 logx dx
calculus
I = ∫( X^a -1)/log(x) dx
Now ,
and why should we not change the sign of second part ,i.e (x+1) ?
calculus
Selected Answer
{
−(x − 1) − (1 + x), if x ≤ − 1
f(x) = −(x − 1) + (1 + x), if −1 < x ≤ 1
+(x − 1) + (1 + x), if 1 < x
Hope it clears your doubt. If not, then take a value for each of the three intervals, put in the formula and convince
yourself that it is correct.
Because it it addition? o.O How will you change the sign? from (x+1) to +(1+x)?
we are not changing the sign bcz x-1 is less than 1. we are changing it bcoz say, x=0.9999, then 0.9999-1=-0.00001,
which is a -ve value. after coming out of mod, it will be +ve.
20.45 A function is defined over an open interval atleast at one point in this
interval, dy/dx is exactly?GATE_2013-EC,EE,IN top gateoverflow.in/39070
A function y= 5x^2+ 10x is defined over an open interval x = (1,2). Atleast at one point in this interval, dy/dx is exactly
calculus engineering-mathematics
F'(c)=f(b)-f(a)/b-a
F(2)=40
F(1)=15
dy/dx = 10x + 10
calculus
http://gateoverflow.in/37766/given-that-%CE%B1-%E2%89%A5-0-and-value-of-integral-at-%CE%B1-0-is-0-the-value-of
I=
I=
Now issue is that on LHS also I have I and on RHS also I have I after evaluating the above expression so how to resolve this
issue ?
∫5−5 ∣ x + 1 ∣ dx is ____
Solution Given : 26
My Solution : 25
calculus
Selected Answer
∫5−5 | x + 1 | dx
= ∫ −1 5
−5 − (x + 1) dx + ∫ −1 (x + 1) dx
([ ] [ ] )
(x+1 )2 −1 (x+1 )2 5
2 2
= − +
−5 −1
( )( )
( −4 )2 62
2 2
= − 0− + −0
= 8 + 18
= 26
how to solve it
Selected Answer
LHL != RHL.
Function y = f(x) is continuous at point x = a if the following three conditions are satisfied
1. f(a) is defined
2. lim x → a, f(x) exists (i.e., is finite)
3. lim x → a, f(x) = f(a)
Now according to question f(x) = x4 . When x = − 1, left lim=1, right lim = -1. lhl not equal to rhl and so not continuous. Not
continuous implies not differentiable.
calculus engineering-mathematics
At x = 0, the function takes 0/0 form. So, the function is not continuous at x = 0.
By mentioning f(x) = 1 at x = 0, an attempt has been made to make the function continuous. So, let us check whether at
lim x → 0, the function value equals 1 ?
1 +ex
x
Using L'Hospital's rule, it becomes x+e and putting x = 0, it is 2.
So, even after adding f(0) = 1, the function couldn't be made continuous.
Answer is d.
A n × n matrix is given and an element aij is called saddle point if all the element in the ith row are less than aij and all the
element in jth column are greater than aij. How many maximum no of saddle point are possible.
a. 2
b. 3
c. n
d. 1
engineering-mathematics
Just take the matrix. for 2 point to be saddler the conditions specified will say this. suppose u have two points of a column
as saddler point i.e. q and p .
while if u have to say 2 also sadller point q<p . only one can happen at a time . make other case yourself and u wll get
this .
5 4 3
6 3 2
7 2 1
only 5 is sadler point as considering 6 should say that 6 should be least but 5 is least .
value of integral in (1,2) is zero. that means interval (1,x) and (x,2) having area with different sign..
1 1 ln (cot (x) ) 1
ln (x) ln (x)
ln (x)
limx→0 cot(x) = limx→0 e ×ln (cot (x) ) limx→0 = − 1 limu → −1 eu = e −1 = e
http://gateoverflow.in/?qa=blob&qa_blobid=11477564903327944491
1)sin-1(sin x) x∈[0,2π]
2)cos-1(cos x) x∈[0,2π]
3)tan-1(tan x) x∈[0,π]-{π/2}
Selected Answer
Now we can precisely define and differentiate the functions in the given intervals using the above graphs as follow:
sin-1(sinx) = {
x when x ∈ [0, π/2]
It can be seen from the graph of sin -1(sinx) that it is not smooth at x = π/2 and x = 3π/2.
At all other points the function can be easily differentiated using the above definitions and we will get
cos-1(cosx) = {
x when x ∈ [0, π]
It can be seen from the graph of cos -1(cosx) that it is not smooth at x = 0, x = π and x = 2π.
At all other points the function can be differentiated using the above definitions and we will get
tan-1(tanx) = {
x - π when x ∈ (π/2, π]
It can be seen from the graph of tan -1(tanx) that it is not continuous at x = π/2.
At all other points the function can be differentiated and we will get
1. Domain of this function will be the domain of (sinx) i.e. the set of all real numbers.
2. Range of this function will be the range of sin -1x i.e. [-π/2, π/2].
4. The inner function i.e. sinx of this composite function is a periodic function so the composition could be a periodic
function with same period.
5. Since both sin(x) and sin -1(x) are odd fuctions the composition should be an odd function.
6. sin -1 and sin are inverse of each other so intutively at least in some part of the graph, they should cancel the effect of
each other leaving behind only x.
All these ideas can be combined to get a rough idea about the graph of this functions, similarly for the other two functions
too.
discontinuous at x=3..
LHL = 1/2
RHL = 0
Value function = 0
LHL != RHL= value of function.
a)-1/5
b)1/5
c)π/4
d)None
Evaluate
20.60 Is the integral of second half i.e [π , 2π] being subtracted from that of
the first[0, π] ? Is it right to do so? top gateoverflow.in/7795
2π
∫
If 0 | x sinx | dx = kπ, then the value of k is equal to ______.
Integral is actually not subtracted. It is added. Just that the integrated value is negative. You can read the explanation.
http://gateoverflow.in/2040/gate2014-3_6?show=8807#a8807
A. 1
B. 2
C. 3
D. 4
calculus
1
2
∫∞ −y3dx
0y e
Take y 3/2 =t so that 3/2 y 1/2 dy=dt ,Also reverse the limit values from infinity to zero and place a negative sign Now ur
integration becomes as per this link , Now when u will evaluate it u will get the answer as 4/3
http://www.hostmath.com/Show.aspx?Code=-
2%2F3%5Cint_%7B%5Cinfty%7D%5E%7B0%7D1%2Fe%5Csurd%20t%20%20%20dt%0A%5CRightarrow%20%0A%0At%3Dx%5E%7
4%2F3%5Cint_%7B%5Cinfty%7D%5E%7B0%7Dxe%5E%7B-x%7Ddx%20
http://gateforum.com/wp-content/uploads/2013/01/EC-2005.pdf
question 35 .....
1
2
Here graph of function f(x) is something like f(x) = 1 + x (Even Function. )
2x
(1 + x2 )2
So we get f ′ (x) = − (odd function. )
http://www.questionpapers.net.in/Question%20Papers/gate-question-papers-download/gate-question-papers-download-
civil-engineering-2007.pdf
e −ax sin(bx)
∞ x ∞ b
I(a, b) = ∫ 0 dx = ∫ 0 ∫ 0 e −ax cos(yx)dydx
e −ax
[ ]
∞
b ∞ −ax ∞ a2 + y2 (ysin(yx) − acos(yx))
I(a, b) = ∫∫ 0 0
e cos(yx)dxdy = ∫ 0
dy
0
a b
I(a, b) = ∫
b y2
0
+ a2 dy = tan −1 a
()
sinx 1 π
I(0, 1) = ∫
∞
0
x
dx = tan −1 ()
0
= tan −1 (∞) =
2
Q.64
A function f (x) is differentiated twice such that its differential equation λ 2f (x) – 2λf ′(x) + f ′′(x) = 0 provides two equal
value of λ for all x. It f (0) = 1, f′(0) = 2, then f(x) at x = 1 will be _________.
made-easy calculus
Order of a differential equation is defined as the order of the highest order derivative of the dependent variable with
respect to the independent variable.
Degree is the highest power (positive integral index) of the highest order derivative involved in the given differential
equation.
REFERENCE
=limx->∞ ((1-cosx)/sinx)
=tan ∞
= undefined
http://gateforum.com/wp-content/uploads/2013/01/IN-2010.pdf
Question 21
The integral ∫∞ 6
−∞δ(t − )6sin(t)dt evaluates to
(A).6
(B).3
(c).1.5
(D).0
gate-2010-maths
http://www.gate.iisc.ernet.in/gate-ques-2015/CE%20SET_2_GATE_2015.pdf
question 3
plz help me
eix=cos x + i sin x
e-ix=cos x - i sin x
I=e2ix /2i
=-2/2i
=-1/i
=i
answer is i.
Selected Answer
answer = option D
at large value of x the value of sinx will always be between −1, 1 while x will keep growing which is a denominator hence,
sinx
lim
x→∞ x
=0
Find Volume under surface z(x,y)=x+y and above the triangle defined in x-y plane by 0<=y<=x and 0<=x<=12
Selected Answer
∬
Volume is calculate as V f(x, y) dy dx
so, ∫12 x
0 ∫0 z(x, y) dy dx
= ∫12 x
0 ∫0 (x + y) dy dx
y2
= ∫12
0 (xy + 2 ) | x0 dx
x2
= ∫12
0 (x
2 + 2 ) dx
= 2 ∫12 2
0 x dx
( )
3 x3
2 3 12
= |0
= 864
21 Programming top
21.1 Ace Test Series: C recursive program top gateoverflow.in/35417
programming-in-c ace-test-series
Selected Answer
--n in every function call will decrease the value of n in the local scope of the function also.
programming-in-c ace-test-series
Selected Answer
when a number is preceded by 0 , it represents an octal number so %d will print the decimal equivalent of an octal
number like (40)8=32 in decimal so op is 32 ,
Ans is given as (D). But I am not getting it. If we consider HEX format, then it is giving me (A) and in normal format it is
giving 2240. Where's the problem??
programming-in-c ace-test-series
0570 is in octal so in binary its 101111000 (In C language any numeral starting with 0 is octal and starting with 0x is
hexa)
Its 'cd' only. With a compiler having int size of 4, it is giving 'gh'. So, with 2 bytes of size , it should give 'cd'.
a. 123456
b. 135246
c. 456456
d. 456789
programming-in-c arrays
A one dimensional array A has indices 1....75.Each element is a string and takes up three memory words. The array is stored starting at location 1120
decimal. The starting address of A[49] is
A. 1167 B. 1164
C. 1264 D. 1169
I think the location of A[49] will be 1264 because location of A[49] is 1264= (1120+(48*3))as it takes three memory words.is this correct answer?Does each
memory word represents a single character? or am i doing something wrong?
arrays programming
Selected Answer
If tthere are two lower triangular matrix A and B.A and transpose B are stored in C. by storing only non zero elements.what
should be the dimension of C.
B[i][j]= C[i][j+1]
data-structure arrays
21.8 Arrays: What will be the O/P of the following C code? Virtual gate top
gateoverflow.in/38868
Selected Answer
You will get a compile time error, because i is not defined. As there is no option for compile time error, hence option D
I am stuck after JAN. It is not getting balanced even after 2 rotations. Can somebody help?
Answer is (c) Mar, try assigning numbers in place of months that will make it easy to solve and find result.
21.10 Avl Tree: VIRTUALGATE II Q.18 Find the root of the AVL tree. ? gateoverflow.in/37975
top
27...
21.11 Avl Tree: Insert elements in AVL tree so that it doesn't have any
rotation top gateoverflow.in/36534
The number of ways we can insert elements { 1, 2, 3, .... 7 } to make an AVL tree, so that it does not have any rotation are
_______ ?
with 3 as root we are able to create 8 trees which are balanced BST. With 4 as root we can create just one balanced BST
and with 5 as root we can create again 8 BST. Hence 17 BST should be the answer
{3}{1,6}{2,5,7}{4};
{3}{2,5}{1,4,6}{7} ;
{3}{1,5}{2,4,6}{7};
{3}{2,6}{1,4,7}{5};
{3}{1,6}{2,4,7}{5};
{3}{2,5}{1,4,7}{6};
{3}{1,5}{2,4,7}{6};
with 4 as root, balanced avl only kind of AVL is created and sequences is {4}{2,6}{1,3,5,7} which gives 48 permutations
with 5 as root we have 8 insertion sequence with 12 permutations in each {same as 3 as root} i.e. total of 12*8 i.e 96
sequence.
So total ways to insert keys in AVL without rotation is 48 +2*96 i.e 48+ 192 i.e. 240..................
26 . A / B+ tree index is to be built on the name attribute of the relation STUDENT. Assume that all students names are of
length 8 bytes, disk block are of size 512 bytes and index pointers are of size 4 bytes. Given this scenario what would be the
best choice of the degree (i.e. the number of pointers per node) of the B+ tree ? (A) 16 (B) 42 (C) 43 (D) 44
data-structure b-tree
(p-1)K+p*Bp<=Block Size
(p-1)8+ P*4=512
12p=520
p=43
int q = 10;
p = &q;
int main()
int r = 20;
int *p = &r;
fun(p);
printf("%d", *p);
return 0;
Selected Answer
because the pointer p in main and pointer p in function are different having different addresses... the p in function is local
to the func()
A set of n-distinct element and unlabelled binary tree with n nodes is given. In how many ways we can populate the tree
with given set so that it become BST
A 1
B 0
c n!
D 2ncn/(n+1)
binary-tree
Just the simple logic is that we have 2nCn/(n+1) unlabelled trees , now each unlabelled tree will always correspond to one
BST , consider 1,2,3 now say you draw a right skewed unlabelled tree , now u can label it only in one way 1 2 3 to form a
BST , if say u draw a left skewed unlabelled tree , then u can label it as 3 2 1 , to form BST therefore each unlabelled tree
gives rise to only 1 BST.
But in the question it is already given that we are provided with one unlabelled tree therefore there is only 1 way in which
we can populate it to form a BST therefore answer is option A .
A binary search tree was constructed by inserting following elements into an initially empty binary tree.
50, 27, 16, 88, 34, 65, 52, 77, 93, 4, 12, 29, 44, 92
Preorder and postorder traversals of the resultant binary search tree were stored in arrays A and B respectively. The length of LCS present in these to array A and B ___________.
Everything is ok here,, But not getting how length of LCS is calculated here.
data-structure bst
Selected Answer
Preorder : 50 27 16 4 12 34 29 44 88 65 52 77 93 92
Postorder : 12 4 16 29 44 34 27 52 77 65 52 93 88 50
How tokens are assigned for a string having escape sequence in C lexical phase
Eg..
compiler-tokenization
Selected Answer
N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key
operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the
list in this order:
Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key
What is the time complexity of all these operations put together
(A) O(Log2 N)
(B) O(N)
(C) O(N2 )
(D) Θ(N2 Log N)
time taken to delete N elements is N^2 and time taken insert N elements is NlogN lly for all operation
How many asterisks ( ∗ ) in terms of k will be printed by the following C function, when called as count(m) where m = 3k ? Justify
your answer.
Assume that 4 bytes are used to store an integer in C and k is such that 3k can be stored in 4 bytes.
Selected Answer
I tried it for 3 5 ,
and each function call 3 functions for n/3 recursively till get 1 at each node . it becomes a ternary tree
= 1 * (1 - 3 k+1 )/(1-3)
= (3k+1 -1 )/2
21.19 Functions: What will be the output, Please explain? top gateoverflow.in/43006
programming-in-c functions
Selected Answer
This will print Binary equivalent of number n. It will keep dividing by two, the number until it will reach to 1 or 0. Then
it start printing in reverse.
The reverse order comes from the fact that its a head Recursion (A recursion is called head recursion when function get
called before print statement).
21.20 Geeks: Which of these programs are possible in C++/Java without the
use of File I/O ? top gateoverflow.in/41311
Which of these programs are possible in C++/Java without the use of File I/O ?
Options:
A. P1 possible
B. P1 and P2 possible.
C. None Possible.
D. All are possible
First you should notice that File Input/Output is not allowed. If its allowed then option (D) would be the correct answer.
But as its not allowed hence it will not be the answer.
Correct answer is (B). Here is the explanation. A computer program which print it's own source code is called quine.
A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for
these programs in the computability theory and computer science literature are "self-replicating programs", "self-reproducing programs", and "self-
copying programs".
It can print twice or thrice. But number of times should be fixed. It can not take input from user. Hence P3 will not be possible.
21.21 Graph Algorithms: leaf constrained minimum spanning tree top gateoverflow.in/40516
what is the suitable algorithm for the construction of leaf constrined minimum spanning tree .
graph-algorithms
Consider a hashing function that resolves collision by quadratic probing .Assume the address space is indexed from 1 to 6.
Which of the following locations will never be probed if a collision occurs at position 5 ?
A). 4
B). 5
C). 8
D). 6
Ans:
Ans Explanation:
→ (5 + 22 )%6 + 1 = 4
→ (5 + 32 )%6 + 1 = 3
→ (5 + 42 )%6 + 1 = 4
→ (5 + 52 )%6 + 1 = 1
→ (5 + 62 )%6 + 1 = 6
→ (5 + 72 )%6 + 1 = 1
→ (5 + 82 )%6 + 1 = 4
→ (5 + 92 )%6 + 1 = 3
data-structure hashing
Because address space is indexed from 1 to 6. If you get 0 after some modulus operation and you don't have zero as any
location. Therefore, 1 is added.
The number of elements that can be sorted in O(logn) time using heap sort is
(A)
Answer: (C)
Selected Answer
=logn/loglogn * log(logn/loglogn )
second term is (logn*(logy /y)) where y=loglogn and logy/y <<1 so second term is <<logn, second term can be
ignored
=O(logn)
21.24 Identify Function: What will be the output of right shift? top gateoverflow.in/37315
functions identify-function
Selected Answer
In C language an integer constant starting with a 0 is treated as octal. So, 0235 = 157 in decimal. Now, the code is giving
the position of the most significant bit in the binary representation of the number. 157 = (10011101)2 , so, MSB is at position
8.
21.25 Linked Lists: which statement is true about doubly linked list? top gateoverflow.in/10256
linked-lists
Selected Answer
Double linked list may contains a cycle of length less than n where n is no of nodes .. that linked list neither linear nor
circular..
Extra space required for Back Pointer storage..
What does the following function do for a given Linked List with first node ashead?
fun1(head->next);
printf("%d ", head->data);
}
will it print 5-4-3-2-1 or 4-3-2-1 if i/p is 1-2-3-4-5?Will the last 5 get printed or not ,
due to return;
linked-lists
linked-lists
int main(){
int a;
a = 1;
while(a-- >= 1)
programming-in-c loop
Selected Answer
intially a=1 then due to inside while loop use post decrement operator which means firstly assign the value then
decrement so firstly
while(1==1)true the decrement 'a' by 1 then a become 0 then while(0=0) true then 'a' decrement by 1 by which a=-1
then go inner while loop while(-1=0) false then decrement then a=-2 then go outer while loop again condition false and
finally 'a' become -3
so answer is a=-3
Assume that the array contains list of all the numbers from 1 to k –1. What is the return value of function BSR?
------------------------------------------------------------------------------------------------------------------------------------------------
-----------------
Here I think answer should Be D, None of these, as as per me this program will add up all no from 1 to k-1. i.e. (k-1 * k ) /2
in value & substracting last from it which is also (k-1*k) /2 . So it will always return 0.
Q 37
Assume that the array contains list of all the numbers from 1 to k –1. // main line
i.e. we have two take all no. form 1- k-1 when no. of values are k.
k= 7
1,2,3,4,5,6,6
return = 27-21= 6
so 6 is repeated.
top
i am doing strcpy from a larger string into a relatively smaller string using two ways.According to me
both the methods allocate space statically(as i am not using any malloc or calloc in either of my cases).
but still method1 gives me segementation fault(in ubuntu) or just cracshes the exe generated (in
windows),i.e i am trying to access area out of my way, while method2 doesn't . why?
method 1:
char *a = "hi";
char *b = "hisi";
try
{
strcpy(a, b);
cout << "all ok";
}
catch (exception e)
{
cout << "error";
}
method2:
Selected Answer
char *a = "hi";
Here you are declaring a pointer a, and assigning a value to it which is the address of "hi". "hi" is a string literal here
meaning it is nothing but a constant. So, compiler stores this string in a READ ONLY (RO data segment) region as string
literals are not meant to be modified. So, if we try to modify this memory region (by strcpy or any other means), OS won't
allow it.
Here variable a is allotted memory for storing 3 characters and the characters 'h', 'i' and '\0' are stored to it. Since scope
of a is "auto", this allocation happens in stack and programmer is free to modify this memory location with in the function.
But there is memory for only 3 characters. If using strcpy more than 3 characters are assigned, behaviour is undefined-
sometimes it might work if there are some unused memory given by the compiler, sometimes it might crash due to
memory corruption by writing to unallocated memory or sometimes program might give wrong output by modification of
unintended memory locations.
21.31 Minimum Spanning Trees: MSTs the graph have? top gateoverflow.in/39013
minimum-spanning-trees graph-theory
Selected Answer
Among E, Band C, you can choose exactly two edges, because choosing less than 2 edges will make the tree disconnected
and choosing 3 edges will add a cycle to the tree. Hence, there are 3 C2 = 3 ways. Similarly, there are 3 ways to choose
edges from A, Dand E. So, total possible ways = 3 ∗ 3 = 9.
#include<stdio.h>
int main()
{
7 printf("%c\n", ["IndiaBIX"]);
0 return ;
}
Please explain how the output is X ? I know while counting in Array will make X . But how this CODE works.........>>?
programming-in-c output
Selected Answer
working like
char a[]="IndiaBIX";
printf("%c\n", 7[a]);
here 7[a]=a[7]
so *(a + i) = *(i+ a)
a[i] = i[a]
P(X:integer,Y:integer) {
X = 6;
A = 8;
return ( X + Y )
}
programming parameter-passing
21.34 Parameter Passing: What will be the second value printed by the
program if parameter passing mechanism is call by reference? top gateoverflow.in/4481
What will be the second value printed by the program if parameter passing mechanism is call by reference?
programming parameter-passing
Selected Answer
Static scoping: Here if a variable is not in local scope, it is looked in global scope.
So, b in func() is the global b. So, 10 is printed. a is incremented by 10 when x = x + b, (due to pass by reference) and a
is again incremented by 10 when y = y + b. So, print(a) will print 30.
Dynamic scoping: Here if a variable is not in local scope, it is looked in the function which called the current one.
So, b in func() is the b from main. So, 20 is printed and a is incremented two times by 20 and final print(a) will print 10 +
20 + 20 = 50.
int i = 1;
int main()
{
int a[]= { 0,1, 2} ;
f(a[i], i);
printf("%d", a[i]);
}
void f(int x, int y)
{
y++;
x=5*i;
}
In above function f() uses " call by name" technique, what is the output printed?
a) 2 b) 10 c) 5 d) 1
programming parameter-passing
Selected Answer
Using a C style creates confusion for call by name. The scope of variables comes from the function where it is called
(dynamic scoping) in call by name.
y++; i becomes 2
The output printed is 1 i.e., option d). The function f() doesn't return any value neither does it make changes in the
original value of a[i] and hence no matter what goes inside the body of f(), the output will be the initial value of a[i] i.e.,
1.
option b .
http://www.cs.rit.edu/~rpj/courses/plc/lab4/lab47.html#Q12
void main()
{
int x=10, y=5;
swap(x,y);
print(x,y);
}
void swap(int a, int b)
{
int c, x=0;
c=a;
a=b;
b=c;
}
a) 5 0
b) 5 10
c) 10 0
d) 10 10
programming parameter-passing
according to the concept of inline functions... that is how we represent the the concept of call by text or call by name in c
++
option A: 5 0
but as per the concept of macros in c i am still not clear for the correct answer for this.
here is a link for anyone who wanna go through the details of this:
http://www.cs.rit.edu/~rpj/courses/plc/lab4/lab47.html#Q12
Output :
str1 is Gate, str2 is Overflow
programming-in-c pointers
Selected Answer
In this function whatever the exchange you are doing, is local only since str1, str2 and temp char pointers are local to
swap() function.That is the reason your swap function is not working.
21.38 Pointers: Find the output of the following c code - top gateoverflow.in/15319
main()
{
char *ptr="gatebuddy";
*(ptr)++;
ptr++;
printf("%s\n",ptr);
}
programming-in-c pointers
Selected Answer
char *ptr="gatebuddy"; // ptr is a pointer variable pointing to a string literal 'gatebuddy'. C by default adds a null
character (\0) at the end of any string literal.
*(ptr)++; // ptr point 2nd element of string literal 'gatebuddy' as postincrement has higher precedence than
indirection.
Ref: http://en.cppreference.com/w/c/language/operator_precedence
printf("%s\n",ptr); //it ll print all character of string from 3rd element to that index where null character is stored.
Now I suppose if i have a statement like *P++ then it is broken down as first (P++) and then *p
and if we have statement like a=*p++ then it is broken down into a=*p and then p is incremented !!
Am i right ?
pointers programming-in-c
so P++ (dont increment P, use P value as it is . after whole operation increment it).
Then a = *P
Now P++..
Case 1:
int a,b ;
int *p =&b;
b=9;
printf("%d",*p++);
Case 2:
a=*p++;
printf("%d",a);
Main () {
int a [3] [4] = $\begin{pmatrix}
1&2&3&4 \\
5&6&7&8 \\
9&10&11&12 \\
\end{pmatrix}$
printf ("\n% u% u% u", a[0]+1, * (a[0] + 1),
*(*(a + 0)+1));
}
What is the output of the above program? Assume array begin at address 10.
arrays pointers
12, 2 , 2
first will print address of 1st row 2st column element which is 10 +2= 12
#include<stdio.h>
int main()
int n = 7;
printf("%.*s", n, s);
return 0;
Selected Answer
OUTPUT: Geeks Q
EXPLANATION
Store the string "Geeks Quiz" in memory and stores the base address in pointer s.
printf("%.*s",n,s);
1. .number: Its a precision which specifies the minimum number of character/digits to be printed.
2. .*: The precision is not specified in the format string, but as an additional integer value argument preceding the
argument that has to be formatted.
3. Therefore, the above line will print 7 characters (as specified by n) of string s.
SOURCE: Tutorials Point (Click on link to read more about formatting in printf)
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct xx
{
int x;
char s;
};
struct xx *t;
t->x=5;
t->s='a';
printf("%d %c\n", t->x, t->s);
}
pointers easy
Selected Answer
struct xx *t;
//Here t is a pointer to struct xx
t->x=5;
Assigns 5 to the int part of struct xx object pointed to by t. But t is not assigned any struct xx object to point to. So, this is doing invalid memory access and
should result in segmentation fault.
main()
char * z="abc";
z[0]='x';
printf("%s",z);
programming-in-c pointers
Selected Answer
Here, b is a 2D array and it contains 3*4 = 12 elements. Suppose address of b starts from 1000. Now the elements will be
stored as:
1000-3: 1
1004-7: 2
1008-11: 3
1012-15: 4
1016-19: 5
....
1045-48: 12
So, *p will have 1. (assuming a 32 bit architecture, on 64 bit architecture *p will be 8 bytes and the array element being
int is only 4 bytes)
Now, *p+1, is pointer arithmetic. It will add 1 *sizeof(int) to *p. So, *p+1 will give 1 + 4 = 5. (This 5 is not the element
5 in the array)
Similarly, *p+2, will add 2*sizeof(int) = 2*4 = 8 to *p. So, *p+2 will give 1+8 = 9.
These are all valid only on a 32 bit compiler. On a 64 bit compiler, if we use
(long)*p
From 1000, the content of memory will be (assuming a little endian machine)
0000 0001 0000 0000 0000 0000 0000 0000 | 0000 0010 0000 0000 0000 0000 0000 0000
This output is entirely implementation dependent as it depends on the sizeof (int) and sizeof pointer and also depends on the endianness of the machine(if sizeof
(int) is different from sizeof pointer) .
For more details about pointer arithmetic you can see here:
http://gatecse.in/wiki/Chapter_3:_Pointers#Pointer_Arithmetic
a=4; **c=5;
b) assigns address of c to a
d) assigns 5 to a
pointers programming-in-c
Selected Answer
answer = option D
To this
mynode *head;
add_node (head,10);
add_node( struct node* head, into value)
programming-in-c pointers
Selected Answer
Both can be used, Although first is considered better due to certain flexibility available inside the function to change where
head will point.
In first case , you are sending a double pointer(address of head pointer) to function as argument, so you can change
value of head pointer(where head is pointing) using
In second case, directly changing head inside function is not possible as it's the value of head pointer itself that you are
passing so you cannot access its address to change it(head is just a local var containing address pointed by head and not
address of head itself) . To change it you can return new head value (an address essentially) at end and at the place of
fun call reassign to head pointer.
struct Node * test_Func(struct Node *head) //Func Definition
{
head=sm addr;
return head;
}
head= test_Func(head); //Func Call
is correct way.double pointer will help you to directly modify conents of head pointer in main function.
add_node( struct node* head, into value) is wrong.to make this correct you should reuturn new address that your function
modified and assign this address as a new head.
int main()
{
int a;
char *x;
x = (char *) &a;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%d\n",a);
return 0;
}
output?
A. M/C dependent
B. 513
C. 258
D. compiler error
programming-in-c non-gate
Selected Answer
A. Machine dependent.
x = (char *) &a;
a = 512;
x[0] = 1;
x[1] = 2;
Here, we modify the first and second bytes from the starting location of a. So, this modification depends on whether the
machine is little endian (LSB stored at lowest address) or big endian (MSB stored at lowest address).
Initial content of a
0 0x02 0 0
Final content of a
Initial content of a
0 0 0x02 0
Final content of a:
top
Please Explain.
programming-in-c
Now here see the analysis first we have a++ ,no issue we got a=5 ,now what I did is 5++ which is blunder since post-
increment returns rvalue and for any further operation I need lvalue for it ,therefore it is an error post-increment .
Also you can see that when we write a++ it is evaluated as a=a+1 ,but when we write 5++ it makes no sense since it
would be 5=5+1 ,which is invalid ,hence lvalue required
http://stackoverflow.com/questions/17440117/confused-with-pre-and-post-increment-operator
programming-in-c
Selected Answer
∗ is used for de-referencing and the operator & is used to get the address.
These operators cancel effect of each other when used one after another. We can apply them alternatively, any number of
times.
For example,
Find the output of the below program in case of Dynamic Scoping with call by need evaluation method
int x=10,y=10;
main()
int x=2;
int y=3;
fun1(x+y,5);
printf("x");
fun1(int z,int k)
k=z+k;
programming-in-c
I went through this article but couldn't get one point where it says that
"It only makes a difference if the integer is negative (for signed inputs) or between INT_MAX+1 and UINT_MAX (e.g. between 231 and 232-1). In that
case, if you use the %d specifier, you'll get a negative number, whereas if you use %u , you'll get a large positive number."
http://stackoverflow.com/questions/5208641/difference-between-printing-a-memory-address-using-u-and-d-in-c
programming-in-c
I'm explaining assuming int is of size 4, but only the minimum size of 2 is guaranteed by C standard. Still, in all real C
compilers, 4 is the default now.
With 4 bytes we have 32 bits for int. Now, if we have only unsigned integers, this corresponds to 0 − 23 2 − 1.
As shown in the above table as long as the most significant bit is 0, the number is positive and signed and unsigned
representation is the same. When we use "%d", the parameter is assumed to be in "signed representation" and when
we give "%u", the parameter is assumed to be in "unsigned representation". Since both representations are same as
long as the most significant bit is 0, we are safe to use both format specifiers for these range of values. But depending on
the type being passed to print, compiler might produce warnings.
NB: Format specifiers never do any type conversion. They simply assume the parameter as whichever type the format
tells. So, giving "%d" and passing a float value or vice versa produces unexpected result and not the int value of the
float.
#include <stdio.h>
func(a,b);
void main(){
printf("hello");
return 0;
}
here the code runs although it shows warning , so how is it that although func has no return type mentioned,it works .
Also the return type of main is void but I am returning a value 0 , so then why is there no error here ?
programming-in-c
First of all everything that is not correct is not ERROR in C. C language has evolved from 1970s and C89 (ANSI) was the
first standard followed by C99 and now C11. These standards were introduced based on current architectures to ensure
best performance for C code. But backward compatibility is always an issue and no one wants an old code just not
compiling.
Return type of a function is assumed to be "int" in C. But this assumption is removed from C99 standard on wards.
Compiler might not show error for this, but you can tell compiler to do this. See the compiler warnings for the above code:
gcc func.c
func.c:2:1: warning: data definition has no type or storage class
func(a,b);
^
func.c:2:1: warning: parameter names (without types) in function declaration
func.c: In function ‘main’:
func.c:6:1: warning: ‘return’ with a value, in function returning void
return 0;
^
so to rectify it we write :
int *ptr=(void*)9;
why is this stmt true , what happens on type casting this 9 to a void pointer type since 9 is an integer constant .
programming-in-c
Selected Answer
ptr = 9;
This is not an error. But it is not recommended to directly assign values to pointers as we cannot be sure of dereferencing
them as actual memory address using * operator.
int *ptr=(void*)9;
This also does the same job as above. Only difference is we explicitly typecast 9 as an address which would avoid compiler
warning.
So, both would work but both are to be avoided in good programming. If we need to use one, use the second one.
NB: These kind of questions are way out of GATE scope. You can see previous GATE questions here (see the ones with
GATEXXXX tags).
programming-in-c
Try to solve taking a list having loop in the list otherwise it will give true whether it is even or odd no of nodes in the list.
Now It will return false when loop is detected because pointer B runs twice fast than pointer A. So after sometime pointer
A will catch pointer B and B!=A become faulty and return false because there is B==null condition always faulty.Since
there is loop in the list then B can't have null.
s2 will be executed if
a)a <= b
b)b > c
Point here to be noted is that when I write if (a >b) now after this I haven't written any braces so anything written within
it would be considered as a single statement hence it is equivalent to if(a>b){ if (b < c) {s1 ;} else {s2 ;}
therefore clearly if s2 has to execute then we must have the condition a>b to be true simultaneously with b<=c , so
option D is correct .
#include<stdio.h>
int main(){
int test=0;
float a = 3424.34;
printf("hello \n %d",(test? a: 3));
return 0;
}
It is giving output as hello 0 ,I am unable to understand the logic for this so plz clarify this .
programming-in-c
Selected Answer
In ternary operator of type (x ? y : z), type of expression is type of y and z. If y and z don't have common type, then one
is converted to other (according to standard conversion rules) to make type same.
Now in your question, type of a is float, and type of 3 is int, so 3 is converted to float i.e. to 3.0, but you are printing a
float value with %d format specifier, which is undefined behavior, and hence the garbage value. Try %f instead if %d, it
will print correct value.
(a) Finds the hypotenuse of a triangle with sides a+2 and b+3
(b) Finds the square root of (a+2)2 and (b+3) 2
(c) Is invalid
(d) Find the square root of 3 *a+4*b+5
Selected Answer
hypotenuse(a+2,b+3)
int B[2][3];
int *p = B; // why this is wrong?
int (*p)[3] = B; // why this is correct?
programming-in-c
When you write B, then it is address of first element of B, Now first element of B is whole 1D array of 3 int, so address of
first element can be stored in pointer which points to whole 1D array of 3 int, which is int (*p)[3], not int *p.
21.59 Programming In C: why is the below code compile time error and not
run time error ? top gateoverflow.in/14746
#include<stdio.h>
int f();
int main()
{
f();
return 0;
}
programming-in-c
Your 2nd line is just function declaration .When gcc compiles these , it'd reference to actual function definition.
programming-in-c
Selected Answer
4- x-y-1
#include<stdio.h>
int f();
int main(){
printf("hello");
int a=f();
printf("%d",a);
return 0;
}
int f(){
main();
return 8;
}
Why is 8 not printed here? I am a bit confused that afterf returns, it returns 8, so a must be assigned 8. Then how come it is not getting printed?
programming-in-c
Because the print statement will never be executed. Until the stack overflow there will be call from main to function f and
vice-versa.
21.62 Programming In C: Why does the below code produces error when one
of its parameters have no data type associated with it ? top gateoverflow.in/14786
CASE A:
CASE A:
#include<stdio.h>
int divide( int a, b)
{ return 7; }
int main() {
int a=divide(8,3);
printf("%d",a);
return 0;
}
CASE B :
CASE B :
#include<stdio.h>
int divide( a, b)
{ return 7;
}
int main()
{ int a=divide(8,3);
printf("%d",a);
return 0; }
why is CASE A an error and CASE B error free , in CASE B acc to c99 standard it assumes the variables to be of type int but
then why not in case A , why is the type of b not considered to be of type int ?
in CASE B acc to c99 standard it assumes the variables to be of type int but then why not in case A , why is the type of b not
considered to be of type int ?
programming-in-c
One of the major changes in C99 standard is the removal of implicit 'int' and 'implicit function declaration'.
Ref: http://stackoverflow.com/questions/8220463/c-function-calls-understanding-the-implicit-int-rule
I could not get the exact rule for implicit int, but the following isn't the place where 'implicit' works as clear from the error.
Why worry about some stuff outdated in 1999? Currently we have to write declaration for all identifiers in C.
int divide( int a, b)
#include<stdio.h>
void main(void){
int shifty;
shifty=0570;
shifty=shifty>>4;
shifty=shifty<<6;
printf("the value of shifty is %o \n",shifty);
}
a) 15c0 b) 4300
c) 5700 d) 2700
programming-in-c
Selected Answer
Ans is D) 2700
If an integer constant starts with 0, it is considered an octal constant. So 0570 = 101 111 000 in binary as each octal digit
can be directly converted to 3 bits. Now, >>4 (right shift 4) gives 010 111 and <<6 (left shift 6) gives 010 111 000 000 =
2700 in octal. If we use "%d" in printf, this would be 1024+64*7 = 1472.
C problem takes a circular linked list as an input argument. It modifies the list by deleting the front node.
programming-in-c
After performing the operations before blank1 and blank2, you have to perform two finalizing tasks/operations :
1. *head = temp->next
2. free(temp);
I went through these two links and found that this behaviour is undefined , but the only issue which I have is that in one
sense we say that since local variables live on stack , hence they cannot be located on read only memory region but if this is
so then if I try to alter the value of the constant directly through assignment then why does it show error if it is not located
in the read only memory region :
#include
#include int main() { const int a=12; int *ptr ; ptr=&a; *ptr=8; // no error a=45; // error printf("\n %d", a); return 0; }
http://stackoverflow.com/questions/3801557/can-we-change-the-value-of-a-constant-through-pointers
programming-in-c
auto variables are in stack and there is no RO section inside stack, But compiler can do constant propagation and a constant variable might not have a
memory. This can throw a compile error or unexpected result.
http://www.geeksforgeeks.org/const-qualifier-in-c/
#include <stdio.h>
char str1[100];
char *fun(char str[]) {
static int i = 0;
if (*str)
{
fun(str+1);
str1[i] = *str;
i++;
}
return str1;
}
int main() {
char str[] = "GATE CS 2015 Mock Test";
printf("%s", fun(str));
return 0;
}
D)Segmentation Fault
i think answer should be option C.But the answer given as B.please explation how.
programming programming-in-c
Selected Answer
if (*str) {
fun(str+1); // Keeps calling fun with next character as argument
str1[i] = *str;
i++;
}
As long as we have a non-NUL character in *str, code keeps calling fun with (pointer to) next character as argument (and
nothing changes due to these callings).
When *str becomes NUL character, function returns str1 and ends, and now control goes to previously called instance of
fun(), which assigns character *str to str1[i]. Here *str is last character of string.
Note that, code doesn't insert NUL character explicitly in str1, but since str1 is global variable and so all characters are
zero, so str1 is printed correctly.
Q.43
4,500
4,501
5,500
3,500
made-easy programming-in-c
Ans is 3402.
http://codepad.org/7cUKSeRR
say I have a single linked list of 6 elements and I do some operation like
temp->link->link->link->link=p , Now assume that p is a pointer holding the address of third node whose data part is 3 and
link part is pointing to 4 th node , and let's assume that it has the base address of 300 .
Now assume that this entire LHS operation evaluates to the base address of 600 which is of the 6th node ,now my confusion
is that after this expression evaluates ,scene would be like
600 = p ,so now how come through this expression the link part of the 6th node starts pointing to the address held by the
pointer variable p ,i.e. how come this link points to 3rd variable ,plz clarify this .
programming-in-c
Now to explain more I assume C language and sizeof int 4 and size of pointer 8.
0600 = p.
And this is works just like a normal assignment but changes the structure of the list as shown in bottom table.
node5->next = p;
because in C language first operand of "=" operator must be an lvalue- 600 is not an lvalue but a constant. An lvalue can
be a non-const variable or a pointer but never a constant.
Now, it doesn't end here. I suppose no one will think above this during B.Tech. unless one makes a compiler himself. For
this reason Prof. Srikant Sir in IISc. still makes everyone of his course students make a compiler himself for taking
compiler course in IISc.
The thing to the last statement is p has an address as well as value. By definition of "=" in C language, the value of p is
copied to node5->next and not address. i.e., the value of right operand (rvalue) is copied to the address of left operand
(lvalue)- making it a necessity that left operand must have an address. This is all there to l and rvalues.
Now p has the value 0214 (third node address as given in question). So, the final list will be
Making a loop inside the list. Now the list looks like a smoking pipe as shown below (assume the bend is complete).
programming-in-c
func(int a[][6]) // This implies that a is going to an array of 6 columns ,right now we don't know the rows
fine ,but it is pointing to a 2D array .
I hope you are fine with this declaration. Here a will be having the address of first element a[0][0].
func(int (*a)[6]) //Now how is this notation correct for a to point to a 2D array since it implies that a is a
pointer to an array of 6 elements so that implies that it would be pointing to a 1D array .I am unable to get
the exact way in this pointer a would be pointing to the 2D array .
As you know passing an array is just sending Base address.
Now in given declaration "int (*a)[6]", as you have mentioned you can access the each row of 6 integers base
address.Once you will do (a+1) it will increment to next row base address and so on.
To access the each element of that row you have to just do like below
int *t;
t = a; // As you know a is a pointer to an array of 6 elements.
// It means it can have address to such array of 6 elements.
// we are assigning that base address to a integer pointer.
// Since integer pointer can hold the address of integer element.
// (i.e. first element of first array)
int i;
for( i =0;i<6;i++)
printf("%d", *(t+i);
This way you can access each elements of the 2-D array.
Find the output of a program, address of x is 2000(in decimal) and an integer requires 4 bytes of memory.
#include<stdio.h>
int main ()
{
unsigned int x[4][3]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3);
}
b)2012, 4, 2204
c)2036, 10, 10
d)2012, 4, 6
programming-in-c
int i=1,2,3 then why is this an error , how does comma acts here as a separator ,
programming-in-c
Selected Answer
That is how C grammar is written. In declaration and function argument list comma acts as separator but in expressions it
acts as comma operator.
int abc ;
int arr[abc] ;
printf("%d",sizeof(arr));
Now this abc holds some garbage value so then how come the size of the array is negative value , does it means that the
array arr is not allocated any memory space ?
programming-in-c
I executed same on unix machine and output is : 1504931616 . I am using 64bit unix O.S , gcc compile to run the
program .
U are getting negative it could be due randomness of the garbage values. That's why it's called garbage as there is no
such pattern which is followed in displaying values.
And moreover negative does not mean that address space is not allocated , negative may mean that the way variable are
stored .They could be stored in unsinged form.
programming-in-c
top
#include<stdio.h>
void main()
{
int index;
for(index=1;index<=5;index++)
{
printf("%d",index);
if(index==3)
continue;
}
}
a)1245
b)12345
c)12245
d)12354
programming-in-c
12345
int main() {
int a;
struct node *new=(struct node*) malloc(sizeof(struct node));
//printf("%p",new->link);
new->i=1;
new->link=NULL;
struct node *new1=(struct node*) malloc(sizeof(struct node));
new1->i=2;
new1->link=new;
struct node *new2=(struct node*) malloc(sizeof(struct node));
new2->i=3;
new2->link=new1;
struct node *temp;
temp=new2;
temp++;
printf("%d",temp->i);
return 0;
}
I am not getting that why is the op not 2 ,why is it showing some garbage value ?
programming-in-c
Selected Answer
It's because the way you are doing is wrong. You cannot get next value by incrementing like this.
Because Array provide contiguous memory allocation so there we can take advantage of storage organization and get next
object value by incrementing.
Since all the node new, new1 and new2 are not contiguously stored in memory so you can not get address of node which
is being pointed by incrementing the current node.
Actually the program output is correct, here once you are trying to increment to temp then its pointing to next memory
location with an increment of sizeof(struct node) but that is garbage because you have not initialized it.
by changing
temp++
to
temp = temp->link;
http://ideone.com/7qf0cV
main(){
int i=66;
printf("%d",sizeof(i));
programming programming-in-c
output will be 1.(size of i ) since pre processor is used as #define int char which change the int to char .
#include<stdio.h>
#include<math.h>
int main() {
double pi=3.1415926535;
int a=1;
int i;
for(i=0;i<3;i++)
if(a=cos(pi*i/2))
printf("%d",1);
else
printf("%d",0);
}
a. 0 0 0
b. 0 1 0
c. 1 0 1
d. 1 1 1
programming-in-c non-gate
if (a= something) means 'something' assigned to 'a' and it will return 'a' value (i.e. something) to if condition.
A. 0,0,1,2,3,4
B. 4,3,2,1,0
C. 4,3,2,1,0,0
D. 0,1,2,3,4
programming-in-c
char getstr(){
static char s[] = "GATE2016";
return s;
}
int main(){
printf("%s", getstr());
return 0;
}
Although I know I am returning an address using a character return type , and the return type must be char* getstr(); but
still if I do like this only then I am getting null on GCC compiler and segmentation fault on another compiler so what is the
programming-in-c
Selected Answer
Here is the assembly code (inside main) for the correct version with "char *"
Here is the assembly code (inside main) when "char *" is replaced with "char"
As we can see and as mentioned din the question, the change is that, due to the prototype of getstr being char, in the
second case, the returned value is truncated to just 8 bits. Now this 8 bits with higher bits padded with 0's or 1's (due to
sign extension and x64 calling convention) will be used as an address in the second case and that causes segmentation
fault.
i.e., suppose address of s in first case is 0x 4F A1 23 43, in second case this becomes 0x 00 00 00 43.
Even the above is not a strict guarantee as we are using a char (integer) as an address and there might be alignment
issue.
b=b-1;
if(b==0) return 1;
a=a+1;
return a+A(a,b);
Note that first parameter is passed by reference and second by value. What is the return value by A(x,x) where the value of
x is 5.
Confusion is that in C there is no order of evaluation of operands of a operator. So here, will the a value is calculated first or
is the function called...As per the ans they have used the modified value of a...is there a logic for this resolution of
operands...??
programming-in-c
Let a, b be two positive integers, which of the following options correctly relates / and %?
* I am getting answer as c but the answer given is b. Please tell me which one is correct.
programming programming-in-c
Check for
1) b = 1
2) a = b.
All the options except C) are dead on at least one of the above substitutions.
programming-in-c algorithms
Selected Answer
http://stackoverflow.com/questions/17721778/what-is-the-meaning-of-ax-1000-in-the-following-c-program
#include <stdio.h>
int main(){
int i = 4;
i = printf(" %d ", ++i) + printf(" %d ", i--);
printf(" %d ", i);
}
programming-in-c programming
main()
{
int i =300;
char *ptr=&i;
*++ptr=2;
printf("%d",i);
}
programming-in-c
Selected Answer
Here, we are modifying an integer variable using a char pointer. The modification happens to the second byte (from the
left of the starting location) and it is changed to 2.
i.e., 300 will be stored as (lower address on left) on a big endian machine
0 * 224 0 * 216 1 * 28 44 * 20
and as
44 * 20 1 * 28 0 * 216 0 *224
In both the cases using the char pointer we point to the starting byte. And we are incrementing the starting byte by 2.
0 * 224 2 * 216 1 * 28 44 * 20
44 * 20 2 * 28 0 * 216 0 *224
(This is the most common method of checking if an architecture is little endian or big endian)
#include<stdio.h>
#define decode(s,t,a,m,p,e,d)m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf("hello");
}
programming programming-in-c
There is no error. ## does string concatenation in a macro. So, macro will expand as follows:
So, the function name becomes main and program prints "hello"
in following program :
#include <stdio.h>
void f(char**);
int main()
{
char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" };
f(argv);
return 0;
}
void f(char **p)
{
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
}
programming-in-c
Selected Answer
if sizeof(int) = 2
then
t = (p += sizeof(int))[-1]
t = (p = p + 2)[-1]
t = *(p + 2 -1) = *(p+1) = address of second element i.e. 'cd'
if sizeof(int) = 4
then
t = (p += sizeof(int))[-1]
t = (p = p + 4)[-1]
t = *(p + 4 -1) = *(p+3) = address of forth element i.e. 'gh'.
Given a string,in which anything except digits are treated as separators, and between each set of separators,there is some
substring. count number of separators and substrings and return it with only 1 return statement
programming-in-c
#include <ctype.h>
int count (char * string)
{
int ret = 0;
if(string[0] != '\0')
{
if(!isdigit(string[0]))
{
ret = 1 + count(string[1]);
}
}
return ret;
}
This returns the number of separators, number of sub strings will be one plus the number of separators. Guess this is
what is meant in question.
21.88 Programming In C: try to print this in one loop itself. top gateoverflow.in/3998
try to print this in one loop itself.i have already done this in two loops(one nested into another).so please try to do in one
loop itself.
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
programming programming-in-c
Selected Answer
#include <stdio.h>
int main(int argc, char * argv[])
{
int i, j=1, k=1, n=atoi(argv[1]);
for(i = 1; j <= n; k++)
{
printf("%d ",i);
if(k == j)
{
k = 0; i = ++j;
printf("\n");
}
else i += j;
}
}
pattern(1,row*row); pattern(i,n)
{
if(i*i>n)
return;
else
{
for(k=i;k<=i*i;k=k+i)
print("%d",k);
print("/n");
pattern(i+1,n);
}
}
#include<stdio.h>
#include<conio.h>
int main()
{
int j=1;
for(int i =1; i<=5;i++)
{
if(i*j<=i*i)
{
printf("%d \t",i*j);
i--;
j=j+1;
}
else
{
printf("\n");
j=1;
}
}
getch();
return 0;
}
programming programming-in-c
*a++;
will be parsed as
*(a++);
Now a++, returns the content of a (which is an address to integer variable) and then increments a to hold the next
address (increments by sizeof(int))
So, *(a++) will return the content at the address contained in a. (since, a is pointer to int, this will return 4 bytes of data
from a assuming sizeof(int) is 4)
So, we can do
int *p, *a, b[2] = {1, 2}, c, d;
a = (int*) &b;
c = *a++;
d = *a;
Here c will get the value 1 and d will get the value 2.
If a is an integer pointer, we can also do (*a)++, which returns the value at the memory location in a and also increments
it.
when constant type variables cannot be modified then why do we consider them as lvalues , why not only r-values ?
programming-in-c
Selected Answer
Const type variables - examples "const int a" - are variables and they do have a memory location which makes them
lvalues.
String literals- example "hello world" - are lvalues as they have a memory location (stored in RO data segment).
int * p(void)
{
int *x;
*x=10;
return (x);
}
We create *x, and dereference it before assigning anything to it (x). Most likely, when we are declaring something on the stack, it will have a
random value. The assignment - *x = 10 will try to write the value 10 to whichever address the pointer is pointing to (i.e. the value of x itself)
, so then what's the issue i.e. when we can assign a value 10 at some random location pointed by x so then why does this result in
segmentation fault ?
programming-in-c
Good one. You told everything perfectly and the only question remaining is "why can't we write to some random location
in memory?". Well, that is due to OS protection. Suppose we write to a random location and changes the memory content
of some other process, that can crash rt? So, OS allows a process to modify only the memory allowed by it- in Segmented
memory managed systems, a process can only access the memory in its assigned segments and when it accesses a
memory outside that it gets segmentation fault.
In a uniprocess system this protection is not needed. One of the main uses of virtual memory in addition to extension of
memory address space is this memory protection.
#include <stdio.h>
char *c[] = {"GatsQuiz", "MCQ", "TEST", "QUIZ"};
char **cp[] = {c+3, c+2, c+1, c};
char ***cpp = cp;
int main()
{
printf("%s ", **++cpp);
printf("%s ", *--*++cpp+3);
printf("%s ", *cpp[-2]+3);
printf("%s ", cpp[-1][-1]+1);
return 0;
}
programming-in-c
i.e.from string 'MCQ' leave 1 character and print untill null encountered.
CQ will be printed.
21.92 Programming In C: please explain the reason for the "weird" false
condition coming out from for conditional checking. top gateoverflow.in/5531
In this program the TOTAL_ELEMENTS calculates properly when not used in for loop. And the first printf prints properly.
But why the 2nd printf is not working even if the condition in the loop is true. TOTAL_ELEMENTS returns 7.
#include<stdio.h>
int main()
{
int d;
printf("Total= %d\n", TOTAL_ELEMENTS);
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
return 0;
}
programming programming-in-c
Selected Answer
When we operate on two different data types, the smaller one is implicitly casted to bigger one. And between signed and
unsigned, unsigned is ranked higher.
http://gatecse.in/wiki/Chapter_2:_Data_Types_and_Operators_in_C#Implicit_Type_Conversion
In the definition of TOTAL_ELEMENTS, sizeof, returns unsigned int, and unsigned int divided by unsigned int returns
unsigned int. When compared with d, an integer, d is promoted to unsigned and becomes 2 n-1, where n is the number of
bits used for storing an int. So, the comparison here returns false.
21.93 Programming In C: What is the problem with this code? top gateoverflow.in/43281
#include<stdio.h>
int main()
{
char arr[10];
memset(arr,0,sizeof(arr));
gets(arr);
printf("\n The buffer entered is [%s]\n",arr);
return 0;
}
programming-in-c
Selected Answer
I do not think there is any problem in the code. Except gets() function does not check the size of array, for which it taking
the data. Hence that may create some problem. Other than that it will work fine.
int x=5;
void f()
{
x = x+50;
}
void g(h())
{
int x=10;
h();
print(x);
}
void main()
{
g(f());
print(x);
}
programming programming-in-c
Selected Answer
Deep/shallow binding makes sense only when a procedure can be passed as an argument to a function.
Deep binding binds the environment at the time a procedure is passed as an argument.
Shallow binding binds the environment at the time a procedure is actually called.
1. Deep binding.
f() gets the environment of main, since f() is passed as an argument in main. At the time of passing, x in main (the global
x) is 5. So, f changes the global x to 55, and g prints the local x as 10.
2. Shallow binding.
f() gets the environment of g at the time it is called. So, f changes the x in g to 10+50 = 60, and g prints the value 60.
21.95 Programming In C: What is the problem with this program? top gateoverflow.in/43282
The following program seg-faults (crashes) when user supplies input as ‘freeze’ while it works fine with input ‘zebra’. Why?
#include<stdio.h>
int main(int argc, char *argv[])
{
char *ptr = (char*)malloc(10);
if(NULL == ptr)
{
printf("\n Malloc failed \n");
return -1;
}
else if(argc == 1)
{
printf("\n Usage \n");
}
else
{
memset(ptr, 0, 10);
strncpy(ptr, argv[1], 9);
while(*ptr != 'z')
{
if(*ptr == '')
break;
else
ptr++;
}
if(*ptr == 'z')
{
printf("\n String contains 'z'\n");
// Do some more processing
}
free(ptr);
}
return 0;
}
programming-in-c
Selected Answer
The problem here is that the code changes the address in ‘ptr’ (by incrementing the ‘ptr’) inside the while loop. Now when
‘zebra’ is supplied as input, the while loop terminates before executing even once and so the argument passed to free() is
the same address as given by malloc(). But in case of ‘freeze’ the address held by ptr is updated inside the while loop and
hence incorrect address is passed to free() which causes the seg-fault or crash.
This question and solution is available at internet. before posting any questions please search on the google first. If you
could not get solution or if you could not understand the solution or if you think its really good questions then and only
then post. By the way it was a good que Thx.
programming-in-c programming
programming-in-c data-structure
1. If (z)
2. For (a, b, c)
3. While (a, b)
4. None of these.
programming-in-c
Selected Answer
D) None Of these .
As C language is case sensitive, it treats them as function declaration or function calling [depending where those used].
But this question has a typo with first letter as capital in each options then option is (b) because both option a and c has
no syntax error.
a) if(z) ' if ' can accepts integer identifier as well in place of logical expression.
b) This option is wrong because for(a,b,c) is not a correct syntax because for accepts semicolon ' ; ' not comma ' , '.
Why C language does not provide heap or garbage collection ?? Is there any higher level mechanism??
programming-in-c
==> We all know the phrase "necessity is mother of invention". The Concept of Garbage Collection was first
introduced by Games Gosling, when he developed the Java Language. Many don't know but the most important reason
behind the java development was Memory leaks problem. When James Gosling was working on a projects (named Green
Project and He was using C++ as Language) then he got frustrated by Memory leaks problem hence he thought to solve
this. And there is only one way to solve this memory leaks problem is to write another programming language. Hence
Garbage collection comes to reality. Most people think that Platform Independency was the most important reason behind
Java Development, but It was not the first thought when James Gosling was developing Java. Platform Independecy was
second thought. First Thought was Memory leaks.
==> No. C still does not provide any kind of Garbage Collection.
I had hoped that a garbage collector which could be optionally enabled would be part of C++0x, but there were enough technical problems that I
have to make do with just a detailed specification of how such a collector integrates with the rest of the language, if provided. As is the case with
essentially all C++0x features, an experimental implementation exists.
Please see the above link for a more detailed discussion on why GC is hard.
int main(void) {
char p[20];
char *s = "Gate015";
int length = strlen(s);
int i=0;
for(i=0;i<length;i++)
p[i]=s[length-i];
printf("%s",p);
return 0;
}
programming-in-c
Selected Answer
printf("%s",p);
%s prints all characters from the start address given by p till the first occurrence of '\0'; But p[0] = s[length - 0] = '\0';
So, nothing will be printed.
for(i=0;i<length;i++)
p[i]=s[length-i-1];
int main(){
int n=1,sum =0;
while(n<=10){
sum += n++*n++;
}
printf("Sum = %d\n",sum);
return 0
}
programming-in-c
Selected Answer
sum += n++*n++;
Here, the variable 'n' is modified more than once without an intermediate sequence point. So, the output comes under
"undefined behaviour" part and whatever code the compiler generate, we cannot say it is wrong. i.e., even if the program
outputs "0" compiler is correct and programmer is wrong.
Before writing C code one must know the rules of C. But people even write C book without knowing the rules of C :)
int main(){
swap(&str1,&str2);
printf("%s",str1);
printf("%s",str2);
if we replace str1[20] and str2[20] by *str1 and *str2. then string is swapped.but not in this case why?? please explain..
programming-in-c
Why 'count' variable value doesn't set to 0 on every call to 'incr' function?
algorithms programming-in-c
Selected Answer
here static int count= 0 means memory create for count for compile time only ..ans will be 15 only
at cal(0)= 0
at cal(1)= 1
at cal(2)=3
at cal(3)= 6
at cal(4)= 10
at cal(5)=15
Count is a static variable which allocates its memory in data segment unlike the usual stack . Therefore when a function is
called again the value still remains stored and it refers to the old location in data segment every time. Had count been a
local variable (int count =0 )it would be stored in stack and then every time function is called count would be allocated
different memory locations in stack since the activation records are different for each call of the function. Then what you
asked would have been true and j value would be 5.
1 int main() {
int b;
b = f(20,30);
printf("%d",b);
return 0;
}
int f(int a,int b){
int z;
z= a + b;
return z;
2 int main() {
int b;
b = f(20,'a');
printf("%d",b);
return 0;
}
int f(int a,char b){
int z;
z= a + b;
return z;
programming-in-c
Selected Answer
You are writing the function f() after main without declaring its prototype. Before main write int f(int,char); or write the
entire function f() before main(), in that case no prototype declaration is needed.
programming-in-c
Selected Answer
None of them not even giving any compiler warning even with strict C standard.
programming-in-c
Selected Answer
If you know C programming you don't need to study that for GATE :)
That is the same for all topics. I was good in C basics as I had done all my btech lab exercises in C and had tried to
understand any C question I found anywhere. So, never had any problem with C questions in GATE.
Now, if you are not comfortable with C, then again GATE is the best exam for you. Because there won't be any syntax
based questions in GATE. They have included C and not any other programming language because C covers most of the
"program language" techniques- pointers, parameter passing, scope, lifetime and data types. I guess most C questions
come from these portions. Understand these things from any standard book
(http://gatecse.in/wiki/Best_books_for_CSE#Programming_.26_Data_Structures) or from good online resource (not some
unauthorized blogs). And I believe previous year questions from GATE almost cover all the ares (not all the possible
questions- don't think studying all questions is any useful in GATE, but covering topics of questions is usually enough). You
can see previous questions in below link:
http://gateoverflow.in/tag/programming-in-c
A. 14,12,14
B. 13,12,13
C. 11,12,12
D. 14,14,14
programming-in-c
Please explain and give the postfix for the expression [ z=x++-y*b/a ].
programming-in-c
z =x++-y*b/a
= 5-(-10)*2/4
= 5-(-20)/4
= 5 - (-5) =10
for(i=0;i<10;i++)
printf("%d",i>>1);
for(i=0;i<10;i++)
printf("%d",i&1);
for(i=0;i<10;i++)
printf("%d",i&&1);
for(i=0;i>0;i--);
print("%d",i)
int i = 5;
i = (i, ++i, 1) + 1;
printf("%d\n", i);
OUTPUT
0011223344
0101010101
0111111111
i was trying to make a wrap around question . failed . output 0
2
programming-in-c
Selected Answer
1.
for (i=0;i<10;i++) printf ("%d",i>>1);
i = 0, Shift i value one bit right. so it will print 0.
i = 1, Shift i value one bit right. so it will print 0.
i = 2, Shift i value one bit right. so it will print 1.
i = 3, Shift i value one bit right. so it will print 1.
Do same for all i values..
3. for(i=0;i<10;i++) printf("%d",i&&1);
Used to Check i is NON zero or not. for Non zero i value it will print 1 and for i=0 it will print ).
even after i value become large (i Range exceeded) again i value reset to 0 and it will take forever i.e. Stackoverflow.
0011223344
so ,for i=0;i/2=0
for i=1,i/2=0
for i=2,i/2=1
for i=3,i/2=1
for 2nd ,
for
printf("%d",i&&1);
you get 011111111 and output where you check if first operand of AND is zero or not.so this is not a bitwise AND.
always remeber bitwise shift never ever modifies your orignal data
#include<stdio.h>
int main()
{
int x=3;
int const *ptr =&x;
printf("%d",++x);
printf("\n %d",++*ptr);
return 0;
}
I am unable to get that when x is a variable not a constant then how come the error is that the since ptr is a pointer to a
constant hence we cannot change its value, although ++x works fine, whats the logic behind this ?
programming-in-c non-gate
Selected Answer
Type of ptr is pointer to const int, hence it is an error for compiler if we try to change the value it is pointing to.
ptr is a pointer to a constant integer and hence we are not supposed to modify the pointed to value of ptr. This is
particularly useful when passing a pointer to a function and we want to ensure no modification to the pointed value
happens.
#include <stdio.h>
main()
{
static char*s[] = {"black","white","yellow","violet"};
char **ptr[]={s+3,s+2,s+1,s},***p;
p=ptr;
++P;
printf("%s",*--*++p+3);
}
et
ite
ck
yellow
programming-in-c
Selected Answer
main()
{
unsigned i = 3;
if(i > -1)
printf("Hell");
else
printf("Heaven");
}
Here since i is unsigned type....-1 should be converted to unsigned type for comparison..What would -1 be in unsigned ....or
with what value should i be compared in if(i > -1).....?
Plz explain...
programming-in-c
In C language unsigned int data type is ranked higher than signed and whenever two operands are of different ranks, they
are converted to the rank of the highest ranked type operand.
When a value with integer type is converted to another integer type other than _Bool,
So, here -1 is converted as per condition 2 above as follows (assuming 32 bit integers)
So, the comparison returns false. The only unsigned value for which the comparison (> changed to >=) returns true is
UINT_MAX.
#include<stdio.h>
#include<limits.h>
int main()
{
unsigned i = UINT_MAX;
if(i >= -1)
printf("Hell");
else
printf("Heaven");
return 0;
}
But, it is a real stupidity to compare a signed integer with an unsigned integer. This shows the programmer doesn't know
how to use data types.
int f(int);
int main() {
int b;
b = f(20);
printf("%d",b);
return 0;
}
int f(int a){
a>10 ?return(20):return 10;
}
programming-in-c
Selected Answer
The operator ?: works as follows expr1 is evaluated first if it is true expr2 is evaluated otherwise expr3 is evaluated.
According to K&R C, " Return statement can not be used in conditional operator".
Instead of
It is advisable to use
programming-in-c
Selected Answer
if(printf("Hello") != 5)
printf("Hello");
else
printf("World");
int main(){
int a = 4,b = 5,c = 6;
int k = ++a || ++b && c++;
printf("%d %d %d %d",a,b,c,k);
return 0;
}
o/p 5 5 6 1
Above code will not increment b and c why??even the precedence of logical And is more than logical Or
programming-in-c
Selected Answer
if && and || would have the same precedence, it would look like
Here, the second operand won't be evaluated if the first operand returns 0.
PS: Precedence just give the operands for operations (like giving paratheses). Actual execution order is not specified here
and depends on the language semantics.
int main() {
int i = 255;
char *p;
p = &i;
printf("%d", *p);
return 0;
}
Selected Answer
*p is passed to printf and only inside the printf "%d" comes in to play. So, if we pass only a byte for 'char' and we try to
print 4 bytes for 'int' (assuming 32 bit int), we might think result is undefined.
But, C standard says that char is indeed passed as int (as most architecture feature revolve around the size of int). And
while converting from char to int, sign extension is used- meaning sign bit is used for all higher order bits. Thus 255 here
would be passed to printf as 2^32 - 1 (all 1's). Now, %d gives -1, %u gives 2^32 -1 and %c would give the character
corresponding to (2^32 - 1) mod 256 = 255. (actually %c considers just the lower 8 bits and hence mod 256).
But we shouldn't use '%f' and it will give neither the int value converted to float nor the floating point representation
corresponding to that value. It'll just give garbage value on most occasion as printf would then be using floating point
register to read the value. C standard clearly says this- if the format specifiers are not matching with passed arguments,
behaviour is undefined. But character and integer are an exception, as in C character is just a 8 bit integer.
Also, here little endian and big endian would give same result.
(An advise- if you are learning C stuffs by running code, never use online compilers).
The answ depends on the arcitecture u are using and most probably it will output -1 now the logic is see that when u see
the type of the pointer is character hence it specifies that the pointer must access 8 bits of a particular location now those
8 bits on little endian actually shows the last 8 bits since representation of 255 would be (0...8 time ) (0...8 time ) (0...8
time ) (1...8 time ) now the pointer will point to these last 8 bits now since they all are 1's and we are using %d format
specifer hence it would be treated as signed now signed means MSB here is 1 hence negative now for calculating its
magintude complement all bits and then add 1 to it the magnitude would be 1 hence op would be -1 ,
It may give compile time error on some compilers and warning on some compilers.
programming-in-c non-gate
Selected Answer
It should print
xy
The first argument to printf is a pointer to character. printf now starts reading all characters from that pointer address
until '\0' is encountered. Before this if it finds any format specifier it reads further arguments and interprets them as per
the format specifier. Here, no format specifiers are given and so the last 2 arguments will be simply ignored.
21.117 Programming In C: what is the o/p please explain every step top gateoverflow.in/13205
main()
int i;
i=64/square(4);
printf("%d",i);
programming-in-c
Selected Answer
in this case : i=64/square(4) evaluate like this : i=64/4*4 ( because square(x) = x*x )
o/p will be 64
=> (64/4) *4
=> 64
recurrence-equation asymptotic-notations
n^2 logn
as the leading term of n^2+n*logn polynomial is n^2 ...and it will be some special case of masters theorem ...
http://cse.unl.edu/~choueiry/S06-235/files/MasterTheorem.pdf
Let P be a procedure that for some inputs call itself (i.e. recursive). If P is guaranteed to terminate, which of
the following must be true?
1. P has local variable
2. P has an execution path where it does not call itself
3. P either refers to a global variable or has atleast one parameter
1 only
2 only
1 and 2 only
2 and 3 only
recursion
but the thing garuntes is confusing since. a bad coder like me may go into infite loop with improper implemantion of aqbove
condition
programming-in-c recursion
int rec(int x)
{
static int f;
if(x == 1)
return(1);
else
f = f * 1 + rec(x-1) ;
return f ;
}
in this
f = f * 1 + rec(x-1) ;
is equal to writing f=f+rec(x-1) so f has to be computed when rec(x-1) value is returned to function
Since f is declared as static so it will be initialized to 0
so rec(5)=8
f=f+rec(4)=4+4
f=f+rec(3)=2+2
f=f+rec(2)=1+1
f=f+rec(1)=0+1 return (rec(1))=1
2)
int rec(int x)
{
static int f;
if(x == 1)
return(1);
else
f = f * x + rec(x-1) ;
return f ;
}
in this
f = f * x + rec(x-1) ;
here multiplication will be done first and then function will be called ,so returning value of function will not change the result
and thus changed value of f will not reflect.
Since f is declared as static so it will be initialized to 0
so rec(5)=1
f=f*x+rec(4)=0+1
f=f*x+rec(3)=0+1
f=f*x+rec(2)=0+1
f=f*x+rec(1)=0+1 return (rec(1))=1
#include<stdio.h>
int fun(int n)
{
int x=1,k;
if (n==1) {
return 1;
}
for (k=1;k<n;++k) {
x=x+fun(k)*fun(n-k);
} return x ;
}
int main()
{
int b,j;
b=5;
j=fun(b);
printf("%d",j);
return 0;
}
algorithms recursion
Selected Answer
http://gateoverflow.in/8060/gate2015-2_11
recursion recurrence
Selected Answer
So, we can have the recurrence relation for the sum of values being printed as
21.123 Recursion: How to solve recursion problem in less time? top gateoverflow.in/16814
I'm solving questions of recursion. But those problems are hard to debug in few minutes? Have you any such method that
solve recursive problem in less time? I have written problem below: please help me in this problem:
int fun(int n){
int x=1,k;
if(n==1) return x;
for(k=1; k<n;
x=x+fun(k)*fun(n-k);
return;
}
recursion
Selected Answer
Calculate the value of the function for smaller values first, then calculate for the next larger value, and so on.
For example, in this question, calculate in the sequence f(1) → f(2) → f(3) → f(4) → f(5)
If you try to calculate from top to bottom, you will end up evaluating the function for an exponential number of times.
So,
f(1) = 1
f(2) = 2
f(3) = 5
f(4) = 15
f(5) = 51
programming recursion
Selected Answer
I am getting 240.
Note that f is static, so its value will not change at each call and initialized to 0.
Now, backtrack:
since, f = f + x*rec(x-1)
rec(1)=>1
rec(2)=>f=0+2*1=2
rec(3)=>f=2+3*2=8
rec(4)=>f=8+4*8=40
rec(5)=>f=40+5*40=240
programming recursion
10 / 2 = 5
c which is not modified anywhere will be returned. It is garbage as auto variables are not initialized in C.
scope programming-in-c
You can find lots of those here: http://gateoverflow.in/tag/variable-binding. But this portion is not there for GATE 2016.
21.127 Sorting: Sorting array with elements in reverse order top gateoverflow.in/36647
Selected Answer
21.128 Sorting: If we have two sorted array of size 'a' and 'b' and "one array
smallest element is greater than largest element of other one".Then in the
merge procedure, what will be its time complexity? top gateoverflow.in/14157
P.S. Applied conditions given in " " is applicable on any(as per choice)
algorithms sorting
then the complexity will be O(a+b) because merge procedure isnt in place . And the comparisons required is min of a,b .
Given an unsorted array. The array has this property that every element in array is at most k distance from its position in sorted array where k is
a positive integer smaller than size of array. Which sorting algorithm can be easily modified for sorting this array and what is the obtainable time
complexity?
Answer: (B)
algorithms sorting
We have a heap..
To sort the given array,, we only have to convert that heap to either max heap or min heap...
Now,,
Elements are atmost k spaces apart we need logk time to move one element to its sorted place..
So for n elements,,
To get a sorted array from a max heap required time is order of n..
Method 1 :
It takes O(n) time to convert a infix expression into the postfix expression and only one left to right scan is enough to
compute the value of the expression which will take O(n) again.
Reference :
2] http://faculty.cs.niu.edu/~hutchins/csci241/eval.htm
Method 2 :
Alternative to method 1, you can also go for evaluation using two stacks, Operator stack & Operand stack.
consider the following infix expression which is to be converted to postfix expression using stack.
(((P+Q)*(R+S))/T)+(A*(B+C))
The sum of all unique possible heights of stack when converting infix to postfix is______
ans given:15
stack
Hight of stack is 6
If I write
#include<stdio.h>
int a;
main()
{
//code
}
programming-in-c storage-classes-in-c
Selected Answer
No, it is of static storage class because you have also defined variable here.
If you have written extern int a;, then it would have been of extern storage class.
Ref: http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/CONCEPT/storage_class.html
What is the difference between struct node* head= NULL and struct node* head= (struct node*)NULL ?
As NULL in C is #defined as
Andas c supports implicit type conversion so in case of struct node* head= NULL, from the (#define ) mentioned above
NULL will automatically be type-casted into (struct node*) NULL.
In the syllabus given by IISC, it just says Programming in C. But it doesn't mention about the subtopics.
As there are many topics are there in c like :
C - Overview
C - Environment Setup
C - Program Structure
C - Basic Syntax
C - Data Types
C - Variables
C - Constants
C - Storage Classes
C - Operators
C - Decision Making
C - Loops
C - Functions
C - Scope Rules
C - Arrays
C - Pointers
C - Strings
C - Structures
C - Unions
C - Bit Fields
C - Typedef
C - Input & Output
C - File I/O
C - Preprocessors
C - Header Files
C - Type Casting
C - Error Handling
C - Recursion
C - Variable Arguments
C - Memory Management
C - Command Line Arguments
syllabus
3.Advanced topics(Array,string,pointers,structure,union)
time-complexity
Selected Answer
main()
{
n=2^2^k, k>0
for(i = 1 to n)
{
j=2
while(j ≤ n)
{
j=j^2
}
}
}
programming time-complexity
Selected Answer
Θ(nk) = Θ(nloglogn)
time-complexity algorithms
21.137 Variable Binding: What is the difference between static scoping and
dynamic scoping? top gateoverflow.in/19381
programming variable-binding
Selected Answer
STATIC SCOPING
by default C is static scoping in this scoping firstly the value which going to be printed is looked in local scope if it is
present than the values will be printed if it is not present than the values will searched in STATIA AREA(i,e int a=10,b=2)
also when the program will complie the memory will be allocated to static area and these values will remain till the
program did not end .here is small example :
int a=10,b=2;
main()
int t=6;
printf(a,b,t); // here a=10 , b=2 ,t=6 will be printed becoz firstly it try to look within this red scope if it find these
values ,than these value will be printed but here it did n't find so it will print the static variables
( i,e nt a=10,b=2)
}
DYNAMIC SCOPING :
main()
{
int a=10,h=567;
d();
}
d()
int p=90;
printf(h,p); // p=9 will be printed and wt for h?? h is not present in the local scope so it will look in previous local
scope from where this d() is being called so here h will be printed as 567.
}
now if in above dynamic program if the int p=90 is not present than it will be looked in static area in case of STATIC
SCOPING but IN DYNAMIC SCOPING it will be looked up in the previous local scope from where the function is being
called..
21.138 How to find the number of height balanced nodes in a tree in O(n)
time ? top gateoverflow.in/42251
A node is height balanced if difference between height of left subtree and right subtree is either -1 , 0 or 1 , so how to count
such nodes , without maintaining any extra field in the node except for left and right child pointers .
Selected Answer
First we traverse the left subtree - let it return the height of it - say n1.
Traverse the right subtree - let it return its height - say n2.
Selected Answer
explanation pls
void main(){
float a;
a=6.7;
if(a==6.7)
printf("A");
else
printf("B");
}
Print B
here float is compared with long double condition become false.So B is Printed .
or
stack overflow occurs if the call stack pointer exceeds the stack bound. the program uses to store information during a
function call about where to return to. Each time you call a function, the CPU saves the location of what's currently
executing onto the stack, then jumps to the new function. When the function is done, it pops that location off the stack
and returns there. This is what makes recursion possible.
When a program attempts to use more space than is available on the call stack, typically resulting in a program crash.
Possible causes are Infinite recursion, Very deep recursion or Very large stack variables.
The actual size of the stack is completely platform-dependent. Many operating systems tend to limit the size of the stack
to a few megabytes, but allow that size to be changed. If the system runs out of virtual memory, this can also limit the
stack size. Some (much) older CPUs have a fixed-size stack (the Intel 8008 only has 7 stack entries).
If we run this program, compiler will print "Stack Overflow" until stack overflows.
#include<stdio.h>
int main()
{
printf("Stack Overflow");
main();
}
programming
Selected Answer
should be d
14 15 6 none
2nCn/n+1
=6C3/4
in c option
it says f(n)<=2n+10
here f(n)=2n-4
means
2n-4 <=2n+10
2n * 2-4 <=2n * 210
similarly for (a) option there exist a positive constant for which this function is theta of n hence true
also we can both are asymptotically equal so (a) option is true.
(b) option
f(n)>=n1000
2n-4 >=n1000
asymptotically we can say :2
n >=n1000
Main()
int a[2][3][2]={{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
Printf("%u",a);
Printf("%u",*a);
Printf("%u",**a);
Printf("%u",***a);
Printf("%u",a+1);
Printf("%u",*a+1);
Printf("%u",**a+1);
Printf("%u",***a+1);
Selected Answer
int a[2][3][2];
Printf("%u",a); //address of a
Printf("%u",***a+1); 2+1 = 3.
Which of the following data structures would programmer be least likely to use to implement an abstract data type that must
include an efficient implementation of the operation " find the maximum"?
a. Ordered array.
b. Binary search.
c. Heap.
d. Ordered linked list.
the answer should be d. ordered linked list.(if ordering is done in ascending order then it will take O(n) time to retrieve
max value as it need to traverse the link list)
//First Case
char *p, q[100];
p = "Hello"; //1
q = "Hello"; //2
//Second Case
char *p, q[100];
scanf("%s",p); //1
scanf("%s",q); //2
In the first case, 1st works but 2nd does not work. why?
In the second case, 1st does not work while 2nd work. why?
Selected Answer
//First Case
char *p, q[100];
p = "Hello"; //1
q = "Hello"; //2
//1 : Here compiler, allocates memory location for "Hello" in the memory and assigned base address of that memory
location to pointer p.
//2 : Here also compiler allocates memory for "Hello", But when it tries to assigned the base address to pointer q, then
compiler rejects that, because q is a constant pointer pointing to the array of size 100. Read any array chapter of any C
book, you will get the concepts.
//Second Case
char *p, q[100];
scanf("%s",p); //1
scanf("%s",q); //2
//1 : Here In this case compiler receives a string, but when it goes for memory location to put that string then it does not
get that memory location, hence it give error. To make it working we have to do the following.
char *p;
p = (char *) malloc(100*sizeof(char));
scanf("%s",p); //1
We want to reverse elements of stack using a queue. Suppose stack operations push and pop take 1 unit of time each and
queue operations insert and delete take 2 units of time each. Assume n elements are there in the stack .The minimum time
to reverse the stack is a) 4n units a) 6n units a) 8n units a) 9n units
Selected Answer
1. POP 1 element from stack i.e 1 unit of time & Enqueue in the queue i.e 2 unit of time
repeat five times till stack is empty So total time till here (1+2)* 5 = 15 unit time
2 Dequeue from queue i.e 2 unit of time and push into stack i.e 1 unit of time
repeat five times till queue is empty So total time till here (1+2)* 5 = 15 unit time
#include<stdio.h>
int main()
{ char *x;
x = (char *) &a;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%d\n",a);
return 0;
What is the output of above program? (a) Machine dependent (b) 513 (c) 258 (d) Compiler Error
x = (char *) &a;
you are trying to get the address of a identifier which have not declared and defined. Once you define a variable then only
compiler will allocate memory space to it and once you will have a memory allocated to it then only you can get the
address of that memory.
Once you are declaring 'a' output of program will be dependent on which machine you are running this program whether
its Big Endian/Little Endian.
Lets assume that you are using a machine which stores data in Little Endian format and integer is of size 4 bytes. So once
you are defining variable like below
int a;
It will allocate a 4 bytes to it. So for you have not assigned a value to it, this integer will contain a garbage value. Suppose
memory is byte addressable and memory allocated to int is starts with memory location 2012 - 2015 where location
2012th byte contain least significant bit of the 4 byte integer. (Here i have assumed little endian format. Check it for more
detail : http://williams.comp.ncat.edu/Endian.htm)
x = (char *) &a;
This way &a will represent the starting address of integer i.e. 2012 and once you are type casting it into char pointer still
char pointer x will hold the address 2012.
a = 512
It will assign the value to the integer as 512. Bit at 2012 to 2015 will look like
X[0] = 1
it will put 1 at the location (x+0) i.e. 2012 th byte will be changed to 00000001
x[1] = 2
it will put 2 at the location (x+1) i.e. 2013 th byte will be changed to 00000010
Now the complete memory from 2012 to 2015 will be look like
** That's what you have got. In case you would have using a machine which uses Big Endian format to store binary
numbers.
Then the value of 'a' would have become (00000000 00000010 00000010 00000001)2 = (131585) 10 .
#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
str_ref++; }
int main()
strcpy(str, "ravindras");
fun(&str);
puts(str);
free(str);
return 0; }
data-structure
Data structures can implement one or more particular abstract data types(ADT), which specify the operations that can be
performed on a data structure . A data structure is a concrete implementation of the specification provided by an ADT.
What will be the output of the following program assuming that parameter passing is
i. call by value
answer is 3 ?
No of non-negative integral solutions for x1 +x2 + x3 +.......x n = r where x1,x2,...x n >=0 is C(n+r-1,r).
x1+x2+x3 = 11 => (x1-1) + (x2-2) +(x3-3) = 5 => Y1 + Y2 +Y3 = 5 where Y1 = x1-1;Y2 = x2-2;Y3 = x3-3
Option C is correct
Option a is wrong -- Since you are rouding off the whole result of addition and not x
option d is -- You are converting an x into integer first then after adding with 0.5 you will again get a result as floating
value .
Selected Answer
abs function
SYNOPSIS
#include <stdlib.h>
int abs(int j);
long int labs(long int j);
long long int llabs(long long int j);
the height of tree is the length of the longest of the longest root to leaf path in it.the max and min no of
nodes of height 5 are_________
Selected Answer
so at h=5 ; n=2^6-1=63
The cost of optimal binary serch tree for the identifier set (a1,a2,a3) = (do , if , while ) with p(1) =0.3,p(2) =0.2, p(3) =
0.15, q(0) = 0.05,q(1) = 0.15,q(2) =0.1,q(3) =0.05 is ?
Consider a three dimensional array A[50][20][30] stored in linear array in column major order . If the base address starts at
1000, the location of A[20][10][10] is ..? (assume first element is stored at A[1][1][1])
Five nodes labeled 1,2,3,4,5 are used to construct different binary trees. How many such binary trees can
be constructed whose preorder traversal is 1,2,3,4,5?
Selected Answer
number of tree with labeled node=(2nCn/n+1)*n!(each number can arrange themself in n! ways that is why we are
multiplying with n!)
now if you label each structure then total 5! different trees are possible in each structure
But there will be only one tree which will produce preorder as 1,2,3,4,5
that means from each structure you will get only one tree which has preorder as 1,2,3,4,5
you try to draw a structure then you will get a clear idea
A simple undirected graph 'X' has 10 vertices.If 'X' has 5 equally sized connected components, the maximum no of edges in
the graph 'X' is_____
graph-theory
ans is 5.
no of egdes=k*(n/k-1)
T(n)=16T(n/4)+n!
Selected Answer
For Master theorem, a = 16, b = 4, nlogb a = nlog4 16 = n2 . Now, n2 is having a polynomial time difference with n!? yes, because
n3 = O(n!). So, we can say f(n) = n! = Ω nlogb a +ϵ . ( )
Now, this is Case 3 of Master theorem. But we need to show the regularity condition also for Case 3. i.e.,
n
af b
() ≤ cf(n).
Here, we get af
() ()
b
= 16f 4
= 16 4 !.
1
16
This should be less than cf(n) = cn!. Here, it is easy, take c = and we are done.
Actually we need not do all these in exam if we understand Master theorem properly. The case 1 of Master theorem is
saying the recurrence is mainly dependent on the recursive call but not on f. Case 2 is when the recurrence is dependent
on both. Case 3 is when the recurrence is dependent on f only. So, if we see that f is abnormally large like n!, we can
straight away write the complexity.
http://www.csd.uwo.ca/~moreno/CS433-CS9624/Resources/master.pdf
A simple undirected graph ‘X’ has 10 vertices. If ‘X’ has 5 equally sized connected components, the maximum number of edges
in graph ‘X’ is _________.
data-structure
Selected Answer
#define is a Macro. What is the meaning of Macro is that, it will replace the value at compile time. It means that
If we have defined
#define FIVE 5
When compiler compile the above line then it will replace FIVE with 5. The point I want to make here that Program replaces
Macro before starting the execution of the program.
Now comes to Question.
#define Rec(a) a + a * a
Rec(a)=a+a*a
Rec(a+1)=a+1+a+1*a+1
After compilation this line a = 20 + Rec(a) * Rec(a + 1); become convert into this:-
a=20+a+a*a * a+1+a+1*a+1
for a=3
value of a will be printed 58.
Selected Answer
Function add all digits of parameter and then return f(sum of digits)
If sum of digit is 9 then it will return 1 else 0.
int *(*func())[]
According to me , it means that its an array of pointers to functions which returns pointers of type int. Am I correct?
Selected Answer
For these type of complicated declarations, you can follow Clockwise/Spiral rule : http://c-
faq.com/decl/spiral.anderson.html
By that rule, func is a function taking no arguments and returning a pointer to an array of pointers to int.
Under which of the following conditions, the size of an one-dimensional array need to be specified ?
b) when it is a declaration
option d
Because,
Similarly when we use that as formal and actual parameter, we do not have to give the size. Compiler figure that out
automatically.
b) when it is a declaration
Q1:
If the array is 1-ordered, it means that It is an array of ascending order. This is the only chance that it can be of 1-
ordered.
It means that if array has 2N element and 1-ordered then its element can be of [1,2,3,4,5,...........,2N-1,2N].
Now an array can be 2-ordered only when its odd position is 1-ordered with odd position and even position is 1-ordered
with even position element. So it can be arranged like this. [N+1,1,N+2,2,N+3,3,N+4,4,N+5,5,..........,N-2,2N-2,N-1,2N-
1,N,2N].
So the maximum number of position difference can be N. ( See the First Element of both the array).
Q2:
The first element has to be <= the 3rd, 5th, ... elements by the 2-orderedness and <= the 4th,6th,... elements by the 3-
orderedness and the 2-orderedness combined. So it has to be in either the 1st or 2nd position.
Suppose that the first element (if any) not in its usual position is the kth element. Then it has to be in position k+1 by a
similar argument.
Now consider what must be in position k - it has to be k+1. If not it is bigger than k+1 and comes at least 2 before k+1 in
the list, acontradiction.
So at worst k,k+1 have swapped places. Then the first k+1 places can not effect the remainder of the list (as
they must all be less than any element in the remainder of the list) so we can repeat the same argument further on. Thus
the answer must be (d) i.e.1.
So the answer is (d).
programming
data-structure
One of the ways of solving Travelling Salesman Problem is by Dynamic Programming using Held-Karp algorithm.
For that only a 2-D array is used to store the values in a table for memoization.
How to calculate the static and dynamic value for the given program
top
+ precedes /
/ precedes -
- precedes *
Then correct stack priorities for +,*,^, / for correctly converting infix to postfix form?
21.171 The number of possible ordered trees with 3 nodes A,B,C top gateoverflow.in/19903
amount of time it would take to send 500 packets using 6-packet size window and without sliding window will be, when the
time to send in one direction is 5 ms
31000, 5000
4600, 21600
5000, 30000
a) int (**p) [ ];
b) int *(*p) ( );
c)int (*f( ) ) [ ];
d)int *f( ) [ ];
Selected Answer
Option D is invalid .
21.173 overloaded mean use same operator in multiple form basic mean shd
same then how a is ans shd b ans na top gateoverflow.in/12130
When a programming Language has the capacity to produce new datatype, it is called as
programming
Extensible Language
void main()
float a=55555;
printf("%.2E %.2e\n",a);
a)5.56E+004 8.12e+268
b)compilation error
c) runtime error
d)555.55E+002
void main()
int i=12345,j=0xabcd9,k=077777;
its actually
Please see this link it will even more clear your doubts : http://codingfox.com/4-2-formatting-output-using-printf/
main()
{
char line[80];
scanf("%[^,]s",line);
printf("\n%s",line);
}
Selected Answer
scanf("%[^,]s", line);
This reads every character till the first "," is given. So, if just "Dear students" is given the program will continue waiting
for input.
PS: These questions are not relevant for GATE. Format specifiers of printf is not in GATE syllabus.
Selected Answer
in fun() p is the copy of the main functions pointer p..hence any change in the pointer p in fun()...does not affect the
pointer p in main fun()...thus when fun() returns to the main fun()..that copy of the local variables and pointers gets
deleted..hence the pointer p keeps on pointing to r whose value is 20. Always remember-if we want to change a local
pointer of one function inside another function, then we must pass pointer to the pointer. By passing the pointer to the
pointer, we can change pointer to point to something else.
There are two arrays A and B having N/2 elements. The elements are stored in ascending order already . Merge these
arrays and create a new array C of size N . A code fragement is given. fill the missing part in it. the index variables have
initial value as zero
if(...........)
C[] =.......... ;
else
C[]=...........;
http://gpl4you.com/viewquestype.php?type=3&company=VIRTUSA
static variables are assigned memory during compile time. Hence they cannot be initialized with the result of a function
call- only compile time constants can be used to initialize them. So, invalid initialization.
Of the choices given, the most apt would be 'B' rvalue required. The error I got with gcc is
#ifndef include<stdio.h>
void main()
#endif
printf("%d",900*90/90);
Supposing include is not defined during compilation, the code should produce compile warning/error.
since #include<stdio.h> is not defined here, so the (#ifndef ...) statement will be true and whatever that is there inside
the #ifndef.....#endif construct, gets executed !
void main()
printf("%d", 900*90/90);
21.180 What is the output ? int x=8; x-=--x-x--; printf("%d",x); top gateoverflow.in/10942
programming
Selected Answer
There is a rule called "sequence point rule" in C. We are not allowed to modify a memory location more than once or read
and write the same location (reading other than for the purpose of getting a value to write) between two sequence points.
If we do this, the result is "Undefined".
Reference: http://gatecse.in/wiki/Undefined_Value
A stack is implemented as an array Stack of size N. TOS points to the current top of the stack . The initial value of TOS is -1.
The code for push operation for a value in stack is given. fill EMPTY BOX 1 and EMPTY BOX 2
Selected Answer
if (TOS < N)
Stack[++TOS] = value;
programming
Find output
main()
int i=0;
for(;i++;printf("%d",i));
printf("%d",i);
Plz explain
In condition part of for loop, i++ evaluates to 0, and thus control doesn't go into for loop.
So answer is (C) 1.
21.183 How to print the enter key character which gets stored inside the
buffer during scanning of a value into a variable ? top gateoverflow.in/13671
char ch;
scanf("%c",&ch) // after I do scanning of this variable then after I press enter key then it gets stored inside the buffer so can
we print this enter key .Since during the next call to scanf function the enter key gets stored inside the variable .
Do one more
scanf("%c", &ch)
printf("c", ch);
21.184 How does concatenation of 2 circular linked lists takes constant time
? top gateoverflow.in/13746
I am not getting that when head pointer has no information regarding the tail pointer then how is it that circular linked list
will have a constant time for its concatenation with another circular linked list , wouldn't it take same time if we perform
concatenation on a single or double linked list .
data-structure
You can easily concatenate two lists in O(1) time using either a single linked list or a doubly linked list, provided that you
have a pointer to the last node in at least one of the lists. (And, of course, pointers to the list heads.)
You can't do it with an array implementation, because you end up having to allocate more memory and copy the new
resulting list to it. Even if the array already has memory allocated, you still have to copy all of the new items to it. So it's
either O(m+n) or O(n) (where m and n are the lengths of the individual lists, respectively).
With a circularly linked list, you can easily concatenate them in O(1) time. It's just a matter of breaking a link in both lists,
and then hooking them together. This assumes, of course, that the order of items isn't especially important.
ref:http://stackoverflow.com/questions/25938499/linked-list-concatenation-in-o1-time
21.185 why is the time complexity of operations like isempty, isfull, size,
delete stack takes constant time ? top gateoverflow.in/13748
According to me when we perform the above operations we have to traverse the entire list so then why does it all take
constant time ?
data-structure
For all the standard stack operations (push, pop, isEmpty, size), the worst-case run-time complexity can be O(1). We say
can and not is because it is always possible to implement stacks with an underlying representation that is inefficient.
However, with the representations we have looked at (static array and a reasonable linked list) these operations take
constant time. It's obvious that size and isEmpty constant-time operations. push and pop are also O(1) because they only
work with one end of the data structure - the top of the stack. The upshot of all this is that stacks can and should be
implemented easily and efficiently.
ref:http://pages.cs.wisc.edu/~siff/CS367/Notes/stacks.html
stack data structure be like :1)STACK 2)STACK POINTER (points to top of stack) let's say stack starts from address AA1
and ends in KK1.initially stack pointer points to address (AA1-001)... ok now lets come to the operation isempty() if stack
pointer points to (AA1-001) isfull() if stack pointer points to KK1 size() STACK POINTER - AA1 delete() pop STACK[STACK
POINTER] and free[STACK POINTER] all of these operations take constant time
21.186 How does the for loop works wherein in all test condition and update
expression we have function calls ? top gateoverflow.in/13931
#include<stdio.h>
int fun()
{
static int num = 16;
return num--;
}
int main()
{
for(fun(); fun(); fun())
printf("%d ", fun());
return 0;
}
The three parts of for loop (separated by semicolon) are required to be expressions (technically, first part can be a
declaration, but that distinction is not required here)
First part is executed once. It evaluates to 16 (since num-- has postfix decrement operator, not prefix), and side-effect is
num becomes 15.
Second part is condition part, which, if non-zero, is true, otherwise false. Again fun() is called, and value of this condition
expression is 15 (and num becomes 14), which is non-zero and thus control goes into loop body.
In loop body, again fun() is called, which evaluates to 14 and 14 is printed, and num becomes 13.
In third part of for loop, fun() is called again, which evaluates to 13, and num becomes 12. The value 13 is ignored, and
then again condition part is checked. This continues and prints 11, 8 ,5, 2.
When 2 is printed, num becomes 1, then in third part of for loop, num becomes 0, and then condition part evaluates to 0,
and loop breaks.
So it prints 14 11 8 5 2
when is it possible in binary search tree that (preorder,inorder) ,(postorder,inorder),and (preorder,postorder) are
equal.please explain
see ,BST inorder will be always ascending order and If you have just preorder or postorder its enough to create a unique
BST .
incase of binary tree you need (preorder,inorder) ,(postorder,inorder) to create a unique binary tree . If we restrict 1 rule
that tree node will have either 0 or 2 children then for these 3 cases (preorder,inorder) ,(postorder,inorder),and
(preorder,postorder) it will give unique binary tree .
how static scoping and dynamic scoping works in c language.please explain every point which is helpfull for gate
C language is completely statically scoped. Dynamic scoping is not there in C but in GATE syllabus though not asked
recently. These are the previously asked question from this:
http://gateoverflow.in/tag/variable-binding
main(){
A) 3 3 1
B) 3 6 1
C) 6 6 1
D) 1 1 1
Plz explain
a[1][0][0]-a[0][0][0]=2-1=1
a[1][0]-a[0][0]=(address of a[1][0][0]- address of a[0][0][0])/size(int)=6*sizeof(int)/sizeof(int)=6;
(note: here a[1][0] is of type int *(i.e, starting address of 1D array or Integer pointer ) hence we divide by sizeof(int) )
a[1]-[0]=(address of a[1]-address of a[0])/ sizeof(int[2])=6*sizeof(int)/sizeof(int[2])=3
(note: here a[1] is of type int (*)[2](i.e, starting address of 2D array or pointer to a Integer array int[2]) hence we divide
by sizeof(int [2]) )
Hence the answer is B
I am unable to understand the implementation of stack using queue , I understood queue implementation using stack but
not this one , I searched for a video lecture too but found for implementation of queue only , so plz help in making me this
understand .
data-structure
http://www.geeksforgeeks.org/implement-stack-using-queue/
Selected Answer
If we see the 3rd sequence given. 911 > 360 and after this 950 came. So, this is an invalid sequence.
x=(int*)realloc(x,sizeof(int)*200);
c) realloc might throw null pointer exception if malloc fails to allocate memory.
#include <stdio.h>
int main(void) {
static char s[25]="TheCocaine Man";
int i=0;
char ch;
ch=s[++i];
printf("%c",ch);
ch=s[i++];
printf("%c \n",ch);
ch=i++[s];
printf("%c\n",ch);
ch=++i[s];
printf("%c ",ch);
return 0;
In second case --> ++i[S] is expanded to ++*(i+S) by the preprocessor. * and ++ both are unary operators and priority
are same for both. So they will go for Right to Left associativity. So first *(i+S) will be computed which equals "C" and
then is incremented to D
int i=0;
i++;
main()
main()
int i= 1, j=2;
programming
j =1 and i = 2.
main()
{
int x, y= 100;
float *P;
P=&y;
x=*P;
printf("%d", x);
}
what is output?
a) 100
b) 1
c) 0
d) none
programming non-gate
x = *P; //this line is problematic as it converts an integer (assuming it is a float) to float and then converts that float to
integer.
Now *P will return a float value (the content of the memory location of P will be treated as in IEEE single precision
format).
0 01001000 10000000000000000000000
[sign exponent mantissa]
So, this value will be 1.1 * 2^(72-127) which is a very small value close to 0 (127 is bias in IEEE repr.). When assigned to
an integer, it becomes 0 due to rounding.
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
char A[20];
A="gate";
d) none of these
programming
21.198 what does b=(int *)**c contain address or integer value? top gateoverflow.in/4928
O/p:2,2
main(void) {
char a,*b=&a,**c=&b;
a=2;
**c=2;
b=(int *)**c;
printf("%d %d",a,b);
return 0;
}
programming
char a,*b=&a,**c=&b;
a=2;
**c=2;
b=(int *)**c;
b = &a; b now contains 1000. (Don't get confused with * as it is part of char * and there is no dereferencing here)
**c = 2; //c contains 1001 and 1001 memory location now contains 1000. Since there is **, we go to memory location
1000, and because c is char**, a byte of memory storing 2 is copied to memory location 1000. (which makes a = 2)
b = (int *) **c;
**c returns 2 due to previous assignment. Now (int *) does a type conversion which makes 2 an address (nothing
happens here, compiler just treats 2 as an address). So, now b contains 2.
So, printf a,b, prints 2,2. But assigning integer values to pointers is a bad because dereferencing that location using *,
should result in segmentation fault as that shouldn't be a valid memory location.
'\r' is no more useful in C. It is supposed to take the output to the beginning of a line (useful in typewriters), but C just
outputs this character to the terminal. Now, the terminal must decide what to do with this. Most current terminals just
ignore this.
def brian(n):
count = 0
while ( n != 0 )
n = n & ( n-1 )
count = count + 1
return count
Here n is meant to be an unsigned integer. The operator & considers its arguments in binary and computes their bit wise
AND. For example, 22 & 15 gives 6, because the binary (say 8-bit) representation of 22 is 00010110 and the binary
representation of 15 is 00001111, and the bit-wise AND of these binary strings is 00000110, which is the binary
programming normal
Selected Answer
Each time we & a number n with (n − 1) the 1 at the least significant bit position of the binary representation of the number
changes to 0.
This is because when we subtract a 1, the least significant bit always changes. If it was 1, it changes to 0 and if it was 0, it
changes to 1. If the change is 1 -> 0, no other bits are affected. So, the result of (n & (n-1)) will be n with its last bit as 0.
Now, if the change is 0 -> 1, this would mean all the bits to the left till the next 1 are complemented for n − 1 (consider 8
and 7 whose binary representations are 1000 and 0111). So, when we do (n & (n-1)), all the bits towards right from the
least significant 1 in the number become 0. So, in both the cases when we do (n & (n-1)), the least significant 1 changes
to 0.
Thus, the above code is doing nothing other than counting the number of 1's in the binary representation of the given
number. This is an efficient way as the loop runs only for O(k) where k is the number of 1's in the given number as
compared to O(d) where d is the number of bits in the given number for a normal code doing the same purpose.
Various parameter passing mechanisms have been in used in different programming languages. Which of the following
statements is true?
(a) Call by value result is used in language Ada
(b) Call by value result is the same as call by name.
(c) Call by value is the most robust.
(d) Call by reference is the same as call by name.
(e) Call by name is the most efficient.
Selected Answer
(a) is true. Ada supports in-out parameter passing, which is nothing other than call by value result (but Ada in GATE
syllabus?)
(b) Not true.
(c) Most robust? I don't know what is meant by robust here.
(d) Not true.
(e) Not true. Because in call by name, the parameter is re-evaluated at every occurrence of the formal paramater and
hence efficiency will only be less.
Reference:
http://courses.cs.washington.edu/courses/cse341/03wi/imperative/parameters.html
programming easy
Selected Answer
result in unstructured code and there can be blocks with multiple entry and exit points which can cause a nightmare for program verification.
21.202 How to represent int a=7 in little endian architecture computer. gateoverflow.in/297
top
00000111000000000000000000000000
This will be the representation of int a = 7, assuming sizeof int is 4 bytes and a little endian machine (start address of
memory is from the left).
programming
str = "Gate2015";
In memory
1000: G
1001: a
....
1007: 5
1008: \0
what are the reasons to use unions or not to use unions in C?why unions in ada are better than C implementation ?
Selected Answer
Use unions to save memory. Currently when we have so much of memory space in systems, there is no point in using a
union. But it is still useful in embedded systems.
Ada has better implementation for union? That can't be true. Because C doesn't specify how a union must be
implemented. And being so simple and close to hardware language is C, no language other than Assembly, written by
some really really great programmer can outperform a C code compiled by a decent C compiler. So, "better than C" can
mean ease to use, not "better in performance".
class Codechef {
right to left...so
++k + 1 + 2;
3 ++k increments k and uses that value (++2) returning 3 3 + 1 + 2; //k
is 3
4.now, go left to right: so, 3 + 1 + 2 = 6
BUT, according to the book, the expression is "parsed as ( (++k) +
int k=1;
(((++k) + (k++)) + (+k)); //++k has the highest priority and hence () put over that, then (k++) and (+k). Arithmetic + has the
least priority here and it's associativity is from left to right.
Precedence just groups the operands to operator and it is not telling the evaluation order of operations. Evaluation order
depends on language semantics and varies from language to language. In Java, evaluation order is strictly from left to right
where as in C, it depends on the operator and defined sequence points. (The same statement in C produces undefined
behaviour).
++k, returns 2
k++ returns 2
+k returns 3
So, 2 + 2 + 3 = 7.
When associativity computed, the value is not evaluated (in compiler phases). In compiler phase the associativity is
computed based on the grammar parsed in syntax analysis.
Step1: Operating precedence table helps to compute the precedence relation and based on those relations associativity
assigned as follows before converting into three address translation.
x= (++k) + (k++) + (+k); // this is only possible way to give associativity based on precedence rules and syntax rules.
Note: Do not try to evaluate the expression because still this code is in high level.
Step2: Now convert this code into three address code as follows:
Find number of pre-increments and post increments: one preicrement and one post increment.
k= k+1;
t1=k+k;
t2=t1+k; // this instuction and above instuction is similar to t2 = k + k + k where k is already incremented once.
Step 3: Above instructions are result of 3-Address code. Now evaluate run time using assembly instructions, you will get
answer 7 when k=1 initially.
a. 10
b. −9
c. 15
d. Error.
follow the operator precedence rules . you will get ans 10. Product(x+4,y-3) expands to x + 4 * y - 3 => 5 + (4 * 2) - 3
=> (5 + 8) - 3 =10.
Instead of macro if you had used normal function like this
int product(int a, int b)
{
return a*b;
}
then the answer will be -9
Does any one know the formula for Row major order and column major order of symmetric square band matrix
#include<stdio.h>
int main(){
int a = 320;
char *ptr;
printf("%d ",*ptr);
return 0;
(A) 2
(B) 320
(C) 64
1000 -->01000000
1001 -->00000001
Since typecasting is done and ptr is a char pointer hence it will display only 1 Byte data i.e. data at loc 1000
a) 0.5 * i(i+1)j
b)i+j
c) i(i+1)j
http://gateoverflow.in/2452/gate1994_1-11
21.210 If memory for the run-time stack is only 150 cells (words) how big
can N be in Factorial(N) before encountering Stack overflow? top gateoverflow.in/8962
options are:
a)24
b)15
c)66
d)50
In the best case, we need to pass a parameter to a function and we need to save the return address. Assuming sizeof (int)
takes word size, this would mean, 2 words. And in factorial (N) there will be N-1 recursive calls so for say N = 76, surely
there will be stack overflow.
But to realize how stupid my explanation is and also the question, please see here:
http://www.tenouk.com/Bufferoverflowc/Bufferoverflow2a.html
21.211 What will be the output for f(p,p), if p is initialized to 4. top gateoverflow.in/5198
{
c=c-1;
if(c==0) return 1;
x=x+1;
return f(x,c) * x;
}
What will be the output for f(p,p), if p is initialized to 4.
http://gateoverflow.in/60/gate2013_42
21.212 number of v's that are pushed more than once in a dfs? top gateoverflow.in/5296
I start from vertex 6 , so vertex 6 is pushed onto stack. After that by DFS , we can have two options either vertex 3 or
vertex 8 . Let's say we choose vertex 3 , so vertex 3 is pushed onto the stack. then vertex 1 is pushed ( I choose vertex 1
over vertex 7 ). Then vertex 2 is pushed.Now , I can choose either vertex 4 or vertex 5. Say I choose vertex 5. Now ,
vertex 8 is chosen.
Now , from vertex 8 , I can choose either vertex 4 or vertex 7 .If I choose vertex 4 , then already vertex 2 is selected. So ,
I need to backtrack.
then for second expression it is ((14-8)/9)*3 = (6/9)*3 = 0*3 (integer division 6/9 is zero.) = 0
then for second expression it is ((15-8)/9)*3 = (7/9)*2 = 0*3 (integer division 7/9 is zero.) = 0
D> is not the answer cause let's say (y-8) = 3K (K belongs to integer).
then for second expression it is ((3K)/9)*3 = (K/3)*3 not equal to K for say (k=5 in integer division)
Let S be a stack k of size n > 1. Starting with the empty stack, suppose we push the
first n natural numbers in sequence, and then perform n pop operations. Assume
that Push and Pop operation take X seconds each , and Y seconds elapse between
the end of the one such stack operation and the start of the next operation. For
m > 1, define the stack-life of mcs the time elapsed from the end or Push (m) to
the start of the pop operation that removes m from S . The average stack-life of
an element of this stack is
(A) n(X+Y) (B) 3Y+2X
(C) n(X+Y)-X (D) Y+ 2X
here numbers are entered in natural order from 1,2,---------n these are coming in AP so simply do this.... first first
element 1... n-1 nelements has to push and n-1 elements has to pop so total time=2(n-1)X and b/w each y sec elapse so
total elapse=[2(n-1)+1]Y.
21.215 Which of the the above functions are likely to cause problem with
pointers? top gateoverflow.in/13940
int *f1(void){
int x=10;
return (&x);
int *f2(void){
int *ptr;
*ptr=10;
return ptr;
int *f3(void)
int *ptr;
ptr=(int*)malloc(sizeof(int));
return ptr;
Which of the above 3 functions is/are likely to cause problem with pointers?
f1 can cause problem because it is returning address of local variable x. After the function call, memory location of x get
free and accessing that memory location can crash the program.
In f2, ptr is a wild pointer and dereferencing a wild pointer can crash the program.
f3 is fine.
21.216 what is the utility of variables declared using extern keyowrd ? gateoverflow.in/13962
top
Case A :
#include <stdio.h>
extern int i; //extern variable
int main(){
printf("%d",i);
return 0;
}
Case B :
#include <stdio.h>
int i; //By default it is extern variable
int main(){
printf("%d",i);
return 0;
}
Now my ques is that what is the utility of just declaring a variable when in any of the functions we can neither modify it or
access it .
Also one more confusion is that when we declare any variable with storage class extern then it is initialized to 0 but here in
Case A , we have simply declared the variable using extern no memory allocation has been done so then how come that it
gets initialized to 0 , its only the case when I dnt use extern implicitly that the variable gets the value 0 so then whats the
utility , except for the case when I have actually initalized it like extern int y=90 ;
extern int a; // a is having memory in some other file (global variable in some other file) and that might be known only at
link time.
int a; // when we declare like this in global scope, a is given a memory and by default all global and static int variables are
initialized to 0. This global variable is also visible to other compilation units (they must use extern to access it).
So, extern is a way for a compilation unit to access a global variable in another unit. Both are related.
So, now what is the use of static? - If we want to declare something in the global scope and not want other compilation
units to use it using extern, then we use static.
static- has full life scope as global, but visible only in the current compilation unit (usually a file).
Use
gcc -c file.c -o file.o
to compile a C file without linking. This way different parts of a program can be compiled separately. Finally
getting ans 61
http://gateoverflow.in/1310/gate2009_18
What it means ?
int (*p)[R][C];
#include <stdio.h>
int main()
{
int a[][3] = {1, 2, 3, 4, 5, 6};
int (*ptr)[3] = a;
printf("%d %d ", (*ptr)[1], (*ptr)[2]);
++ptr;
printf("%d %d\n", (*ptr)[1], (*ptr)[2]);
return 0;
}
op=2 3 5 6
(*ptr)[0]=1
(*ptr)[1]=2
(*ptr)[2] =3
so,
(*ptr)[0]=4
(*ptr)[1]=5
(*ptr)[2] =6
Consider the C function given below. Assume that the array listA contains n (> 0) elements, sorted in ascending
order.
int ProcessArray(int *listA, int x, int n)
{
int i, j, k;
i = 0;
j = n-1;
do
{
k = (i+j)/2;
if (x ≤ listA[k])
j = k-1;
if (listA[k] ≤ x)
i = k+1;
}
while (i ≤ j);
if (listA[k] = = x)
return(k);
else
return -1;
}
Which one of the following statements about the function ProcessArray is CORRECT?
(a) It will run into an infinite loop when x is not in listA.
(b) It is an implementation of binary search.
(c) It will always find the maximum element in listA.
(d) It will return −1 even when x is present in listA
http://gateoverflow.in/2076/gate2014-3_42
x = x & (x-1)
what is the significance of the value in the integer pointed to by j when the function completes..
http://gateoverflow.in/?qa=blob&qa_blobid=15647475923541120156
How can i solve a DFA which is divisible by 3 with the states ( like - state q0 ,return q1 ) in java programming language.
if it is multiple of 3 return Q0
ELSE Q1; this is logic and more if you have knowledge string handling in java it is simpler.
We are given a set of n distinct elements and an unlabeled binary tree with n nodes. In how many ways can we populate the tree with
the given set so that it becomes a binary search tree?
A) 0
B) 1
C) n!
D) (1/(n+1)).2nCn
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void fun(char** str_ref)
{
str_ref++;
}
int main()
{
char *str = (void *)malloc(100*sizeof(char));
strcpy(str, "gate2016");
fun(&str);
puts(str);
free(str);
return 0;
}
op gate2016
please explain ?
int main()
{
static int i=5;
if(--i)
{
main();
printf("%d ",i);
}
op = 0000
Selected Answer
int main()
{
static int i=5; // only one time memory declare use same remaining time.
if(--i) //start decreasing value of i by 1 at a time
{
main(); this happen before printing function means when i becomes 0 then all printf will start printing
printf("%d ",i);
}
Reason is :
If I assume size of integer is 4 Byte , then this above line will increment the pointer to
(&a)+1 will be simple - it will point to next entry in array from the base address.
You can refer to this snippet if you want to play around various test cases regarding this problem
http://code.geeksforgeeks.org/4rzf87
C.Garbage Value
Printf returns the number of characters written on console successfully.
Here, without variable printf will pull any random data from the stack. Thus if condition will become true and loop will halt!
http://ideone.com/06HF02
http://stackoverflow.com/questions/437816/behaviour-of-printf-when-printing-a-d-without-supplying-variable-name
Consider the following program fragment: char c= ‘a’ while (c++ ≤ ‘z’) putchar (xxx);
Now c++ update the pointer and pointing to the next location, i.e. location of 'b'
In a hash table of size 6 currently the locations 0,2,4 and 5 are occupied. The probability of a new record going into location
1 with a hash function resolving collisions by linear probing is (assume uniform hashing)
a)2/3
b)1/3
c)1
d) 1/6
Selected Answer
OPTION A
With uniform probability 1/6 ,it may go to any of the slot numbered 1 , 0 , 4, 5 {In any of these case it will end up in slot
1 , with linear probing.}
1 1 1 1 4 2
I got HEAP DS as a ADT(abstract data type). Means i can perform few operations on it like getMin(),getMax(),deleteRoot()
etc.
So if i have to get 2nd smallest in min heap then it will be in 2nd level definitely. so should i approach it as make a level
order traversal and get it in O(1) time. or i should take it as standard way like delete root, hepify ,getRoot() ,insert() deleted
item=O(2Logn) ?
I found a prev. gate question as find 7th min in min heap, and all answers are O(1).
in a heap only getmin() or getmax(), insertion can be performed. if u are doing any other operation , then the ds cannot
be treated as heap. so you should use only getmin() 7 times to get 7th minimum element
the given ans is (d) but it will run forever as ch is character type and can have max value 255 and then it will be reset. also
char would be implicitly typecasted to int so comparison is valid. why would it give compilation error
Selected Answer
int main()
{
extern int i;
printf("%d ", i);
{
int i = 10;
printf("%d ", i);
}
}
(a) 0 10 (b) Compiler Error
(c) 0 0 (d) 10 10
ans b
http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
int main()
{
extern int i;// here compiler has expecting that 'i' is already defined in some file but is has not defined thats why we are
getting compiler Error
printf("%d ", i);
{
int i = 10;
printf("%d ", i);
}
}
answer is option B
int main()
{
extern int i;
printf("%d ", i);
{ // what is this thats y compiler error.
int i = 10;
printf("%d ", i);
}
}
x is array of 20 pointer to function passing a pointer 'a' to integer returning pointer to float.
For more info you can go this url
http://unixwiz.net/techtips/reading-cdecl.html
begin
x:=x+1;
end;
begin
x:=5;
A(y);
write(y)
end;
int x=0,i;
for(i=0;i<10;i++)
if(i%2&&x++)
x=+2;
i=0 x=0
i=1 x=1
i=3 x=4
i=5 x=7
i=7 x=10
i=9 x=13
when i is even i%2 is false.
x=13 is the answer.
int x, y= 2, z, a;
printf(“%d”, x);
(a) prints 8
(b) prints 6
Suppose graph G has minimum spanning tree computed.How quickly can we update minimum spanning tree if we add new
vertex and incident edges to G?
Adding vertex and incident edges to minimum.spanning tree we get a graph.Check for cycles in graph and remove max
edge from each cycle..this will give new spanning tree
21.241 How to evaluate the remainder when we have a negative divisor? top
gateoverflow.in/15986
main( ){ int i=-4, j, num=10; j = i % -3; j = j?0: num*num; printf(“j = %d”, j); }
I tried with the formula Dividend = (Quotient × Divisor) + Remainder, but got confused.
the right answer is according to c99 specification the whenever we do % operation this thing holds. that is
(a/b)*b+a%b should be equal to a . so here
-4/-3=1
1*(-3)+ a%b=-4
21.242 Fill up the blank in the following code for retrieving the element top
gateoverflow.in/16211
A matrix X of order (N × N) is stored in an array indexed from 0 to 2N − 2, by first storing the diagonal, followed by anti
diagonal.
Fill up the blank in the following code for retrieving the element.
a) A[N + i]
b) A[i − 1]
c) A[N + i − 1]
d) A[N − i + 1]
Question is nothing but store all diagonal(principal as well as anti diagonal) element in an array. So total n diagonal + n-1
anti diagonal element. we have to store total 2n-1element. Array size should be 2n-1 but starting from 0 It will go upto
2n-1. Final array is something like A[0.1.2........2n-2].
now question,
int main(void) { char *p = "arjun"; *(p+3) = 'a'; char arr[] = "arjun"; arr[3] = 'a'; printf("%c",arr[3]); printf("%c",*(
I am trying to modify a string. It works fine when string is declared via array but it is giving runtime error when string is
declared via pointer. Reason ??
In the question it is mentioned "string constant" and that is the reason. A constant cannot be modified.
char *p = "arjun";
Here, "arjun" is a string constant which is usually stored in Read Only Data section and p contains the address of its start.
So, trying to modify the content of "arjun" causes segmentation fault- writing to a segment which is RO- (an example of a
segmentation fault which can occur even with a TLB hit). Other string constants like "%c" used in the above code are also
stored in RO data section.
Now,
char arr[] = "arjun";
Here also "arjun" is a string constant, but arr[] is an array and the initialization causes 6 bytes to be allocated for arr, each
containing the characters 'a', 'r', 'j', 'u', 'n' and '\0' ('\0' is added at end of all string literals by the compiler). So, here we
are free to modify the contents of arr.
The minimum number of temporary variables needed to swap the contents of two variables is:
(a) 1 (b) 2
(c) 3 (d) 0
programming
Selected Answer
var a ,b;
a=a+b;
b=a-b;
a=a-b;
or
a=a*b;
b=a/b;
a=a/b;
no temporary variables is needed
21.245 How to calculate the sum of money in the below question ? top gateoverflow.in/15415
The sum of money in kept in a bank amounts to 1240 in 4 yrs and Rs 1600 in 10 yrs at Simple interst . then how to find sum
?
I formed an AP
1240= a+(4-1)d
1600= a+(10-1) d
If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the
variable should be declared as (a) extern (b) static ( c) volatile (d) const
the answer is b . Static memebers of a class share same memory by all the object. if u want to check just make a class
and define a variable static in it . else if u don't want to type here u go . check this post . http://www.learncpp.com/cpp-
tutorial/811-static-member-variables/
21.247 How does the function return in the below code ? top gateoverflow.in/14065
#include <stdio.h>
void e(int);
int main()
{
int a = 3;
e(a);
putchar('\n');
return 0; }
void e(int n)
{
if (n > 0)
{
e(--n);
printf("%d ", n);
e(--n);
}
}
I am not getting here that when e(0) is called how is the code executed ?
when e(0) is called, if condition becomes false, and control doesn't go into if block, and simply returned from e() function.
21.248 How is the comma operator evaluated in the below code ? top gateoverflow.in/14066
#include<stdio.h>
int main()
{
int a = 2;
if(a == (1,2))
printf("Hello");
if(a == 1,2)
printf("World");
return 0;
}
I am having just one confusion in this that why is it that World is getting printed here when a=2 and when the second
comma operator executes since the precedence of == is greater and its associativity is from left to right so then a==1
,condition false hence World should not be printed then why is it getting printed here ?
You are right, In second "if", a==1 evaluates to false, which is 0. So if(a==1,2) becomes if(0,2).
Now 0,2 evaluates to 2, so condition in "if" becomes true, and "world" is printed.
Also note that here associativity plays role only when operators are of equal precedence, here == has higher precedence
than comma operator, so (a==1,2) is binded as ((a==1),2).
21.249 How many stacks are required for converting an infix expression to
postfix expression involving inbuilt functions ? top gateoverflow.in/14156
If any infix expression has embedded function calls in it then how many stacks will it require for computing postfix expression , does it depend on the number of
function calls in it +1 for computing other operands ?
Why do you need extra stack for function calls. For example, if infix expression is f() + g(), then we can simply write it as
f()g()+ in postfix notation using just one stack, as normally done.
21.250 Is the size of a struct variable always equal to the size of its data
members ? top gateoverflow.in/14259
1. VALID
2.Can't say
Selected Answer
which of the following is not represented in a subroutine's activation record frame for a stack-based programming language?
b)Return address
c)Heap area
Answer is Heap Area since even if u dynamically allocate a memory region inside a function still that memory area won't
be created inside the stack frame of that segment , it would be created in the heap region so even if u exit from the
function without freeing the dynamically created node , it would be still persisting in the heap memory region .
which of the following class of statement usually produces no executable code when compiled?
a)declaration
b)assignment statements
d)structural statements
After compilation of the program, we could not identify the structure of the program. Since, after intermediate code
generation we lost the structure of the program (you could not identify where the loop is? or other similar stuffs). So,
correct option must be D.
following statment
printf("%f",9/5);
prints
Selected Answer
The reason is pretty simple. Any integer constant is considered as "int" in C and when we operate on "int" we get only "int"
(even when we divide). So, 9/5 returns "int". This return value 1 (See behaviour of integer division ). But there is another
significant issue with the code - "%f" is used and an integer is passed to the function- which causes "undefined behaviour"
in C (integer value won't be promoted to float). So, output can be anything.
pl.c:4:2: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=]
arjun@parambara:~/dump$ ./a.out 0.000000
a)assigns 3 to a[5]
b)assigns 4 to a[5]
c)assigns 4 to a[4]
Selected Answer
It is an undefined behaviour since between two sequence points which is here ; at the end of this statement and the other
; which would be present above this statement in the actual code we cannot modify the value of a variable more than once
therefore here u r trying to modify the value of n two times so it depends on compiler wither it will evaluate ++n inside
array subscript or assign ++n to array index .
d) 1111111111
Answer is A.the loop runs from 0 to 9 and i&1 MEANS BITWISE AND WITH THE BINARY FORMS OF 0 TO 9 WITH 1.SO THE
NUMBERS HAVING LAST BIT AS 0 GIVES OUTPUT 0 AND NUMBERS HAVING LAST BIT AS 1 GIVES OUTPUT 1.
e^d-a*b^f/g+h*c/i+j-k
Selected Answer
Step 2 : ^ed -/ *a^bfg + h*c /i +j -k (Since * , / has same precedence we go by the associativity that is left to right .)
Step 6 : ++-^ed/*a^bfg/*hcij-k
Step 7 : -++-^ed/*a^bfg/*hcijk
21.257 Why is the output of these two programs different in C? top gateoverflow.in/18349
#include
int main(){
float x = 0.1;
if (x == 0.1)
printf("IF");
else if (x == 0.1f)
printf("ELSE IF");
else
printf("ELSE");
return 0;
}
#include
int main{
float x = 0.5;
if (x == 0.5)
printf("IF");
else if (x == 0.5f)
printf("ELSE IF")
else
printf("ELSE");
return 0;
}
I tried the following code segment to get the exact representation of 0.1 & 0.5 being used by my machine:
#include<stdio.h>
int main(void)
{
float a = 0.1;
float b = 0.5;
printf("%x\n",*(int*)&a); /*Prints the value of 0.1 as stored by computer in hexadecimal format.*/
printf("%x\n",*(int*)&b); /*Prints the value of 0.5 as stored by computer in hexadecimal format.*/
return 0;
}
-----------------------------------------
3dcccccf
3f000000
--------------------------------
On converting this values back to the float using IEEE Floating Point Representation 754 I got 0.09999999404 & 0.5.
It means that 0.1 can not be EXACTLY represented using 32 bit floating point, but 0.5 can be represented.
given an array of n element, what will be the time complexity to find 1st repeated element when array have
more than one repeated elements??
From a theoretical point of view, it will take O(nlogn) time in the worst case. It can be done by sorting the array and
then sequentially searching for any adjacent elements that are equal.
Note: The problem doesn't mention any bound on the elements of the array. The elements can be as large as wanted,
and need not be integers! Assuming that the elements are bounded (as in Saurav's answer) or that the elements hash to
unique locations (as in Sonu's answer) completely changes the problem.
Practically, you will always have a bound on the elements. If the bound is sufficiently small ( < 32 bits, for example),
Saurav's answer will be efficient (if the n ≫ 232). Or you could have a hash function that provides unique hashes for all
practical purposes. Then Sonu's answer would be the better way to go.
21.259 which of the following is true with respect to Reference? top gateoverflow.in/17420
A) References cannot be null,every reference refers to some object, although it may or may not be valid.
D) They are entirely different concept. Pointer stores the address whereas Reference is an alias of some variable.
https://en.wikipedia.org/wiki/Reference_(C%2B%2B)
21.260 What is the approach to find preorder from given inorder? top gateoverflow.in/17582
The in-order traversal of a tree resulted in FBGADCE. Then pre-order traversal would result in.
a)FGBDECA
b)ABFGCDE
C)BFGCDEA
d)AFGBDEC
data-structure
If we are given preorder and inorder then we can generate a unique binary tree. But in question we are given only in
order.
So, what we do now - we take inorder & options one by one (as preorder) and try to make unique binary tree from them.
Only B & D can generate unique trees. so, options (B) & (D) are correct
I am geting confused with the term maximum of p sons , otherwise I was applying handshaking lemma but this maximum
word is where I am getting stucked , so plz clarify this .
Selected Answer
maximum of p sons means a node can have maximum p children and therefore p pointer fields are allocated in each node.
Now total number of nodes is q, so total number of fields allocated is pq. Every node in the tree must be pointed by its
parent (except root), so q − 1 fields must point to some node. So fields which are NULL = pq − (q − 1) = q(p − 1) + 1
21.262 What is the no. of nodes in the tree that has exactly one child? gateoverflow.in/17825
top
In a binary tree with n nodes every node has an odd no. of descendants. Every node is considered to be its own descendant.
What is the no. of nodes in the tree that has exactly one child?
(a) 0
(b) 1
(c) (n-1)/ 2
(d) n-1
data-structure
Selected Answer
It is mentioned that each node has odd number of descendants including node itself, so all nodes must have even number
of descendants 0, 2, 4 so on. Which means each node should have either 0 or 2 children. So there will be no node with 1
child. Hence 0 is answer.
In a stack (index from 1 to n) the command to access ith element from the top pf the stack S will be known as Peep(S,i).
What is the condition to check for underflow on Peep.
A)S[Top-i] <= 0
B)S[Top+i] <= 0
C)S[Top-i+1] <= 0
D)NONE
6
5
4
3
2
1
0
Let's say , I pass Peep(S,i) as i=3 , so i should check the element at the 4th index ( I assume bottom of the element at
index 0 and so on).
so , it will be (6-3+1) = 4
22 DS top
22.1 Arrays: ISRO-2013-9 top gateoverflow.in/43767
In an array of 2N elements that is both 2-ordered and 3-ordered, what is the maximum number of positions that an element
can be from its position if the array were 1-ordered?
A. 1
B. 2
C. N/2
D. 2N − 1
isro2013 arrays
1 2 3 4 5 6 7 8
Let A(1: 8, − 5: 5, − 10: 5) be a three dimensional array. How many elements are there in the array A?
A. 1200
B. 1408
C. 33
D. 1050
isro2013 arrays
Selected Answer
so option b
data-structure arrays
Selected Answer
it will be 200+((j-5)*(20-5+1)+(i-5))*1=115+16j+i
A is an array [2.....6, 2.....8, 2.......10] of elements. The starting location is 500. The location of an element A(5, 5, 5) using column
major order is __________.
Selected Answer
It contains 2-D arrays (comprises of 5 rows and 7 columns) arranged in 9 layers making it a 3-D array.
So in the layer 1 ({ 2,3,4,5,6,7,8,9,10}) we have 7 Columns * 5 Rows = 35 Elements. In the similar way each of the
remaining layers also contain 35 elements.
Here we have to use column major Order to find the address of A[5][5][5]. Base Address is 500.
Here the index of z is 5. so we can have the required element in the 4 th layer({2,3,4, 5,6,7,8,9,10}). Upto 3
layers({2,3,4,5,6,7,8,9,10}) we will have (3 layers *35 elements) 105 elements.
Now in the 4th layer we can find the number in 4th column({2,3,4,5,6,7,8}) in 4th row({2,3,4, 5,6}). As we have to
look in column major order upto 3rd column ({2,3,4,5,6,7,8}) we will have (3 columns * 5 rows) 15 elements.
So the address of the element in the location A[5][5][5] is Base Address + (Total Number of elements) * Size of each
element
I considered the above as 9*(7x5) 2D arrays in that case to reach A[5], we need to cross 4*(7x5) 2D arrays ie. 140.
After that add 4*7 iterations + 4 to reach A[5][5] , this makes it- 28+4=32
asymptotic-notations
Selected Answer
https://www.youtube.com/watch?v=gS4Z-fBiOU4
B. Insertion of an element into an AVL tree requires at most a double rotation
D. None of these
data-structure avl-tree
Selected Answer
Answer is d
Option a :
option b )
Option c
AVL is favourable over skewed tress have complexity of O(N) for deletion
But AVL are balanced tree so it would require logn for deletion
http://www.geeksforgeeks.org/avl-tree-set-1-insertion/
data-structure avl-tree
Selected Answer
The number of rotations required to insert a sequence of elements 9, 6, 5, 8, 7, 10 into an empty AVL tree is?
A. 0
B. 1
C. 2
D. 3
isro2013 avl-tree
Number of rotation = 3
1. LL
2 LL
3.RR
b-tree
22.10 Binary Heap: Number of nodes in heap of height 'h' top gateoverflow.in/36667
A. h
B. 2h
[]
n
h
C. ceil 2
[ ]
n
2h + 1
D. ceil
Answer is given as D, But I think it should be C. Because, even if you take height=1 then possible nodes are 3 and 2.
Selected Answer
Answer shd be C.
if we take n=9 and required h=3(e.g.) then according to option d it will produce answer as (9/16=1(ceil))..and thats not
correct..
22.11 Binary Search: [ME Test Series] When searching for the key value 50
When searching for the key value 50 in a binary search tree, node containing the key values 10, 30, 40, 70, 90, 120, 150,
175 are traversed, in any order. The number of different orders passing in which these keys values can occur on the search
path from the root to node containing the value 50 are ________.
Selected Answer
8!
3 !.5 !
= 56.
Ref: http://gateoverflow.in/3462/gate2007-it_29
binary-search
There is no way to index the elements in the linked list which makes it unsuitable for binary search.
binary-search-tree
No of possible orders=8C3=56
data-structure binary-tree
Yes It is an inorder traversal of bst..the trick we used here is making the whichnode static to increase it one by one and
get our desired node..
22.15 Binary Tree: How to form a recurrence for finding the height of a
weight balanced binary tree? top gateoverflow.in/35078
A weight balanced tree is a binary tree in which for each node, the no. of nodes in the left subtree is atleast half and at most twice the no. of nodes in the
right sub tree. So how to approach for forming a recurrence for finding the height of this weight balanced binary tree ?
binary-tree data-structure
If I am given an array X of n distinct integers which is interpreted as a complete binary tree, so if the parent is at index i,
then it's left child would be at index 2i and it's right child would be at index 2i + 1. If root is considered to be at level 0, then
how can we find the level of an element X[i]?
I followed the approach of first considering the fact that at a level k, I would be having 2k nodes. So I just considered that in
the array starting from certain index a up to b, I have all the numbers at the same level k. That is, in a particular portion I
have 2k nodes inclusive of a and b.
Thus, before a the total no of nodes is 20 + 21 + 22 + … + 2k−1 , since index a is at level k, and before it there would be k − 1
levels.
binary-tree data-structure
Selected Answer
level = log2(index)
Number of nodes before a can be given as: 20 + 21 + 22 + … + 2k−1 . This huge sum is just the sum of a Geometric
Progression, and is equal to 2k − 1.
So, a, the first element at level k is infact the 2kth element of the tree! (This is a nice property of complete trees)
( )
Since the indices of the first and last elements on the level L are 2L and 2L+1 − 1 respectively, we know that i must be
within that range. So,
2L ≤ i ≤ 2L+1 − 1
L ≤ log2 i ≤ L+1−ε
ε is a small error which was introduced when we ignored the −1 while taking log of 2L+1 − 1
So, we have:
L= log2i
2 votes -- Pragy Agarwal ( 13675 points)
if two identical elements are present in BST then how inorder can give sorted array as output ?
for ex. if 50,30,45,35,56,58,74,50,15 are inserted to make BST.
binary-tree
Selected Answer
Most specify left children as <= and right children as >. Practically speaking, a BST which allows either of the right or left children to be equal to the
root node, will require extra computational steps to finish a search where duplicate nodes are allowed.
REF : http://stackoverflow.com/questions/300935/are-duplicate-keys-allowed-in-the-definition-of-binary-search-trees
Which of the following number of nodes can form a full binary tree?
A. 8
B. 15
C. 14
D. 13
isro2013 binary-tree
Selected Answer
option B
Q). Find the number of trees that are possible .If we construct a binary search tree by successively inserting 5 distinct items
int an initially empty tree.
a). 4
b). 10
c). 14
d). 20
I used the formula 2n!/(n+1)!*n!. Is it right ? also the ans given is 14,but I am getting 7.
no of BST=2nCn/n+1
=10C5/6
=42
10
/ \
5 20
/ / \
4 15 30
/
11
If we randomly search one of the keys present in above BST, what would be the expected number of comparisons?
(A) 2.75
(B) 2.25
(C) 2.57
(D) 3.25
data-structure binary-tree
Selected Answer
Expected number of comparisons will be the sum of the product of probability of an item being the searched value and the
no. of comparisons for the same. We are given that search key is chosen randomly from one of the keys present in the
1
tree. So, the probability for each item being the searched key = n , where n is the total no. of keys in the tree.
So, Expected no. of comparisons = ∑ni=1 hi × n where hi is the level of node i = ∑7i =1 hi × 7 = 7 + 7 + 7 + 7 + 7 + 7 + 7 = 7 = 2.57.
22.21 Bst: Postorder traversal after creating AVL tree top gateoverflow.in/43473