Cognzant Technology Solutions Interview Questions
- 0of 0 votes
AnswerHi Implemented this sample code for N-ary postOrder Traversal.
- sunny346 October 11, 2016 in India
Now i want to throw error statement id the parent node is dependent on child.
Can some one help
package dependencyAlgorithm;
import java.util.*;
public class Dependency
{
class MainRule
{
String ruleName;
ArrayList<MainRule> subrule;
public MainRule(String name)
{
this.ruleName=name;
subrule=new ArrayList<>();
}
}
public static void postOrder(MainRule rootRule)
{
Stack<List<MainRule>> stack = new Stack<>();
MainRule rule = rootRule;
List<MainRule> list = null;
while (true)
{
if(rule != null)
{
list = rule.subrule;
for(int i=0;i<list.size();i++)
{
if(rule.ruleName == list.get(i).ruleName)
break;
}
rule = null;
if(list!=null && list.size()>0)
{
//push the list in the stack (do not modify original tree structure).
stack.push(new ArrayList<>(list));
//get first item from this list
rule = stack.peek().get(0);
System.out.print("\n1 ListSize: "+list.size());
}
}
else if (!stack.isEmpty())
{
System.out.print("\n2 \n");
list = stack.pop();
System.out.print("\n2 ListSize: "+list.size());
rule = list.remove(0); //shift left
System.out.print("\n2.1 ListSize: "+list.size());
System.out.print("\n"+rule.ruleName+" ");
rule = null;
if(list.size()>0)
{
System.out.print("\n3 ListSize "+list.size());
stack.push(list); //push back remaining list into stack
rule = stack.peek().get(0); //prepare for next iteration
}
}
else
break;
}
System.out.println(rootRule.ruleName);
}
/*
Fml001
/ | \
/ | \
/ | \
Fml002 C001_Base Tot001
/ / | \
/ / | \
Fml003 Fml004 R001_Base R001_TxPat
/
/
Tot002
\
\
C001_TxPat
*/
public void createBinaryTree()
{
MainRule rootRule;
MainRule Fml001 =new MainRule("Fml001");
MainRule Fml002=new MainRule("Fml002");
MainRule Fml003=new MainRule("Fml003");
MainRule Fml004=new MainRule("Fml004");
MainRule C001_Base=new MainRule("C001_Base");
MainRule R001_Base=new MainRule("R001_Base");
MainRule Tot001=new MainRule("Tot001");
MainRule Tot002 =new MainRule("Tot002");
MainRule R001_TxPat =new MainRule("R001_TxPat");
MainRule C001_TxPat =new MainRule("C001_TxPat");
rootRule=Fml001;
rootRule.subrule.add(Fml002);
rootRule.subrule.add(C001_Base);
rootRule.subrule.add(Tot001);
Fml002.subrule.add(Fml003);
C001_Base.subrule.add(Fml004);
C001_Base.subrule.add(R001_Base);
C001_Base.subrule.add(R001_TxPat);
R001_Base.subrule.add(Tot002);
Tot002.subrule.add(C001_TxPat);
postOrder(rootRule);
}
public static void main(String[] args)
{
Dependency dependency=new Dependency();
// Creating a tree structure
System.out.println("Path Traversed:");
dependency.createBinaryTree();
}
}| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Dev Lead Trees and Graphs - 0of 0 votes
AnswersYou are given an integer N. Write a code to calculate 1! - 2! + 3! ... up to N terms.
- eduandabhi August 15, 2016 in India| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Android Engineer - 1of 1 vote
AnswersYou are given a function F6() which return 1,2,3,4,5,6 randomly with equal probability. Implement a new function F12() which returns 1 to 12 randomly with equal probability using F6().
- eduandabhi August 15, 2016 in India| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Android Engineer - -1of 1 vote
AnswerIf the stored Proc suddenly start running slow ,what will you do??
- hrishi.wankhade February 26, 2014 in India for DOD| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Developer Program Engineer - 1of 1 vote
Answers1>Draw structure of cluster and non cluster index.
- hrishi.wankhade February 26, 2014 in India for DOD
2>Fregrementation ,types,how to unfregement
3>When will you go for rebuild and reorginise index.
4>coloumn in (1,2,3,'null',null) what will be the result.| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Developer Program Engineer - 0of 0 votes
AnswersHow to find the number of static objects and dynamic objects created for a class?
Let say,class MyClass { public: }; int main() { MyClass cls;//Static Object MyClass *obj = new MyClass();//Dynamic Object ... ... //So on } void NewFun() { MyClass my; MyClass *Obj1; }
It should work for all the cases, like big or small projects
- rasmiranjanbabu November 20, 2013 in United States for Embedded| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Analyst C++ - 1of 1 vote
AnswersHow answer is coming as zero instead of garbage? Does compiler sets "0" to uninitialized variable?
- rasmiranjanbabu August 15, 2013 in India#include<stdio.h> void fun(void *p); int i; int main() { void *vptr; vptr = &i; fun(vptr); return 0; } void fun(void *p) { int **q; q = (int**)&p; printf("%d\n", **q); }
| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer C - 0of 0 votes
AnswersWhat is the main difference between BDD and TDD?
- paramjitmaan786 November 01, 2012 in India for ruby on rails
(ruby on rails)
BDD focuses on validation while TDD focuses on verification
BDD focuses on verification while TDD focuses on validation
BDD is better than TDD at testing methods independently
BDD generally uses mocks and stubs more than TDD| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Developer Program Engineer - 0of 0 votes
AnswerWhich of the following statements are true regarding mocks in RSpec? Select all that apply.(ruby on rails)
- paramjitmaan786 November 01, 2012 in India for ruby on rails
Mocks are used to isolate tests from the database
Model mocks automatically have access to all existing methods of the model
Mocks can be created with default attribute values| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Developer Program Engineer - 0of 0 votes
AnswersWhich of the following lists the kinds of tests in order of increasing code exercise complexity?(ruby on rails)
- paramjitmaan786 November 01, 2012 in India for ruby on rails
Integration tests, functional or module tests, unit tests
Unit tests, integration tests, functional or module tests
Unit tests, functional or module tests, integration tests
Functional or module tests, unit tests, integration tests| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Developer Program Engineer - 1of 1 vote
AnswersDetermine efficiently if an integer is a power of 2 without using any branching or loop.
- ashok.singh.sairam September 10, 2012 in India| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer Bit Manipulation - 0of 0 votes
AnswersFind the maximum and minimum of two integers without use branching (i.e. without using any conditional statements like if if else etc)
- ashok.singh.sairam September 10, 2012 in India| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer Bit Manipulation - 0of 0 votes
Answers{
- Anonymous July 09, 2011
int i=0;
++i;
i++;
int *p = &i;
++*p++;
++i++;
}
What happens in the last 2 statements and their respective outputs ?
Here ++*p++ does not throw an error, whereas ++i++ gives an error that lvalue required.
Can someone explain what happens and the reason for the error. Thank you| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer C++