[Geeks for Geeks] Maximum path sum from any node

Maximum path sum from any node

Given a binary tree, the task is to find the maximum path sum. The path may start and end at any node in the tree.

Read more
[Geeks for Geeks] Minimum Depth of a Binary Tree

Minimum Depth of a Binary Tree

Given a binary tree, find its minimum depth.

Read more
[Geeks for Geeks] Quick Sort

Quick Sort

Quick Sort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot.

Given an array arr[], its starting position low and its ending position high.

Implement the partition() and quickSort() functions to sort the array.

Read more
[Geeks for Geeks] Heap Sort

Heap Sort

Given an array of size N. The task is to sort the array elements by completing functions heapify() and buildHeap() which are used to implement Heap Sort.

Read more
[Geeks for Geeks] Merge Sort

Merge Sort

Given an array arr[], its starting position l and its ending position r. Sort the array using merge sort algorithm.

Read more
[Geeks for Geeks] Punish the Students

Punish the Students

A Professor conducts a Computer Science paper for N students. He had strictly instructed all students to sit according to their roll numbers. However when he started checking the papers, he found out that all the papers were randomly ordered because the students had sat randomly during the exam instead of sitting according to their roll numbers. The order is given in list of integers roll[ ]. The professor became very angry and he wanted to teach the students a lesson.

He decided to sort the papers according to roll numbers by Bubble Sort and count the number of swaps required for each and every student and deduct as many marks of a student as were the number of swaps required for that student. The marks of every student is given in list of integers marks[ ] in the order in which they were sitting. However he also has to maintain the class average greater than or equal to a set minimum avg, else he may lose his job. The Professor wants to know whether he should punish the students or save his job.

Read more
[Geeks for Geeks] Search in a Rotated Array

Search in a Rotated Array

Given a sorted and rotated array A of N distinct elements which is rotated at some point, and given an element key. The task is to find the index of the given element key in the array A.

Read more
[Geeks for Geeks] Find the minimum time

Find the minimum time

Geek wants to scan N documents using two scanners. If S1 and S2 are the time taken by the scanner 1 and scanner 2 to scan a single document, find the minimum time required to scan all the N documents.

Read more
[Geeks for Geeks] Boolean Parenthesization

Boolean Parenthesization

Given a boolean expression S of length N with following symbols.

Symbols

  • ‘T’ —-> true
  • ‘F’ —-> false

and following operators filled between symbols

Operators

  • & —-> boolean AND
  • | —-> boolean OR
  • ^ —-> boolean XOR

Count the number of ways we can parenthesize the expression so that the value of expression evaluates to true.

Read more
[Geeks for Geeks] 0 - 1 Knapsack Problem

0 - 1 Knapsack Problem

You are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note that we have only one quantity of each item.
In other words, given two integer arrays val[0..N-1] and wt[0..N-1] which represent values and weights associated with N items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item or dont pick it (0-1 property).

Read more