Copy of Algorithms
Copy of Algorithms
For comparison based sorting we already have known algorithms like heap sort and
merge sort, which solves the problem in
O(nlogn) (See O) and now if we show that this is the best possible by any algorithm our
answer becomes Θ(nlogn).
Kisi research paper me likha hai : Minimum number of comparisons =⌈log(n!)⌉
Answer should be : C
Dono hi quick sort k worst cases honge.
Dekh kar lagta hai option B hoga kyuki most of the times randomised quick sort
nlogn hi deta hai par worst case me n2 ja sakta hai. So the correct ans is C.
Pehle laga ki DFS ka O(n) hoga and Kth smallest ka O(n2) hoga par ye sahi hai :
I thought it would be n-1 but :
We just require n/2 swaps in the worst case. The algorithm is as given below:
Find positive number from left side and negative number from right side and do
exchange. Since, at least one of them must be less than or equal to n/2, there cannot be
more than n/2 exchanges.
Sawal padhte time end me bracket wala part miss kr diya aur dimag bhi nhi chala :
https://gateoverflow.in/258/Gate-cse-2003-question-66
If we draw the recursion tree we have 3 children for each n>3, as the height of the
tree is n-1 so the number of subproblems is limited by 3^n. Each computation will
require constant time and hence the time complexity is O(3^n).
(loglogn)
Ans aaya tha 2
Further solve krte ye property use krke: a^logb=b^loga
lognlog2 = logn which is option B
Ese ques me example leke solve karo :
https://gateoverflow.in/497/Gate-cse-2008-question-78
Remember this :
Ans is Option A
Trick:
Size of the problem will reduce as we go down a level each time in the tree.
https://gateoverflow.in/1826/Gate-cse-2006-question-49
Thande Dimag se socho !
https://gateoverflow.in/61/Gate-cse-2013-question-44
https://gateoverflow.in/39667/Gate-cse-2016-set-1-question-10
Thande Dimag se socho !
https://gateoverflow.in/39684/Gate-cse-2016-set-1-question-41
Give up in this :
if we assume left associativity for + (default), we get ABCD+∗F/+DE∗+ but this is not
among the options.So, considering right associativity for + we get ABCD+∗F/DE∗++
Correct Answer: B
Thande Dimag se socho !
https://gateoverflow.in/951/Gate-cse-2003-question-64
Confusing ques !
https://gateoverflow.in/3758/Gate-it-2005-question-13
1. A tree edge (T) is an edge in a DFS-tree.
2. A back edge (B) connects a vertex to an ancestor in a DFS-tree. (Includes a
self-loop and this indicates the presence of a cycle)
3. A forward edge (F) is a non-tree edge that connects a vertex to a descendent in a
DFS-tree.
4. A cross edge (C) is any other edge in graph
5. G.
6. G. It either connects vertices in two different DFS tree or two vertices in the same
DFS tree neither of which is the ancestor of the other.
https://gateoverflow.in/88152/Gate-cse-1989-question-4-vii
https://gateoverflow.in/3813/Gate-it-2005-question-52
Good question !
Mujhe laga range 0 to 100 hai to array of 100 integers would be the ans but but but :
As we our area of interest is only the 50 numbers so take An array of 50 numbers where
A[0] corresponds to 51...A[49] corresponds to 100 then after reading an input just
increment the counter in correct position as said above.
Correct Answer: A
https://gateoverflow.in/2076/Gate-cse-2014-set-3-question-42
Remember how to solve this :
Independent set is a set of vertices such that any two vertices in the set do not have
a direct edge between them.
Maximal independent set is an independent set having highest number of vertices.
Tricky :
Answer is (A).
Here, lower bound imply best algorithm which works for all cases and hence we should
consider worst-case.
Max-Heapify(root)
Correct Option: A
The inorder traversal order of a ternary tree is left → root → middle → right.
Aliasing in the context of programming languages refers to multiple variables having the
same memory location.
https://gateoverflow.in/2124/Gate-cse-2011-question-22
Tricky one
https://gateoverflow.in/3701/Gate-it-2004-question-58
Mene B option laga diya tha :
But a+2 is c.
https://gateoverflow.in/204076/Gate-cse-2018-question-2
https://gateoverflow.in/735/Gate-cse-2001-question-2-17-ugcnet-aug2016-iii-21
https://gateoverflow.in/483/Gate-cse-2008-question-60
You don’t even know ki double hashing kese apply krte hai :|
Double hashing:
https://gateoverflow.in/2272/Gate-cse-1997-question-12
Are bhaiya dekho pehle 3 slots khali rakhne hai to pehle insertion me ye 3 chod k baki
slot fill ho jaay iski probability = 97/100
https://gateoverflow.in/2074/Gate-cse-2014-set-3-question-40
https://gateoverflow.in/82129/Gate-cse-2005-question-82b#google_vignette
REMEMBER THIS :
Answer is A: Queue
We can find single source shortest path in unweighted graph by using Breadth First
Search (BFS) algorithm by using "Queue" data structure , in time O(m+n) (i.e. linear with
respect to the number of vertices and edges. )
https://gateoverflow.in/1824/Gate-cse-2006-question-48
Good question !!
https://gateoverflow.in/39620/Gate-cse-2016-set-2-question-41
Nai samajh aaya !!
https://gateoverflow.in/333191/Gate-cse-2020-question-40
Good question !
https://gateoverflow.in/357494/Gate-cse-2021-set-2-question-46
https://gateoverflow.in/3856/Gate-it-2005-question-84a
https://gateoverflow.in/3457/Gate-it-2007-question-24
Good question :
Thoda Dimag lagane wala ques:
Question acche se padha karo didi !!
https://gateoverflow.in/204095/Gate-cse-2018-question-21
Sab kuch sahi kiya par printf me counter ki value print honi thi aur me c*c*c nikal
rhi thi : (
Remember this prime no wala concept:
<> is nothing but not equal to in Pascal, means if we write x<>y it is true if x is not equal to y. you can
equate with x!=y in C.
https://gateoverflow.in/2615/Gate-cse-1995-question-2-3
https://gateoverflow.in/1501/Gate-cse-1999-question-2-24
Confused while solving this… lots of calculations
https://gateoverflow.in/8060/Gate-cse-2015-set-2-question-11
https://gateoverflow.in/302822/Gate-cse-2019-question-26
Ye to mene nahi padha :
https://gateoverflow.in/43484/Gate-cse-2008-question-81
The algorithm is storing the optimal solutions to subproblems at each point (for each i),
and then using it to derive the optimal solution of a bigger problem. And that is a
dynamic programming approach.