# Algorithm Questions

Showing Questions 1 - 20 of 60 Questions
First | Prev | Next | Last Page
Sort by:
|
•

#### Characteristics of an Algorithm

List out the characteristics of an algorithm

#### Hiral

• Nov 26th, 2018

Characteristics of algorithm :
1.Unambiguous
2.Input
3.Output
4.Finiteness
5.Independent
6.Effectiveness

#### osoriri2004 Profile Answers by osoriri2004 Questions by osoriri2004

• Dec 20th, 2008

Should have the following five characteristics:1. Input2. Output3. Definiteness4. Effectiveness5. Termination

•

#### Array Values Algorithms

How many values can be held by an array with dimensions A(0:n), B(-1:n,1:m), C(-n:0,2)?

#### Mark Webb

• May 24th, 2018

A: n+1
B: m(n+2)
C: 2(n+1)

#### sweta sachan

• May 22nd, 2017

Sir how would you calculate it? Please share the solution

•

#### loki

• Feb 27th, 2018

Searching means finding whether the element is present in the list or not whereas sorting means Arranging the list in ascending or descending order.

#### Jeff

• Jun 4th, 2017

Searching mean when you are performing an operation looking for a specific thing that you need...the thing that you are looking for does not alike to any thing so you have to find your exact requireme...

•

#### Linked List Kth largest Element

How to find the kth largest element in a linked list? Can you do this without using extra memory and also without modifying (sorting) the list?

#### Anonymous

• Jun 19th, 2017

It does not work when duplicate elements are present.

#### batman

• Oct 4th, 2011

Not enough information about the data in the linked list. Solution 1. Assuming int & no duplicates & rather small [min,max] interval: Iterate through the list once to find the min&max. Make a bi...

•

#### Calculate Money Paid to Each Worker

A carpenter is paid a contract fee of \$2000.00 for 3 days work. He hires 3 workers who work for the 3 days at \$75.00 a day: calculate and print the amount of money paid to each worker; the total paid to all workers and the amount the carpenter is left with.

#### asd

• May 17th, 2017

public class Test4 { public static void main(String[] args) { double contract; String days; int worker; double dailypaid; double Total; double profit; @Suppre...

#### mssodhi

• May 19th, 2016

\$75/day. (3 days * \$75) = \$225. (\$225 * 3 workers) = \$675. \$2000 - \$675 = \$1325 left for the carpenter

•

#### Pseudocodes and flowcharts

When twice a certain number is subtracted from five times itself, the result equals 60. Find the number by using the try and error method. Use both pseudocode and flowchart.

#### Glenn

• May 8th, 2017

Function getBaseNum(num) {
return num / (5-2);
}
num = 60
60 / (5-2)
60 / 3 = 20

(20 * 5) - (20 * 2)
100 - 40 = 60

#### Ted

• Oct 17th, 2016

1 Start
2 Input try number X
3 C=5*X - 2*X
4 D=C - 60
5 If D=0, print "you found the number X which make the figure equal 60", go to step 8
6 If D

•

#### Calculate Primary and Secondary Diagonal

Write an algorithm that calculates all the elements of rows and columns of a square matrix and calculate the total of primary and secondary diagonal.

#### Kavya oleti

• Jan 22nd, 2017

If it is a square matrix order n
Primary diagonal
if(i==j)
{
sum+=a[i][j];
}
Secondary diagonal
if(i==(n-1)-j)
{
sum+=a[i][j];
}

#### hema

• Jan 3rd, 2015

Tested Java code"java package testCode; public class SquareMatrix { public static void main(String[] args) { int [][] squarematrix = { { 1,1,1,10}, { 1,10,-1,2}...

•

#### joseph

• Aug 27th, 2016

Can also be done using constructor overloading concept (by sending in different number of parameters)

#### Sushobhit Singh Profile Answers by Sushobhit Singh Questions by Sushobhit Singh

• Feb 28th, 2016

I think this is the right answer. :)

•

#### Read the Day and the Weather

A club plays cricket only on Sundays and only if it is not raining. Read the day and the weather and "Game on" if the weather is good and the day is Sunday, or "Play Suspended" if it is not Sunday and it is raining.

#### ranveer

• Jun 10th, 2016

1. Check if the day is Sunday, If yes, Check weather if weather is good then game on else no game else Game off

•

#### Calculate Number of Oil Pipes Required

Pipes are laid by an oil company. If the company has to laid down 3 km of pipe and each pipe is 25 metres long, calculate and print the number of pipes needed to cover the distance.

#### Guddu

• May 19th, 2016

Total Distance = 3 x 1000 m = 3000m
Number of pipe required = 3000/25 = 120

•

#### Topological Sort Algorithm

Are there any topological sorting algorithms that, given a binary matrix A, (1) find the number of distinct rows of A and (2) for any row find the set of all equal rows? Can you give me some references of where I can find them?

•

How will you reverse a singly linked list?

#### Code2Live

• Jun 9th, 2015

"java reverse(Node root) { Node x = root; if (x != null) { Stack nodes = new Stack(); while(x != null) { nodes.push(x); x = x.next; } ...

• Jun 7th, 2015

```Codepublic void reverse(Node node) {
if (node.next == null) {
return;
}
reverse(node.next);
node.next.next = node;
node.next = null;
}```

•

#### Game of Jack Straws

In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table and players try to remove them one-by-one without disturbing the other straws. In the question here, we are concerned with the following, related problem: First n straws are dumped on the table. Next, for every pair of straws, we want to determine if the straws are connected by a path of touching straws. In other...

•

#### There are numbers from 1 to N in an array. out of these, one of the number gets duplicated and one is missing. The task is to find out the duplicate number. Conditions: you have to do it in O(n) time without using any auxilary space (array, bitsets, maps etc..). Read Best Answer

• Dec 27th, 2006

use the following method:

mark the missing number as M and the duplicated as D

1) compute the sum of regular list of numbers from 1 to N call it RegularSum

