TutorMe homepage
Subjects
PRICING
COURSES
Start Free Trial
Ritesh J.
Computer Science graduate from University of Florida, Senior Software Engineer since last 4 years in Silicon Valley
Tutor Satisfaction Guarantee
Python Programming
TutorMe
Question:

Given a list of N numbers, use a single list comprehension to produce a new list that only contains those values that are: (a) even numbers, and (b) from elements in the original list that had even indices For example, if list contains a value that is even, that value should be included in the new list, since it is also at an even index (i.e., 2) in the original list. However, if list contains an even number, that number should not be included in the new list since it is at an odd index (i.e., 3) in the original list.

Ritesh J.

A simple solution to this problem would be as follows [x for x in list[::2] if x%2 == 0] For example, given the following list: # 0 1 2 3 4 5 6 7 8 list = [ 1 , 3 , 5 , 8 , 10 , 13 , 18 , 36 , 78 ] the list comprehension [x for x in list[::2] if x%2 == 0] will evaluate to: [10, 18, 78] The expression works by first taking the numbers that are at the even indices, and then filtering out all the odd numbers.

Java Programming
TutorMe
Question:

What is immutable object? Can you write immutable object?I

Ritesh J.

Immutable classes are Java classes whose objects can not be modified once created. Any modification in Immutable object result in new object. For example is String is immutable in Java. Mostly Immutable are also final in Java, in order to prevent sub class from overriding methods in Java which can compromise Immutability. You can achieve same functionality by making member as non final but private and not modifying them except in constructor.

Computer Science (General)
TutorMe
Question:

Find Inorder Successor in a Binary Search Tree

Ritesh J.

In a Binary Tree, Inorder successor of a node is the next node in Inorder traversal of the Binary Tree. Inorder Successor is NULL for the last node in Inoorder traversal. In Binary Search Tree, Inorder Successor of an input node can also be defined as the node with the smallest key greater than the key of input node. So, it is sometimes important to find next node in sorted order. The Algorithm is divided into two cases on the basis of right subtree of the input node being empty or not. 1) If right subtree of node under consideration is not NULL, then successor lies in right subtree. Do following. Go to right subtree and return the node with minimum key value in right subtree. 2) If right sbtree of node is NULL, then start from root and use search like technique. Do following. Travel down the tree, if a node’s data is greater than root’s data then go right side, otherwise go to left side. struct node * inOrderSuccessor(struct node *root, struct node *n) { if( n->right != NULL ) return minValue(n->right); struct node *succ = NULL; // Start from root and search for successor down the tree while (root != NULL) { if (n->data < root->data) { succ = root; root = root->left; } else if (n->data > root->data) root = root->right; else break; } return succ; }

Send a message explaining your
needs and Ritesh will reply soon.
Contact Ritesh