2) compute the sum of your array (the one with M and D) call it MySum

now you know that MySum-M+D=RegularSum

this is one equation.

the second one uses multiplication:

3) compute the multiplication of numbers of regular list of numbers from 1 to N call it RegularMultiplication

4) compute the multiplication of numbers of your list  (the one with M and D) call it MyMultiplication

now you know that MyMultiplication=RegularMultiplication*D/M

at this point you have two equations with two parameters, solve and rule!

#### Gaurav.khurana Profile Answers by Gaurav.khurana Questions by Gaurav.khurana

• Apr 25th, 2015

@vandita Just a minor correction i think we should go till n-1 only so the in for loop it should be and should use i+1 since nbrs are starting from 1 and not 0

```Codefor (int i=0 ; i<n ; i++)
{
swap(a[i],a[a[i]-1]
}
//since 1 is stored at 0th position```

#### bakesh

• Mar 16th, 2015

9

•

#### Distinct palindromic sub strings

I want to calculate number of DISTINCT palindromic substrings in a string.How to do it?

Like if aba is string the their are 3 distinct palindromic subsrings:{a,aba,b}

length of string could be 10^5 range.So i dont think O(n^2) solution will work.I want a algorithm to do this in less than O(n^2).

#### Eric Nantel

• Apr 22nd, 2015

"cpp /*something like this*/ bool isPalin = true; const char* msg; char* ptr_1 , ptr_2; ptr_1 = msg; unsigned int size = ARRAYSIZE(msg); ptr_2 = msg + (size - 1); auto sub; ...

•

#### How can you traverse a matrix of m lines and n columns in a zig-zag way ?

Example : 1)m = 3,n = 2 a11 a12 a21 a22a31 a32Output : a11 a21 a12 a31 a22 a322) m = 3, n = 4a11 a12 a13 a14a21 a22 a23 a24a31 a32 a33 a34Output : a11 a21 a12 a31 a22 a13 a32 a23 a14 a33 a24 a34

#### Amit Verma

• Feb 21st, 2015

A very basic solution and easy to understand

```Codeint r=0;
for(int i=0;i<row;i++)
{
r=i;
for(int j=0;j<=i;j++)
{
if(j<col)
{
cout<<m[r][j]<<" ";
r--;
}
}

}

int c=0;

for(int i=1;i<=col-1;i++)
{
c=i;
r=row-1;
for(int j=row-1;j>=0;j--)
{
if(c<col)
{

cout<<m[r][c]<<" ";;
r--;
c++;

}
}
}```

#### charlypa Profile Answers by charlypa Questions by charlypa

• Jun 19th, 2009

define two varibles initial_x and initial_y define another two varibles x and yint initial_x =  m;int initial_y = n;while (x != m && y! =n){ print (x,y) x--; y++; // Traverse downwar...

•

#### Algorithm help

Create the flowchart and algorithm for a module that will prompt the user to enter the amount of cash they have in their pocket. The program should output “Not Enough” (\$0 - \$0.64), “Vending Machine” (\$0.65 - \$1.99), “Fast Food” (\$2.00 - \$4.99), “Cafeteria” (\$5.00 - \$14.99) or “Steak House” (\$15 and up) depending on what the user can afford for lunch.

#### Jole

• Jan 15th, 2015

Create a basic CASE statement. Then for the diagram just have all the different options spidering out. Google other examples.

•

#### Python - How to Write a function

How to Write a function kinda_format ( ) that take three arguments (each of which positive int ) - a,b,c- and tests whether the equality a^n +b^n=c^n holds for each n{2,3,...,10}. The function should return false if the equality does not hold for any value of n in the given range, and if there is a value of n for which the equality holds, the lowest such value (as in int)

#### Hema

• Jan 3rd, 2015

Python code attached"python def kinda_format(a,b,c): for i in range(1,10): if( (a**i + b**i) == (c**i)): flag=1 return(i,1) ...

•

#### Finding a 'circle' in a linked list

You have n numbrer Node objects - could be 1,000,000 for all you know. Each Node has a getNext() method that returns the next Node (a linked list).But the chain of n number of Node objects linked together by the getNext() method, somewhere in the chain, points back to a Node earlier in the chain so if you keep calling getNext() to walk the chain you will never get to the last Node - it will loop forever.What...

#### Beniskickbutt Profile Answers by Beniskickbutt Questions by Beniskickbutt

• Dec 22nd, 2014

P1 == p2->next will only work if your circle only encompasses 2 elements of your list.

Also, S == p2 will never be true (causing an infinite loop) if you dont have a circular list to begin with

#### kaushurtz Profile Answers by kaushurtz Questions by kaushurtz

• Mar 2nd, 2010

There are many ways to find loops in linked list but the best one is known as tortoise and hare algorithm.In this we take 2 nodes say slow and fast node. Then we move the slow node by one shift ie sta...

•

#### Intersection of two convex polygons

Suppose that you are given m convex polygons P1; P2; : : : ; Pm in the plane. Let ni denote the
number of vertices on Pi and n =
Pm
i=1 ni. The vertices of each polygon is listed in counter-
clockwise order, starting at the leftmost vertex of Pi (that is, the one with the smallest x-
coordinate). Two polygons Pi and Pj are said to intersect if they contain any point in...

Showing Questions 1 - 20 of 60 Questions
First | Prev | Next | Last Page
Sort by:
|  